* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #312e2b;          /* chess.com app shell */
  --panel: #262522;
  --panel2: #3c3936;
  --panel3: #454341;
  --text: #ffffffdd;
  --muted: #a29e9b;
  --green: #81b64c;       /* signature green */
  --green-dark: #45753c;
  --sq-light: #ebecd0;    /* classic green board */
  --sq-dark: #779556;
}
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
header {
  display: flex; align-items: baseline; gap: 12px;
  padding: 10px 16px 6px;
  padding-top: calc(10px + env(safe-area-inset-top));
}
header h1 { font-size: 1.15rem; font-weight: 800; letter-spacing: -.01em; }
header h1::before { content: "♞ "; color: var(--green); }
#status { color: var(--muted); font-size: .78rem; }

main { max-width: 560px; margin: 0 auto; padding: 0 8px 24px; }

/* desktop: board left, analysis right (chess.com analysis layout) */
@media (min-width: 920px) {
  main {
    max-width: 1060px;
    display: grid;
    grid-template-columns: minmax(420px, 640px) 400px;
    gap: 18px;
    align-items: start;
  }
  .col-side { position: sticky; top: 10px; }
  .moves-panel { max-height: 300px; }
}

/* ---------- board + eval bar ---------- */
.board-area { display: flex; gap: 0; }
#board {
  position: relative; flex: 1; aspect-ratio: 1/1;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  border-radius: 0 4px 4px 0; overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
#squares { position: absolute; inset: 0; display: grid; grid-template: repeat(8,1fr)/repeat(8,1fr); }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq { position: relative; }
.sq::before, .sq::after {
  position: absolute; font-size: .62rem; font-weight: 700; opacity: .9; pointer-events: none;
}
.sq.light::before, .sq.light::after { color: var(--sq-dark); }
.sq.dark::before, .sq.dark::after { color: var(--sq-light); }
.sq::before { content: attr(data-rank); top: 2px; left: 3px; }
.sq::after { content: attr(data-file); bottom: 1px; right: 3px; }

#pieces { position: absolute; inset: 0; pointer-events: none; }
.piece {
  position: absolute; width: 12.5%; height: 12.5%;
  background-size: cover; will-change: transform;
}
.piece.dragging { z-index: 5; pointer-events: none; }

#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#overlay .lastmove { fill: rgba(255, 255, 51, .45); }   /* chess.com yellow */
#overlay .selsq { fill: rgba(255, 255, 51, .55); }
#overlay .dot { fill: rgba(0,0,0,.24); }
#overlay .capdot { fill: none; stroke: rgba(0,0,0,.24); stroke-width: 1.1; }
#overlay .arrow line { stroke: rgba(114, 176, 66, .9); stroke-width: 2.6; stroke-linecap: round; }
#overlay .arrow polygon { fill: rgba(114, 176, 66, .9); }
#overlay .badge {
  font-size: 3px; font-weight: 800; fill: #fff;
  text-anchor: middle; dominant-baseline: central;
}

#promo {
  position: absolute; inset: 0; z-index: 10;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
#promo[hidden] { display: none; }
#promo button {
  width: 17%; aspect-ratio: 1; border: none; border-radius: 8px;
  background-color: #fff; background-size: 85%; background-position: center; background-repeat: no-repeat;
}
#promo .promo-cancel { width: 10%; font-size: 1.2rem; background-color: var(--panel2); color: var(--text); }

/* eval bar flush against the board's left edge, chess.com style */
#evalBar {
  width: 24px; border-radius: 4px 0 0 4px; overflow: hidden; position: relative;
  background: #403d39; display: flex; flex-direction: column-reverse; flex: none;
}
#evalFill { background: #f2f2f2; width: 100%; height: 50%; transition: height .4s ease; }
#evalBar.flipped { flex-direction: column; }
#evalText {
  position: absolute; left: 1px; right: 1px; bottom: 4px; text-align: center;
  font-size: .53rem; font-weight: 800; color: #312e2b;
  background: rgba(255,255,255,.0); border-radius: 3px;
}
#evalText.blackleads { top: 4px; bottom: auto; color: #f2f2f2; }
#evalBar.flipped #evalText { top: 4px; bottom: auto; }
#evalBar.flipped #evalText.blackleads { bottom: 4px; top: auto; }

/* ---------- controls ---------- */
.controls { display: flex; gap: 6px; margin: 10px 0; }
.controls button {
  flex: 1; padding: 10px 0; font-size: 1.05rem;
  background: var(--panel2); color: var(--text);
  border: none; border-radius: 6px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.25);
  cursor: pointer;
}
.controls button:active { background: var(--panel3); box-shadow: inset 0 -1px 0 rgba(0,0,0,.25); }

/* ---------- panels ---------- */
.panel {
  background: var(--panel); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 10px;
  border: 1px solid rgba(255,255,255,.04);
}
.panel summary { color: var(--muted); font-weight: 700; cursor: pointer; padding: 2px 0; }
.engine-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.score {
  font-size: 1.15rem; font-weight: 800; min-width: 3.4ch;
  background: #f2f2f2; color: #312e2b; border-radius: 5px;
  padding: 2px 8px; text-align: center;
}
.depthnow { color: var(--muted); font-size: .8rem; }
.arrowlbl { color: var(--muted); font-size: .8rem; display: flex; align-items: center; gap: 4px; }
.arrowlbl input { accent-color: var(--green); }
.depthctl { margin-left: auto; color: var(--muted); font-size: .8rem; display: flex; align-items: center; gap: 6px; }
.depthctl input { width: 110px; accent-color: var(--green); }
.pv {
  color: var(--muted); font-size: .85rem; margin-top: 8px; min-height: 1.2em;
  white-space: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
button.wide {
  display: block; width: 100%; margin-top: 10px; padding: 11px;
  background: var(--green); color: #fff; font-weight: 800; font-size: .95rem;
  border: none; border-radius: 8px;
  box-shadow: inset 0 -4px 0 var(--green-dark);   /* chess.com button bevel */
  text-shadow: 0 1px 0 rgba(0,0,0,.25);
  cursor: pointer;
}
button.wide:active { box-shadow: inset 0 -1px 0 var(--green-dark); }
button.wide:disabled { opacity: .5; }
.progress { height: 8px; background: var(--panel2); border-radius: 4px; margin-top: 10px; overflow: hidden; }
#progressBar { height: 100%; width: 0; background: var(--green); transition: width .2s; }
.hint { color: var(--muted); font-size: .8rem; margin-top: 6px; }

/* ---------- review summary (accuracy card) ---------- */
.accrow { display: flex; gap: 10px; margin: 10px 0; }
.accbox { flex: 1; border-radius: 10px; padding: 12px 10px; text-align: center; font-size: .78rem; }
.accw { background: #f2f2f2; color: #312e2b; }
.accb { background: #1f1e1b; color: #e8e6e3; border: 1px solid #454341; }
.accpct { font-size: 1.7rem; font-weight: 800; line-height: 1.15; }
.accname { font-weight: 700; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gtable { width: 100%; border-collapse: collapse; font-size: .88rem; }
.gtable td, .gtable th { padding: 4px 6px; text-align: left; }
.gtable td:nth-child(3), .gtable td:nth-child(4),
.gtable th:nth-child(3), .gtable th:nth-child(4) { text-align: center; }

/* circular grade chips (board badge is SVG; these are for lists/tables) */
.chip {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.35em; height: 1.35em; border-radius: 50%;
  color: #fff; font-weight: 800; font-size: .78em;
  vertical-align: baseline;
}

/* ---------- move list ---------- */
.moves-panel { max-height: 220px; overflow-y: auto; padding: 6px 8px; }
.mrow { display: flex; gap: 4px; padding: 1px 0; font-size: .92rem; align-items: center; }
.mrow:nth-child(odd) { background: rgba(255,255,255,.02); }
.mnum { color: var(--muted); width: 2.6em; flex: none; text-align: right; padding-right: 4px; }
.mv {
  flex: 1; padding: 3px 6px; border-radius: 4px; cursor: pointer;
  display: flex; align-items: center; gap: 6px; font-weight: 600;
}
.mv.cur { background: var(--panel3); box-shadow: 0 0 0 1px #5d5955; }
.mv.empty { cursor: default; }

/* ---------- import ---------- */
.importrow { display: flex; gap: 8px; margin-top: 8px; }
.importrow input {
  flex: 1; padding: 9px 10px; border-radius: 6px; border: 1px solid #4a4744;
  background: var(--panel2); color: var(--text); font-size: 16px;
}
.importrow button {
  padding: 9px 18px; border: none; border-radius: 6px;
  background: var(--green); color: #fff; font-weight: 800;
  box-shadow: inset 0 -3px 0 var(--green-dark);
  cursor: pointer;
}
#ccList { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.ccgame {
  display: flex; align-items: center; gap: 10px; text-align: left;
  background: var(--panel2); color: var(--text); border: none;
  border-radius: 6px; padding: 9px 10px; font-size: .85rem; cursor: pointer;
}
.ccgame:active { background: var(--panel3); }
.ccgame .res { font-weight: 800; width: 1.4em; text-align: center; border-radius: 4px; flex: none; }
.ccgame.resW .res { color: var(--green); }
.ccgame.resL .res { color: #fa412d; }
.ccgame.resD .res { color: var(--muted); }
.ccgame .opp { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ccgame .meta { color: var(--muted); font-size: .75rem; flex: none; }
textarea {
  width: 100%; margin-top: 8px; padding: 9px 10px; border-radius: 6px;
  border: 1px solid #4a4744; background: var(--panel2); color: var(--text);
  font-size: 16px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical;
}

/* ---------- analysis cache ---------- */
.cachenote { color: var(--green); font-weight: 600; }
.ancount { color: var(--green); font-size: .8em; }
#anList { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.anrow { display: flex; gap: 6px; }
.anload {
  flex: 1; display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--panel2); color: var(--text); border: none;
  border-radius: 6px; padding: 9px 10px; font-size: .85rem; text-align: left; cursor: pointer;
  min-width: 0;
}
.anload:active { background: var(--panel3); }
.anplayers { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.anmeta { color: var(--muted); font-size: .75rem; flex: none; }
.andel {
  flex: none; width: 36px; border: none; border-radius: 6px;
  background: var(--panel2); color: var(--muted); font-size: 1.1rem; cursor: pointer;
}
.andel:active { background: #5a2521; color: #fff; }
.anactions { display: flex; gap: 8px; margin-top: 10px; }
.anactions button {
  flex: 1; padding: 8px; border: none; border-radius: 6px;
  background: var(--panel2); color: var(--text); font-weight: 600; font-size: .82rem;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); cursor: pointer;
}
.anactions button.danger { color: #fa8072; }
.ccdone {
  flex: none; color: var(--green); font-weight: 800; font-size: .78rem;
  border: 1px solid var(--green); border-radius: 4px; padding: 1px 5px;
}

#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px);
  background: #1f1e1b; color: var(--text); padding: 10px 18px; border-radius: 8px;
  font-size: .9rem; opacity: 0; pointer-events: none; transition: all .25s;
  border: 1px solid #4a4744; max-width: 90vw; z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
