/* TI4 table helper. Dark "deep space" theme; TV view scales up, phone view is touch-first. */
:root {
  --bg: #0b0f1a;
  --bg2: #121828;
  --card: #161d30;
  --line: #2a3350;
  --text: #e7eaf3;
  --muted: #8f98b3;
  --gold: #e8c35a;
  --hot: #ff9d3c;
  --ok: #46b066;
  --danger: #e05a5a;
  --radius: 10px;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 16px; line-height: 1.4; }
body { background: radial-gradient(1200px 600px at 70% -10%, #1a2340 0%, transparent 60%), var(--bg); min-height: 100vh; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.2; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; color: var(--gold); font-weight: 600; }
p { margin: .4em 0; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.boot { padding: 2rem; color: var(--muted); }
.row { display: flex; gap: .5rem; align-items: center; margin: .4rem 0; }
.row.wrap { flex-wrap: wrap; }
.right { margin-left: auto; }
code.select { user-select: all; display: block; padding: .5rem; background: #0006; border-radius: 6px; word-break: break-all; font-family: var(--mono); font-size: .85rem; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card.empty { text-align: center; padding: 2rem; }

.btn { background: #232c47; border: 1px solid #364168; border-radius: 8px; padding: .5rem .9rem; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { background: #2b365a; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--gold); color: #1a1406; border-color: var(--gold); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #f3d277; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.big { padding: .8rem 1.4rem; font-size: 1.1rem; }
.btn.tiny { padding: .15rem .5rem; font-size: .85rem; border-radius: 6px; }

input, select { background: #0e1424; border: 1px solid var(--line); border-radius: 8px; padding: .55rem .7rem; max-width: 100%; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
label.check { display: flex; gap: .4rem; align-items: center; margin: .4rem 0; cursor: pointer; }

.badge { display: inline-block; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; padding: .1rem .45rem; border-radius: 999px; background: #e8c35a22; color: var(--gold); border: 1px solid #e8c35a55; margin-left: .3rem; }
.badge.hot { background: #ff9d3c22; color: var(--hot); border-color: #ff9d3c66; }
.badge.dim { color: var(--muted); background: transparent; border-color: var(--line); }
.badge.win { background: #46b06622; color: var(--ok); border-color: #46b06666; }
.offline { color: var(--danger); font-size: .8rem; font-weight: 600; }
.hot { color: var(--hot); }

.swatch { display: inline-block; width: .9em; height: .9em; border-radius: 50%; vertical-align: -.1em; border: 1px solid #fff4; flex: none; }
.swatch[data-empty] { border-style: dashed; }
.swatch.big { width: 1.4em; height: 1.4em; }

.sc-chip { display: inline-flex; align-items: center; justify-content: center; min-width: 1.6em; height: 1.6em; padding: 0 .35em; border-radius: 6px; background: #e8c35a; color: #1a1406; font-weight: 700; font-family: var(--mono); font-size: .85em; gap: .35em; }
.sc-chip.used { background: #5b5a52; color: #ccc; text-decoration: line-through; }
.sc-chip.big { font-size: 1rem; }
.sc-chip small { font-family: var(--sans); font-weight: 600; font-size: .75em; }
.btnchip { border: none; cursor: pointer; background: #2a3350; color: var(--text); }
.btnchip.on { background: var(--gold); color: #1a1406; }
.btnchip:disabled { opacity: .25; }

.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: none; }
.st-btn { width: 2.2rem; height: 2.2rem; border: none; background: #232c47; cursor: pointer; font-size: 1.2rem; }
.st-btn:disabled { opacity: .3; }
.st-val { min-width: 2.4rem; text-align: center; font-family: var(--mono); font-weight: 600; }

.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .8rem; }
.tab { background: transparent; border: 1px solid var(--line); border-radius: 999px; padding: .3rem .8rem; cursor: pointer; }
.tab.on { background: var(--gold); color: #1a1406; border-color: var(--gold); font-weight: 600; }

#toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%) translateY(150%); background: #000c; border: 1px solid var(--line); padding: .6rem 1rem; border-radius: 999px; transition: transform .25s; z-index: 50; pointer-events: none; }
#toast.show { transform: translateX(-50%) translateY(0); }

/* ---------------- home / choose / setup */
.narrow { max-width: 34rem; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.title { font-size: 2rem; letter-spacing: .02em; }
.title small { display: block; font-size: .9rem; color: var(--muted); font-weight: 400; letter-spacing: .04em; margin-top: .3rem; }
.home form, .narrow form { display: flex; gap: .5rem; }
.home form input, .narrow form input { flex: 1; }
.code-input { text-transform: uppercase; font-family: var(--mono); font-size: 1.4rem; letter-spacing: .3em; text-align: center; }
.code { font-family: var(--mono); color: var(--gold); letter-spacing: .12em; }
.foot { text-align: center; font-size: .85rem; }
.colors { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: 1.2rem; }
.colorbtn { padding: .8rem; border-radius: 8px; border: 2px solid transparent; background: var(--pc); color: #fff; text-transform: capitalize; font-weight: 600; cursor: pointer; text-shadow: 0 1px 2px #000a; }
.colorbtn.on { border-color: #fff; box-shadow: 0 0 0 2px var(--gold); }
.colorbtn:disabled { opacity: .2; cursor: not-allowed; }
.factions { display: grid; gap: .4rem; }
.factionbtn { display: flex; flex-direction: column; align-items: flex-start; text-align: left; padding: .6rem .8rem; border-radius: 8px; border: 1px solid var(--line); background: var(--card); cursor: pointer; }
.factionbtn.on { border-color: var(--gold); background: #e8c35a18; }
.factionbtn:disabled { opacity: .35; cursor: not-allowed; }

/* ---------------- table (TV) view */
.v-table { font-size: 18px; }
@media (min-width: 1600px) { .v-table { font-size: 21px; } }
.table-wrap { display: flex; flex-direction: column; height: 100vh; }
.tbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; border-bottom: 1px solid var(--line); background: #0b0f1acc; flex-wrap: wrap; }
.tbar-left, .tbar-mid, .tbar-right { display: flex; align-items: center; gap: .7rem; }
.tbar-mid { flex: 1; justify-content: center; }
.tcode { font-family: var(--mono); font-size: 1.6rem; font-weight: 600; color: var(--gold); letter-spacing: .15em; }
.join b { color: var(--text); }
.round { font-weight: 600; }
.phase-name { font-size: 1.25rem; font-weight: 600; color: var(--gold); }
.tbody { flex: 1; display: flex; min-height: 0; }
.tmain { flex: 1; overflow: auto; padding: 1rem; }
.tref { width: 25rem; max-width: 38vw; border-left: 1px solid var(--line); overflow: auto; padding: 1rem; background: #0e1322; font-size: .9em; }

.banner { display: flex; align-items: center; gap: .8rem; padding: .8rem 1rem; border-radius: var(--radius); background: linear-gradient(90deg, color-mix(in srgb, var(--pc, #888) 35%, transparent), transparent 70%); border: 1px solid color-mix(in srgb, var(--pc, #888) 60%, transparent); margin-bottom: 1rem; flex-wrap: wrap; }
.banner-label { text-transform: uppercase; letter-spacing: .08em; font-size: .8rem; color: var(--muted); }
.banner-name { font-size: 1.5rem; font-weight: 600; }
.banner-actions { margin-left: auto; display: flex; gap: .5rem; }

.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 1rem; }
.pcard { background: var(--card); border: 1px solid var(--line); border-top: 6px solid var(--pc); border-radius: var(--radius); padding: .9rem 1rem; }
.pcard.active { box-shadow: 0 0 0 2px var(--hot), 0 0 24px #ff9d3c44; }
.pcard.passed { opacity: .6; }
.pc-top { display: flex; justify-content: space-between; gap: .5rem; }
.pc-name { font-size: 1.3rem; font-weight: 600; }
.pc-name .off { color: var(--muted); font-size: .7em; }
.pc-faction { color: var(--muted); }
.pc-vp { font-family: var(--mono); text-align: right; }
.pc-vp span { font-size: 2.2rem; font-weight: 600; color: var(--gold); line-height: 1; }
.pc-vp small { color: var(--muted); display: block; }
.pc-row { display: flex; gap: .35rem; flex-wrap: wrap; align-items: center; margin: .6rem 0; min-height: 1.7em; }
.pc-row .badge { margin-left: 0; }
.pc-techs { display: flex; gap: .4rem; align-items: center; }
.tdot { display: inline-flex; align-items: center; justify-content: center; min-width: 1.7em; height: 1.7em; border-radius: 50%; background: var(--tc); color: #0b0f1a; font-weight: 700; font-family: var(--mono); font-size: .85em; }
.below { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
.laws ul, .log { margin: 0; padding-left: 1.1rem; }
.log { list-style: none; padding: 0; color: var(--muted); font-size: .9em; }
.log li { padding: .15rem 0; border-bottom: 1px dashed #ffffff10; }

/* reference */
.ref h3 { margin-top: 0; }
.ref-block { margin-bottom: 1rem; }
.init { list-style: none; padding: 0; margin: 0; }
.init li { display: flex; align-items: center; gap: .5rem; padding: .3rem .4rem; border-radius: 6px; }
.init li.active { background: #ff9d3c22; outline: 1px solid #ff9d3c66; }
.init li.passed { opacity: .5; }
.init-name { flex: 1; }
.init-cards { display: flex; gap: .2rem; }
.ref-phase { border: 1px solid var(--line); border-radius: 8px; margin-bottom: .5rem; padding: .3rem .6rem; background: #ffffff05; }
.ref-phase summary { cursor: pointer; font-weight: 600; padding: .2rem 0; }
.ref-phase.current { border-color: var(--gold); background: #e8c35a12; }
.ref-phase.current > summary { color: var(--gold); }
.ref-phase.current > summary::after { content: "  ◀ now"; font-size: .75em; color: var(--hot); }
.ref-phase.sub summary { font-weight: 500; color: var(--muted); }
.ref-phase ol { margin: .3rem 0 .4rem; padding-left: 1.2rem; }
.ref-phase li { margin: .2rem 0; }
.sc-ref dt { font-weight: 600; margin-top: .5rem; }
.sc-ref dd { margin: .2rem 0 0; font-size: .92em; color: #c9cfe0; }

/* controls drawer */
.manage { border-color: var(--gold); }
.mtable { width: 100%; border-collapse: collapse; font-size: .9em; }
.mtable td { padding: .4rem .3rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.mtable td .btn { margin: .1rem; }
.sc-pick { white-space: nowrap; }
.sc-pick .sc-chip { margin: .1rem; }
.vpn { display: inline-block; min-width: 1.6em; text-align: center; font-family: var(--mono); }
.mround > div { margin: .6rem 0; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.agenda-list { max-height: 50vh; overflow: auto; display: grid; gap: .3rem; margin-top: .5rem; }
.agenda-item { text-align: left; background: #0e1424; border: 1px solid var(--line); border-radius: 8px; padding: .5rem .7rem; cursor: pointer; }
.agenda-item:hover { border-color: var(--gold); }
.mbattle { display: grid; gap: .7rem; max-width: 40rem; }
.mbattle label { display: flex; gap: .5rem; align-items: center; }
.relink { margin-top: 1rem; }

/* ---------------- agenda */
.agenda-board { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 1.2rem; align-items: start; }
.agenda-card { background: linear-gradient(160deg, #1d2a4a, #121a2e); border: 2px solid #4a5f9a; border-radius: 14px; padding: 1.4rem 1.6rem; }
.agenda-card.directive { border-color: #8a6bc6; background: linear-gradient(160deg, #2a2150, #141a2e); }
.ac-type { letter-spacing: .3em; font-size: .8rem; color: var(--muted); }
.agenda-card h2 { font-size: 2rem; margin: .3rem 0; color: #fff; }
.ac-target { display: inline-block; font-weight: 600; color: var(--gold); border-bottom: 1px solid #e8c35a66; margin-bottom: .6rem; }
.agenda-card p { font-size: 1.1rem; white-space: pre-line; }
.vote-order { list-style: none; padding: 0; margin: 0 0 1rem; }
.vote-order li { display: flex; gap: .6rem; align-items: center; padding: .45rem .5rem; border-radius: 8px; }
.vote-order li.current { background: #ff9d3c1f; outline: 1px solid #ff9d3c77; }
.vname { min-width: 6em; font-weight: 600; }
.tally-row { display: grid; grid-template-columns: minmax(6em, auto) 1fr 3em; gap: .6rem; align-items: center; margin: .35rem 0; }
.tally-row.win .tl { color: var(--gold); font-weight: 700; }
.tbar-bg { height: .8rem; background: #ffffff10; border-radius: 999px; overflow: hidden; }
.tbar-fg { display: block; height: 100%; background: var(--gold); }
.tally-row b { font-family: var(--mono); text-align: right; }
.result .big { font-size: 1.4rem; }
.onbehalf { margin: .8rem 0; }
.onbehalf summary { cursor: pointer; color: var(--muted); }
.vote-widget { display: grid; gap: .5rem; }
.opt { padding: .6rem 1rem; border-radius: 8px; border: 1px solid var(--line); background: #0e1424; cursor: pointer; }
.opt.on { background: var(--gold); color: #1a1406; border-color: var(--gold); font-weight: 600; }
.myvote { border-color: var(--hot); }

/* ---------------- battle */
.bhead { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .6rem; }
.bhead h2 { margin: 0; font-size: 1.6rem; }
.bstep { background: #ff9d3c22; color: var(--hot); border: 1px solid #ff9d3c66; border-radius: 999px; padding: .2rem .8rem; font-weight: 600; }
.bhead-actions { margin-left: auto; display: flex; gap: .5rem; }
.bnote { color: var(--gold); }
.bwinner { font-size: 2rem; font-weight: 700; color: var(--ok); text-align: center; margin: .5rem 0 1rem; }
.bsides { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.bside { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.bs-head { display: flex; align-items: center; gap: .5rem; border-left: 6px solid var(--pc); padding-left: .6rem; margin-bottom: .6rem; flex-wrap: wrap; }
.bs-role { text-transform: uppercase; font-size: .75rem; letter-spacing: .1em; color: var(--muted); }
.bs-name { font-size: 1.3rem; font-weight: 600; }
.frow { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .35rem 0; border-bottom: 1px dashed #ffffff12; }
.bside h4 { margin: .8rem 0 .2rem; color: var(--muted); font-weight: 500; }
.bside.edit > .btn { margin-top: .8rem; width: 100%; }
.ulist { list-style: none; padding: 0; margin: 0; font-size: 1.1rem; }
.ulist li { padding: .2rem 0; }
.ucount { display: inline-block; min-width: 1.8em; text-align: right; font-family: var(--mono); font-weight: 700; color: var(--gold); }
.dmg { color: var(--hot); font-size: .85em; }
.rolls { margin-top: .7rem; border-top: 1px solid var(--line); padding-top: .6rem; }
.rgroup { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin: .25rem 0; }
.rlabel { min-width: 10em; }
.rlabel small { color: var(--muted); }
.dice { display: flex; gap: .3rem; flex-wrap: wrap; }
.die { width: 2em; height: 2em; display: inline-flex; align-items: center; justify-content: center; border-radius: 6px; background: #2a3350; color: #aab; font-family: var(--mono); font-weight: 700; animation: pop .35s ease-out; }
.die.hit { background: var(--ok); color: #fff; box-shadow: 0 0 10px #46b06688; }
@keyframes pop { from { transform: scale(.4) rotate(-30deg); opacity: 0; } to { transform: none; opacity: 1; } }
.hits { font-size: 1.3rem; font-weight: 700; color: var(--gold); margin-top: .3rem; }
.bcontrols { margin-top: 1rem; display: grid; gap: .6rem; justify-items: center; }
.bcontrols.assign { grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); justify-items: stretch; }
.atable { width: 100%; border-collapse: collapse; }
.atable td { padding: .3rem; border-bottom: 1px dashed #ffffff12; white-space: nowrap; }
.reminders { margin-top: .6rem; font-size: .88em; color: #c9cfe0; }
.reminders summary { cursor: pointer; color: var(--muted); }
.reminders ul { margin: .3rem 0; padding-left: 1.1rem; }
.bhist { margin-top: 1rem; color: var(--muted); font-size: .9em; }

/* ---------------- player (phone) view */
.player { max-width: 52rem; margin: 0 auto; padding-bottom: 3rem; overflow-x: hidden; }
.phead { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .7rem 1rem; border-bottom: 3px solid var(--pc); background: var(--bg2); position: sticky; top: 0; z-index: 5; }
.ph-id { display: flex; gap: .6rem; align-items: center; }
.ph-id .swatch { width: 1.6rem; height: 1.6rem; }
.ph-info { display: flex; flex-direction: column; align-items: center; }
.phead .pc-vp span { font-size: 1.6rem; }
.ptabs { display: flex; overflow-x: auto; scrollbar-width: none; gap: .2rem; padding: .5rem .6rem; border-bottom: 1px solid var(--line); position: sticky; top: 3.7rem; background: var(--bg); z-index: 4; }
.ptab { background: transparent; border: none; padding: .5rem .8rem; border-radius: 8px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.ptab.on { background: #e8c35a22; color: var(--gold); font-weight: 600; }
.pmain { padding: 1rem .8rem; }
.player .banner { margin: .6rem .8rem 0; }
.nudge { display: block; width: calc(100% - 1.6rem); margin: .6rem .8rem 0; padding: .7rem; border-radius: 8px; border: 1px solid var(--hot); background: #ff9d3c22; color: var(--hot); font-weight: 600; cursor: pointer; }

.tview { display: flex; gap: .6rem; align-items: center; justify-content: space-between; margin-bottom: .8rem; flex-wrap: wrap; }
.tcounts { display: flex; gap: .3rem; }
.tcols { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .6rem; }
@media (max-width: 760px) { .tcols { grid-template-columns: 1fr 1fr; } }
.tcol h3 { color: var(--tc); border-bottom: 2px solid var(--tc); padding-bottom: .2rem; }
.tsec { margin-top: 1.2rem; }
.tgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: .5rem; }
.tile { border: 1px solid var(--line); border-left: 4px solid var(--tc, #888); border-radius: 8px; background: var(--card); margin-bottom: .45rem; }
.tile.owned { background: color-mix(in srgb, var(--tc, #888) 22%, var(--card)); border-color: color-mix(in srgb, var(--tc, #888) 70%, transparent); }
.tile.locked { opacity: .62; }
.tile.ready { box-shadow: inset 0 0 0 1px #e8c35a55; }
.tile-head { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: .15rem .4rem; text-align: left; padding: .5rem .6rem; background: none; border: none; cursor: pointer; }
.tile-name { font-weight: 600; font-size: .95em; }
.fmark { color: var(--gold); margin-left: .25em; }
.prq { display: flex; gap: .15rem; align-items: center; }
.prq i, .miss i { display: inline-block; width: .65rem; height: .65rem; border-radius: 50%; vertical-align: middle; }
.tstate { grid-column: 1 / -1; font-size: .78em; color: var(--muted); }
.tile.owned .tstate { color: #fff; font-weight: 700; }
.tile.ready .tstate { color: var(--gold); }
.miss { margin-right: .4em; }
.tile-body { padding: 0 .6rem .6rem; font-size: .9em; }
.ttext { white-space: pre-line; }
.stats { font-family: var(--mono); font-size: .85em; color: var(--gold); }
.abilities summary { cursor: pointer; font-weight: 600; color: var(--gold); }
.ability p { white-space: pre-line; margin-top: .2rem; }
.hint { border-color: var(--gold); }
.hint .btn { margin: .2rem; }

.sc-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .4rem; }
.scbtn { display: flex; align-items: center; gap: .5rem; padding: .5rem; border-radius: 8px; border: 1px solid var(--line); background: #0e1424; cursor: pointer; text-align: left; }
.scbtn small { margin-left: auto; color: var(--muted); font-size: .75em; }
.scbtn.on { border-color: var(--gold); background: #e8c35a1c; }
.scbtn.used { opacity: .6; }
.scbtn:disabled { opacity: .35; cursor: not-allowed; }
.sc-detail { margin-top: .6rem; font-size: .9em; }
.plist { list-style: none; padding: 0; margin: 0; }
.plist li { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; border-bottom: 1px dashed #ffffff12; }

/* phone layouts for boards */
@media (max-width: 760px) {
  .atable td { white-space: normal; }
  .bcontrols.assign { grid-template-columns: 1fr; }
  .agenda-board, .bsides, .below { grid-template-columns: 1fr; }
  .agenda-card h2 { font-size: 1.5rem; }
  .bhead h2 { font-size: 1.25rem; }
  .tref { display: none; }
}
