:root {
  color-scheme: dark;
  --bg: #14181f;
  --surface: #1d232c;
  --surface-2: #262e39;
  --line: #333d4a;
  --text: #e8ecf1;
  --muted: #9aa5b4;
  --accent: #f2c94c;
  --accent-text: #1b1b1b;
  --go: #6fcf97;
  --danger: #eb5757;
  --radius: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}
#app { min-height: 100%; display: flex; flex-direction: column; }
.loading { padding: 2rem; color: var(--muted); }

a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.2rem; letter-spacing: .02em; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
h4 { font-size: .9rem; color: var(--muted); font-weight: 600; margin-top: .75rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.hint { color: var(--accent); font-size: .92rem; }

button, input, select {
  font: inherit;
  color: inherit;
}
button {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .45rem .8rem;
  cursor: pointer;
  min-height: 40px;
}
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.link { background: none; border: 0; padding: .2rem 0; min-height: 0; color: var(--accent); text-align: left; }
button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
input, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .55rem .7rem;
  margin-top: .25rem;
}
label { display: block; margin-bottom: .8rem; color: var(--muted); font-size: .9rem; }
label.radio { display: flex; gap: .6rem; align-items: center; color: var(--text); font-size: 1rem; }
label.radio input { width: auto; margin: 0; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; }

/* header */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: calc(.6rem + var(--safe-top)) 1rem .6rem;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.bar a { color: var(--text); text-decoration: none; }
.bar h1 { margin: 0; }
.bar .me { color: var(--muted); white-space: nowrap; }

/* pages */
.page { width: 100%; max-width: 40rem; margin: 0 auto; padding: 1rem 16px calc(2rem + var(--safe-bottom)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.card.narrow { max-width: 26rem; margin: 2rem auto; }
.card h3 { margin-top: 1rem; }
.game-list { display: flex; flex-direction: column; gap: .5rem; margin-top: .5rem; }
.game-item {
  display: grid; grid-template-columns: 1fr auto; gap: .1rem 1rem; align-items: center;
  padding: .7rem .8rem; border-radius: 8px; background: var(--surface-2); color: var(--text); text-decoration: none;
  border: 1px solid transparent;
}
.game-item .who { font-weight: 600; }
.game-item .meta { color: var(--muted); font-size: .85rem; grid-row: 2; }
.game-item .badge { grid-row: 1 / span 2; grid-column: 2; font-size: .85rem; color: var(--muted); }
.game-item.your-turn { border-color: var(--go); }
.game-item.your-turn .badge { color: var(--go); font-weight: 600; }
details summary { cursor: pointer; color: var(--muted); margin-top: .75rem; }

/* game */
.game-top {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem;
  padding: .5rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line);
}
.game-top .title { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; }
.game-top .actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.game-top .actions select { width: auto; margin: 0; }
.dot { width: .8rem; height: .8rem; border-radius: 50%; display: inline-block; }
.chip { font-size: .8rem; padding: .1rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.chip.go { background: var(--go); color: #10251a; font-weight: 600; }

/* height from the window, not from the panel content (flex-basis auto) */
.game { flex: 1 1 auto; display: flex; min-height: 0; height: calc(100vh - 7.5rem); height: calc(100dvh - 7.5rem); }
.map-wrap { position: relative; flex: 1; min-width: 0; }
.map-frame { position: absolute; inset: 0; --ruler-w: 26px; --ruler-h: 18px; }
.map-scroll { position: absolute; top: 0; right: 0; left: var(--ruler-w); bottom: var(--ruler-h); overflow: auto; background: #000; -webkit-overflow-scrolling: touch; }
.ruler { position: absolute; display: block; }
.ruler.rows { left: 0; top: 0; width: var(--ruler-w); height: calc(100% - var(--ruler-h)); }
.ruler.cols { left: var(--ruler-w); bottom: 0; width: calc(100% - var(--ruler-w)); height: var(--ruler-h); }
.map-scroll canvas { display: block; }
.map-layer { position: relative; width: max-content; }
.map-layer canvas.band { position: absolute; left: 0; top: 0; pointer-events: none; }
.zoom { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; }
.zoom button { width: 40px; height: 40px; padding: 0; font-size: 1.3rem; background: rgba(29, 35, 44, .9); }

.panel {
  width: 21rem; flex: none; overflow-y: auto; overflow-x: hidden; background: var(--surface); border-left: 1px solid var(--line);
  padding: .75rem .75rem calc(.75rem + var(--safe-bottom));
}
.box { margin-bottom: 1rem; }
.box.attention { background: var(--surface-2); border-radius: var(--radius); padding: .6rem .75rem; }
.box ul { list-style: none; padding: 0; margin: 0; }
.box li { padding: .15rem 0; }
.stats { color: var(--muted); font-size: .92rem; }
.dpad { display: grid; grid-template-columns: repeat(3, 52px); gap: 6px; margin: .5rem 0 .75rem; }
.dpad button { height: 52px; font-size: 1.3rem; padding: 0; }
.dpad .wait { font-size: 1.6rem; }
.orders { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .5rem; }
.orders button { font-size: .9rem; }
.production { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem; margin-bottom: .75rem; }
.production button { display: flex; flex-direction: column; align-items: flex-start; gap: 0; text-align: left; font-size: .9rem; line-height: 1.25; hyphens: auto; -webkit-hyphens: auto; }
.production small { opacity: .75; font-size: .78rem; }
.stack { display: flex; flex-direction: column; align-items: flex-start; }
.log ul { font-size: .88rem; }
.log summary { margin: 0 0 .4rem; }

@media (max-width: 760px) {
  .game { flex-direction: column; height: auto; flex: 1; }
  .map-wrap { height: 52vh; height: 52dvh; flex: none; }
  .panel { width: auto; border-left: 0; border-top: 1px solid var(--line); flex: 1; }
  .game-top .actions { width: 100%; }
  .game-top .actions button { flex: 1; }
}

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(1.5rem + var(--safe-bottom)); transform: translate(-50%, 1rem);
  max-width: calc(100% - 32px); padding: .7rem 1rem; border-radius: 8px; z-index: 10;
  background: var(--danger); color: #fff; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.info { background: var(--surface-2); border: 1px solid var(--line); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
