:root {
  --font-primary: 'RocknRoll One', system-ui, sans-serif;
  --font-mark: 'Source Sans 3', system-ui, sans-serif;
  --font: system-ui, -apple-system, sans-serif;

  --bg-primary: #0a0e14;
  --bg-card: #12161c;
  --bg-panel: #161920;
  --bg-sunken: #0e1014;
  --border: #1e242d;
  --line-soft: #161b22;
  --gold: #0fb0a2;
  --gold-light: #5ecfc4;
  --text-primary: #e8e6e0;
  --text-secondary: #9a9890;
  --muted: #6b7280;
  --accent: var(--gold);
  --radius: 6px;
  --page-pad-x: clamp(16px, 4vw, 44px);
  --page-max-width: 1400px;

  --fire: #ff6b35;
  --ice: #38bdf8;
  --lightning: #9b7ed9;

  --footer-bg: var(--bg-primary);
  --footer-text: #6b7280;
  --footer-text-secondary: #b4bcc8;
  --footer-border: rgba(55, 65, 81, 0.5);
}

* { box-sizing: border-box; }

html {
  background: var(--bg-primary);
  color-scheme: dark;
}

html, body {
  margin: 0;
  min-height: 100vh;
}

body {
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(15, 176, 162, 0.1), transparent),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(29, 155, 240, 0.04), transparent),
    linear-gradient(180deg, var(--bg-primary) 0%, #080b0f 100%);
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

main {
  flex: 1 0 auto;
  padding-block: 1.25rem 2rem;
}

.page-container {
  width: 100%;
  max-width: var(--page-max-width);
  margin-inline: auto;
  padding-inline: var(--page-pad-x);
}

/* ── Header ───────────────────────────────────────────────────────────── */

.header-bar {
  --header-by: #5c5a55;
  background: linear-gradient(#14171ef2, #0d0f13e6);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid #0fb0a233;
  padding: 0.65rem 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  min-height: 4.25rem;
}

.header-brand {
  display: flex;
  flex-direction: row;
  align-items: baseline;
  gap: 0.85rem;
  flex-wrap: nowrap;
  min-width: 0;
}

.site-logo-title {
  margin: 0;
  font-family: var(--font-primary);
  font-weight: 400;
  font-size: 1.5rem;
  letter-spacing: 0.01em;
  line-height: 1.4;
  padding-bottom: 0.12em;
  color: var(--text-primary);
  -webkit-text-fill-color: var(--text-primary);
  opacity: 0.92;
}

.site-home-link {
  color: inherit;
  text-decoration: none;
}

.site-home-link:hover {
  color: var(--gold-light);
  -webkit-text-fill-color: var(--gold-light);
}

.header-by {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  color: var(--header-by);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}

.kaia-mark {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1;
}

.kaia-mark:hover .kaia-mark-kaia {
  color: #12c9b8;
  -webkit-text-fill-color: #12c9b8;
}

.kaia-mark-kaia {
  font-family: var(--font-primary);
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  color: #0fb0a2;
  -webkit-text-fill-color: #0fb0a2;
}

.kaia-mark-tools {
  font-family: var(--font-mark);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-primary);
  -webkit-text-fill-color: var(--text-primary);
}

.header-encounter {
  margin: 0;
  font-family: var(--font-mark);
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.85;
}

/* ── Layout ───────────────────────────────────────────────────────────── */

.view {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 24px;
  align-items: start;
}

.stage {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.card h2 {
  margin: 0 0 8px;
  font-family: var(--font-primary);
  font-size: 0.95rem;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.card > .hint:first-of-type { margin-top: 0; }

.hint {
  margin: 10px 0 0;
  color: var(--text-secondary);
  font-size: 0.75rem;
  line-height: 1.6;
}

/* Keyboard legend — two-column key / action list */
.kbd-legend-hint {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 7px;
  width: 100%;
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.35;
}

.kbd-legend-row {
  display: grid;
  grid-template-columns: minmax(0, 0.85fr) 9.75rem;
  align-items: center;
  column-gap: 10px;
  min-height: 1.75rem;
}

.kbd-legend-keys {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 5px 6px;
  min-width: 0;
}

.kbd-legend-action {
  color: var(--text-secondary);
  font-size: 0.78rem;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.kbd-legend-sep {
  color: var(--text-secondary);
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  text-transform: lowercase;
  opacity: 0.65;
  flex-shrink: 0;
}

.kbd-legend-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 5px 6px;
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.45em;
  min-height: 1.45em;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: linear-gradient(180deg, #1a1f28 0%, var(--bg-sunken) 100%);
  color: var(--text-primary);
  font-family: var(--font-mark);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.kbd-cluster {
  display: inline-grid;
  gap: 2px;
  vertical-align: middle;
  flex-shrink: 0;
}

.kbd-cluster .kbd {
  min-width: 1.3em;
  min-height: 1.3em;
  padding: 1px 5px;
  font-size: 0.62rem;
}

.kbd-wasd {
  grid-template-columns: repeat(3, auto);
  grid-template-rows: repeat(2, auto);
}

.kbd-wasd .kbd:nth-child(1) { grid-column: 2; }
.kbd-wasd .kbd:nth-child(2) { grid-column: 1; grid-row: 2; }
.kbd-wasd .kbd:nth-child(3) { grid-column: 2; grid-row: 2; }
.kbd-wasd .kbd:nth-child(4) { grid-column: 3; grid-row: 2; }

.kbd-arrows {
  grid-template-columns: repeat(3, auto);
  grid-template-rows: repeat(2, auto);
}

.kbd-arrows .kbd:nth-child(1) { grid-column: 2; }
.kbd-arrows .kbd:nth-child(2) { grid-column: 1; grid-row: 2; }
.kbd-arrows .kbd:nth-child(3) { grid-column: 2; grid-row: 2; }
.kbd-arrows .kbd:nth-child(4) { grid-column: 3; grid-row: 2; }

.sim-hints-card .kbd-legend-hint.is-gamepad .kbd-legend-row {
  grid-template-columns: minmax(0, 1fr) 7.5rem;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
}

.slide-spell {
  margin: 0;
  font-family: var(--font-primary);
  font-size: 1.15rem;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.sim-status-card .slide-spell + .hint {
  margin-top: 8px;
}

.sim-status-card .hint:empty {
  display: none;
}

.text-fire { color: var(--fire); }
.text-ice { color: var(--ice); }
.text-lightning { color: var(--lightning); }
.text-dark-current,
.text-dark-current-2,
.text-dark-current-3 { color: #e85d4c; }
.text-severed-dark-current { color: #e85d4c; }
.text-vacuum-wave { color: #9b6fd4; }

/* ── Order list ───────────────────────────────────────────────────────── */

.order-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.order-item {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius);
  background: var(--bg-sunken);
  border: 1px solid var(--line-soft);
  font-size: 0.8125rem;
}

.order-num {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  background: #1a1f28;
  color: var(--text-secondary);
  font-family: var(--font-primary);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}

.order-empty { color: #6b7280; font-style: italic; }
.order-element { font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; }
.order-fire .order-element { color: var(--fire); }
.order-ice .order-element { color: var(--ice); }
.order-lightning .order-element { color: var(--lightning); }
.order-item[class*="order-dark-current"] .order-element { color: #e85d4c; }
.order-vacuum-wave .order-element { color: #9b6fd4; }
.order-item.is-set { border-color: var(--border); }

.order-fire.is-current { border-color: var(--fire); }
.order-ice.is-current { border-color: var(--ice); }
.order-lightning.is-current { border-color: var(--lightning); }
.order-item[class*="order-dark-current"].is-current { border-color: #e85d4c; }
.order-vacuum-wave.is-current { border-color: #9b6fd4; }
.order-fire.is-current .order-head { color: var(--fire); }
.order-ice.is-current .order-head { color: var(--ice); }
.order-lightning.is-current .order-head { color: var(--lightning); }
.order-item[class*="order-dark-current"].is-current .order-head { color: #e85d4c; }
.order-vacuum-wave.is-current .order-head { color: #9b6fd4; }
.order-fire .order-num { background: rgba(255, 107, 53, 0.18); color: var(--fire); }
.order-ice .order-num { background: rgba(56, 189, 248, 0.18); color: var(--ice); }
.order-lightning .order-num { background: rgba(155, 126, 217, 0.18); color: var(--lightning); }
.order-item[class*="order-dark-current"] .order-num { background: rgba(232, 93, 76, 0.18); color: #e85d4c; }
.order-vacuum-wave .order-num { background: rgba(155, 111, 212, 0.18); color: #9b6fd4; }

.order-item .sim-wave-mark { justify-self: end; }

.order-item.is-hoverable {
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.order-item.is-hoverable:hover {
  border-color: var(--gold);
  background: rgba(15, 176, 162, 0.1);
}

.sim-wave-mark {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 4px;
  font-family: var(--font-primary);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}

.sim-wave-mark.is-clean {
  color: rgba(88, 250, 170, 0.95);
  background: rgba(88, 250, 170, 0.14);
  border: 1px solid rgba(88, 250, 170, 0.45);
}

.sim-wave-mark.is-clipped {
  color: var(--fire);
  background: rgba(255, 107, 53, 0.14);
  border: 1px solid rgba(255, 107, 53, 0.45);
}

.sim-wave-status { color: var(--text-secondary); }

.order-item.is-clean .order-element { color: rgba(88, 250, 170, 0.95); }
.order-item.is-clipped .order-element { color: var(--fire); }
.order-item.is-clipped { border-color: rgba(255, 107, 53, 0.45); }

/* ── Buttons ──────────────────────────────────────────────────────────── */

.button-row { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; }

.btn {
  flex: 1;
  min-width: 90px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-sunken);
  color: var(--text-primary);
  font-family: var(--font-primary);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
}

.btn:hover:not(:disabled) {
  border-color: var(--gold);
  background: #1a1f28;
}

.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--gold);
  border-color: var(--gold);
  color: #06231f;
}

.btn-primary:hover:not(:disabled) {
  border-color: var(--gold-light);
  background: var(--gold-light);
}

/* ── Simulator stage ──────────────────────────────────────────────────── */

.sim-stage {
  display: flex;
  flex-direction: column;
  gap: 10px;
  outline: none;
}

/* Ready layout: cast bar is display:none — drop flex gap so arena padding matches top/bottom. */
body:not(.is-sim-run) .sim-stage {
  gap: 0;
}

body:not(.is-sim-run) #simStage.stage {
  padding-block: 12px;
}

.sim-cast-bar {
  display: none;
}

body.is-sim-run .sim-cast-bar {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  box-sizing: border-box;
  flex-shrink: 0;
  width: min(420px, 90%);
  /* Fixed slot so Phase title / resolve / cast never resize the arena. */
  height: 72px;
  margin-inline: auto;
  padding: 8px 0 8px;
  visibility: hidden;
}

body.is-sim-run .sim-cast-bar.is-active { visibility: visible; }

.sim-cast-spell {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  min-height: 0;
  font-family: var(--font-primary);
  font-size: 1.25rem;
  line-height: 1.2;
  letter-spacing: 0.03em;
  text-align: center;
  color: #ffffff;
}

.sim-cast-bar.is-resolve .sim-cast-spell {
  font-size: 1.35rem;
}

/* Beat element tint classes on the cast label; dodge/clip keep their colours. */
body.is-sim-run .sim-cast-spell {
  color: #ffffff;
}

body.is-sim-run .sim-cast-spell.is-resolve-clean {
  color: rgba(88, 250, 170, 0.95);
}

body.is-sim-run .sim-cast-spell.is-resolve-hit {
  color: var(--fire);
}

.sim-cast-spell.is-phase-title {
  font-size: 1.55rem;
  font-weight: 400;
  letter-spacing: 0.02em;
  color: #ffffff;
  white-space: nowrap;
}

.sim-cast-track {
  flex-shrink: 0;
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  overflow: hidden;
}

.sim-cast-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--gold), var(--gold-light));
  transition: width 0.05s linear;
}

.sim-arena-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  max-width: min(100%, 78vh, 820px);
  margin-inline: auto;
  display: grid;
  place-items: center;
}

.arena-canvas {
  grid-area: 1 / 1;
  display: block;
  width: 100%;
  height: 100%;
  /* Layout size comes from the wrap (scales with the viewport). JS only
     sets the backing-store pixel dimensions to match CSS size × DPR. */
}

#arenaFx {
  touch-action: none;
}

/* ── Run action bar (Sprint / Pause / 180°) — arena bottom-right overlay ─ */

.sim-actions-overlay {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 2;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}

.sim-actions-overlay[hidden] { display: none; }

.sim-actions-hud {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 8px;
  width: auto;
}

.sim-action-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.sim-action-slot.is-sprint-used .sim-sprint-btn { opacity: 0.35; }

.sim-action-hint {
  margin: 0;
  min-height: 1.3em;
  font-family: var(--font-mark);
  font-size: 0.6875rem;
  line-height: 1.3;
  text-align: center;
  color: #e8eef5;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
}

.sim-action-hint.kbd-legend-hint {
  align-items: center;
  gap: 0;
}

.sim-action-hint[hidden] { display: none; }

.sim-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 52px;
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
}

.sim-action-btn:hover:not(:disabled) { transform: translateY(-1px); }
.sim-action-btn:focus-visible {
  outline: 2px solid rgba(15, 176, 162, 0.45);
  outline-offset: 2px;
}
.sim-action-btn:disabled { opacity: 0.45; cursor: default; }

.sim-sprint-icon {
  display: block;
  width: 34px;
  height: auto;
  object-fit: contain;
  pointer-events: none;
}

.sim-pause-glyph {
  position: relative;
  display: block;
  width: 22px;
  height: 26px;
  pointer-events: none;
}

.sim-pause-bars {
  position: absolute;
  inset: 0;
  transition: opacity 0.12s ease;
}

.sim-pause-bars::before,
.sim-pause-bars::after {
  content: '';
  position: absolute;
  top: 3px;
  bottom: 3px;
  width: 6px;
  border-radius: 1px;
  background: #e8eef5;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.sim-pause-bars::before { left: 2px; }
.sim-pause-bars::after { right: 2px; }

.sim-pause-play {
  position: absolute;
  top: 50%;
  left: 55%;
  width: 0;
  height: 0;
  margin: 0;
  opacity: 0;
  transform: translate(-50%, -50%);
  border-style: solid;
  border-width: 9px 0 9px 14px;
  border-color: transparent transparent transparent #e8eef5;
  filter: drop-shadow(0 0 1px rgba(0, 0, 0, 0.45));
  transition: opacity 0.12s ease;
}

.sim-pause-btn[aria-pressed="true"] .sim-pause-bars { opacity: 0; }
.sim-pause-btn[aria-pressed="true"] .sim-pause-play { opacity: 1; }

.sim-camera-btn[aria-pressed="true"] {
  box-shadow: inset 0 0 0 1px rgba(15, 176, 162, 0.55);
  background: rgba(15, 176, 162, 0.12);
}

.sim-camera-glyph {
  display: block;
  font-family: var(--font-mark);
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #e8eef5;
  line-height: 1;
  pointer-events: none;
}

.sim-sprint-status {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0;
  background: transparent;
  color: var(--gold-light);
  font-family: var(--font-mark);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
}

.sim-sprint-status[hidden] { display: none; }
.sim-sprint-status-icon { width: 28px; flex-shrink: 0; }
.sim-sprint-status-timer { width: 100%; text-align: center; }

/* ── Phase selector ───────────────────────────────────────────────────── */

.sim-phases-heading {
  margin: 0 0 12px;
  font-size: 1rem;
}

.sim-phases-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sim-phase-btn {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.sim-phase-check {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border: 1px solid rgba(232, 238, 245, 0.35);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.25);
  position: relative;
}

.sim-phase-btn.is-selected .sim-phase-check {
  border-color: rgba(15, 176, 162, 0.75);
  background: rgba(15, 176, 162, 0.35);
}

.sim-phase-btn.is-selected .sim-phase-check::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid #e8eef5;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.sim-phase-btn:hover:not(:disabled) {
  border-color: var(--gold);
  background: rgba(15, 176, 162, 0.08);
}

.sim-phase-btn:focus-visible {
  outline: 2px solid rgba(15, 176, 162, 0.45);
  outline-offset: 2px;
}

.sim-phase-btn.is-selected {
  border-color: var(--gold);
  background: rgba(15, 176, 162, 0.16);
  box-shadow: inset 0 0 0 1px rgba(15, 176, 162, 0.25);
}

.sim-phase-btn.is-soon,
.sim-phase-btn:disabled {
  opacity: 0.72;
  cursor: default;
  border-style: dashed;
  background: rgba(0, 0, 0, 0.12);
}

.sim-phase-btn-label {
  font-weight: 600;
  min-width: 0;
  text-align: left;
  line-height: 1.25;
  white-space: normal;
}

.sim-phase-btn-note {
  flex-shrink: 0;
  margin-left: auto;
  font-family: var(--font-mark);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.8;
  text-align: right;
}

.sim-results-segment {
  list-style: none;
  margin: 12px 0 4px;
  padding: 0;
  border: none;
  background: none;
}

.sim-results-segment:first-child {
  margin-top: 0;
}

.sim-results-segment-label {
  display: block;
  font-family: var(--font-primary);
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.25;
  color: var(--text-secondary);
}

/* ── Options ──────────────────────────────────────────────────────────── */

.sim-options-details {
  margin: 0;
}

.sim-options-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  font-family: var(--font-primary);
  font-size: 0.95rem;
  font-weight: 400;
  letter-spacing: 0.02em;
  color: var(--text-primary);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.sim-options-summary::-webkit-details-marker { display: none; }

.sim-options-summary::after {
  content: '';
  flex-shrink: 0;
  width: 0.45rem;
  height: 0.45rem;
  border-right: 1.5px solid var(--text-secondary);
  border-bottom: 1.5px solid var(--text-secondary);
  transform: rotate(45deg);
  margin-top: -0.15rem;
  transition: transform 0.15s ease;
}

.sim-options-details[open] > .sim-options-summary::after {
  transform: rotate(-135deg);
  margin-top: 0.15rem;
}

.sim-options-body {
  padding-top: 16px;
}

.sim-option + .sim-option {
  margin-top: 14px;
}

.sim-option-phantom {
  cursor: default;
}

.sim-phantom-job-btn {
  flex: none;
  width: auto;
  min-width: 6.5rem;
  padding: 6px 10px;
  text-align: center;
}

.sim-phantom-job-btn-label {
  display: block;
  font-family: var(--font-primary);
  font-size: 0.8125rem;
  letter-spacing: 0.01em;
}

/* ── Phantom job modal ────────────────────────────────────────────────── */

body.sim-phantom-modal-open {
  overflow: hidden;
}

.sim-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: grid;
  place-items: center;
  padding: 16px;
}

.sim-modal[hidden] {
  display: none !important;
}

.sim-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 10, 0.72);
}

.sim-modal-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 560px);
  max-height: min(88vh, 720px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 2px);
  background: var(--bg-card);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

.sim-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line-soft);
}

.sim-modal-title {
  margin: 0;
  font-family: var(--font-primary);
  font-size: 1rem;
  font-weight: 400;
  letter-spacing: 0.02em;
}

.sim-modal-close {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-sunken);
  color: var(--text-secondary);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.sim-modal-close:hover {
  border-color: var(--gold);
  color: var(--text-primary);
}

.sim-modal-hint {
  margin: 0;
  padding: 10px 16px 0;
}

.sim-phantom-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: 8px;
  padding: 12px 16px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sim-phantom-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 8px 8px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--bg-sunken);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease, transform 0.12s ease;
}

.sim-phantom-option:hover {
  border-color: var(--gold);
  background: rgba(15, 176, 162, 0.08);
}

.sim-phantom-option.is-selected {
  border-color: var(--gold);
  background: rgba(15, 176, 162, 0.14);
  box-shadow: inset 0 0 0 1px rgba(15, 176, 162, 0.25);
}

.sim-phantom-option-sprite {
  display: block;
  width: 48px;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.sim-phantom-option-label {
  font-size: 0.72rem;
  line-height: 1.25;
  text-align: center;
  color: var(--text-secondary);
}

.sim-phantom-option.is-selected .sim-phantom-option-label {
  color: var(--text-primary);
}

body.is-sim-run .sim-modal {
  z-index: 300;
}

.sim-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.8125rem;
  line-height: 1.5;
  cursor: pointer;
}

.sim-option-label { flex: 1; min-width: 0; }

.sim-option + .sim-option,
.sim-option-slider + .sim-option,
.sim-option + .sim-option-slider,
.sim-option-slider + .sim-option-slider {
  margin-top: 12px;
}

.sim-option-slider {
  display: block;
  font-size: 0.8125rem;
  line-height: 1.5;
  cursor: default;
}

.sim-option-slider > .sim-option-label {
  display: block;
  flex: none;
}

.sim-slider {
  display: block;
  width: 100%;
  margin-top: 8px;
  accent-color: var(--gold);
  cursor: pointer;
}

.sim-slider-ticks {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 0.6875rem;
  color: var(--muted);
  line-height: 1.3;
}

.sim-slider-ticks span { flex: 1; text-align: center; }
.sim-slider-ticks span:first-child { text-align: left; }
.sim-slider-ticks span:last-child { text-align: right; }

.sim-toggle {
  position: relative;
  flex-shrink: 0;
  width: 44px;
  height: 24px;
}

.sim-toggle input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}

.sim-toggle-track {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: #1a1f28;
  border: 1px solid var(--border);
  position: relative;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.sim-toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text-secondary);
  transition: transform 0.15s ease, background 0.15s ease;
}

.sim-toggle input:checked + .sim-toggle-track {
  background: rgba(15, 176, 162, 0.22);
  border-color: var(--gold);
}

.sim-toggle input:checked + .sim-toggle-track::after {
  transform: translateX(20px);
  background: var(--gold-light);
}

.sim-toggle input:focus-visible + .sim-toggle-track {
  box-shadow: 0 0 0 2px rgba(15, 176, 162, 0.35);
}

.sim-touch-note {
  margin-top: 10px;
  margin-bottom: 0;
}

.sim-hints-card .hint { margin: 0; }
.sim-hints-card .hint + .hint { margin-top: 10px; }

/* ── Immersive run mode ───────────────────────────────────────────────── */

body.is-sim-run { overflow: hidden; }

body.is-sim-run .header-bar,
body.is-sim-run footer { display: none; }

body.is-sim-run main.page-container {
  padding: 0;
  max-width: none;
  height: 100dvh;
}

body.is-sim-run #simulatorView {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 0;
  align-items: stretch;
  height: 100%;
  padding:
    env(safe-area-inset-top, 0)
    env(safe-area-inset-right, 0)
    env(safe-area-inset-bottom, 0)
    env(safe-area-inset-left, 0);
  box-sizing: border-box;
  background: var(--bg-primary);
}

body.is-sim-run #simulatorView .panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  padding: 16px;
  gap: 12px;
  border-left: 1px solid var(--border);
  background: var(--bg-primary);
}

/* Keep chrome / coaching / hints from being crushed; only results may shrink. */
body.is-sim-run #simulatorView .panel > .card:not(#simResultsCard) {
  flex: 0 0 auto;
}

/* Run results fill leftover space and scroll — never push the bottom stack away. */
body.is-sim-run #simResultsCard {
  flex: 1 1 0%;
  min-height: 0;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.is-sim-run #simResultsCard h2 {
  flex: 0 0 auto;
  margin-bottom: 6px;
}

body.is-sim-run #simResultsList {
  flex: 1 1 0%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
  scrollbar-gutter: stable;
}

/* Coaching + control legend stay below results and never shrink away. */
body.is-sim-run #simStatusCard,
body.is-sim-run .sim-hints-card {
  flex: 0 0 auto;
}

/* Summary hides status — keep hints pinned to the bottom. */
body.is-sim-run #simStatusCard[hidden] + .sim-hints-card {
  margin-top: auto;
}

body.is-sim-run .sim-sprint-status,
body.is-sim-run .sim-actions-overlay { right: 32px; }
body.is-sim-run .sim-actions-overlay { bottom: 32px; }

body.is-sim-run #simStage {
  height: 100%;
  min-height: 0;
  border: none;
  border-radius: 0;
  padding: 0;
  background: transparent;
  gap: 0;
}

body.is-sim-run .sim-cast-bar.is-resolve .sim-cast-track,
body.is-sim-run .sim-cast-bar.is-phase-title .sim-cast-track {
  visibility: hidden;
}

body.is-sim-run .sim-arena-wrap {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: none;
  aspect-ratio: auto;
  /* Keep both canvases stacked in the same grid cell. */
  display: grid;
  place-items: center;
}

body.is-sim-run .arena-canvas {
  grid-area: 1 / 1;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  /* Square canvas letterboxed inside the flex wrap; size set by JS. */
}

/* ── Footer ───────────────────────────────────────────────────────────── */

footer {
  margin-top: auto;
  flex-shrink: 0;
  border-top: 1px solid var(--footer-border);
  background: var(--footer-bg);
}

.footer-inner {
  padding-block: 1rem;
  text-align: center;
  font-size: 0.72rem;
  color: var(--footer-text);
}

footer p { margin: 0; }

.footer-disclaimer {
  max-width: 40rem;
  margin-inline: auto;
  line-height: 1.45;
  color: var(--footer-text);
}

.footer-credit {
  margin: 0.5rem 0 0;
  color: var(--footer-text-secondary);
}

/* Short viewports — compress sidebar density; results stay scrollable above fixed hints. */
@media (max-height: 860px) {
  body.is-sim-run #simulatorView .panel {
    padding: 10px 12px;
    gap: 8px;
  }

  body.is-sim-run #simulatorView .panel > .card {
    padding: 10px 12px;
  }

  body.is-sim-run #simResultsCard h2 {
    margin-bottom: 4px;
    font-size: 0.85rem;
  }

  body.is-sim-run .order-list {
    gap: 3px;
  }

  body.is-sim-run .order-item {
    padding: 4px 8px;
    gap: 6px;
    font-size: 0.75rem;
  }

  body.is-sim-run .order-num,
  body.is-sim-run .sim-wave-mark {
    width: 18px;
    height: 18px;
    font-size: 0.65rem;
  }

  body.is-sim-run .sim-results-segment {
    margin: 6px 0 2px;
  }

  body.is-sim-run .sim-results-segment-label {
    font-size: 0.78rem;
  }

  body.is-sim-run .sim-status-card .slide-spell {
    font-size: 1rem;
  }

  body.is-sim-run .sim-status-card .slide-spell + .hint {
    margin-top: 4px;
  }

  body.is-sim-run .kbd-legend-hint {
    gap: 5px;
  }

  body.is-sim-run .kbd-legend-row {
    min-height: 1.5rem;
    column-gap: 10px;
  }

  body.is-sim-run .kbd-legend-action {
    font-size: 0.72rem;
  }

  body.is-sim-run .kbd {
    min-height: 1.3em;
    padding: 1px 6px;
    font-size: 0.64rem;
  }

  body.is-sim-run .kbd-cluster .kbd {
    min-width: 1.2em;
    min-height: 1.2em;
    padding: 0 4px;
    font-size: 0.58rem;
  }
}

@media (max-height: 700px) {
  body.is-sim-run #simulatorView .panel {
    padding: 8px 10px;
    gap: 6px;
  }

  body.is-sim-run #simulatorView .panel > .card {
    padding: 8px 10px;
  }

  body.is-sim-run .eyebrow {
    margin-bottom: 4px;
  }

  body.is-sim-run .button-row {
    gap: 6px;
  }

  body.is-sim-run .btn {
    padding: 0.45rem 0.75rem;
    font-size: 0.8rem;
  }
}

@media (max-width: 1040px) {
  .view { grid-template-columns: minmax(0, 1fr); }

  body.is-sim-run #simulatorView {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  body.is-sim-run #simulatorView .panel {
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: min(42vh, 360px);
  }

  .header-encounter {
    width: 100%;
    order: 3;
  }
}

@media (max-width: 640px) {
  .header-brand { flex-wrap: wrap; gap: 0.35rem 0.85rem; }
}
