/* Find the Spy. Layout: a case board. Home: your name, the open tables and a new table on the left; online play, the
   app and the AI brain on the right. At a table: the seats on the left; the card, the action desk and the case log on
   the right. One column on phones. */
:root {
  --bg: #E7EAF0;
  --surface: #FFFFFF;
  --surface-2: #F2F4F8;
  --ink: #131A29;
  --muted: #586278;
  --line: #D2D7E1;
  --lamp: #F2B300;
  --lamp-ink: #1C1600;
  --spy: #C0352A;
  --safe: #1F7F55;
  --under: #A9650A;
  --a0: #131A29; --a1: #3A66CF; --a2: #B8457F; --a3: #24877D; --a4: #7A52C4; --a5: #C4632A;
  --a6: #2F7FA8; --a7: #9A6B1F; --a8: #5C7A2E; --a9: #A33F4F;
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, "Courier New", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F141E; --surface: #182031; --surface-2: #1F293D; --ink: #E7EBF3; --muted: #9AA3B6; --line: #2C374D;
    --lamp: #FFC52E; --lamp-ink: #1C1600; --spy: #F0695C; --safe: #4CC08A; --under: #E9A23B;
    --a0: #E7EBF3; --a1: #6D93F0; --a2: #E07AAE; --a3: #4DBDB1; --a4: #A483EC; --a5: #EB8C55;
    --a6: #5BB0DA; --a7: #D3A24E; --a8: #93B85C; --a9: #E07A8A;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 15px; line-height: 1.5; }
.wrap { max-width: 1180px; margin: 0 auto; padding-top: max(22px, env(safe-area-inset-top, 0px)); padding-bottom: max(40px, env(safe-area-inset-bottom, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: flex; flex-direction: column; gap: 18px; }
a { color: inherit; }

header { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; }
.brand { display: flex; flex-direction: column; gap: 4px; }
.case { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 0; font-family: var(--display); font-weight: 800; font-size: clamp(30px, 5vw, 46px); line-height: 1; letter-spacing: -.02em; text-wrap: balance; }
h1 .tape { background: var(--lamp); color: var(--lamp-ink); padding: 0 .18em; border-radius: 4px; }
h1 a { text-decoration: none; }
.status { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { font-family: var(--mono); font-size: 12px; padding: 5px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill b { color: var(--ink); font-weight: 700; }
.nav { display: flex; gap: 8px 16px; align-items: center; flex-wrap: wrap; }
.nav:empty { display: none; }
.linkbtn { all: unset; cursor: pointer; font: 600 13px var(--body); color: var(--muted); }
.linkbtn:hover { color: var(--ink); text-decoration: underline; }
.linkbtn:focus-visible { outline: 3px solid var(--lamp); outline-offset: 2px; border-radius: 4px; }
.foot { font-size: 12px; color: var(--muted); display: flex; gap: 6px 16px; flex-wrap: wrap; justify-content: center; text-align: center; }

.layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.layout.one { grid-template-columns: minmax(0, 560px); justify-content: center; }
@media (max-width: 880px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  /* a game on a phone: the card and what to do now come first, then the table and the log */
  .layout.game { display: flex; flex-direction: column; align-items: stretch; gap: 14px; }
  .layout.game > .col { display: contents; }
  .o1 { order: 1; } .o2 { order: 2; } .o3 { order: 3; } .o4 { order: 4; margin-top: 6px; } .o5 { order: 5; } .o6 { order: 6; margin-top: 6px; } .o7 { order: 7; } .o8 { order: 8; } .o9 { order: 9; }
  .rolecard.static { height: 128px; }
  .rolecard.static .big { font-size: 21px; }
}
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.col:empty, #gameFoot:empty { display: none; }
.label { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0; }
.note { font-size: 13px; color: var(--muted); margin: 0; }
.what { font-weight: 600; }

.panel, .desk { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 18px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel h2, .desk h2 { margin: 0; font-family: var(--display); font-weight: 800; font-size: 22px; line-height: 1.15; text-wrap: balance; }
.desk p, .panel p { margin: 0; }
.desk > p:not([class]), .panel > p:not([class]) { color: var(--muted); }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row input, .field { flex: 1 1 160px; min-width: 0; font: 500 16px var(--mono); padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); }
.field.text { font-family: var(--body); }
.err { color: var(--spy); font-size: 13px; min-height: 1em; }
.err:empty { display: none; }
.split { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Setup controls */
.counts { display: flex; flex-wrap: wrap; gap: 12px 28px; }
.count { display: flex; align-items: center; gap: 10px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stepper button { all: unset; cursor: pointer; width: 38px; height: 36px; display: grid; place-items: center; font: 700 18px var(--mono); color: var(--ink); background: var(--surface-2); }
.stepper button:disabled { opacity: .35; cursor: not-allowed; }
.stepper button:focus-visible { outline: 3px solid var(--lamp); outline-offset: -3px; }
.stepper output { min-width: 52px; height: 36px; display: grid; place-items: center; border-inline: 1px solid var(--line); font: 700 16px var(--mono); font-variant-numeric: tabular-nums; background: var(--surface); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; flex-wrap: wrap; }
.seg button { all: unset; cursor: pointer; padding: 8px 13px; font: 600 13px var(--body); color: var(--muted); background: var(--surface-2); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.seg button:focus-visible { outline: 3px solid var(--lamp); outline-offset: -3px; }
.seg button:disabled { opacity: .4; cursor: not-allowed; }
.setting { display: flex; flex-direction: column; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.roster { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 520px; overflow-y: auto; }
.rrow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 10px; background: var(--surface-2); }
.rrow .av { width: 30px; height: 30px; font-size: 14px; }
.rrow .nm { flex: 1 1 120px; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kind { font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.kind.human { background: var(--lamp); color: var(--lamp-ink); border-color: transparent; }
.badge { font-family: var(--mono); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; padding: 3px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.you { background: var(--ink); color: var(--surface); border-color: transparent; }
.badge.host { color: var(--ink); border-color: var(--lamp); }
.badge.away { color: var(--under); border-color: currentColor; }
select { font: 500 13px var(--body); padding: 7px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); max-width: 100%; }
.x { all: unset; cursor: pointer; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; color: var(--muted); font-size: 14px; }
.x:hover { background: var(--surface); color: var(--spy); }
.x:focus-visible { outline: 3px solid var(--lamp); }

/* Tables list and invites */
.tlist { display: flex; flex-direction: column; gap: 8px; }
.trow { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.trow .meta { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1 1 200px; }
.trow .meta b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code { font-family: var(--mono); font-weight: 700; letter-spacing: .12em; }
.bigcode { font-family: var(--mono); font-weight: 700; font-size: 34px; letter-spacing: .16em; line-height: 1; }
.invite { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.invite > div { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.invite > .qr { background: #fff; padding: 8px; border-radius: 12px; width: 196px; max-width: 100%; flex: none; display: block; line-height: 0; }
.qr svg { width: 100%; height: auto; display: block; }
.mono, .steps code { font-family: var(--mono); font-size: 13px; color: var(--ink); background: var(--surface-2); padding: 2px 6px; border-radius: 6px; overflow-wrap: anywhere; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 14px; }
.steps b { color: var(--ink); }

/* Brain */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat b { font-family: var(--display); font-size: 26px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--lamp); }
#trainForm input { flex: 0 1 150px; }
.path { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; color: var(--ink); background: var(--surface-2); padding: 2px 6px; border-radius: 6px; }

/* Seats */
.seats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 600px) { .seats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
.seat { position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; min-height: 168px; min-width: 0; transition: border-color .2s, box-shadow .2s; }
@media (max-width: 600px) { .seat { padding: 12px; min-height: 150px; } }
.seat.speaking { border-color: var(--lamp); box-shadow: 0 0 0 3px color-mix(in srgb, var(--lamp) 35%, transparent); }
.seat.picked { border-color: var(--spy); box-shadow: 0 0 0 3px color-mix(in srgb, var(--spy) 30%, transparent); }
.seat.out .who, .seat.out .chips { opacity: .45; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; padding-right: 4px; }
.av { flex: none; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-weight: 800; font-size: 17px; color: var(--surface); }
.name { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { font-size: 12px; color: var(--muted); }
.chips { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.chip { display: flex; gap: 8px; align-items: baseline; font-family: var(--mono); font-size: 13px; background: var(--surface-2); border-radius: 6px; padding: 4px 8px; min-width: 0; }
.chip span:first-child { color: var(--muted); font-size: 10px; flex: none; }
.chip span:last-child { overflow-wrap: anywhere; }
.thinking { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.thinking::after { content: "…"; animation: dots 1s steps(3) infinite; }
@keyframes dots { 0% { content: "."; } 33% { content: ".."; } 66% { content: "..."; } }
.seat-foot { margin-top: auto; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.votes { font-family: var(--mono); font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--ink); color: var(--surface); }
.hintchip { font-family: var(--mono); font-size: 11px; padding: 3px 8px; border-radius: 999px; background: color-mix(in srgb, var(--lamp) 28%, transparent); color: var(--ink); }
.statechip { font-family: var(--mono); font-size: 11px; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.statechip.ok { color: var(--safe); }
.statechip.warn { color: var(--under); }
.stamp { position: absolute; top: 12px; right: 10px; rotate: -9deg; font-family: var(--mono); font-weight: 700; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; border: 2px solid currentColor; border-radius: 5px; padding: 2px 6px; background: var(--surface); }
.r-civilian { color: var(--safe); }
.r-undercover { color: var(--under); }
.r-spy { color: var(--spy); }
.wordtag { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.btn { font: 600 14px/1 var(--body); border-radius: 10px; padding: 11px 16px; border: 1px solid transparent; cursor: pointer; background: var(--ink); color: var(--surface); text-decoration: none; display: inline-block; }
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.lamp { background: var(--lamp); color: var(--lamp-ink); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.small { padding: 7px 10px; font-size: 12px; border-radius: 8px; }
.btn.vote { background: transparent; color: var(--spy); border-color: color-mix(in srgb, var(--spy) 50%, transparent); }
.btn.vote[aria-pressed="true"] { background: var(--spy); color: var(--surface); }
.btn.danger { background: transparent; color: var(--spy); border-color: color-mix(in srgb, var(--spy) 50%, transparent); }
:focus-visible { outline: 3px solid var(--lamp); outline-offset: 2px; }
.countdown { font-family: var(--mono); font-size: 12px; padding: 5px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.countdown.low { background: color-mix(in srgb, var(--spy) 16%, transparent); color: var(--spy); }

/* Role card */
.cardwrap { perspective: 1000px; }
.rolecard { all: unset; display: block; width: 100%; height: 240px; cursor: pointer; position: relative; transform-style: preserve-3d; transition: transform .6s cubic-bezier(.2, .8, .2, 1); border-radius: 16px; -webkit-tap-highlight-color: transparent; }
@media (max-width: 600px) { .rolecard { height: 210px; } }
.rolecard:focus-visible { outline: 3px solid var(--lamp); outline-offset: 3px; }
.rolecard.up { transform: rotateY(180deg); }
.rolecard.static { cursor: default; }
.face { position: absolute; inset: 0; border-radius: 16px; backface-visibility: hidden; -webkit-backface-visibility: hidden; padding: 18px 20px; display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; }
.face.down { background: repeating-linear-gradient(135deg, var(--ink) 0 14px, color-mix(in srgb, var(--ink) 86%, var(--lamp)) 14px 28px); color: var(--surface); }
.face.down .big { font-family: var(--display); font-weight: 800; font-size: 26px; line-height: 1.05; }
.face.down .case { color: color-mix(in srgb, var(--surface) 70%, transparent); }
.face.front { transform: rotateY(180deg); background: var(--surface); border: 2px solid var(--ink); }
.face.front.isspy { border-color: var(--spy); }
.secret { font-family: var(--display); font-weight: 800; font-size: clamp(32px, 6vw, 46px); line-height: 1; letter-spacing: -.02em; overflow-wrap: anywhere; }
.def { margin: 0; font-size: 14px; line-height: 1.35; color: var(--ink); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.isspy .secret { color: var(--spy); }
.hint { font-size: 13px; color: var(--muted); }

.pass { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.ideas { display: flex; flex-wrap: wrap; gap: 6px; }
.idea { all: unset; cursor: pointer; font-family: var(--mono); font-size: 13px; padding: 6px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); }
.idea:focus-visible { outline: 3px solid var(--lamp); }
.aihint { font-size: 13px; padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, var(--lamp) 18%, transparent); color: var(--ink); }
.result-big { font-family: var(--display); font-weight: 800; font-size: 30px; line-height: 1.05; }
.result-big.win { color: var(--safe); }
.result-big.lose { color: var(--spy); }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
td, th { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
th { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 500; }

.log { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; max-height: 340px; overflow-y: auto; }
.entry { font-size: 14px; line-height: 1.45; }
.entry.round { font-family: var(--mono); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 8px; margin-top: 2px; }
.entry.round:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.entry.sys { color: var(--muted); font-style: italic; }
.entry b { font-weight: 600; }
.entry q { font-family: var(--mono); font-size: 13px; quotes: "“" "”"; }
.autotag { font-family: var(--mono); font-size: 10px; font-style: normal; padding: 1px 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }

details.rules { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; }
details.rules summary { cursor: pointer; font-weight: 600; }
details.rules ul { margin: 10px 0 2px; padding-left: 20px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }

@media (pointer: coarse) {
  .btn { padding: 13px 18px; }
  .btn.small { padding: 9px 12px; font-size: 13px; }
  input, select, .field { font-size: 16px !important; }
}
@media (prefers-reduced-motion: reduce) {
  .rolecard, .seat { transition: none; }
  .thinking::after { animation: none; content: "..."; }
}
