:root {
  --bg: #0f1117;
  --panel: #1b1f2a;
  --accent: #f6c56b;
  --accent-dim: #7f5a1a;
  --text: #f5f3ef;
  --muted: #8c92a3;
  --danger: #ff6b6b;
  --success: #4ade80;
  font-size: 16px;
}

.hidden {
  display: none !important;
}

body.high-contrast {
  --panel: #11141d;
  --text: #ffffff;
  --muted: #d7dbe6;
  --accent: #fbd277;
  background: radial-gradient(circle at top, #151c2d, #050609 70%);
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, rgba(18, 22, 33, 0.92), rgba(6, 8, 12, 0.92));
  z-index: 20;
  padding: 2rem 1.5rem;
  overflow-y: auto;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background: radial-gradient(circle at top, #1f2738, #090a0f 70%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  overflow: hidden;
}

body.title-active #game {
  display: none;
}

body.title-active {
  overflow: auto;
  align-items: center;
}

#toast-layer,
.toast,
.title-card,
.tutorial-card,
.options-card,
.codex-card {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

body.reduced-motion *,
body.reduced-motion *::before,
body.reduced-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
  scroll-behavior: auto !important;
}

#title-screen .title-card,
.tutorial-card,
.options-card,
.codex-card {
  width: min(960px, 100%);
  background: rgba(12, 15, 24, 0.9);
  border: 1px solid rgba(246, 197, 107, 0.22);
  border-radius: 24px;
  padding: 2.5rem;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.title-card {
  max-width: 820px;
}

.title-logo {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.title-icon {
  font-size: 2.5rem;
  color: var(--accent);
  filter: drop-shadow(0 0 18px rgba(246, 197, 107, 0.45));
}

.title-card h1 {
  margin: 0;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.title-tagline {
  margin: 0;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.title-section h2 {
  margin: 0 0 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.85rem;
  color: var(--muted);
}

#mode-options {
  display: grid;
  gap: 0.75rem;
}

#length-options {
  display: grid;
  gap: 0.6rem;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.mode-option {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: rgba(246, 197, 107, 0.08);
  border: 1px solid rgba(246, 197, 107, 0.18);
  border-radius: 14px;
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.mode-option:hover {
  border-color: rgba(246, 197, 107, 0.45);
  transform: translateY(-1px);
}

.mode-option.selected {
  border-color: rgba(246, 197, 107, 0.65);
  background: rgba(246, 197, 107, 0.18);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
}

.mode-option.selected .mode-name {
  color: var(--accent);
}

.mode-option input {
  accent-color: var(--accent);
}

.party-option {
  min-width: 220px;
}

#solo-name-area {
  margin-top: 1rem;
  display: grid;
  gap: 0.75rem;
}

.party-join-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.party-join-form input {
  flex: 1 1 180px;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(246, 197, 107, 0.25);
  background: rgba(246, 197, 107, 0.08);
  color: var(--text);
}

.party-roster {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.party-empty {
  font-size: 0.8rem;
  color: var(--muted);
  letter-spacing: 0.05em;
}

#party-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-top: 0.75rem;
}

#open-lobby-btn.hidden {
  display: none;
}

.party-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid rgba(246, 197, 107, 0.25);
  background: rgba(246, 197, 107, 0.12);
  font-size: 0.8rem;
  letter-spacing: 0.05em;
}

.party-chip button {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 0;
  font-size: 0.9em;
  cursor: pointer;
}

.party-chip button:hover {
  color: rgba(255, 153, 102, 0.9);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.mode-name {
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.mode-desc {
  grid-column: 2 / -1;
  font-size: 0.85rem;
  color: var(--muted);
}

.keyword {
  color: var(--accent);
  font-weight: 600;
}

.title-flow {
  display: grid;
  gap: 1.6rem;
  margin-top: 1.8rem;
}

.title-step {
  display: none;
  animation: titleStepFade 0.3s ease;
  min-height: 220px;
}

.title-step.active {
  display: block;
}

.title-step h2 {
  margin: 0 0 1rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.9rem;
  color: var(--muted);
}

.title-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.title-actions .title-wizard {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.title-actions .title-wizard #title-progress {
  flex: 1 1 auto;
  text-align: center;
}

.title-actions .title-wizard button {
  flex: 0 0 auto;
}

.title-actions .title-secondary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: flex-end;
}

#title-progress {
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.title-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.title-footer .title-note {
  text-align: right;
}

.primary {
  background: linear-gradient(135deg, rgba(246, 197, 107, 0.9), rgba(197, 136, 57, 0.95));
  color: #140d05;
  border: none;
  border-radius: 14px;
  padding: 0.75rem 1.5rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow: 0 12px 26px rgba(246, 197, 107, 0.22);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 16px 36px rgba(246, 197, 107, 0.32);
}

button.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid rgba(246, 197, 107, 0.25);
  padding: 0.75rem 1.5rem;
  border-radius: 14px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

button.ghost:hover,
button.ghost:focus-visible {
  border-color: rgba(246, 197, 107, 0.55);
  color: var(--accent);
  transform: translateY(-1px);
}

.tutorial-card,
.options-card,
.codex-card {
  max-width: 720px;
  gap: 1.25rem;
}

.tutorial-header,
.options-header,
.codex-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tutorial-header h2,
.options-header h2,
.codex-header h2 {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.tutorial-step {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(246, 197, 107, 0.18);
  border-radius: 18px;
  padding: 1.25rem;
}

.tutorial-step-title {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tutorial-illustration {
  height: 140px;
  border-radius: 16px;
  background: radial-gradient(circle at 30% 30%, rgba(246, 197, 107, 0.3), transparent 60%),
    linear-gradient(135deg, rgba(18, 21, 30, 0.72), rgba(9, 11, 18, 0.85));
  position: relative;
  overflow: hidden;
}

.tutorial-illustration::before,
.tutorial-illustration::after {
  content: "";
  position: absolute;
  border: 1px solid rgba(246, 197, 107, 0.4);
  border-radius: 999px;
}

.tutorial-illustration[data-variant="flux"]::before {
  border-color: rgba(79, 191, 255, 0.5);
}

.tutorial-illustration[data-variant="flux"]::after {
  border-color: rgba(255, 107, 107, 0.45);
}

.tutorial-illustration[data-variant="relics"]::before {
  border-color: rgba(255, 239, 180, 0.55);
}

.tutorial-illustration[data-variant="relics"]::after {
  border-color: rgba(246, 197, 107, 0.4);
}

.tutorial-illustration[data-variant="flux"]::before {
  border-color: rgba(79, 191, 255, 0.5);
}

.tutorial-illustration[data-variant="flux"]::after {
  border-color: rgba(255, 107, 107, 0.45);
}

.tutorial-illustration[data-variant="relics"]::before {
  border-color: rgba(255, 239, 180, 0.55);
}

.tutorial-illustration[data-variant="relics"]::after {
  border-color: rgba(246, 197, 107, 0.4);
}

.tutorial-illustration[data-variant="echo"]::before {
  border-color: rgba(191, 144, 255, 0.45);
}

.tutorial-illustration[data-variant="options"]::before {
  border-color: rgba(108, 255, 206, 0.45);
}

.tutorial-illustration::before {
  inset: 18% 32%;
  border-top-color: transparent;
  border-bottom-color: transparent;
  animation: spinDial 14s linear infinite;
}

.tutorial-illustration::after {
  inset: 28% 42%;
  border-left-color: transparent;
  border-right-color: transparent;
  animation: spinDial 10s linear infinite reverse;
}

.reduced-motion .tutorial-illustration::before,
.reduced-motion .tutorial-illustration::after {
  animation: none;
}

body.reduced-motion #flux-indicator .flux-glow {
  animation-duration: 4.5s;
}

body.reduced-motion #flux-indicator[data-state="surge"] .flux-glow {
  animation-duration: 3.6s;
}

.tutorial-step-body {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.tutorial-hints {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.tutorial-footer {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

.options-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.options-section h3 {
  margin: 0;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.85rem;
  color: var(--muted);
}

.lobby-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.lobby-player {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.lobby-player input {
  flex: 1 1 160px;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid rgba(246, 197, 107, 0.25);
  background: rgba(246, 197, 107, 0.08);
  color: var(--text);
}

.lobby-player .ghost {
  flex: 0 0 auto;
}

.lobby-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.lobby-form input {
  flex: 1 1 160px;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  border: 1px solid rgba(246, 197, 107, 0.25);
  background: rgba(246, 197, 107, 0.08);
  color: var(--text);
}

.lobby-form .ghost {
  flex: 0 0 auto;
}

.options-note {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
}

#lobby-overlay {
  background: rgba(10, 12, 18, 0.78);
  backdrop-filter: blur(8px);
}

.lobby-card {
  width: min(520px, 94vw);
  background: rgba(12, 15, 24, 0.95);
  border-radius: 20px;
  border: 1px solid rgba(246, 197, 107, 0.18);
  padding: 2rem;
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.5);
  transform: translateX(40px);
  opacity: 0;
  transition: transform 0.35s ease, opacity 0.35s ease;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

#lobby-overlay.active .lobby-card {
  transform: translateX(0);
  opacity: 1;
}

.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.lobby-section h3 {
  margin: 0 0 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.85rem;
  color: var(--muted);
}

.invite-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

#invite-link-input {
  flex: 1 1 auto;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(246, 197, 107, 0.25);
  background: rgba(246, 197, 107, 0.08);
  color: var(--text);
  font-family: inherit;
  font-size: 0.85rem;
}

#invite-link-input:focus {
  outline: 2px solid rgba(246, 197, 107, 0.45);
}

.invite-section .options-note {
  margin-top: 0.6rem;
}

.lobby-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0;
}

.toggle input {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
}

.options-footer {
  display: flex;
  justify-content: flex-end;
}

#toast-layer {
  position: fixed;
  top: 1.25rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 40;
  pointer-events: none;
}

.toast {
  min-width: 240px;
  max-width: 320px;
  background: rgba(14, 17, 26, 0.95);
  border: 1px solid rgba(246, 197, 107, 0.35);
  color: var(--text);
  border-radius: 16px;
  padding: 0.85rem 1.1rem;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.4);
  display: grid;
  gap: 0.35rem;
  animation: toastSlide 0.3s ease, toastFade 0.3s ease 3.4s reverse forwards;
  pointer-events: auto;
}

.toast .toast-title {
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.75rem;
}

.toast .toast-body {
  font-size: 0.9rem;
  color: var(--muted);
}

.toast .toast-impact {
  font-size: 0.8rem;
  color: var(--text);
  line-height: 1.5;
}

.toast.positive {
  border-color: rgba(74, 222, 128, 0.45);
}

.toast.negative {
  border-color: rgba(255, 107, 107, 0.45);
}

.toast.system {
  border-color: rgba(246, 197, 107, 0.45);
}

.codex-card {
  max-width: 680px;
  gap: 1rem;
}

#codex-list {
  max-height: 60vh;
  overflow: auto;
  display: grid;
  gap: 0.75rem;
  padding-right: 0.5rem;
}

.codex-entry {
  border: 1px solid rgba(246, 197, 107, 0.18);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  background: rgba(255, 255, 255, 0.04);
  display: grid;
  gap: 0.35rem;
}

.codex-entry .codex-name {
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.codex-entry .codex-summary {
  color: var(--muted);
  font-size: 0.9rem;
}

.codex-entry .codex-effects {
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--text);
}

.codex-entry.rarity-timeless {
  box-shadow: 0 0 24px rgba(255, 239, 180, 0.15);
}

.codex-entry.rarity-common {
  border-color: rgba(246, 197, 107, 0.25);
}

.codex-entry.rarity-uncommon {
  border-color: rgba(94, 193, 255, 0.35);
}

.codex-entry.rarity-rare {
  border-color: rgba(191, 144, 255, 0.35);
}

.codex-entry.rarity-legendary {
  border-color: rgba(255, 153, 102, 0.4);
}

.codex-entry.rarity-timeless {
  border-color: rgba(255, 239, 180, 0.55);
}

.codex-entry.rarity-common {
  border-color: rgba(246, 197, 107, 0.25);
}

.codex-entry.rarity-uncommon {
  border-color: rgba(94, 193, 255, 0.35);
}

.codex-entry.rarity-rare {
  border-color: rgba(191, 144, 255, 0.35);
}

.codex-entry.rarity-legendary {
  border-color: rgba(255, 153, 102, 0.4);
}

.codex-entry.rarity-timeless {
  border-color: rgba(255, 239, 180, 0.6);
}

#game {
  max-width: 1100px;
  width: 100%;
  height: calc(100vh - 2.5rem);
  max-height: 980px;
  background: rgba(10, 12, 18, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: rgba(17, 20, 29, 0.95);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  gap: 1rem;
  flex-wrap: wrap;
}

.hud-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.observer-slot {
  flex: 0 0 auto;
}

.observer-banner {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: rgba(246, 197, 107, 0.12);
  border: 1px solid rgba(246, 197, 107, 0.4);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  display: none;
}

body.observer-mode .observer-banner {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--muted);
}

#sanity-bar {
  width: 200px;
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#sanity-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-dim));
  transition: width 0.4s ease;
}

#sanity-value {
  min-width: 48px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

#flux-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(246, 197, 107, 0.3);
  background: rgba(246, 197, 107, 0.12);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  position: relative;
  --flux-level: 0;
}

#flux-indicator::after {
  content: attr(data-charge) "%";
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

#flux-indicator .flux-glow {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(246, 197, 107, 0.9), rgba(246, 197, 107, 0.25));
  box-shadow: 0 0 12px rgba(246, 197, 107, 0.7);
  display: inline-block;
  animation: fluxPulse 2.8s ease-in-out infinite;
  transform: scale(calc(0.8 + (var(--flux-level, 0) * 0.6)));
  transition: transform 0.3s ease;
}

#flux-state {
  font-weight: 600;
  font-size: 0.75rem;
}

.hud-version {
  gap: 0.25rem;
  flex-direction: column;
  align-items: flex-start;
}

#flux-indicator[data-state="active"] {
  background: rgba(79, 191, 255, 0.14);
  border-color: rgba(79, 191, 255, 0.35);
}

#flux-indicator[data-state="active"] .flux-glow {
  background: radial-gradient(circle, rgba(79, 191, 255, 0.9), rgba(79, 191, 255, 0.25));
  box-shadow: 0 0 12px rgba(79, 191, 255, 0.75);
}

#flux-indicator[data-state="surge"] {
  background: rgba(255, 107, 107, 0.18);
  border-color: rgba(255, 107, 107, 0.4);
}

#flux-indicator[data-state="surge"] .flux-glow {
  background: radial-gradient(circle, rgba(255, 107, 107, 0.9), rgba(255, 107, 107, 0.25));
  box-shadow: 0 0 16px rgba(255, 107, 107, 0.8);
  animation-duration: 1.6s;
}

#flux-indicator[data-state="calm"] {
  background: rgba(122, 255, 196, 0.14);
  border-color: rgba(122, 255, 196, 0.35);
}

#flux-indicator[data-state="calm"] .flux-glow {
  background: radial-gradient(circle, rgba(122, 255, 196, 0.9), rgba(122, 255, 196, 0.25));
  box-shadow: 0 0 12px rgba(122, 255, 196, 0.75);
  animation-duration: 3.5s;
}

#game-version {
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

@keyframes fluxPulse {
  0%,
  100% {
    transform: scale(0.8);
    opacity: 0.75;
  }
  50% {
    transform: scale(1.15);
    opacity: 1;
  }
}

@keyframes titleStepFade {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#stage {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 0.6fr) minmax(0, 0.4fr);
  grid-template-areas:
    "scene info"
    "log inventory";
  gap: 1.25rem;
  padding: 1.25rem;
  flex: 1;
  overflow: hidden;
}

#scene {
  display: contents;
}

#scene-board {
  grid-area: scene;
  position: relative;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 24px;
  overflow: hidden;
  aspect-ratio: 3 / 2;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.35), 0 30px 60px rgba(0, 0, 0, 0.45);
}

#scene-board::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 15%, rgba(246, 197, 107, 0.25), transparent 45%),
    radial-gradient(circle at 50% 85%, rgba(246, 197, 107, 0.2), transparent 45%);
  opacity: 0.85;
  mix-blend-mode: screen;
  pointer-events: none;
}

#scene-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  filter: saturate(1.1) contrast(1.1);
}

.hourglass-shell {
  position: absolute;
  inset: 10% 18%;
  display: grid;
  grid-template-rows: 1fr auto 1fr;
  align-items: center;
  pointer-events: none;
  filter: drop-shadow(0 10px 16px rgba(0, 0, 0, 0.45));
  mix-blend-mode: screen;
}

.hourglass-glass {
  background: linear-gradient(135deg, rgba(210, 170, 100, 0.35), rgba(95, 60, 30, 0.25));
  border: 1px solid rgba(246, 197, 107, 0.6);
  backdrop-filter: blur(12px);
}

.hourglass-glass.top {
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}

.hourglass-glass.bottom {
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

.hourglass-glass.neck {
  height: 12%;
  margin: -6% auto;
  width: 24%;
  border-radius: 999px;
}

.hourglass-sand {
  margin: 0 auto;
  width: 18%;
  height: 18%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(246, 197, 107, 0.85), rgba(246, 197, 107, 0.15));
  animation: sandPulse 6s ease-in-out infinite;
}

@keyframes sandPulse {
  0%,
  100% {
    transform: translateY(-10%) scale(0.9);
    opacity: 0.8;
  }
  50% {
    transform: translateY(10%) scale(1.05);
    opacity: 1;
  }
}

#scene-hotspots {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#scene-hotspots .hotspot {
  pointer-events: auto;
}

#scene-info {
  grid-area: info;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 18px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  min-height: 0;
}

#scene-actions-header {
  margin-top: auto;
  font-size: 0.7rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

#scene-actions {
  display: grid;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.action-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(246, 197, 107, 0.18);
  border-radius: 14px;
  color: var(--text);
  padding: 0.75rem 1rem;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  text-transform: none;
  letter-spacing: normal;
  font-size: 0.95rem;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.action-card:hover,
.action-card:focus-visible {
  border-color: rgba(246, 197, 107, 0.5);
  transform: translateY(-2px);
}

.action-card .action-label {
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.8rem;
}

.action-card .action-context {
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.action-card.resolved {
  opacity: 0.6;
  border-style: dashed;
}

.action-card.undiscovered {
  border-style: dotted;
  opacity: 0.85;
}

@keyframes spinDial {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes toastSlide {
  0% {
    transform: translateX(60px);
    opacity: 0;
  }
  100% {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes toastFade {
  0% {
    opacity: 1;
    transform: translateX(0);
  }
  100% {
    opacity: 0;
    transform: translateX(60px);
  }
}

#scene-title {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#scene-description {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

#scene-objective {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: rgba(246, 197, 107, 0.1);
  border: 1px solid rgba(246, 197, 107, 0.25);
  color: var(--accent);
  font-size: 0.9rem;
}

#inventory {
  grid-area: inventory;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 18px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  min-height: 0;
}

#log-panel {
  grid-area: log;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 18px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto;
  min-height: 0;
}

#inventory-items {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  flex: 1 1 auto;
  overflow-y: auto;
  padding-right: 0.35rem;
}

.inventory-item {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.4rem 0.6rem;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(246, 197, 107, 0.18);
  background: rgba(246, 197, 107, 0.08);
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.inventory-item:hover {
  border-color: rgba(246, 197, 107, 0.45);
  transform: translateY(-1px);
}

.inventory-item.selected {
  border-color: rgba(246, 197, 107, 0.7);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

.inventory-item .summary {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.inventory-item .meta {
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--muted);
}

.inventory-item .count {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-left: auto;
}

.inventory-item .effects {
  grid-column: 1 / -1;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

.gacha-controls {
  margin-top: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.gacha-controls .ghost {
  flex: 1;
}

.gacha-controls .label {
  font-size: 0.8rem;
  letter-spacing: 0.08em;
}

#progress-tracker {
  display: grid;
  gap: 0.4rem;
}

#progress-bar {
  width: 160px;
  height: 8px;
  border-radius: 999px;
  border: 1px solid rgba(246, 197, 107, 0.25);
  background: rgba(246, 197, 107, 0.08);
  position: relative;
  overflow: hidden;
}

#progress-fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: linear-gradient(90deg, rgba(246, 197, 107, 0.9), rgba(255, 209, 122, 0.85));
  transition: width 0.3s ease;
}

#progress-text {
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

#hud-team {
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inventory-item.rarity-common,
.detail-card.rarity-common {
  border-color: rgba(246, 197, 107, 0.25);
}

.inventory-item.rarity-common .meta,
.detail-card.rarity-common .rarity-tag {
  color: rgba(246, 197, 107, 0.85);
}

.inventory-item.rarity-uncommon,
.detail-card.rarity-uncommon {
  border-color: rgba(94, 193, 255, 0.35);
  background: rgba(94, 193, 255, 0.08);
}

.inventory-item.rarity-uncommon .meta,
.detail-card.rarity-uncommon .rarity-tag {
  color: rgba(94, 193, 255, 0.9);
}

.inventory-item.rarity-rare,
.detail-card.rarity-rare {
  border-color: rgba(191, 144, 255, 0.4);
  background: rgba(191, 144, 255, 0.08);
}

.inventory-item.rarity-rare .meta,
.detail-card.rarity-rare .rarity-tag {
  color: rgba(191, 144, 255, 0.95);
}

.inventory-item.rarity-legendary,
.detail-card.rarity-legendary {
  border-color: rgba(255, 153, 102, 0.45);
  background: rgba(255, 153, 102, 0.08);
}

.inventory-item.rarity-legendary .meta,
.detail-card.rarity-legendary .rarity-tag {
  color: rgba(255, 153, 102, 0.95);
}

.inventory-item.rarity-timeless,
.detail-card.rarity-timeless {
  border-color: rgba(255, 239, 180, 0.6);
  background: rgba(255, 239, 180, 0.1);
  box-shadow: inset 0 0 12px rgba(255, 239, 180, 0.15);
}

.inventory-item.rarity-timeless .meta,
.detail-card.rarity-timeless .rarity-tag {
  color: rgba(255, 239, 180, 1);
}

.inventory-item .name {
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.inventory-item .effects {
  font-size: 0.8rem;
  line-height: 1.4;
  grid-column: 1 / -1;
  color: var(--muted);
}

.detail-card {
  border-radius: 14px;
  border: 1px solid rgba(246, 197, 107, 0.18);
  background: rgba(8, 10, 16, 0.85);
  padding: 1rem;
  display: grid;
  gap: 0.75rem;
  flex: 0 0 auto;
}

.detail-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.rarity-tag {
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  border: 1px solid rgba(246, 197, 107, 0.35);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.detail-summary {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.5;
}

.detail-effects {
  display: grid;
  gap: 0.6rem;
  margin: 0;
}

.detail-effects div {
  display: grid;
  gap: 0.2rem;
}

.detail-effects dt {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.detail-effects dd {
  margin: 0;
  font-size: 0.85rem;
}

.detail-combos {
  display: grid;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

#log {
  flex: 1;
  overflow-y: auto;
  padding-right: 0.5rem;
  font-size: 0.9rem;
  line-height: 1.5;
}

.log-entry {
  margin-bottom: 0.75rem;
  color: var(--muted);
}

.log-entry strong {
  color: var(--text);
}

#controls {
  display: flex;
  justify-content: flex-end;
  padding: 1rem 1.5rem 1.5rem;
  gap: 1rem;
}

button {
  font-family: inherit;
  border: none;
  cursor: pointer;
  border-radius: 999px;
  padding: 0.6rem 1.5rem;
  background: var(--accent);
  color: #1a1508;
  font-weight: 600;
  letter-spacing: 0.05em;
  transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(246, 197, 107, 0.25);
}

.hotspot {
  position: absolute;
  background: rgba(246, 197, 107, 0.2);
  border: 1px solid rgba(246, 197, 107, 0.5);
  color: var(--text);
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  backdrop-filter: blur(4px);
  min-width: 120px;
}

.hotspot:hover {
  background: rgba(246, 197, 107, 0.4);
}

.hotspot.resolved {
  opacity: 0.5;
  border-style: dashed;
  pointer-events: none;
}

.hotspot.undiscovered {
  border-style: dotted;
  background: rgba(246, 197, 107, 0.08);
  opacity: 0.9;
}

#modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 8, 12, 0.8);
  backdrop-filter: blur(6px);
  padding: 1.5rem;
  z-index: 10;
}

#modal.hidden {
  display: none;
}

#modal-content {
  max-width: 460px;
  width: 100%;
  background: rgba(14, 17, 24, 0.95);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#modal-title {
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#modal-body {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

#modal-choices {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.choice-btn {
  background: rgba(246, 197, 107, 0.15);
  border: 1px solid rgba(246, 197, 107, 0.35);
  color: var(--text);
  border-radius: 12px;
  text-align: left;
  padding: 0.85rem 1rem;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.choice-btn.tone-positive {
  border-color: rgba(74, 222, 128, 0.6);
  box-shadow: 0 0 0 1px rgba(74, 222, 128, 0.25);
}

.choice-btn.tone-negative {
  border-color: rgba(255, 107, 107, 0.6);
  box-shadow: 0 0 0 1px rgba(255, 107, 107, 0.25);
}

.choice-btn.tone-neutral {
  border-color: rgba(140, 146, 163, 0.45);
}

.choice-btn .choice-title {
  display: block;
  font-weight: 600;
}

.choice-btn .choice-effect {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.3rem;
  line-height: 1.5;
}

.choice-btn .choice-effect .keyword {
  color: var(--accent);
  font-weight: 600;
}

#modal-close {
  align-self: flex-end;
  border-radius: 12px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--muted);
  padding: 0.4rem 1rem;
}

#modal-close:hover {
  color: var(--text);
  border-color: rgba(246, 197, 107, 0.35);
}

@media (max-width: 960px) {
  body {
    padding: 0.75rem;
    overflow-y: auto;
  }

  #game {
    height: auto;
    max-height: none;
  }

  #stage {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "scene"
      "info"
      "inventory"
      "log";
    overflow-y: auto;
  }

  #scene-board {
    min-height: 320px;
  }

  .hotspot {
    min-width: auto;
    font-size: 0.75rem;
  }

  #scene-actions {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }

  #scene-info,
  #inventory,
  #log-panel {
    max-height: none;
  }

  .title-flow {
    margin-top: 1.2rem;
    gap: 1.2rem;
  }

  .title-actions .title-wizard {
    gap: 0.6rem;
  }
}

@media (max-width: 600px) {
  :root {
    font-size: 15px;
  }

  #hud {
    flex-direction: column;
    align-items: flex-start;
  }

  button:not(.hotspot) {
    width: 100%;
  }

  #mode-options,
  #length-options {
    grid-template-columns: 1fr;
  }

  #toast-layer {
    top: auto;
    bottom: 1rem;
    right: 0.5rem;
    left: 0.5rem;
    align-items: stretch;
  }

  .toast {
    max-width: none;
  }

  #scene-board {
    min-height: 280px;
  }

  #scene-hotspots {
    display: none;
  }

  #scene-actions {
    grid-template-columns: 1fr;
  }

  .title-card,
  .tutorial-card,
  .options-card,
  .codex-card {
    padding: 1.5rem;
    gap: 1rem;
  }

  .title-actions {
    flex-direction: column;
    align-items: stretch;
  }

  #mode-options {
    grid-template-columns: 1fr;
  }

  .title-actions .title-wizard {
    flex-direction: column;
    align-items: stretch;
  }

  .title-actions .title-secondary {
    width: 100%;
    justify-content: space-between;
    flex-direction: column;
    gap: 0.5rem;
  }
}
.log-entry.positive {
  color: var(--success);
}

.log-entry.negative {
  color: var(--danger);
}

.log-entry.system {
  color: var(--accent);
}
.log-entry.neutral {
  color: var(--muted);
}

