:root {
  color-scheme: dark;
  --bg: #0b1020;
  --bg-soft: #11182a;
  --panel: rgba(15, 22, 40, 0.88);
  --panel-2: rgba(20, 28, 48, 0.96);
  --text: #f4f7ff;
  --muted: #aab5d1;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #ffb86b;
  --accent-2: #86e7ff;
  --success: #8af0b3;
  --danger: #ff8f95;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.32);
  --radius: 22px;
  --radius-sm: 14px;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background:
    radial-gradient(circle at top, rgba(134, 231, 255, 0.10), transparent 32%),
    radial-gradient(circle at 80% 10%, rgba(255, 184, 107, 0.12), transparent 28%),
    linear-gradient(180deg, #050816, var(--bg) 22%, #0f172b 100%);
  color: var(--text);
}

button, input, select, textarea { font: inherit; }
button { border: 0; }
input, select, textarea {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(7, 12, 24, 0.72);
  color: var(--text);
  padding: 0.9rem 1rem;
  outline: none;
}
textarea { resize: vertical; min-height: 96px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(134, 231, 255, 0.32);
  outline-offset: 2px;
}

.app-shell {
  width: min(1360px, calc(100vw - 24px));
  margin: 0 auto;
  padding: 16px 0 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 4px 20px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 110px;
  height: 76px;
  object-fit: cover;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.24);
  background: rgba(7, 12, 24, 0.55);
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent-2);
  font-weight: 800;
}

h1, h2, h3, p { margin-top: 0; }
h1 {
  margin-bottom: 10px;
  font-size: clamp(2.1rem, 4vw, 4rem);
  line-height: 0.94;
  letter-spacing: -0.04em;
  max-width: 12ch;
}
.lede {
  margin: 0;
  max-width: 68ch;
  color: var(--muted);
  line-height: 1.55;
}

.topbar-actions, .form-actions, .badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(0, 2.1fr);
  grid-template-areas:
    'hero scene'
    'sidebar scene';
  gap: 16px;
  align-items: start;
}

.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.hero-panel { grid-area: hero; }
.scene-panel { grid-area: scene; }
.sidebar { grid-area: sidebar; }

.hero-panel, .scene-panel, .sidebar { padding: 18px; }

.start-form {
  display: grid;
  gap: 14px;
}

.premise-randomize {
  align-self: flex-start;
  margin-top: -4px;
}
.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
label span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 650;
}

.hero-class-preview {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}
.hero-class-preview__image {
  width: 112px;
  height: 112px;
  border-radius: 16px;
  object-fit: cover;
  border: 1px solid rgba(134, 231, 255, 0.16);
  background: linear-gradient(135deg, #101a2c, #050816);
}
.hero-class-preview__body h3 {
  margin: 0 0 6px;
  font-size: 1.05rem;
}
.hero-class-preview__text {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}
.hero-class-preview__eyebrow {
  margin-bottom: 8px;
}

.stock-game-preview {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 12px;
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(134, 231, 255, 0.08), rgba(255, 184, 107, 0.06));
  border: 1px solid rgba(134, 231, 255, 0.18);
}
.stock-game-preview__image {
  width: 108px;
  height: 72px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(8, 12, 24, 0.55);
  box-shadow: 0 10px 24px rgba(8, 12, 24, 0.24);
}
.stock-game-preview__body h3 {
  margin: 0 0 6px;
  font-size: 1.02rem;
}
.stock-game-preview__text {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}
.stock-game-preview__meta {
  display: grid;
  gap: 8px;
  justify-items: end;
}
.stock-game-preview__eyebrow {
  margin-bottom: 8px;
}

.primary, .secondary, .ghost, .choice-btn {
  border-radius: 999px;
  padding: 0.9rem 1.05rem;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease, border-color 120ms ease;
  cursor: pointer;
}
.primary {
  background: linear-gradient(135deg, #ffbd76, #ff9a6b);
  color: #251205;
  font-weight: 850;
  box-shadow: 0 16px 30px rgba(255, 163, 100, 0.25);
}
.secondary {
  background: rgba(134, 231, 255, 0.12);
  color: var(--text);
  border: 1px solid rgba(134, 231, 255, 0.22);
}
.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}
.primary:hover, .secondary:hover, .ghost:hover, .choice-btn:hover { transform: translateY(-1px); }

.scene-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
}
.scene-header h2 { margin: 0; font-size: clamp(1.35rem, 2vw, 2rem); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  background: rgba(134, 231, 255, 0.12);
  border: 1px solid rgba(134, 231, 255, 0.18);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
}
.badge.muted {
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line);
  color: var(--muted);
}

.badge.stock {
  background: rgba(138, 240, 179, 0.12);
  border-color: rgba(138, 240, 179, 0.3);
  color: var(--success);
}

.art-frame {
  margin: 0;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0a0f1b;
}
.art-frame img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: linear-gradient(135deg, #101a2c, #050816);
}
.art-frame figcaption {
  padding: 10px 12px 12px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
  border-top: 1px solid var(--line);
}

.scene-text-wrap { margin-top: 14px; }
.scene-text {
  margin: 0 0 14px;
  line-height: 1.7;
  font-size: 1rem;
  color: #eef2ff;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.stat-card {
  padding: 12px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
}
.stat-card .label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.stat-card .value {
  font-size: 1.2rem;
  font-weight: 850;
}
.stat-card .bar {
  margin-top: 10px;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.stat-card .bar > i {
  display: block;
  height: 100%;
  border-radius: inherit;
  width: 0%;
}
.stat-danger .bar > i { background: linear-gradient(90deg, #ff8f95, #ffbd76); }
.stat-hope .bar > i { background: linear-gradient(90deg, #88f0b9, #7be5ff); }
.stat-knowledge .bar > i { background: linear-gradient(90deg, #9fbcff, #d9b3ff); }

.choice-list {
  display: grid;
  gap: 10px;
}
.choice-hint {
  margin: 14px 0 10px;
  color: var(--accent-2);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.choice-btn {
  width: 100%;
  text-align: left;
  background: linear-gradient(180deg, rgba(159, 188, 255, 0.14), rgba(255, 255, 255, 0.04));
  border: 1px solid rgba(159, 188, 255, 0.24);
  color: var(--text);
  font-weight: 700;
  line-height: 1.35;
  padding: 1rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.choice-btn small {
  display: block;
  color: var(--muted);
  font-weight: 600;
  margin-top: 6px;
}
.choice-btn::after {
  content: 'Choose';
  flex: 0 0 auto;
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 800;
  color: rgba(159, 188, 255, 0.9);
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  background: rgba(159, 188, 255, 0.08);
  border: 1px solid rgba(159, 188, 255, 0.18);
}
.choice-btn:hover {
  border-color: rgba(159, 188, 255, 0.5);
  background: linear-gradient(180deg, rgba(159, 188, 255, 0.22), rgba(255, 255, 255, 0.06));
  box-shadow: 0 12px 26px rgba(23, 31, 58, 0.28);
}
.choice-btn:focus-visible {
  border-color: rgba(134, 231, 255, 0.5);
}
.choice-btn[disabled] {
  opacity: 0.7;
  cursor: progress;
}

.activity-status {
  margin: 8px 0 2px;
  padding: 10px 12px 12px;
  border-radius: 16px;
  background: rgba(134, 231, 255, 0.08);
  border: 1px solid rgba(134, 231, 255, 0.18);
}
.activity-status__text {
  color: #eef6ff;
  font-weight: 700;
  line-height: 1.45;
  margin-bottom: 10px;
}
.activity-status__track {
  position: relative;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}
.activity-status__track i {
  display: block;
  height: 100%;
  width: 38%;
  border-radius: inherit;
  background: linear-gradient(90deg, rgba(134, 231, 255, 0.2), rgba(255, 184, 107, 0.96), rgba(134, 231, 255, 0.2));
  animation: activity-progress 1.1s ease-in-out infinite;
}

@keyframes activity-progress {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(280%); }
}

body.modal-open {
  overflow: hidden;
}

.load-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
}
.load-modal[hidden] {
  display: none;
}
.load-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 7, 14, 0.68);
  backdrop-filter: blur(8px);
}
.load-modal__sheet {
  position: relative;
  z-index: 1;
  width: min(920px, calc(100vw - 28px));
  max-height: min(82vh, 900px);
  overflow: auto;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(180deg, rgba(17, 24, 42, 0.98), rgba(9, 13, 24, 0.98));
  box-shadow: 0 40px 110px rgba(0, 0, 0, 0.55);
  padding: 18px;
}
.load-modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.load-modal__header h3 {
  margin: 0 0 6px;
  font-size: 1.2rem;
}
.load-modal__lede {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}
.load-modal__filters {
  display: grid;
  grid-template-columns: 1.2fr 1.2fr 0.8fr auto;
  gap: 12px;
  align-items: end;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  margin-bottom: 14px;
}
.load-modal__filters label span {
  font-size: 0.78rem;
}
.load-modal__results {
  display: grid;
  gap: 12px;
}
.load-modal__results-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.74rem;
  font-weight: 800;
  padding: 0 2px;
}
.load-modal__results-list {
  display: grid;
  gap: 10px;
}
.load-result {
  width: 100%;
  text-align: left;
  padding: 14px 15px;
  border-radius: 18px;
  border: 1px solid rgba(159, 188, 255, 0.2);
  background: linear-gradient(180deg, rgba(159, 188, 255, 0.12), rgba(255, 255, 255, 0.04));
  color: var(--text);
}
.load-result:hover {
  border-color: rgba(159, 188, 255, 0.45);
  transform: translateY(-1px);
}
.load-result__title {
  font-weight: 800;
  margin-bottom: 6px;
}
.load-result__meta {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.audit-modal__filters {
  grid-template-columns: 1fr 1fr 1fr 0.7fr auto;
}

.audit-modal__results-list {
  display: grid;
  gap: 10px;
}

.audit-event {
  padding: 14px 15px;
  border-radius: 18px;
  border: 1px solid rgba(159, 188, 255, 0.18);
  background: linear-gradient(180deg, rgba(159, 188, 255, 0.09), rgba(255, 255, 255, 0.03));
}

.audit-event__title {
  font-weight: 800;
  margin-bottom: 6px;
}

.audit-event__meta {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
  margin-bottom: 8px;
}

.audit-event__detail {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.audit-event__error {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 99, 132, 0.12);
  border: 1px solid rgba(255, 99, 132, 0.2);
  color: #ffb7c3;
}

.outcome-panel {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(134, 231, 255, 0.08);
  border: 1px solid rgba(134, 231, 255, 0.18);
}
.outcome-panel h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}
.outcome-panel p {
  margin: 0;
  color: #eef6ff;
  line-height: 1.6;
}

.story-log-block {
  margin-top: 16px;
}
.story-log-block h3 {
  margin-bottom: 10px;
  font-size: 1rem;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
}
.summary-grid div, .prompt-panel, .list, .log {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
}
.summary-grid div { padding: 12px; }
dt { color: var(--muted); font-size: 0.78rem; letter-spacing: 0.12em; text-transform: uppercase; margin-bottom: 6px; }
dd { margin: 0; font-weight: 800; line-height: 1.35; }

.sidebar { display: grid; gap: 14px; }
.sidebar h3 { margin-bottom: 10px; font-size: 1rem; }
.list, .log {
  margin: 0;
  padding: 10px 14px 10px 18px;
}
.list li, .log li { margin: 8px 0; line-height: 1.45; color: #eef2ff; }
.list li { color: #dce6ff; }
.log li { color: var(--muted); }

.log-entry {
  list-style: none;
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.03);
}
.log-entry + .log-entry { margin-top: 10px; }
.log-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #050816;
}
.log-meta {
  display: grid;
  gap: 6px;
}
.log-meta .step {
  color: var(--accent-2);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
  font-weight: 800;
}
.log-meta .story {
  color: #eef2ff;
  line-height: 1.55;
}
.log-meta .choice {
  color: #cfe8ff;
  font-weight: 700;
}
.log-meta .outcome {
  color: var(--muted);
}

.prompt-panel {
  display: block;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
  overflow: hidden;
}
.prompt-panel summary {
  padding: 12px 14px;
  cursor: pointer;
  font-weight: 800;
  color: var(--text);
}
.prompt-content {
  border-top: 1px solid var(--line);
  padding: 12px 14px 14px;
}
.prompt-line { margin: 0 0 8px; color: var(--muted); font-size: 0.92rem; }
.prompt-content pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: #e9eeff;
  background: rgba(4, 7, 14, 0.45);
  border-radius: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  max-height: 260px;
  overflow: auto;
}

@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(280px, 0.95fr) minmax(0, 1.95fr); }
}

@media (max-width: 760px) {
  .app-shell { width: min(100vw - 14px, 100vw - 14px); padding-top: 10px; }
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas:
      'hero'
      'scene'
      'sidebar';
  }
  .field-grid, .stats, .summary-grid { grid-template-columns: 1fr; }
  .hero-panel, .scene-panel, .sidebar { padding: 14px; }
  .topbar-actions { justify-content: flex-start; }
  h1 { max-width: 100%; }
}
