:root {
  --bg: #101318;
  --panel: #181d25;
  --panel-2: #202734;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: #334155;
  --light-square: #e8edf2;
  --dark-square: #7890a8;
  --selected: #facc15;
  --target: rgba(34, 197, 94, 0.45);
  --last: rgba(59, 130, 246, 0.42);
  --danger: #f87171;
  --ok: #86efac;
}

#board {
  position: relative;
  touch-action: none;
  user-select: none;
}

.square {
  touch-action: none;
}

.square.right-marked {
  box-shadow: inset 0 0 0 9999px rgba(245, 158, 11, 0.35);
}

.square.premove-from,
.square.premove-to {
  box-shadow: inset 0 0 0 9999px rgba(34, 197, 94, 0.35);
}

.square.drag-source {
  filter: brightness(1.12);
}

.square.premove-ready {
  cursor: crosshair;
}

.board-drawing-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 6;
}

.board-arrow {
  fill: none;
  stroke-width: 1;
  stroke-linecap: round;
  opacity: 0.9;
}

.normal-arrow {
  stroke: rgba(245, 158, 11, 0.9);
}

.premove-arrow {
  stroke: rgba(34, 197, 94, 0.9);
}

.preview-arrow {
  stroke: rgba(250, 204, 21, 0.9);
}

.piece-image {
  width: 82%;
  height: 82%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.square.inactive {
  cursor: default;
}

.square:not(.inactive) {
  cursor: pointer;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #1f2937 0, var(--bg) 48rem);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select,
input {
  font: inherit;
}

.pageShell {
  width: min(1180px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 2rem 0;
}

.heroPanel,
.contentGrid,
.card,
.boardPanel {
  border: 1px solid var(--border);
  background: rgba(24, 29, 37, 0.92);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.22);
}

.heroPanel {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  border-radius: 1.25rem;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}

.eyebrow {
  color: var(--ok);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.75rem;
  font-weight: 800;
  margin: 0 0 0.3rem;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0.35rem;
  font-size: clamp(2rem, 4vw, 3.5rem);
  line-height: 1;
}

h2 {
  font-size: 1rem;
  margin-bottom: 0.85rem;
}

.subtle,
.hint {
  color: var(--muted);
}

.subtle {
  margin-bottom: 0;
}

.statusCard {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

.pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-2);
  padding: 0.35rem 0.7rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.pill.ok {
  color: var(--ok);
}

.pill.error {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.contentGrid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
  gap: 1rem;
  border-radius: 1.25rem;
  padding: 1rem;
}

.boardPanel,
.sidePanel,
.card {
  min-width: 0;
}

.boardPanel {
  border-radius: 1rem;
  padding: 1rem;
  background: rgba(15, 23, 42, 0.56);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  width: min(100%, 620px, calc(100vw - 4rem));
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border: 10px solid #0f172a;
  border-radius: 0.75rem;
  overflow: hidden;
  user-select: none;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background-clip: padding-box;
  appearance: none;
  line-height: 1;
  font-size: clamp(1.6rem, 6vw, 4rem);
  cursor: pointer;
  color: #0f172a;
}

.square.light {
  background: var(--light-square);
}

.square.dark {
  background: var(--dark-square);
}

.square {
  position: relative;
}

/* Full-square overlays */
.square.selected::after,
.square.last::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
}

.square.selected::after {
  background: rgba(250, 204, 21, 0.45);
  box-shadow: inset 0 0 0 4px var(--selected);
}

.square.last::after {
  background: var(--last);
}

/* Legal move dot / capture ring */
.square.target::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 28%;
  height: 28%;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  pointer-events: none;
  z-index: 3;
}

.square.capture-target::before {
  width: 78%;
  height: 78%;
  background: transparent;
  border: 0.25rem solid rgba(0, 0, 0, 0.25);
  box-sizing: border-box;
}

.coord {
  position: absolute;
  left: 0.25rem;
  bottom: 0.18rem;
  font-size: 0.68rem;
  font-weight: 800;
  opacity: 0.65;
}

.boardFooter {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  margin-top: 0.9rem;
}

.sidePanel {
  display: grid;
  gap: 1rem;
  align-content: start;
}

.card {
  border-radius: 1rem;
  padding: 1rem;
}

label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
}

select,
input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  background: #0f172a;
  color: var(--text);
  padding: 0.7rem 0.75rem;
  margin-bottom: 0.8rem;
}

.twoCols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

button {
  width: 100%;
  border: 0;
  border-radius: 0.75rem;
  background: #38bdf8;
  color: #082f49;
  font-weight: 800;
  padding: 0.8rem 1rem;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.08);
}

button:disabled {
  opacity: 0.65;
  cursor: wait;
}

.hint {
  font-size: 0.85rem;
  margin: 0.75rem 0 0;
}

.largeStatus {
  font-size: 1.05rem;
  font-weight: 800;
  margin-bottom: 0.75rem;
}

.fenBox,
.engineInfo {
  overflow-wrap: anywhere;
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  background: #0f172a;
  color: var(--muted);
  padding: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.moveHistory {
  margin: 0;
  padding-left: 1.2rem;
  max-height: 12rem;
  overflow: auto;
  color: var(--muted);
}

.moveHistory li {
  margin-bottom: 0.25rem;
}

@media (max-width: 880px) {

  .heroPanel,
  .contentGrid {
    grid-template-columns: 1fr;
  }

  .heroPanel {
    align-items: flex-start;
    flex-direction: column;
  }
}
