:root {
  --bg: #1a0e2a;
  --bg-elev: #261940;
  --bg-card: #2f1f4d;
  --fg: #f0e7ff;
  --fg-dim: #b8a8d0;
  --accent: #b97aff;
  --accent-2: #ff8fc8;
  --link: #d9a3ff;
  --border: #4a3070;
  --success: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.55;
}

header {
  text-align: center;
  padding: 2.5rem 1rem 1rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #2a1a44 0%, var(--bg) 100%);
}
header h1 {
  margin: 0 0 0.25rem;
  font-size: 2.2rem;
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
header .subtitle { color: var(--fg-dim); margin: 0; font-size: 1rem; }

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem 1.75rem;
  margin-bottom: 1.25rem;
}
.card h2 {
  margin: 0 0 1rem;
  font-size: 1.2rem;
  font-weight: 600;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem 1rem;
  margin-bottom: 1rem;
}
.grid-2 label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.grid-2 label span {
  font-size: 0.85rem;
  color: var(--fg-dim);
  font-weight: 500;
}
.grid-2 input, .grid-2 select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0.6rem 0.8rem;
  border-radius: 6px;
  font-size: 0.95rem;
  font-family: inherit;
}
.grid-2 input:focus, .grid-2 select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(185, 122, 255, 0.15);
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.7rem 1.4rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.1s, background 0.15s;
}
button:hover:not(:disabled) { background: #a85df0; }
button:active:not(:disabled) { transform: scale(0.97); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg-dim);
}
button.ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--fg); }

#start-btn { width: 100%; padding: 0.85rem; font-size: 1rem; }

.story-meta {
  font-size: 0.95rem;
  color: var(--fg-dim);
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px dashed var(--border);
}
.story-meta strong { color: var(--fg); }
.badge {
  display: inline-block;
  font-size: 0.7rem;
  background: var(--bg-card);
  color: var(--accent);
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.turns { color: var(--accent-2); font-variant-numeric: tabular-nums; }

.story-log {
  max-height: 500px;
  overflow-y: auto;
  margin-bottom: 1rem;
  padding: 0.5rem;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.turn {
  margin-bottom: 1.25rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.turn:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.turn-scene, .turn-cont {
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 0.6rem;
}
.turn-scene {
  background: rgba(255, 143, 200, 0.08);
  border-left: 3px solid var(--accent-2);
}
.turn-cont {
  background: rgba(185, 122, 255, 0.08);
  border-left: 3px solid var(--accent);
}
.turn-cont p, .turn-scene p { margin: 0; }
.turn-label {
  font-size: 0.75rem;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
  margin-bottom: 0.4rem;
}
.turn-label .ts {
  color: var(--fg-dim);
  font-size: 0.7rem;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  margin-left: 0.4rem;
  font-variant-numeric: tabular-nums;
}

#scene-form textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 0.85rem 1rem;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  min-height: 70px;
  margin-bottom: 0.75rem;
}
#scene-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(185, 122, 255, 0.15);
}
.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.actions button.primary { flex: 1; }

#stories-list { display: flex; flex-direction: column; gap: 0.5rem; }
.story-item {
  display: block;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, transform 0.1s;
}
.story-item:hover { border-color: var(--accent); transform: translateX(2px); }
.story-title { font-weight: 600; color: var(--fg); margin-bottom: 0.25rem; }
.story-sub { font-size: 0.85rem; color: var(--fg-dim); }

.empty {
  text-align: center;
  color: var(--fg-dim);
  padding: 1.5rem;
  font-style: italic;
}
.error {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 0.85rem 1rem;
  border-radius: 8px;
}

.hidden { display: none; }

footer {
  text-align: center;
  padding: 1.5rem 1rem 2rem;
  color: var(--fg-dim);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}
#health { margin-bottom: 0.5rem; }
#health.ok { color: var(--success); }
#health.err { color: var(--danger); }

@media (max-width: 600px) {
  .grid-2 { grid-template-columns: 1fr; }
  header h1 { font-size: 1.7rem; }
  .card { padding: 1.1rem 1.25rem; }
}
