:root {
  --bg: #0d1b2a;
  --panel: #14263a;
  --panel2: #1b3149;
  --line: #2a4561;
  --text: #e8eef5;
  --muted: #93a7bd;
  --accent: #f0b429;
  --danger: #e05252;
  --ocean: #1a4766;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
body { overflow: hidden; overscroll-behavior: none; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 12px; }
.muted { color: var(--muted); font-weight: normal; font-size: .85em; }
.note { color: var(--muted); font-size: .9em; margin: 8px 0 0; min-height: 1em; }

.screen { display: none; height: 100dvh; }
.screen.active { display: flex; }
#menu, #setup, #lobby { align-items: flex-start; justify-content: center; overflow-y: auto; padding: 24px 14px calc(24px + var(--safe-b));
  background: radial-gradient(ellipse at 30% 20%, #1f4a6e 0%, var(--bg) 70%); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: 100%; max-width: 440px;
  box-shadow: 0 20px 50px rgba(0,0,0,.35); margin: auto 0; }
.menu-card { display: flex; flex-direction: column; gap: 10px; }
h1 { font-size: 48px; letter-spacing: 8px; text-align: center; color: var(--accent); line-height: 1; margin-bottom: 10px; }
h1 small { display: block; font-size: 13px; letter-spacing: 4px; color: var(--muted); margin-top: 6px; text-transform: uppercase; }

.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 16px; cursor: pointer;
  font-weight: 600; transition: background .15s, transform .05s; min-height: 44px; }
.btn:hover:not(:disabled) { background: #24405e; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: #1a1300; border-color: #c9931a; }
.btn.primary:hover:not(:disabled) { background: #ffc441; }
.btn.danger { background: var(--danger); border-color: #b33; color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: .9em; }
.btn.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; width: 40px; height: 40px;
  font-size: 20px; cursor: pointer; display: inline-grid; place-items: center; padding: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.row.end { justify-content: flex-end; }
.col { display: flex; flex-direction: column; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: .9em; }
.field input, .field select, select { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; color: var(--text); font-size: 16px; }

.seats { display: flex; flex-direction: column; gap: 8px; }
.seat { display: flex; align-items: center; gap: 10px; background: var(--panel2); border-radius: 10px; padding: 8px 10px; }
.seat .swatch { width: 18px; height: 18px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px rgba(255,255,255,.25); }
.seat .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat select { padding: 6px 8px; font-size: 14px; }
.seat input { flex: 1; min-width: 0; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 16px; }
.seat .x { background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; padding: 0 4px; }
.options { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; margin-top: 16px; }
.options .field select { padding: 7px; font-size: 14px; }
.code-box { text-align: center; background: var(--bg); border-radius: 12px; padding: 12px; margin-bottom: 12px; color: var(--muted); }
.code { font: 700 36px/1.2 ui-monospace, monospace; letter-spacing: 6px; color: var(--accent); margin: 2px 0 8px; }

/* ---------- Game ---------- */
#game { display: none; height: 100dvh; }
#game.active { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr auto;
  grid-template-areas: "top" "map" "side"; }
#topbar { grid-area: top; display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: var(--panel);
  border-bottom: 1px solid var(--line); padding-top: max(6px, env(safe-area-inset-top)); }
#players { display: flex; gap: 6px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.pchip { display: flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 9px; background: var(--panel2);
  border: 2px solid transparent; font-size: 12.5px; white-space: nowrap; flex: none; }
.pchip.cur { border-color: var(--c); box-shadow: 0 0 10px -2px var(--c); }
.pchip.dead { opacity: .4; text-decoration: line-through; }
.pchip .sw { width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }
.pchip .nm { font-weight: 700; max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
.pchip .st { color: var(--muted); }
.pchip .off { color: var(--danger); }
#netStatus { font-size: 12px; color: var(--muted); }
#netStatus.bad { color: var(--danger); }

#mapWrap { grid-area: map; position: relative; overflow: hidden; background: #0d1a2e; touch-action: none; min-height: 0; }
#zoomCtl { position: absolute; right: 8px; top: 8px; display: flex; flex-direction: column; gap: 6px; z-index: 3; }
#zoomCtl .icon-btn { width: 36px; height: 36px; background: rgba(20,38,58,.85); }

/* board (svg) styles: design/map.css */

#dice { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 4; background: rgba(13,27,42,.92);
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; text-align: center; font-size: 13px;
  box-shadow: 0 8px 20px rgba(0,0,0,.4); max-width: calc(100% - 80px); pointer-events: none; }
#dice .dice-row { display: flex; gap: 14px; justify-content: center; align-items: center; margin-bottom: 4px; }
#dice .grp { display: flex; gap: 4px; }
.die { width: 28px; height: 28px; border-radius: 6px; display: grid; place-items: center; font-weight: 800; font-size: 16px;
  animation: roll .35s ease-out; }
.die.a { background: var(--da, #d64545); color: #fff; }
.die.d { background: var(--dd, #eee); color: #fff; }
.die.lost { opacity: .35; }
@keyframes roll { 0% { transform: rotate(-200deg) scale(.4); } 100% { transform: none; } }
#toast { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); background: rgba(0,0,0,.82); padding: 8px 14px;
  border-radius: 20px; font-size: 14px; z-index: 5; pointer-events: none; max-width: 90%; text-align: center; }
#banner { position: absolute; left: 0; right: 0; top: 0; background: var(--danger); color: #fff; text-align: center; padding: 6px; z-index: 6; font-size: 14px; }

#side { grid-area: side; background: var(--panel); border-top: 1px solid var(--line); display: flex; flex-direction: column;
  padding-bottom: var(--safe-b); min-height: 0; }
#panel { padding: 10px 12px; }
.ph-head { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.ph-head .sw { width: 14px; height: 14px; border-radius: 50%; background: var(--c); flex: none; }
.ph-head .phase { color: var(--muted); }
.ph-head .spacer { flex: 1; }
.hint { color: var(--muted); font-size: 13.5px; margin: 4px 0 8px; min-height: 1.2em; }
.hint b { color: var(--text); }
.ctrls { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.ctrls .grow { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { background: var(--panel2); border: 0; padding: 8px 12px; min-height: 40px; cursor: pointer; font-weight: 600; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #1a1300; }
.seg button:disabled { opacity: .4; }
.slider-row { display: flex; align-items: center; gap: 8px; width: 100%; margin-bottom: 6px; }
.slider-row input[type=range] { flex: 1; accent-color: var(--accent); height: 30px; }
.slider-row .val { min-width: 2.5em; text-align: center; font-weight: 700; font-size: 18px; }
.cards-btn { position: relative; }
.cards-btn.must { background: var(--danger); color: #fff; border-color: #b33; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(224,82,82,.3); } }
.ticker { font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); padding: 6px 12px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
#logBox { display: none; }
.log-line { padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,.04); font-size: 13px; color: #c4d2e0; }
.log-full { max-height: 60vh; overflow-y: auto; }
.thinking::after { content: ''; display: inline-block; width: 1em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 18px;
  width: min(520px, calc(100% - 24px)); max-height: calc(100dvh - 40px); overflow-y: auto; }
dialog::backdrop { background: rgba(0,0,0,.55); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.gcard { background: #f3ead2; color: #2b2213; border-radius: 10px; padding: 8px 6px; text-align: center; cursor: pointer;
  border: 3px solid transparent; min-height: 104px; display: flex; flex-direction: column; justify-content: space-between; font-size: 12px; }
.gcard .sym { font-size: 30px; line-height: 1.1; }
.gcard .kind { text-transform: uppercase; font-size: 10px; letter-spacing: 1px; opacity: .7; }
.gcard.picked { border-color: var(--accent); transform: translateY(-3px); box-shadow: 0 6px 12px rgba(0,0,0,.4); }
.gcard.owned .tn { font-weight: 800; color: #6a3d00; }
.rules p { margin: 0 0 10px; font-size: 14px; color: #c9d6e3; }

/* Desktop: sidebar on the right */
@media (min-width: 880px) and (min-aspect-ratio: 1/1) {
  #game.active { grid-template-columns: minmax(0, 1fr) 340px; grid-template-rows: auto 1fr; grid-template-areas: "top side" "map side"; }
  #side { border-top: 0; border-left: 1px solid var(--line); }
  #panel { border-bottom: 1px solid var(--line); padding: 14px; }
  #logBox { display: block; flex: 1; overflow-y: auto; padding: 8px 14px; min-height: 0; }
  .ticker { display: none; }
  .pchip { font-size: 13.5px; padding: 6px 10px; }
}
/* Phone landscape: sidebar on the right, compact */
@media (max-height: 500px) and (min-aspect-ratio: 1/1) {
  #game.active { grid-template-columns: minmax(0, 1fr) 260px; grid-template-rows: auto 1fr; grid-template-areas: "top side" "map side"; }
  #side { border-top: 0; border-left: 1px solid var(--line); overflow-y: auto; }
  #topbar { padding: 3px 6px; }
  .icon-btn { width: 34px; height: 34px; }
}
