:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --bg: #2c2c2c;
  --bg-deep: #1a1a1a;
  --stone: #3a3a3a;
  --stone-2: #454545;
  --ink: #e8e4d4;
  --muted: #a8a398;
  --dim: #7a766c;
  --gold: #f0c14b;
  --gold-dim: #c9a227;
  --amber: #e07020;
  --amber-deep: #c45010;
  --line: rgba(240, 193, 75, 0.28);
  --font-display: Palatino, "Palatino Linotype", "Times New Roman", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Palatino, Georgia, serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

.omen, .lede, .how-list, .chronicle-list, .sheet-lead, .event-body {
  -webkit-user-select: text;
  user-select: text;
}

#embers {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.screen {
  display: none;
  position: relative;
  z-index: 1;
  height: 100%;
  padding: calc(var(--sat) + 16px) calc(var(--sar) + 18px) calc(var(--sab) + 18px) calc(var(--sal) + 18px);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

#menu-screen,
#how-screen,
#end-screen {
  align-items: center;
  justify-content: center;
  text-align: center;
}

.menu-mark {
  font-size: 64px;
  color: var(--gold);
  text-shadow: 0 0 24px rgba(224, 112, 32, 0.55);
  line-height: 1;
  margin-bottom: 8px;
  animation: emberPulse 3.2s ease-in-out infinite;
}

.kicker {
  font-size: 11px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--amber);
  margin-bottom: 8px;
}

h1, h2 {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.04em;
}

h1 {
  font-size: clamp(32px, 8vw, 48px);
  margin-bottom: 12px;
}

h2 {
  font-size: 26px;
  margin-bottom: 12px;
}

.lede {
  max-width: 420px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 15px;
  margin: 0 auto 22px;
}

.menu-runes {
  display: flex;
  gap: 18px;
  justify-content: center;
  margin-bottom: 28px;
  font-size: 28px;
  color: var(--gold-dim);
}

.menu-runes span {
  display: grid;
  place-items: center;
  width: 52px;
  height: 64px;
  background: linear-gradient(165deg, #5a5a5a, #2a2a2a);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 220, 140, 0.2), 0 8px 16px rgba(0, 0, 0, 0.35);
}

.menu-actions,
.end-panel,
.how-panel {
  width: min(420px, 100%);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--stone);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 16px;
  letter-spacing: 0.06em;
  padding: 14px 18px;
  min-height: 48px;
  border-radius: 10px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: linear-gradient(180deg, #e07020, #c45010);
  border-color: #f0c14b;
  color: #1a1a1a;
  font-weight: 700;
}

.btn.ghost {
  background: transparent;
  color: var(--gold);
}

.btn:disabled {
  opacity: 0.45;
  pointer-events: none;
}

.panel {
  background: linear-gradient(180deg, rgba(58, 58, 58, 0.92), rgba(26, 26, 26, 0.94));
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px 18px 18px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
}

.how-list {
  text-align: left;
  color: var(--muted);
  line-height: 1.55;
  font-size: 14px;
  padding-left: 18px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.how-list strong {
  color: var(--gold);
}

.how-note {
  text-align: left;
  color: var(--dim);
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 16px;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 10px;
}

.hud-clock {
  font-family: var(--font-display);
  color: var(--gold);
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.hud-when {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.sight-wrap {
  text-align: right;
  border: 1px solid var(--line);
  background: rgba(26, 26, 26, 0.55);
  border-radius: 10px;
  padding: 6px 10px;
  min-width: 72px;
}

.sight-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--amber);
}

.sight-val {
  font-family: var(--font-display);
  font-size: 20px;
  color: var(--gold);
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.stat {
  background: var(--bg-deep);
  border: 1px solid rgba(138, 138, 138, 0.28);
  border-radius: 8px;
  padding: 6px 4px;
  text-align: center;
}

.stat-k {
  display: block;
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
}

.stat-v {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--ink);
}

.stat.warn .stat-v {
  color: var(--amber);
}

.play-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.cast-col, .act-col {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rune-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  min-height: 118px;
  align-items: center;
}

.rune-stone {
  width: 86px;
  height: 108px;
  border-radius: 14px 14px 18px 18px;
  background: linear-gradient(165deg, #6a6a6a 0%, #3a3a3a 42%, #1f1f1f 100%);
  border: 2px solid #b08a2a;
  box-shadow:
    inset 0 2px 0 rgba(255, 220, 140, 0.28),
    inset 0 -10px 18px rgba(0, 0, 0, 0.5),
    0 10px 22px rgba(0, 0, 0, 0.4),
    0 0 18px rgba(224, 112, 32, 0.18);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  animation: settle 0.55s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.rune-stone:nth-child(2) { animation-delay: 0.08s; }
.rune-stone:nth-child(3) { animation-delay: 0.16s; }

.rune-glyph {
  font-size: 42px;
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 0 14px rgba(240, 193, 75, 0.55);
}

.rune-name {
  margin-top: 6px;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #d8c48a;
}

.rune-empty {
  width: 86px;
  height: 108px;
  border-radius: 14px;
  border: 1px dashed rgba(168, 163, 152, 0.35);
  background: rgba(26, 26, 26, 0.35);
}

.omen {
  font-family: var(--font-display);
  font-style: italic;
  text-align: center;
  color: #d7c9a0;
  line-height: 1.45;
  font-size: 15px;
  min-height: 44px;
}

.cast-meta {
  display: flex;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 11px;
  color: var(--dim);
  min-height: 16px;
}

.cast-meta span {
  border: 1px solid rgba(240, 193, 75, 0.18);
  border-radius: 999px;
  padding: 3px 8px;
}

.forecast-block {
  background: rgba(26, 26, 26, 0.55);
  border: 1px solid rgba(138, 138, 138, 0.28);
  border-radius: 12px;
  padding: 12px;
}

.block-label {
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--amber);
  margin-bottom: 8px;
}

.forecast-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  align-items: center;
  margin-bottom: 8px;
}

.forecast-name {
  font-size: 13px;
  color: var(--ink);
}

.forecast-pct {
  font-family: var(--font-display);
  color: var(--gold);
  font-size: 13px;
}

.bar {
  grid-column: 1 / -1;
  height: 6px;
  background: #2a2a2a;
  border-radius: 99px;
  overflow: hidden;
}

.bar > i {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--amber), var(--gold));
  border-radius: inherit;
  animation: barFill 0.7s ease forwards;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 8px;
}

.act-btn {
  text-align: left;
  background: var(--stone-2);
  border: 1px solid rgba(240, 193, 75, 0.2);
  color: var(--ink);
  border-radius: 12px;
  padding: 11px 12px;
  min-height: 52px;
  cursor: pointer;
  touch-action: manipulation;
  font-family: var(--font-body);
}

.act-btn strong {
  display: block;
  font-family: var(--font-display);
  color: var(--gold);
  font-size: 15px;
  margin-bottom: 2px;
}

.act-btn em {
  font-style: normal;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.chronicle-btn {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  align-self: center;
  background: transparent;
  border: 0;
  color: var(--gold-dim);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 11px;
  padding: 10px;
  cursor: pointer;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 5;
  background: rgba(12, 12, 12, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 18px 14px calc(var(--sab) + 16px);
}

.sheet[hidden] {
  display: none;
}

.sheet-card {
  width: min(520px, 100%);
  max-height: min(86vh, 720px);
  overflow: auto;
  background: linear-gradient(180deg, #3f3f3f, #242424);
  border: 1px solid var(--line);
  border-radius: 16px 16px 12px 12px;
  padding: 20px 16px 16px;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.45);
}

.sheet-lead {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 12px;
  line-height: 1.45;
}

.verdict {
  display: inline-block;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  border-radius: 99px;
  padding: 4px 10px;
  margin-bottom: 10px;
}

.verdict.true { background: rgba(240, 193, 75, 0.18); color: var(--gold); }
.verdict.twist { background: rgba(224, 112, 32, 0.18); color: var(--amber); }
.verdict.false { background: rgba(80, 80, 80, 0.5); color: #c8c8c8; }

.event-name {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--gold);
  margin-bottom: 8px;
}

.event-body {
  color: var(--muted);
  line-height: 1.5;
  font-size: 14px;
  margin-bottom: 12px;
}

.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.compare div {
  background: rgba(26, 26, 26, 0.5);
  border-radius: 10px;
  padding: 8px;
  font-size: 12px;
  color: var(--muted);
}

.compare strong {
  display: block;
  color: var(--ink);
  font-size: 13px;
  margin-top: 4px;
}

.deltas {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.delta {
  font-size: 12px;
  border-radius: 99px;
  padding: 4px 8px;
  background: #333;
}

.delta.up { color: var(--gold); }
.delta.down { color: var(--amber); }

.chronicle-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.chronicle-list li {
  background: rgba(26, 26, 26, 0.45);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--muted);
}

.chronicle-list b {
  color: var(--gold);
  font-weight: 600;
}

.end-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.end-stats div {
  background: rgba(26, 26, 26, 0.45);
  border-radius: 10px;
  padding: 8px;
  font-size: 12px;
  color: var(--dim);
}

.end-stats strong {
  display: block;
  color: var(--gold);
  font-size: 18px;
  font-family: var(--font-display);
}

@keyframes settle {
  from { transform: translateY(-36px) rotate(-16deg); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes barFill {
  from { width: 0; }
  to { width: var(--w); }
}

@keyframes emberPulse {
  0%, 100% { opacity: 0.65; filter: drop-shadow(0 0 6px rgba(224, 112, 32, 0.3)); }
  50% { opacity: 1; filter: drop-shadow(0 0 16px rgba(240, 193, 75, 0.55)); }
}

@media (orientation: landscape) and (max-height: 520px) {
  .screen {
    padding-top: calc(var(--sat) + 8px);
    padding-bottom: calc(var(--sab) + 8px);
  }

  .menu-mark { display: none; }
  .menu-runes { display: none; }
  .lede { margin-bottom: 12px; }

  #game-screen.active {
    display: grid;
    grid-template-rows: auto auto 1fr auto;
    grid-template-columns: 1fr 1.15fr;
    gap: 8px 14px;
  }

  .hud { grid-column: 1 / -1; margin-bottom: 0; }
  .stat-row { grid-column: 1 / -1; margin-bottom: 0; }

  .play-layout {
    display: contents;
  }

  .cast-col { min-height: 0; }
  .act-col { min-height: 0; overflow: auto; }

  .rune-stone, .rune-empty {
    width: 70px;
    height: 88px;
  }

  .rune-glyph { font-size: 34px; }
  .omen { font-size: 13px; min-height: 0; }
  .chronicle-btn { grid-column: 1 / -1; }
}

@media (min-width: 820px) {
  .play-layout {
    display: grid;
    grid-template-columns: 1fr 1.1fr;
    gap: 18px;
    align-items: start;
  }
}
