/* ==========================================================================
   StackIt — bright, tactile block theme.
   Palette: cool paper background, deep-indigo ink, and a colourblind-safe
   AZURE (player 1) vs TANGERINE (player 2) pair from the Okabe-Ito family.
   ========================================================================== */

:root {
    --bg:        #eaeef7;
    --bg-2:      #f4f7fd;
    --card:      #ffffff;
    --ink:       #1d2140;
    --ink-soft:  #5a6182;
    --ink-faint: #8a91ad;
    --line:      #dbe1ef;

    --p1:        #2d7dff;
    --p1-top:    #62a0ff;
    --p1-edge:   #1a5ad6;
    --p1-soft:   #e4eeff;

    --p2:        #ff8a1e;
    --p2-top:    #ffab55;
    --p2-edge:   #e06d00;
    --p2-soft:   #fff0df;

    --slot:      #dde3f0;
    --slot-line: #c2cbe0;

    --cell:      62px;
    --gap:       9px;
    --radius:    16px;

    --shadow-sm: 0 1px 2px rgba(29,33,64,.08), 0 4px 12px rgba(29,33,64,.06);
    --shadow-md: 0 6px 22px rgba(29,33,64,.14);
    --shadow-lg: 0 18px 50px rgba(29,33,64,.20);

    --display: "Fredoka", ui-rounded, "Segoe UI Rounded", "Trebuchet MS", system-ui, sans-serif;
    --body:    system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
    font-family: var(--body);
    color: var(--ink);
    background:
        radial-gradient(1100px 600px at 82% -8%, var(--p2-soft) 0%, transparent 55%),
        radial-gradient(1000px 620px at 8% 110%, var(--p1-soft) 0%, transparent 55%),
        linear-gradient(180deg, var(--bg-2), var(--bg));
    background-attachment: fixed;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

/* ---------------------------------------------------------------- header - */
.topbar {
    display: flex; align-items: center; gap: 14px;
    padding: 18px clamp(16px, 4vw, 40px) 10px;
}
.logo {
    font-family: var(--display); font-weight: 700;
    font-size: clamp(26px, 4vw, 36px);
    letter-spacing: -.5px; line-height: 1; margin: 0;
}
.logo .stack { color: var(--p1); }
.logo .it    { color: var(--p2); }
.logo-mark {
    width: 34px; height: 34px; border-radius: 11px;
    background: linear-gradient(160deg, var(--p1-top), var(--p1));
    box-shadow: inset 0 -3px 0 var(--p1-edge), var(--shadow-sm);
}
.topbar .btn { margin-left: auto; }

/* ---------------------------------------------------------------- buttons */
.btn {
    font-family: var(--body); font-size: 15px; font-weight: 600;
    color: var(--ink); background: var(--card);
    border: 1px solid var(--line); border-radius: 12px;
    padding: 10px 16px; cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform .08s ease, box-shadow .12s ease, background .12s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary {
    color: #fff; border-color: transparent;
    background: linear-gradient(160deg, var(--p1-top), var(--p1));
    box-shadow: inset 0 -3px 0 var(--p1-edge), var(--shadow-sm);
}
.btn.ghost { background: transparent; box-shadow: none; }
.btn.ghost:hover:not(:disabled) { background: var(--card); }
.btn.small { font-size: 13.5px; padding: 7px 12px; }
.btn.big   { font-size: 17px; padding: 14px 20px; width: 100%; }

/* ------------------------------------------------------------ setup screen */
/* [hidden] must beat the display rules below, or a hidden screen still shows. */
[hidden] { display: none !important; }

.setup-screen {
    display: flex; justify-content: center;
    padding: 10px clamp(14px, 4vw, 40px) 60px;
}
.setup-card { width: min(560px, 100%); padding: 26px 26px 24px; }
.setup-card h2 {
    font-family: var(--display); font-size: 24px; margin: 0 0 20px;
}
.field { margin-bottom: 20px; }
.field-row { display: flex; gap: 16px; }
.field-row .field { flex: 1; }
.label {
    display: block; font-size: 13px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .06em;
    color: var(--ink-soft); margin-bottom: 9px;
}
.hint { font-size: 12.5px; color: var(--ink-faint); margin: 7px 0 0; line-height: 1.4; }

.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice-list { display: grid; gap: 10px; }
.choice {
    display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
    text-align: left; font-family: var(--body); cursor: pointer;
    background: var(--card); border: 2px solid var(--line);
    border-radius: 14px; padding: 13px 15px;
    transition: border-color .12s ease, background .12s ease, transform .08s ease;
}
.choice:hover:not(:disabled) { transform: translateY(-1px); border-color: var(--slot-line); }
.choice.on { border-color: var(--p1); background: var(--p1-soft); }
.choice:disabled { opacity: .5; cursor: not-allowed; }
.choice.compact { flex-direction: row; align-items: center; gap: 9px; }
.choice-title { font-size: 15px; font-weight: 700; color: var(--ink); }
.choice-sub   { font-size: 12.5px; color: var(--ink-soft); line-height: 1.35; }
.swatch { width: 16px; height: 16px; border-radius: 5px; flex: none; }
.swatch.p1 { background: var(--p1); box-shadow: inset 0 -2px 0 var(--p1-edge); }
.swatch.p2 { background: var(--p2); box-shadow: inset 0 -2px 0 var(--p2-edge); }

.stepper { display: flex; align-items: center; gap: 6px; }
.stepper input {
    flex: 1; min-width: 0; text-align: center;
    font-family: var(--display); font-size: 19px; font-weight: 600; color: var(--ink);
    background: var(--bg-2); border: 1px solid var(--line);
    border-radius: 11px; padding: 9px 4px;
    -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.step {
    width: 38px; height: 38px; flex: none; cursor: pointer;
    font-size: 18px; font-weight: 700; color: var(--ink-soft);
    background: var(--card); border: 1px solid var(--line); border-radius: 11px;
}
.step:hover { background: var(--bg-2); color: var(--ink); }

.setup-error {
    font-size: 13.5px; color: var(--p2-edge); background: var(--p2-soft);
    border-radius: 10px; padding: 10px 12px; margin: 0 0 14px;
}
.setup-error:empty { display: none; }

/* ------------------------------------------------------------- game screen */
.game-screen {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 22px; align-items: start;
    padding: 4px clamp(14px, 4vw, 40px) 60px;
}
.game-screen[hidden] { display: none; }
.board-column { display: flex; flex-direction: column; gap: 14px; min-width: 0; align-items: center; }

/* ------------------------------------------------------------- scoreboard */
.scoreboard {
    display: flex; align-items: stretch; gap: 10px;
    width: 100%; max-width: 640px;
}
.pcard {
    flex: 1; display: flex; align-items: center; gap: 11px;
    background: var(--card); border: 2px solid var(--line);
    border-radius: 14px; padding: 11px 14px; min-width: 0;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.pcard .dot {
    width: 22px; height: 22px; border-radius: 7px; flex: none;
}
.pcard[data-p="1"] .dot { background: var(--p1); box-shadow: inset 0 -3px 0 var(--p1-edge); }
.pcard[data-p="2"] .dot { background: var(--p2); box-shadow: inset 0 -3px 0 var(--p2-edge); }
.pcard.active[data-p="1"] { border-color: var(--p1); box-shadow: 0 0 0 4px var(--p1-soft); }
.pcard.active[data-p="2"] { border-color: var(--p2); box-shadow: 0 0 0 4px var(--p2-soft); }
.pcard .meta { display: flex; flex-direction: column; min-width: 0; }
.pcard .name {
    font-family: var(--display); font-size: 16px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pcard .sub { font-size: 12px; color: var(--ink-soft); }
.vs {
    align-self: center; font-family: var(--display); font-size: 13px;
    color: var(--ink-faint); text-transform: uppercase; letter-spacing: .08em;
}
.thinking-badge {
    display: none; margin-left: auto; align-items: center; gap: 5px;
    font-size: 11.5px; font-weight: 700; text-transform: uppercase;
    letter-spacing: .05em; color: var(--ink-soft);
}
.pcard.thinking .thinking-badge { display: inline-flex; }
.dots { display: inline-flex; gap: 3px; }
.dots i {
    width: 4px; height: 4px; border-radius: 50%; background: var(--ink-soft);
    animation: blink 1.1s infinite;
}
.dots i:nth-child(2) { animation-delay: .18s; }
.dots i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* ------------------------------------------------------------------ board */
.board-stage { position: relative; padding: 16px; }
#board-grid {
    display: grid;
    grid-template-columns: repeat(var(--cols, 5), var(--cell));
    gap: var(--gap);
}
#board-grid.busy .cell { pointer-events: none; }

.cell {
    position: relative;
    width: var(--cell); height: var(--cell);
    border-radius: 13px;
    background: var(--slot);
    box-shadow: inset 0 0 0 1px var(--slot-line), inset 0 3px 7px rgba(29,33,64,.07);
    display: grid; place-items: center;
    font-family: var(--display); font-size: 22px; font-weight: 600;
    color: transparent;
    transition: background .16s ease, box-shadow .16s ease, transform .1s ease;
}
.cell[data-owner="1"] {
    background: linear-gradient(160deg, var(--p1-top), var(--p1));
    box-shadow: inset 0 -4px 0 var(--p1-edge), var(--shadow-sm);
    color: #fff;
}
.cell[data-owner="2"] {
    background: linear-gradient(160deg, var(--p2-top), var(--p2));
    box-shadow: inset 0 -4px 0 var(--p2-edge), var(--shadow-sm);
    color: #fff;
}
.cell.playable { cursor: pointer; }
.cell.playable:hover { transform: translateY(-2px) scale(1.03); }
.cell.playable[data-owner="0"]:hover { background: #e7ecf8; }

/* last move marker */
.cell.lastmove::after {
    content: ""; position: absolute; inset: 5px;
    border-radius: 9px; border: 2px dashed rgba(255,255,255,.75);
    pointer-events: none;
}
.cell[data-owner="0"].lastmove::after { border-color: var(--slot-line); }

/* highlight a cell from the analysis panel */
.cell.peek {
    outline: 3px solid var(--ink); outline-offset: 2px;
    transform: translateY(-2px) scale(1.04); z-index: 2;
}

/* the network's raw policy, painted as a heat halo */
.cell .heat {
    position: absolute; inset: 0; border-radius: 13px;
    pointer-events: none;
    background: radial-gradient(circle at 50% 50%,
                rgba(29,33,64,.0) 30%, rgba(29,33,64,.0) 100%);
    box-shadow: inset 0 0 0 3px rgba(45,125,255,var(--heat, 0));
    opacity: 1;
}
.cell .heat-num {
    position: absolute; right: 4px; bottom: 2px;
    font-size: 10px; font-weight: 700; color: var(--p1-edge);
    background: rgba(255,255,255,.86); border-radius: 5px; padding: 0 3px;
    pointer-events: none;
}
.cell[data-owner="1"] .heat-num, .cell[data-owner="2"] .heat-num { color: var(--ink); }

/* cascade animations */
.cell.pop  { animation: pop .26s ease; }
.cell.flip { animation: flip .3s ease; }
@keyframes pop  { 40% { transform: scale(1.22); } 100% { transform: scale(1); } }
@keyframes flip { 0% { transform: scale(.78) rotate(-7deg); } 100% { transform: scale(1) rotate(0); } }

/* ---------------------------------------------------------- win overlay -- */
.win-overlay {
    position: absolute; inset: 0; display: none;
    place-items: center; border-radius: var(--radius);
    background: rgba(244,247,253,.86); backdrop-filter: blur(3px);
}
.win-overlay.show { display: grid; }
.win-card { text-align: center; padding: 22px; }
.win-emoji { font-size: 46px; display: block; }
.win-msg {
    font-family: var(--display); font-size: 22px; font-weight: 600;
    margin: 8px 0 16px;
}

/* ------------------------------------------------------------- turn bar -- */
.turnbar {
    display: flex; align-items: center; gap: 9px;
    width: 100%; max-width: 640px;
}
.turn-text { font-size: 14.5px; font-weight: 600; color: var(--ink-soft); }
.spacer { flex: 1; }

/* ------------------------------------------------------------- analysis -- */
.analysis { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 12px; }
.analysis[hidden] { display: none; }
.an-head  { padding: 16px 18px; }
.an-block { padding: 15px 18px; }
.an-block[hidden] { display: none; }
.an-block h3 {
    font-family: var(--display); font-size: 15px; font-weight: 600; margin: 0 0 4px;
}
.block-hint { font-size: 12px; color: var(--ink-faint); margin: 0 0 11px; line-height: 1.45; }

.an-title { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.an-engine { font-family: var(--display); font-size: 16px; font-weight: 600; }
.an-when   { font-size: 11.5px; color: var(--ink-faint); margin-left: auto; }
.an-eval   { display: flex; align-items: baseline; gap: 9px; }
.eval-num  { font-family: var(--display); font-size: 32px; font-weight: 700; line-height: 1; }
.eval-cap  { font-size: 12px; color: var(--ink-soft); line-height: 1.3; }
.eval-bar {
    height: 8px; border-radius: 6px; background: var(--slot);
    margin: 11px 0 12px; overflow: hidden;
}
.eval-bar span {
    display: block; height: 100%; width: 0;
    border-radius: 6px; background: var(--p2);
    transition: width .4s ease, background .3s ease;
}
.an-stats { display: flex; flex-wrap: wrap; gap: 6px; }
.stat {
    font-size: 11.5px; color: var(--ink-soft);
    background: var(--bg-2); border-radius: 8px; padding: 4px 8px;
}
.stat b { color: var(--ink); font-weight: 700; }

/* principal variation */
.pv-list { display: flex; flex-wrap: wrap; gap: 6px; }
.pv-step {
    display: inline-flex; align-items: center; gap: 6px; cursor: default;
    font-size: 13px; font-weight: 600;
    border: 1px solid var(--line); border-radius: 10px; padding: 5px 9px;
    background: var(--bg-2);
    transition: border-color .12s ease, background .12s ease;
}
.pv-step:hover { border-color: var(--ink); background: var(--card); }
.pv-step .n {
    font-size: 10.5px; font-weight: 700; color: #fff;
    border-radius: 5px; padding: 1px 5px;
}
.pv-step[data-seat="1"] .n { background: var(--p1); }
.pv-step[data-seat="2"] .n { background: var(--p2); }
.pv-empty { font-size: 13px; color: var(--ink-faint); }

/* candidate moves */
.cand-list { display: flex; flex-direction: column; gap: 7px; }
.cand {
    position: relative; display: flex; align-items: center; gap: 9px;
    font-size: 13px; border-radius: 10px; padding: 7px 10px;
    background: var(--bg-2); overflow: hidden; cursor: default;
}
.cand .fill {
    position: absolute; inset: 0 auto 0 0; width: 0;
    background: var(--p1-soft); transition: width .35s ease;
}
.cand.best .fill { background: #d8e6ff; }
.cand > * { position: relative; }
.cand .mv { font-family: var(--display); font-weight: 600; min-width: 46px; }
.cand .val { font-weight: 700; }
.cand .wt { margin-left: auto; font-size: 11.5px; color: var(--ink-soft); }
.cand:hover { outline: 1px solid var(--ink); }

/* network block */
.net-row { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.net-label { font-size: 12.5px; color: var(--ink-soft); }
.net-val { font-family: var(--display); font-size: 22px; font-weight: 700; margin-left: auto; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.toggle input { width: 16px; height: 16px; accent-color: var(--p1); cursor: pointer; }

/* depth ladder */
.table-scroll { overflow-x: auto; }
.ladder { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ladder td { padding: 5px 6px; border-top: 1px solid var(--line); white-space: nowrap; }
.ladder tr:first-child td { border-top: none; }
.ladder .d { font-weight: 700; color: var(--ink-soft); }
.ladder .s { font-weight: 700; }
.ladder .l { color: var(--ink-soft); }

/* ---------------------------------------------------------------- modal -- */
.modal {
    position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
    background: rgba(29,33,64,.42); backdrop-filter: blur(2px);
    padding: 20px;
}
.modal[hidden] { display: none; }
.modal-card { width: min(460px, 100%); padding: 24px; box-shadow: var(--shadow-lg); }
.modal-card h2 { font-family: var(--display); font-size: 21px; margin: 0 0 14px; }
.rules { margin: 0 0 20px; padding-left: 20px; }
.rules li { font-size: 14.5px; line-height: 1.6; margin-bottom: 7px; }

/* ---------------------------------------------------------------- toast -- */
.toast {
    position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
    background: var(--ink); color: #fff; font-size: 14px; font-weight: 600;
    border-radius: 12px; padding: 11px 18px; box-shadow: var(--shadow-lg);
    opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
    max-width: min(520px, 90vw); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --------------------------------------------------------------- layout -- */
@media (max-width: 1040px) {
    .game-screen { grid-template-columns: minmax(0, 1fr); }
    .analysis { position: static; width: 100%; max-width: 640px; margin: 0 auto; }
}
@media (max-width: 560px) {
    :root { --cell: 46px; --gap: 7px; }
    .field-row { flex-direction: column; gap: 0; }
    .choice-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .001s !important; transition-duration: .001s !important; }
}
