:root {
  --bg: #0b0f2a;
  --bg2: #121842;
  --grid: rgba(80, 200, 255, 0.07);
  --ink: #e8ecff;
  --muted: #8f97c7;
  --win: #c3c3c3;
  --win-ink: #111;
  --win-hi: #fff;
  --win-lo: #6b6b6b;
  --title-a: #000a7a;
  --title-b: #1a84d1;
  --accent: #34e0ff;
  --select: #ffe14d;
  --good: #9bff8a;
  --t-action: #2c4fa6;
  --t-attack: #8b1d2c;
  --t-reaction: #16707a;
  --t-treasure: #d8a91c;
  --t-victory: #2f7d34;
  --t-curse: #5c3974;
  --card-paper: #f3efe3;
  --card-ink: #1a1a1a;
  --font-pixel: 'VT323', ui-monospace, monospace;
  --font-body: 'IBM Plex Sans', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
}
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.label { font-family: var(--font-pixel); font-size: 20px; margin: 14px 0 6px; }
.code { font-family: var(--font-pixel); letter-spacing: 3px; text-transform: uppercase; }
.code.big { font-size: 30px; color: var(--title-a); }

/* ---------- Win98-style windows ---------- */
.win {
  background: var(--win);
  color: var(--win-ink);
  border: 2px solid;
  border-color: var(--win-hi) var(--win-lo) var(--win-lo) var(--win-hi);
  box-shadow: 1px 1px 0 #000, 6px 6px 0 rgba(0, 0, 0, 0.35);
}
.win-title {
  display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(90deg, var(--title-a), var(--title-b));
  color: #fff; font-family: var(--font-pixel); font-size: 20px; padding: 1px 6px;
}
.win-btns::after { content: '▁ ▢ ×'; font-style: normal; letter-spacing: 4px; opacity: 0.85; }
.win-body { padding: 12px; }
.win .muted { color: #555; }
.win a { color: #0018a8; }

.btn {
  font: 600 14px var(--font-body);
  background: var(--win); color: var(--win-ink);
  border: 2px solid; border-color: var(--win-hi) var(--win-lo) var(--win-lo) var(--win-hi);
  box-shadow: 1px 1px 0 #000;
  padding: 6px 12px; cursor: pointer; min-height: 34px;
}
.btn:active:not(:disabled) { border-color: var(--win-lo) var(--win-hi) var(--win-hi) var(--win-lo); transform: translate(1px, 1px); }
.btn:disabled { color: #8a8a8a; cursor: default; text-shadow: 1px 1px #fff; }
.btn.primary { background: #ffe14d; font-weight: 700; }
.btn.primary::before { content: '▶ '; }
.btn.small { padding: 2px 8px; min-height: 26px; font-size: 13px; }
input, select {
  font: 15px var(--font-body); padding: 6px 8px; background: #fff; color: #111;
  border: 2px solid; border-color: var(--win-lo) var(--win-hi) var(--win-hi) var(--win-lo); min-height: 34px;
}
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-weight: 600; }
.field input { width: 100%; }
.field .row input { width: 110px; }

/* ---------- Home ---------- */
.screen { max-width: 1500px; margin: 0 auto; padding: 16px; }
.hero { display: flex; gap: 24px; align-items: center; margin: 12px 0 28px; flex-wrap: wrap; }
.hero-art { width: 220px; aspect-ratio: 4/3; object-fit: cover; border: 3px solid var(--accent); image-rendering: pixelated; box-shadow: 0 0 30px rgba(52, 224, 255, 0.35); }
.hero h1 { font-family: var(--font-pixel); font-size: clamp(56px, 10vw, 104px); margin: 0; line-height: 0.9; color: var(--select); text-shadow: 4px 4px 0 #c2185b, 8px 8px 0 #000; letter-spacing: 4px; }
.tagline { font-size: 20px; margin: 10px 0 4px; }
.sub { color: var(--muted); margin: 0; }
.home-grid, .room-grid { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.room-list { list-style: none; padding: 0; margin: 0; }
.room-list li { display: flex; justify-content: space-between; align-items: center; padding: 8px; border-bottom: 1px dotted #777; gap: 8px; }

/* ---------- Room ---------- */
.seat-list { padding-left: 24px; }
.seat-list li { padding: 6px 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tag { font: 12px var(--font-body); padding: 1px 6px; border: 1px solid #333; background: #fff; }
.tag.bot::before { content: '⚙ '; }
.tag.you { background: #ffe14d; }
.tag.host::before { content: '♛ '; }
.tag.off { background: #ddd; color: #666; border-style: dashed; }
.tag.off::before { content: '⌀ '; }
.kingdom-preview { align-items: start; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin: 12px 0; }
.chat-win { display: flex; flex-direction: column; min-height: 360px; }
.chat-body { display: flex; flex-direction: column; flex: 1; gap: 8px; }
.chat-log { background: #fff; flex: 1; min-height: 200px; max-height: 420px; overflow-y: auto; padding: 6px; font-size: 14px; border: 2px inset #999; }
.chat-log b { color: #0018a8; }
.chat-form { display: flex; gap: 6px; }
.chat-form input { flex: 1; min-width: 0; }

/* ---------- Cards ---------- */
.card {
  --tc: var(--t-action);
  position: relative; width: 150px; flex: 0 0 auto;
  background: var(--card-paper); color: var(--card-ink);
  border: 2px solid #000; border-radius: 6px; overflow: hidden;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6);
  display: flex; flex-direction: column; user-select: none;
  transition: transform 0.12s, box-shadow 0.12s, opacity 0.12s;
}
.card.t-treasure { --tc: var(--t-treasure); }
.card.t-victory { --tc: var(--t-victory); }
.card.t-curse { --tc: var(--t-curse); }
.card.t-attack { --tc: var(--t-attack); }
.card.t-reaction { --tc: var(--t-reaction); }
.card .c-bar {
  display: flex; align-items: center; gap: 4px; background: var(--tc); color: #fff;
  padding: 2px 4px; font-family: var(--font-pixel); font-size: 19px; line-height: 1;
  min-height: 26px;
}
.card.t-treasure .c-bar { color: #1a1300; }
/* Exploit cards get stripes as a non-colour cue; Firewalls get a brick pattern. */
.card.t-attack .c-bar { background-image: repeating-linear-gradient(135deg, transparent 0 6px, rgba(0, 0, 0, 0.28) 6px 9px); }
.card.t-reaction .c-bar { background-image: linear-gradient(rgba(255,255,255,.18) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.18) 1px, transparent 1px); background-size: 10px 6px; }
.c-cost {
  flex: 0 0 auto; width: 24px; height: 24px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff6b0, #e2b21c 60%, #9c7400);
  color: #1a1300; display: grid; place-items: center; font-size: 19px; border: 1px solid #000;
}
.c-name { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.c-art { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: #0b0f2a; border-bottom: 2px solid #000; }
.c-type { font: 700 10px var(--font-body); letter-spacing: 0.8px; text-transform: uppercase; padding: 3px 5px; background: color-mix(in srgb, var(--tc) 22%, white); border-bottom: 1px solid rgba(0,0,0,.2); }
.c-text { padding: 5px 6px 6px; font-size: 11.5px; line-height: 1.3; white-space: pre-line; flex: 1; text-align: center; }
.c-text .big { font: 700 18px var(--font-body); display: block; }
.c-flavor { font-style: italic; font-size: 10.5px; color: #555; padding: 0 6px 6px; text-align: center; }
.card.mini { width: 112px; }
.card.mini .c-text, .card.mini .c-flavor { display: none; }
.card.mini .c-bar { height: 34px; }
.card.mini .c-name { font-size: 15px; white-space: normal; line-height: 0.85; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card.mini .c-type { font-size: 8.5px; padding: 2px 4px; }
.card.tiny { width: 84px; }
.card.tiny .c-text, .card.tiny .c-flavor, .card.tiny .c-type { display: none; }
.card.tiny .c-bar { font-size: 15px; min-height: 20px; }
.card.tiny .c-cost { width: 18px; height: 18px; font-size: 15px; }
.card.large { width: 260px; }
.card.large .c-bar { font-size: 26px; min-height: 34px; }
.card.large .c-cost { width: 32px; height: 32px; font-size: 26px; }
.card.large .c-type { font-size: 12px; }
.card.large .c-text { font-size: 15px; }
.card.large .c-flavor { font-size: 13px; }

.pile { position: relative; }
.pile .count {
  position: absolute; right: -6px; top: -8px; z-index: 2;
  background: #000; color: #fff; border: 2px solid #fff; border-radius: 12px;
  font: 18px var(--font-pixel); padding: 0 7px; line-height: 20px;
}
.pile.empty .card { opacity: 0.35; filter: grayscale(1); }
.pile.empty .count { background: #666; }

/* Interaction states: shape + lightness, never hue alone. */
.card.can { cursor: pointer; outline: 3px dashed var(--accent); outline-offset: 2px; }
.card.can:hover { transform: translateY(-6px); box-shadow: 0 10px 20px rgba(0, 0, 0, 0.6); }
.card.dim { opacity: 0.42; }
.card.sel { outline: 4px solid var(--select); outline-offset: 2px; transform: translateY(-14px); }
.card.sel::after {
  content: '✓'; position: absolute; top: 30px; right: 6px; width: 28px; height: 28px;
  background: var(--select); color: #000; border: 2px solid #000; border-radius: 50%;
  display: grid; place-items: center; font: 700 18px var(--font-body);
}
.card.affordable::before {
  content: 'BUY'; position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%); z-index: 3;
  background: var(--select); color: #000; border: 2px solid #000; font: 22px var(--font-pixel); padding: 0 6px;
  opacity: 0; transition: opacity 0.1s;
}
.card.affordable:hover::before { opacity: 1; }

/* ---------- Game layout ---------- */
/* The side column (inspector + log) runs the full height; supply and play area share the left column. */
#screen-game {
  max-width: none; padding: 8px 12px 0; display: grid; height: 100vh; column-gap: 12px;
  grid-template-columns: minmax(0, 1fr) 280px; grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: 'top top' 'supply side' 'play side';
}
.topbar { grid-area: top; }
.supply-wrap { grid-area: supply; }
.side { grid-area: side; padding-bottom: 8px; }
.play-area { grid-area: play; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding-bottom: 8px; flex-wrap: wrap; }
.brand { font: 30px var(--font-pixel); color: var(--select); text-shadow: 2px 2px 0 #c2185b; }
.players { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.pl {
  background: var(--bg2); border: 2px solid #3a4380; padding: 4px 10px; min-width: 150px;
  font-size: 13px; line-height: 1.35;
}
.pl .nm { font-weight: 700; font-size: 14px; }
.pl .vp { font: 22px var(--font-pixel); color: var(--good); float: right; }
.pl.active { border: 3px solid var(--select); background: #232a66; }
.pl.active .nm::before { content: '▶ '; color: var(--select); }
.pl.waiting .nm::after { content: ' ⏳'; }
.pl.off { opacity: 0.6; border-style: dashed; }

.board { display: contents; }
.supply-wrap { min-width: 0; overflow-y: auto; padding-right: 8px; }
.supply { display: grid; grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); gap: 14px 10px; padding: 10px 6px; }
.supply .card.mini { width: 100%; max-width: 140px; }
.supply.base { border-bottom: 1px dashed #3a4380; }
.trash-line { font: 18px var(--font-pixel); color: var(--muted); padding: 2px 8px; }
.side { display: flex; flex-direction: column; gap: 10px; min-width: 0; min-height: 0; overflow-y: auto; }
.inspector { display: flex; justify-content: center; flex: 0 0 auto; }
.inspector .card.large { width: 210px; }
.inspector .card.large .c-text { font-size: 13.5px; }
.log-win { flex: 1 1 220px; min-height: 220px; display: flex; flex-direction: column; }
.log-win .win-body { padding: 6px; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.log, .chat-pane .chat-log { background: #fff; flex: 1 1 0; min-height: 120px; overflow-y: auto; font-size: 12.5px; padding: 4px 6px; border: 2px inset #999; }
.chat-pane { display: flex; flex-direction: column; gap: 6px; flex: 1; min-height: 0; }
.log div { padding: 1px 0; }
.log .turn { font-weight: 700; margin-top: 6px; border-top: 1px dotted #999; color: #0018a8; }
.tabs { display: flex; gap: 2px; margin-bottom: 4px; }
.tab { font: 14px var(--font-body); border: 2px solid; border-color: var(--win-hi) var(--win-lo) transparent var(--win-hi); background: #b0b0b0; padding: 2px 10px; cursor: pointer; }
.tab.active { background: var(--win); font-weight: 700; }
.tab.unread::after { content: ' •'; font-weight: 700; }

.play-area { border-top: 2px solid #3a4380; padding-top: 4px; }
.zone-label { font: 18px var(--font-pixel); color: var(--muted); }
.inplay-wrap { min-height: 30px; }
.inplay { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px 0; }
.prompt {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--win); color: var(--win-ink); border: 2px solid; border-color: var(--win-hi) var(--win-lo) var(--win-lo) var(--win-hi);
  padding: 8px 12px; margin: 6px 0;
}
.prompt.yours { box-shadow: 0 0 0 3px var(--select), 0 0 24px rgba(255, 225, 77, 0.45); }
.status { display: flex; gap: 12px; font: 24px var(--font-pixel); }
.status span { background: #fff; border: 2px inset #999; padding: 0 8px; }
.prompt-text { flex: 1; font-weight: 600; min-width: 200px; }
.prompt-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.hand-wrap { padding-bottom: 10px; }
.hand { display: flex; gap: 8px; overflow-x: auto; padding: 16px 4px 8px; min-height: 120px; }
.hand .card { width: 140px; }
.hand .card .c-text { font-size: 11px; }

/* ---------- Modal & toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal-win { max-width: min(920px, 100%); max-height: 90vh; overflow: auto; }
.x { background: var(--win); border: 2px solid; border-color: var(--win-hi) var(--win-lo) var(--win-lo) var(--win-hi); width: 24px; height: 22px; padding: 0; cursor: pointer; font-weight: 700; }
.modal-cards { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; justify-content: center; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #000; color: #fff; border: 2px solid var(--select); padding: 10px 18px; z-index: 60; max-width: calc(100% - 32px); }
.scores { border-collapse: collapse; width: 100%; margin: 10px 0; }
.scores td, .scores th { border: 1px solid #888; padding: 6px 10px; text-align: left; }
.scores tr.winner { background: #ffe14d; font-weight: 700; }
.scores tr.winner td:first-child::before { content: '♛ '; }
.picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; }
.picker .card { width: auto; }

/* In play shows compact chips: name and cost only. Hover still fills the inspector. */
.inplay .card.tiny .c-art { display: none; }
.inplay-wrap { display: flex; gap: 10px; align-items: center; min-height: 34px; }
.inplay { padding: 2px 0; }
@media (max-height: 1000px) and (min-width: 1001px) {
  .hand .card { width: 128px; }
  .hand .card .c-flavor { display: none; }
  .hand { padding-top: 12px; min-height: 0; }
  .supply { gap: 12px 8px; padding: 8px 4px; }
  .supply .card.mini { max-width: 118px; }
  .supply .card.mini .c-type { display: none; }
}
@media (max-width: 1000px) {
  #screen-game { display: flex; flex-direction: column; height: auto; }
  .supply-wrap { order: 1; }
  .play-area { order: 2; }
  .side { order: 3; padding-bottom: 16px; }
  .supply-wrap, .side { overflow: visible; }
  .prompt { position: sticky; bottom: 0; z-index: 5; }
  .inspector { display: none; }
  .log, .chat-pane .chat-log { flex: none; height: 150px; }
}
@media (max-width: 700px) {
  .screen { padding: 12px 16px; }
  #screen-game { padding: 6px 8px 0; }
  .home-grid, .room-grid { grid-template-columns: minmax(0, 1fr); }
  .hero-art { width: 140px; }
  .supply { gap: 10px 6px; }
  .supply { grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); }
  .card.mini .c-bar { font-size: 13px; height: 28px; padding: 2px 3px; }
  .card.mini .c-cost { width: 16px; height: 16px; font-size: 13px; }
  .card.mini .c-type { display: none; }
  .card.mini .c-name { font-size: 12.5px; }
  .brand { display: none; }
  .pl { padding: 3px 6px; font-size: 12px; }
  .pl .vp { font-size: 18px; }
  .hand .card { width: 120px; }
  .hand .card .c-text { font-size: 10px; }
  .hand .card .c-flavor { display: none; }
  .kingdom-preview { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pl { min-width: 0; flex: 1 1 40%; }
  .status { font-size: 20px; }
}
