/* ── Reset ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: #161d28;
  color: #d0dce8;
  min-height: 100vh;
}

:root {
  --sq-size: 76px;
  --piece-size: 52px;
  --rank-label-width: 13px;
}

/* ── Header ──────────────────────────────────────── */
.site-header {
  background: #0f1520;
  border-bottom: 1px solid #c9972a55;
  padding: 0.6rem 1.4rem;
  display: flex;
  align-items: center;
  gap: .9rem;
}
.logo     { font-size: 1.2rem; font-weight: 800; color: #c9972a; letter-spacing: .4px; }
.subtitle { font-size: 0.78rem; color: #6888a0; }

/* ── Page ────────────────────────────────────────── */
main { max-width: 960px; margin: 1.2rem auto; padding: 0 .9rem; }

/* ── Round card ──────────────────────────────────── */
.round-card {
  background: #262421;
  border-radius: 10px;
  border: 1px solid #34312d;
  box-shadow: 0 8px 32px rgba(0,0,0,.45);
  width: 100%;
  max-width: 1160px;
  margin: 0 auto;
}

/* ── Position meta bar ───────────────────────────── */
.pos-meta {
  background: #0f1520;
  padding: .4rem 1rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  border-bottom: 1px solid #253548;
  border-radius: 9px 9px 0 0;
  font-size: .78rem;
}
.pos-id   { font-weight: 700; color: #c9972a; }
.pos-tags { color: #5da0c0; }
.pos-diff { color: #c9972a; letter-spacing: 2px; font-size: .72rem; }
.turn-label   { color: #8aaccc; }
.target-label { color: #5da0c0; }

/* ── Board + panel row ───────────────────────────── */
.round-body {
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
}

/* ── Board section ───────────────────────────────── */
.board-area {
  padding: .85rem;
  flex-shrink: 0;
  display: flex;
  align-items: flex-start;
  background: transparent;
  border-radius: 0 0 0 9px;
}

.board-shell {
  background: #2f2b28;
  border-radius: 8px;
  overflow: hidden;
  box-shadow:
    0 4px 18px rgba(0,0,0,.45),
    0 0 0 1px rgba(255,255,255,.04);
}

.player-bar {
  min-height: 42px;
  padding: .45rem .65rem;
  display: flex;
  align-items: center;
  gap: .55rem;
  color: #dad9d8;
  background: #2f2b28;
}

.player-bar-top {
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.player-bar-bottom {
  border-top: 1px solid rgba(255,255,255,.08);
}

.player-avatar {
  width: 26px;
  height: 26px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,.18);
  background:
    radial-gradient(circle at 50% 32%, rgba(255,255,255,.28) 0 22%, transparent 24%),
    radial-gradient(circle at 50% 72%, rgba(255,255,255,.22) 0 30%, transparent 32%),
    #4f4b46;
  flex-shrink: 0;
}

.player-avatar-user {
  background:
    radial-gradient(circle at 50% 32%, rgba(255,255,255,.32) 0 22%, transparent 24%),
    radial-gradient(circle at 50% 72%, rgba(255,255,255,.25) 0 30%, transparent 32%),
    #5e5a55;
}

.player-name {
  font-size: .93rem;
  font-weight: 700;
  color: #e5e5e4;
  line-height: 1;
}

.board-wrap  { display: flex; flex-direction: column; gap: 0; }
.board-row   { display: flex; gap: 4px; align-items: flex-start; }

/* ── Rank labels ─────────────────────────────────── */
.board-ranks {
  display: none;
  flex-direction: column;
  padding-top: 1px;
}
.board-ranks span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--rank-label-width);
  height: var(--sq-size);
  font-size: .62rem;
  color: #c9972a;
  font-weight: 700;
  user-select: none;
}

/* ── File labels ─────────────────────────────────── */
.board-files {
  display: none;
  padding-left: calc(var(--rank-label-width) + 4px);
  margin-top: 4px;
}
.board-files span {
  width: var(--sq-size);
  text-align: center;
  font-size: .62rem;
  color: #c9972a;
  font-weight: 700;
  user-select: none;
}

/* ── Chess board ─────────────────────────────────── */
.chess-board {
  display: grid;
  grid-template-columns: repeat(8, var(--sq-size));
  grid-template-rows: repeat(8, var(--sq-size));
  border: none;
  border-radius: 0;
  box-shadow: none;
}

/* ── Squares ─────────────────────────────────────── */
.square {
  width: var(--sq-size);
  height: var(--sq-size);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  user-select: none;
  transition: filter .1s;
}
/* chess.com-style green palette */
.square.light { background: #eeeed2; }
.square.dark  { background: #769656; }

/* corner radii mirror the board's */
.chess-board .square:nth-child(1)  { border-top-left-radius: 0; }
.chess-board .square:nth-child(8)  { border-top-right-radius: 0; }
.chess-board .square:nth-child(57) { border-bottom-left-radius: 0; }
.chess-board .square:nth-child(64) { border-bottom-right-radius: 0; }

.square.selectable        { cursor: pointer; }
.square.selectable:hover  { filter: brightness(1.15); }

/* selection ring */
.square.selected::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: rgba(20,100,200,.28);
  border: 2px solid rgba(70,150,255,.85);
  pointer-events: none;
}

/* dot on empty selectable squares */
.square.selectable:not(:has(.piece)):hover::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,.2);
  pointer-events: none;
}

/* ── Result marks ────────────────────────────────── */
.square.mark-correct { background: #16a34a !important; }
.square.mark-wrong   { background: #dc2626 !important; }
.square.mark-missed  { background: #ea580c !important; }
.square.mark-answer  { background: #ca8a04 !important; }

/* ── Pieces ──────────────────────────────────────── */
.piece {
  width: calc(var(--sq-size) * 0.93);
  height: calc(var(--sq-size) * 0.93);
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  display: block;
  font-size: 0;
  line-height: 0;
  pointer-events: none;
  position: relative;
  z-index: 1;
  transition: transform .08s;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.22));
}
.square.selectable:hover .piece { transform: translateY(-1px) scale(1.06); }

.piece-P { background-image: url("/static/pieces/chesscom/wp.png"); }
.piece-N { background-image: url("/static/pieces/chesscom/wn.png"); }
.piece-B { background-image: url("/static/pieces/chesscom/wb.png"); }
.piece-R { background-image: url("/static/pieces/chesscom/wr.png"); }
.piece-Q { background-image: url("/static/pieces/chesscom/wq.png"); }
.piece-K { background-image: url("/static/pieces/chesscom/wk.png"); }
.piece-p { background-image: url("/static/pieces/chesscom/bp.png"); }
.piece-n { background-image: url("/static/pieces/chesscom/bn.png"); }
.piece-b { background-image: url("/static/pieces/chesscom/bb.png"); }
.piece-r { background-image: url("/static/pieces/chesscom/br.png"); }
.piece-q { background-image: url("/static/pieces/chesscom/bq.png"); }
.piece-k { background-image: url("/static/pieces/chesscom/bk.png"); }

/* ── Control panel ───────────────────────────────── */
.control-panel {
  flex: 0 0 318px;
  min-width: 270px;
  max-width: 330px;
  padding: .9rem 1.1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .7rem;
  border-left: 1px solid #3c3833;
}

.anon-login-hint {
  font-size: .74rem;
  line-height: 1.35;
  color: #9ca3af;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 7px;
  padding: .45rem .55rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .55rem;
}

.anon-login-hint a {
  color: #cbd5e1;
  text-decoration: none;
  font-weight: 600;
  white-space: nowrap;
}

.anon-login-hint a:hover {
  color: #f8fafc;
}

/* ── Instruction card ────────────────────────────── */
.instruction-card {
  background: #111d2c;
  border-left: 3px solid #c9972a;
  border-radius: 0 5px 5px 0;
  padding: .55rem .8rem;
  font-size: .85rem;
  line-height: 1.5;
}
.instruction-card strong { color: #c9972a; }
.instruction-card .hint  { font-size: .75rem; color: #6888a0; margin-top: .25rem; }

/* ── Buttons ─────────────────────────────────────── */
.btn {
  display: block;
  width: 100%;
  padding: .6rem 1rem;
  border: none;
  border-radius: 6px;
  font: inherit;
  font-size: .87rem;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  transition: filter .12s, transform .09s;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn:hover  { filter: brightness(1.1); }

.btn-confirm { background: #c9972a; color: #0f1520; }
.btn-nav     { background: #1a3d60; color: #b8d4ec; border: 1px solid #235580; }
.btn-reveal  { background: #111d2c; color: #6a9abc; border: 1px solid #1e3a55; }
.btn-skip    { background: transparent; color: #6888a0; border: 1px solid #1e2e40; font-size: .82rem; }
.btn-toggle  { background: #111d2c; color: #6a9abc; border: 1px solid #1e3a55; font-size: .8rem; }

.btn-ai {
  background: linear-gradient(135deg, #4c1d95, #7c3aed);
  color: #f5f0ff;
  font-size: .88rem;
  box-shadow: 0 2px 10px rgba(109,40,217,.4);
}
.btn-ai:hover { filter: brightness(1.12); box-shadow: 0 3px 14px rgba(109,40,217,.55); }
.btn-ai:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-ai-next { background: linear-gradient(135deg, #064e3b, #047857); color: #a7f3d0; }

/* selection counter */
.confirm-row { display: flex; flex-direction: column; gap: .35rem; }
.sel-count   { font-size: .75rem; color: #6888a0; text-align: center; }

/* ── Summary box ─────────────────────────────────── */
.summary-box {
  background: #111d2c;
  border-left: 3px solid #3a6080;
  border-radius: 0 5px 5px 0;
  padding: .55rem .8rem;
}
.summary-box.perfect { border-left-color: #16a34a; }
.summary-msg  { font-weight: 700; font-size: .9rem; margin-bottom: .3rem; }
.summary-stats { display: flex; gap: .6rem; flex-wrap: wrap; font-size: .78rem; }
.stat-hit    { color: #22c55e; }
.stat-wrong  { color: #ef4444; }
.stat-missed { color: #f97316; }
.stat-time   { color: #6888a0; }

/* ── Legend row ──────────────────────────────────── */
.legend { display: flex; gap: .35rem; flex-wrap: wrap; }
.legend-chip {
  padding: 2px 7px;
  border-radius: 4px;
  font-size: .72rem;
  font-weight: 700;
  color: #fff;
}
.lc-correct { background: #16a34a; }
.lc-wrong   { background: #dc2626; }
.lc-missed  { background: #ea580c; }
.lc-answer  { background: #ca8a04; }

/* ── AI section ──────────────────────────────────── */
.ai-section {
  background: #120e24;
  border: 1px solid #4c1d9566;
  border-radius: 8px;
  padding: .75rem .85rem;
  display: flex;
  flex-direction: column;
  gap: .55rem;
  box-shadow: 0 2px 10px rgba(76,29,149,.2);
}
.ai-title {
  font-size: .82rem;
  font-weight: 700;
  color: #a78bfa;
  letter-spacing: .2px;
}
.ai-indicator {
  font-size: .75rem;
  color: #a78bfa;
  font-style: italic;
  text-align: center;
}

/* ── AI result ───────────────────────────────────── */
.ai-result {
  display: flex;
  flex-direction: column;
  gap: .55rem;
  padding-top: .4rem;
  border-top: 1px solid #2d1d5a;
  margin-top: .1rem;
}
.ai-feedback-msg { font-size: .84rem; line-height: 1.6; color: #cddae8; }
.ai-tip      { font-size: .8rem; color: #60a5c8; line-height: 1.5; }
.ai-concepts { font-size: .77rem; color: #9d80e8; }
.ai-error    { font-size: .8rem;  color: #f87171; }

.ai-next-label { font-size: .74rem; color: #6888a0; }
.ai-pos-card {
  background: #1a2840;
  border-radius: 5px;
  padding: .35rem .65rem;
  font-size: .78rem;
  display: flex;
  gap: .5rem;
  align-items: center;
  flex-wrap: wrap;
}
.ai-pos-card .pos-diff { color: #c9972a; }

/* ── Divider ─────────────────────────────────────── */
.divider { height: 1px; background: #1e2e40; }

/* ── HTMX ────────────────────────────────────────── */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator { display: inline; }
.page-indicator { font-size: .76rem; color: #4a6880; text-align: center; }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 720px) {
  :root {
    --sq-size: 44px;
    --piece-size: 32px;
    --rank-label-width: 11px;
  }

  .round-card {
    border-radius: 8px;
  }

  .pos-meta {
    padding: .5rem .65rem;
    font-size: .72rem;
    gap: .45rem;
  }

  .round-body { flex-direction: column; }
  .board-area {
    border-radius: 0;
    justify-content: center;
    padding: .7rem .35rem .75rem;
  }

  .player-bar {
    min-height: 36px;
    padding: .3rem .5rem;
  }

  .player-avatar {
    width: 21px;
    height: 21px;
  }

  .player-name {
    font-size: .82rem;
  }

  .control-panel {
    flex: 1 1 auto;
    max-width: none;
    border-left: none;
    border-top: 1px solid #253548;
    min-width: 0;
    padding: .8rem .75rem 1rem;
  }

  .anon-login-hint {
    font-size: .7rem;
    padding: .4rem .45rem;
  }

  .summary-stats {
    gap: .4rem;
    font-size: .74rem;
  }
}
@media (max-width: 480px) {
  :root {
    --sq-size: 36px;
    --piece-size: 26px;
    --rank-label-width: 10px;
  }

  .board-area {
    padding: .6rem .25rem .65rem;
  }

  .instruction-card,
  .summary-box,
  .ai-section {
    padding: .5rem .6rem;
  }

  .btn {
    padding: .55rem .8rem;
    font-size: .83rem;
  }

  .legend-chip {
    font-size: .68rem;
    padding: 2px 6px;
  }
}

@media (max-width: 360px) {
  :root {
    --sq-size: 32px;
    --piece-size: 22px;
    --rank-label-width: 9px;
  }

  .pos-meta {
    font-size: .68rem;
  }
}

/* ── Gamification ────────────────────────────────── */
.feedback-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.gamification-toast {
  display: flex;
  gap: 0.5rem;
}

.xp-pill, .level-up-pill, .streak-pill {
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
}

.xp-pill {
  background: #c9972a;
  color: #000;
  box-shadow: 0 0 10px rgba(201, 151, 42, 0.4);
}

.level-up-pill {
  background: #4caf50;
  color: #fff;
}

.streak-pill {
  background: #ff5722;
  color: #fff;
}


.combo-pill {
  background: #03a9f4;
  color: #fff;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: bold;
  text-transform: uppercase;
  animation: bounce 0.5s ease;
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

