/* Habita — visual tokens per SPEC.md §5.8 (Bronze Age palette, D-23) */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: #FFFFFF;
  color: #24211E; /* warm ink */
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#app { max-width: 920px; margin: 0 auto; padding: 24px 16px; }

.screen { display: flex; flex-direction: column; gap: 16px; align-items: center; }

h1 { font-size: 46px; letter-spacing: 1px; margin-top: 10vh; }
h2 { margin-top: 8px; }
.tagline { color: #6B645C; }
.muted { color: #7A736A; }

/* Buttons */
.btn {
  background: #F2EDE6; border: 1px solid #DCD3C7; padding: 8px 16px;
  border-radius: 8px; font-size: 14px; cursor: pointer; color: #222;
}
.btn:hover:not(:disabled) { background: #E8E1D6; }
.btn.primary { background: #39587E; color: #fff; border-color: #39587E; } /* lapis */
.btn.primary:hover:not(:disabled) { background: #2F4A6B; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.big { font-size: 17px; padding: 12px 28px; }
.btn.small { font-size: 12px; padding: 3px 10px; }
.menu-buttons { display: flex; gap: 12px; }
.version { color: #9A938A; font-size: 13px; margin-top: 24px; }

/* Color select */
.swatches { display: grid; grid-template-columns: repeat(3, 112px); gap: 14px; }
.swatch {
  height: 72px; border: none; border-radius: 10px; cursor: pointer;
  color: #fff; font-weight: 600; text-transform: capitalize;
  display: flex; align-items: flex-end; justify-content: center; padding: 6px;
}
.swatch:hover { transform: scale(1.05); }
.swatch-label { text-shadow: 0 1px 3px rgba(0, 0, 0, 0.45); }

/* Game screen */
.game { align-items: stretch; }
.game-top { display: flex; justify-content: space-between; align-items: center; width: 100%; }
.turn-label { font-weight: 600; display: flex; gap: 8px; align-items: center; font-size: 18px; }
.meta { color: #666; font-variant-numeric: tabular-nums; }
.game-main { display: flex; gap: 20px; align-items: flex-start; justify-content: center; flex-wrap: wrap; }

.board {
  display: grid;
  --cell: 76px; /* 5×5 board, larger squares (U-3); columns/rows set inline from SIZE */
  gap: 2px; /* white gutters on the white background (G-2/U-3) */
}
.cell {
  background: #C6BFB4; border-radius: 3px; /* warm stone */
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700; color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4); user-select: none;
  position: relative; /* anchors the keyboard cursor ring (U-28) */
}
.cell.legal { cursor: pointer; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.12); }
.cell.legal:hover { filter: brightness(0.9); } /* warm stone #C6BFB4 → darker on hover */
.cell.owner-red { background: #9C4A3B; }
.cell.owner-blue { background: #3E6087; }
.cell.owner-yellow { background: #B8912F; }
.cell.owner-green { background: #6E8B5E; }
.cell.owner-orange { background: #C2763C; }
.cell.owner-purple { background: #6B4A6B; }
.cell.selected { outline: 3px dashed var(--human-color); outline-offset: -3px; }
.cell.cpu-target { outline: 3px solid var(--cpu-color); outline-offset: -3px; }
.cell.pulse { animation: pulse 0.5s ease; }
@keyframes pulse { 0% { transform: scale(0.6); } 60% { transform: scale(1.12); } 100% { transform: scale(1); } }
.cell.own-selected { outline: 3px dashed #fff; outline-offset: -3px; }

/* U-28: keyboard cursor. A pseudo-element rather than a fourth outline or box-shadow,
   so it can sit on a square that is simultaneously legal, selected, and last-moved. */
.cell.cursor::after {
  content: ''; position: absolute; inset: 2px; border-radius: 2px;
  border: 2px solid #24211E; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.55);
  pointer-events: none;
}
.draft-cell { cursor: pointer; }
.draft-cell:hover, .draft-cell.cursor { background: var(--draft-color); }
.cell.hit { animation: hitflash 0.4s ease; }
@keyframes hitflash { 30% { filter: brightness(0.55); } }

.side { width: 250px; display: flex; flex-direction: column; gap: 14px; }

/* Coin-flip panel (G-15) */
.flip-panel { border: 1px solid #ddd; border-radius: 10px; padding: 12px; text-align: center; }
.flip-title { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: #888; }
.flip-digit { font-size: 56px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; color: #bbb; }
.flip-digit.live { color: #333; animation: jitter 0.12s infinite; }
@keyframes jitter { 50% { transform: translateY(-2px); } }
.flip-digit.final-one { color: #5F7D4F; }
.flip-digit.final-zero { color: #9C4A3B; }
.flip-sub { font-size: 13px; color: #666; min-height: 18px; }
.flip-result { font-weight: 600; min-height: 20px; }

.players { display: flex; flex-direction: column; gap: 4px; }
.player-row { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; }
.player-row.active { background: #F2EDE6; font-weight: 600; }
.player-row.dead { opacity: 0.4; text-decoration: line-through; }
.count { margin-left: auto; font-variant-numeric: tabular-nums; }
.chip { width: 14px; height: 14px; border-radius: 4px; display: inline-block; flex: none; }
.status { min-height: 42px; color: #444; font-size: 14px; }

/* Mini-log & last-move (U-23) */
.mini-log { display: flex; flex-direction: column; gap: 2px; min-height: 58px; }
.mini-log-line { font-size: 12px; color: #aaa; }
.mini-log-line:first-child { color: #555; }
.cell.last-move { box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.3); }

/* Stats (U-24/U-25) */
table.stats { border-collapse: collapse; font-size: 13px; margin: 2px 0; }
.stats th, .stats td { padding: 3px 12px 3px 0; text-align: left; border-bottom: 1px solid #eee; font-weight: normal; }
.stats th { color: #888; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
.stats td .chip { width: 11px; height: 11px; border-radius: 3px; vertical-align: middle; margin-right: 4px; }
.lifetime { text-align: center; }
.expander-row td { text-align: center; padding: 10px; background: #fafafa; }
.tier-caption { font-size: 13px; margin: -8px 0 0; min-height: 2.9em; } /* reserves two lines so tier toggles never resize the panel */

/* Settings */
.settings { display: flex; flex-direction: column; gap: 14px; width: 360px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.setting-label { font-weight: 600; }
.seg-group { display: flex; gap: 4px; }
.btn.seg { padding: 6px 12px; }
.btn.seg.active { background: #39587E; color: #fff; border-color: #39587E; }

/* Dialogs */
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.dialog {
  background: #fff; border-radius: 12px; padding: 24px; max-width: 440px;
  display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}
.dialog-buttons { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }
.save-status { font-size: 13px; color: #666; }

/* Keyboard hint and cheat sheet (U-28) */
.keys-hint { font-size: 12px; text-align: center; }
table.keys { border-collapse: collapse; font-size: 14px; }
.keys td { padding: 4px 12px 4px 0; vertical-align: baseline; }
.keys td:first-child { white-space: nowrap; }
kbd {
  font: inherit; font-size: 12px; background: #F2EDE6; border: 1px solid #DCD3C7;
  border-radius: 5px; padding: 2px 7px; white-space: nowrap;
}
.hidden { display: none !important; }

/* History */
.hist-list { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.hist-row {
  display: grid; grid-template-columns: 1.4fr 0.5fr 1fr 1fr; gap: 8px; align-items: center;
  text-align: left; padding: 10px 12px; border: 1px solid #ddd; border-radius: 8px;
  background: #FBF9F6; cursor: pointer; font-size: 14px; color: #24211E;
}
.hist-row:hover { background: #F4EFE8; }
.hist-row .chip { vertical-align: middle; margin-right: 4px; }
.detail p .chip { vertical-align: middle; margin: 0 2px; }
.table-wrap { width: 100%; overflow-x: auto; }
table.log { border-collapse: collapse; width: 100%; font-size: 13px; }
.log th, .log td { border-bottom: 1px solid #e5e5e5; padding: 6px 8px; text-align: left; white-space: nowrap; }
.log td .chip { width: 11px; height: 11px; border-radius: 3px; vertical-align: middle; margin-right: 4px; }
.elim-row td { background: #FAF2EE; }

/* --- Small screens (U-27): board scales to the viewport, panels go full-width --- */
@media (max-width: 640px) {
  #app { padding: 16px 10px; }
  h1 { margin-top: 6vh; }
  .board { --cell: min(76px, calc((100vw - 28px) / 5)); }
  .cell { font-size: clamp(13px, 4.5vw, 20px); }
  .game-main { gap: 14px; }
  .side { width: 100%; max-width: 420px; }
  .settings { width: 100%; max-width: 360px; }
  .swatches { grid-template-columns: repeat(3, minmax(88px, 1fr)); width: 100%; max-width: 380px; }
  .game-top { flex-wrap: wrap; row-gap: 4px; }
  .dialog { margin: 0 12px; }
  .hist-row { grid-template-columns: 1.3fr 0.6fr 1fr 1fr; gap: 4px; padding: 8px; font-size: 12px; }
  .keys-hint { display: none; } /* U-28 keys still work with a paired keyboard; the hint is just noise on a phone */
}

/* Games whose move log was pruned to make room (D-21) — result and stats kept. */
.hist-row.no-detail { opacity: 0.72; }
.storage-note { text-align: center; max-width: 560px; }

/* Brand mark above the wordmark on the menu (D-23). */
.brand-mark { width: 96px; height: 96px; margin-top: 8vh; }
.menu h1 { margin-top: 4px; }
@media (max-width: 640px) {
  .brand-mark { width: 74px; height: 74px; margin-top: 4vh; }
}

/* Online play (SPEC.md §13) — lobby, draft, and the room entry screen.
   Same Bronze Age tokens as everything above; no new colours introduced. */
.field { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; }
.field label { color: #7A736A; font-size: 14px; min-width: 84px; text-align: right; }

.text-input, .select {
  background: #FFFDF9; border: 1px solid #DCD3C7; border-radius: 8px;
  padding: 8px 12px; font-size: 15px; color: #24211E; font-family: inherit;
}
.text-input:focus, .select:focus { outline: 2px solid #39587E; outline-offset: 1px; }
.code-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 4px; text-transform: uppercase; width: 190px; text-align: center; font-size: 19px;
}

.room-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 5px; background: #F2EDE6; border: 1px solid #DCD3C7;
  border-radius: 8px; padding: 2px 12px;
}
.share-link {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
  max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.lobby { gap: 18px; }
.seat-list { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 420px; }
.seat {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid #DCD3C7; border-radius: 10px; padding: 8px 12px; background: #FFFDF9;
}
.seat.me { border-color: #39587E; background: #F7F4EF; }
.seat-name { font-weight: 600; }
.seat-tag { font-size: 12px; margin-left: auto; }
.seat .btn.tiny { font-size: 11px; padding: 2px 8px; margin-left: 8px; }

.color-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; }
.mini-swatch {
  width: 30px; height: 30px; border-radius: 8px; border: 2px solid transparent; cursor: pointer;
}
.mini-swatch.picked { border-color: #24211E; transform: scale(1.12); }
.mini-swatch:disabled { opacity: 0.25; cursor: default; }

.lobby-settings { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.lobby-controls { display: flex; gap: 12px; align-items: center; }

.draft-board { display: grid; gap: 6px; }
.draft-board .cell:disabled { cursor: default; }

@media (max-width: 640px) {
  .field label { min-width: 0; text-align: left; }
  .share-link { max-width: 80vw; }
}
