/* ============================================================
   ARCANE TERRITORIES — "Ink-night cartographer" theme
   Palette is intentionally placeholder: every color routes
   through CSS variables so the final tarot-site palette can be
   swapped in without touching component rules.
   ============================================================ */

:root {
  /* --- palette placeholders (to be replaced) --- */
  --bg-primary: #100d16;
  --bg-elevated: #191320;
  --bg-panel: #221a2e;
  --ink-line: #3a3050;
  --ink-line-soft: #2a2238;
  --text-primary: #e9e1cf;
  --text-muted: #9c90b4;
  --accent-gold: #c9a14f;
  --accent-gold-soft: rgba(201, 161, 79, 0.18);
  --accent-ember: #c25b35;
  --danger: #b04545;

  --terrain-forest: #2e5d3f;
  --terrain-ruin: #59596a;
  --terrain-dragon: #7c2f2f;
  --terrain-city: #3e5180;

  --player-1: #d9a441;
  --player-2: #5fa8a0;
  --player-3: #b75d8c;
  --player-4: #7d9e5a;

  --font-display: "Cinzel", "Noto Serif TC", serif;
  --font-body: "Noto Serif TC", serif;

  --cell: 56px;
  --hud-bottom-h: 64px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-body);
  overscroll-behavior: none;
  overflow-x: hidden;
}

/* Layered atmosphere: vignette + faint grain via gradients */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(201, 161, 79, 0.06), transparent 55%),
    radial-gradient(140% 110% at 50% 110%, rgba(60, 35, 80, 0.35), transparent 60%);
}

.hidden { display: none !important; }

.screen {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  margin: 0 auto;
  max-width: 480px;
  display: flex;
  flex-direction: column;
}

/* ---------------- Setup ---------------- */

#screen-setup { justify-content: center; padding: 24px; }

.setup-card {
  border: 1px solid var(--ink-line);
  background: linear-gradient(180deg, var(--bg-elevated), var(--bg-panel));
  border-radius: 4px;
  padding: 32px 24px;
  box-shadow: 0 0 0 4px var(--bg-primary), 0 0 0 5px var(--ink-line-soft), 0 24px 60px rgba(0, 0, 0, 0.6);
}

.game-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 34px;
  letter-spacing: 0.18em;
  text-align: center;
  margin: 0;
  color: var(--accent-gold);
  text-shadow: 0 2px 18px rgba(201, 161, 79, 0.35);
}

.title-rune { font-size: 18px; vertical-align: middle; margin: 0 10px; opacity: 0.7; }

.game-subtitle {
  text-align: center;
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.5em;
  color: var(--text-muted);
  margin: 6px 0 28px;
}

.setup-field { margin-bottom: 18px; }
.setup-field > label {
  display: block;
  font-size: 13px;
  letter-spacing: 0.2em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.seg-group { display: flex; gap: 8px; }
.seg {
  flex: 1;
  padding: 10px 0;
  font-family: var(--font-display);
  font-size: 16px;
  background: var(--bg-primary);
  color: var(--text-muted);
  border: 1px solid var(--ink-line);
  border-radius: 3px;
  cursor: pointer;
}
.seg.active {
  color: var(--accent-gold);
  border-color: var(--accent-gold);
  background: var(--accent-gold-soft);
}

.name-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.name-row input {
  flex: 1;
  /* flex items refuse to shrink below their intrinsic width without this,
     which pushed inputs and the join button past the card edge on iPhone */
  min-width: 0;
  width: 100%;
  /* 16px+ also prevents iOS Safari from auto-zooming on focus */
  font-size: 16px;
  padding: 10px 12px;
  font-family: var(--font-body);
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1px solid var(--ink-line);
  border-radius: 3px;
  outline: none;
}
.name-row .btn-card { flex: none; white-space: nowrap; }
.name-row input:focus { border-color: var(--accent-gold); }

.player-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
  box-shadow: 0 0 8px currentColor;
}

.btn-primary {
  width: 100%;
  margin-top: 8px;
  padding: 14px 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.3em;
  text-indent: 0.3em;
  color: var(--bg-primary);
  background: linear-gradient(180deg, #e0bb6a, var(--accent-gold));
  border: none;
  border-radius: 3px;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(201, 161, 79, 0.25);
}
.btn-primary:active { transform: translateY(1px); }

.btn-secondary {
  width: 100%;
  margin-top: 10px;
  padding: 12px 0;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.2em;
  text-indent: 0.2em;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--ink-line);
  border-radius: 3px;
  cursor: pointer;
}
.btn-secondary:active { transform: translateY(1px); }

.overlay-title-small { font-size: 20px; }

.setup-hint, .overlay-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin: 14px 0 0;
}

/* ---------------- Lobby ---------------- */

#screen-lobby { justify-content: center; padding: 24px; }

.lobby-code { letter-spacing: 0.35em; text-indent: 0.35em; font-size: 34px; }

.lobby-qr {
  display: flex;
  justify-content: center;
  margin: 6px 0 2px;
}
.lobby-qr img, .lobby-qr canvas {
  width: 168px; height: 168px;
  border: 6px solid #fff;
  border-radius: 4px;
  image-rendering: pixelated;
}

.lobby-players { margin: 14px 0 6px; }
.lobby-player-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 4px;
  font-size: 15px;
  border-bottom: 1px solid var(--ink-line-soft);
}
.lobby-player-row .lobby-status { margin-left: auto; font-size: 12px; color: var(--text-muted); }
.lobby-player-row .lobby-host-tag { font-size: 11px; color: var(--accent-gold); border: 1px solid var(--accent-gold); border-radius: 3px; padding: 1px 6px; }

/* ---------------- Pause banner + button ---------------- */

.pause-banner {
  position: absolute;
  left: 0; right: 0;
  bottom: var(--hud-bottom-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 9px 14px;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--accent-gold-soft);
  border-top: 1px solid var(--accent-gold);
  backdrop-filter: blur(4px);
  z-index: 6;
}

.btn-pause {
  flex: none;
  width: 42px; height: 42px;
  font-size: 16px;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--ink-line);
  border-radius: 3px;
  cursor: pointer;
}

.btn-end-turn:disabled {
  opacity: 0.35;
  cursor: default;
}

.hud-stat-value.timer-low { color: var(--accent-ember); }

/* ---------------- Game chrome ---------------- */

#screen-game { height: 100dvh; overflow: hidden; }

#hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--ink-line-soft);
  background: var(--bg-elevated);
}

.hud-player { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hud-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-round { font-size: 11px; color: var(--text-muted); white-space: nowrap; }

.hud-resources { display: flex; gap: 10px; flex: none; }
.res {
  display: flex; align-items: center; gap: 3px;
  font-size: 14px; font-weight: 600;
}
.res .res-glyph { font-size: 13px; opacity: 0.9; }

#tabs {
  display: flex;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--ink-line);
}
.tab {
  flex: 1;
  position: relative;
  padding: 11px 0 9px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.25em;
  text-indent: 0.25em;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.tab.active { color: var(--accent-gold); border-bottom-color: var(--accent-gold); }

.badge {
  position: absolute;
  top: 6px; right: 14%;
  min-width: 16px; height: 16px;
  padding: 0 4px;
  font-size: 10px; line-height: 16px;
  letter-spacing: 0;
  text-indent: 0;
  color: var(--bg-primary);
  background: var(--accent-ember);
  border-radius: 8px;
}
.badge:empty { display: none; }

#panels { flex: 1; min-height: 0; position: relative; }
.panel { position: absolute; inset: 0; display: none; flex-direction: column; }
.panel.active { display: flex; }

#panel-hand, #panel-market {
  overflow-y: auto;
  padding: 14px 14px calc(var(--hud-bottom-h) + 14px);
}

/* ---------------- Map panel ---------------- */

#action-chips {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  overflow-x: auto;
  flex: none;
}
.chip {
  flex: none;
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-panel);
  border: 1px solid var(--ink-line);
  border-radius: 18px;
  cursor: pointer;
}
.chip:disabled { opacity: 0.35; cursor: default; }
.chip.armed {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
  background: var(--accent-gold-soft);
  box-shadow: 0 0 12px rgba(201, 161, 79, 0.25);
}
.chip .chip-terrain {
  width: 12px; height: 12px;
  border-radius: 2px;
  display: inline-block;
}

#board-viewport {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  touch-action: none;
  background:
    repeating-linear-gradient(0deg, transparent 0 27px, rgba(255,255,255,0.015) 27px 28px),
    repeating-linear-gradient(90deg, transparent 0 27px, rgba(255,255,255,0.015) 27px 28px),
    var(--bg-primary);
  cursor: grab;
}

#board-plane {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.cell {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  border: 1px solid var(--ink-line-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell.tile {
  border: 1px solid rgba(0, 0, 0, 0.55);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  background-size: cover;
  background-position: center;
  cursor: pointer;
}

/* Solid colors remain as fallback while the artwork loads */
.cell.t-forest { background-color: var(--terrain-forest); background-image: url("../assets/tiles/forest.jpg"); }
.cell.t-ruin   { background-color: var(--terrain-ruin);   background-image: url("../assets/tiles/ruin.jpg"); }
.cell.t-dragon { background-color: var(--terrain-dragon); background-image: url("../assets/tiles/dragon.jpg"); }
.cell.t-city   { background-color: var(--terrain-city);   background-image: url("../assets/tiles/city.jpg"); }

.cell .meeple {
  position: absolute;
  right: 4px; bottom: 4px;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.75);
  box-shadow: 0 0 10px currentColor, 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.cell.hl-place {
  border: 1px dashed var(--accent-gold);
  background: var(--accent-gold-soft);
  cursor: pointer;
  animation: pulse 1.4s ease-in-out infinite;
}
.cell.hl-occupy {
  outline: 2px solid var(--accent-gold);
  outline-offset: -3px;
  cursor: pointer;
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

#event-ticker {
  flex: none;
  padding: 8px 14px calc(var(--hud-bottom-h) + 8px);
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--ink-line-soft);
  background: var(--bg-elevated);
  min-height: calc(var(--hud-bottom-h) + 34px);
}

/* ---------------- Cards (hand + market) ---------------- */

.section-title {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 0.35em;
  color: var(--accent-gold);
  margin: 6px 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-title::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--ink-line), transparent);
}

.card {
  border: 1px solid var(--ink-line);
  border-left: 3px solid var(--ink-line);
  background: linear-gradient(180deg, var(--bg-panel), var(--bg-elevated));
  border-radius: 3px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.card.type-mage     { border-left-color: var(--terrain-city); }
.card.type-knight   { border-left-color: var(--terrain-dragon); }
.card.type-artifact { border-left-color: var(--accent-gold); }
.card.type-spell    { border-left-color: var(--accent-ember); }

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card-name { font-weight: 700; font-size: 15px; }
.card-points { font-family: var(--font-display); font-weight: 700; color: var(--accent-gold); font-size: 14px; white-space: nowrap; }
.card-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.card-cost { display: flex; gap: 8px; margin-top: 6px; font-size: 13px; }
.card-cost .cost-item { display: flex; gap: 3px; align-items: center; }
.card-cost .lacking { color: var(--danger); }

.card-actions { margin-top: 8px; display: flex; gap: 8px; }
.btn-card {
  padding: 7px 16px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  color: var(--accent-gold);
  background: none;
  border: 1px solid var(--accent-gold);
  border-radius: 3px;
  cursor: pointer;
}
.btn-card:disabled { opacity: 0.3; cursor: default; }

.fate-condition { font-size: 12px; color: var(--accent-ember); margin-top: 4px; }
.fate-condition.met { color: var(--player-4); }

.empty-note { font-size: 13px; color: var(--text-muted); padding: 6px 0 14px; }

/* ---------------- Bottom HUD ---------------- */

#hud-bottom {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  margin: 0 auto;
  max-width: 480px;
  height: var(--hud-bottom-h);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 14px;
  padding-bottom: env(safe-area-inset-bottom, 0);
  background: linear-gradient(180deg, var(--bg-elevated), var(--bg-primary));
  border-top: 1px solid var(--ink-line);
  z-index: 5;
}

.hud-stat { flex: 1; text-align: center; }
.hud-stat-label { display: block; font-size: 10px; letter-spacing: 0.3em; color: var(--text-muted); }
.hud-stat-value { font-family: var(--font-display); font-weight: 700; font-size: 19px; color: var(--text-primary); }

.btn-end-turn {
  flex: 1.6;
  height: 42px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2em;
  text-indent: 0.2em;
  color: var(--bg-primary);
  background: linear-gradient(180deg, #d8825c, var(--accent-ember));
  border: none;
  border-radius: 3px;
  cursor: pointer;
}
.btn-end-turn:active { transform: translateY(1px); }

/* ---------------- Overlays ---------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(10, 8, 14, 0.92);
  backdrop-filter: blur(6px);
}

.overlay-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
  border: 1px solid var(--ink-line);
  background: linear-gradient(180deg, var(--bg-elevated), var(--bg-panel));
  border-radius: 4px;
  padding: 28px 22px;
  box-shadow: 0 0 0 4px var(--bg-primary), 0 0 0 5px var(--ink-line-soft);
}

.overlay-kicker {
  font-size: 12px;
  letter-spacing: 0.45em;
  text-indent: 0.45em;
  color: var(--text-muted);
  margin: 0 0 6px;
}

.overlay-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 28px;
  color: var(--accent-gold);
  margin: 0 0 16px;
}

.handoff-events {
  list-style: none;
  text-align: left;
  margin: 0 0 16px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg-primary);
  border: 1px solid var(--ink-line-soft);
  border-radius: 3px;
  max-height: 160px;
  overflow-y: auto;
}
.handoff-events:empty { display: none; }
.handoff-events li { margin: 3px 0; }

.end-scores { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.end-scores td {
  padding: 7px 4px;
  font-size: 14px;
  border-bottom: 1px solid var(--ink-line-soft);
}
.end-scores td:first-child { text-align: left; }
.end-scores td:last-child { text-align: right; font-family: var(--font-display); font-weight: 700; }
.end-scores tr.winner td { color: var(--accent-gold); }

/* ---------------- Tile info sheet ---------------- */

#tile-sheet {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(10, 8, 14, 0.45);
}

.sheet-card {
  position: absolute;
  left: 0; right: 0;
  bottom: 0;
  margin: 0 auto;
  max-width: 480px;
  display: flex;
  gap: 14px;
  padding: 16px 18px calc(var(--hud-bottom-h) + 16px);
  background: linear-gradient(180deg, var(--bg-panel), var(--bg-elevated));
  border-top: 2px solid var(--accent-gold);
  box-shadow: 0 -16px 50px rgba(0, 0, 0, 0.65);
  animation: sheet-in 0.22s ease-out;
}

@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

.sheet-art {
  flex: none;
  width: 84px; height: 84px;
  border-radius: 4px;
  border: 1px solid var(--accent-gold);
  background-size: cover;
  background-position: center;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}

.sheet-body { min-width: 0; }
.sheet-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 20px;
  color: var(--accent-gold);
  margin: 0 0 4px;
}
.sheet-line { font-size: 13px; color: var(--text-muted); margin: 2px 0; }
.sheet-line .sheet-strong { color: var(--text-primary); font-weight: 600; }
.sheet-line .player-dot { width: 10px; height: 10px; vertical-align: -1px; margin-right: 4px; }

/* ---------------- Toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--hud-bottom-h) + 18px);
  transform: translateX(-50%);
  z-index: 30;
  max-width: 86vw;
  padding: 10px 18px;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--bg-panel);
  border: 1px solid var(--accent-gold);
  border-radius: 3px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  animation: toast-in 0.18s ease-out;
}
.toast.error { border-color: var(--danger); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
