:root {
  color-scheme: dark;
  --bg: #0f0d0c;
  --ink: #f7efe5;
  --soft: #c8b8aa;
  --faint: #82766d;
  --line: rgba(247, 239, 229, 0.14);
  --line-strong: rgba(247, 239, 229, 0.32);
  --accent: #d14a70;
  --font: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: var(--font);
  background:
    radial-gradient(circle at 20% 0%, rgba(209, 74, 112, 0.1), transparent 18rem),
    linear-gradient(180deg, #0f0d0c 0%, #11100f 52%, #0c1110 100%);
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

textarea {
  width: 100%;
  border: 0;
  color: var(--ink);
  background: transparent;
  outline: none;
  resize: none;
  line-height: 1.45;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  border: 0;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.story-shell {
  display: flex;
  flex-direction: column;
  width: min(100%, 44rem);
  min-height: 100svh;
  margin: 0 auto;
  padding: clamp(0.7rem, 2vw, 1.4rem) 1rem max(0.75rem, env(safe-area-inset-bottom));
}

.thread {
  order: 1;
  display: grid;
  gap: 0;
  padding: 0.25rem 0 0.7rem;
}

.has-story .thread {
  min-height: 36svh;
}

.turn {
  display: block;
}

.turn + .turn {
  margin-top: 2rem;
  padding-top: 2rem;
  border-top: 1px solid var(--line);
}

.turn-scene {
  min-height: 1.7rem;
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: clamp(1.02rem, 4.25vw, 1.2rem);
  line-height: 1.68;
  white-space: pre-wrap;
}

.turn.is-streaming .turn-scene::after {
  display: inline-block;
  width: 0.5ch;
  height: 1.05em;
  margin-left: 0.08em;
  background: var(--accent);
  content: "";
  animation: cursor-blink 850ms steps(2, start) infinite;
  transform: translateY(0.16em);
}

@keyframes cursor-blink {
  0%,
  45% {
    opacity: 1;
  }

  46%,
  100% {
    opacity: 0;
  }
}

.choice-panel {
  order: 2;
  margin: 0.4rem 0 0.9rem;
}

.choices {
  display: grid;
  gap: 0.6rem;
}

.choice-button,
.starter-grid button,
.text-button {
  border: 0;
  color: inherit;
  background: transparent;
}

.choice-button {
  width: 100%;
  padding: 0.72rem 0;
  border-top: 1px solid var(--line);
  color: var(--soft);
  text-align: left;
  line-height: 1.38;
}

.choice-button:hover,
.choice-button:focus-visible {
  color: var(--ink);
  outline: none;
}

.composer {
  order: 0;
  display: grid;
  gap: 0.75rem;
  margin: 0 0 1.1rem;
  padding-top: 0.35rem;
}

.has-story .composer {
  order: 3;
  margin-top: 0.8rem;
  padding-top: 0;
}

.composer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: end;
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--line-strong);
}

.composer-row:focus-within {
  border-color: rgba(209, 74, 112, 0.7);
}

.composer textarea {
  min-height: 2.6rem;
  max-height: 10rem;
  padding: 0.48rem 0;
}

.text-button:disabled,
.choice-button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

.starter-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.75rem;
  color: var(--faint);
  font-size: 0.86rem;
}

.has-story .starter-grid {
  display: none;
}

.starter-grid button {
  padding: 0;
  color: var(--faint);
  text-align: left;
}

.starter-grid button:hover,
.starter-grid button:focus-visible,
.text-button:hover,
.text-button:focus-visible {
  color: var(--ink);
  outline: none;
}

.composer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.status-text {
  min-width: 0;
  margin: 0;
  color: var(--faint);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.status-text:empty {
  display: none;
}

.text-button {
  flex: 0 0 auto;
  padding: 0;
  color: var(--faint);
  font-size: 0.82rem;
  text-decoration: none;
}

.text-button.strong {
  color: var(--ink);
  font-weight: 700;
}

.age-gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(15, 13, 12, 0.92);
  backdrop-filter: blur(18px);
}

.age-card {
  width: min(27rem, 100%);
  padding: 1.2rem 0;
}

.age-card p {
  margin: 0 0 0.55rem;
  color: var(--soft);
  line-height: 1.55;
}

.age-card h1 {
  margin: 0 0 1.2rem;
  font-family: var(--serif);
  font-size: 2.2rem;
  line-height: 1;
}

.age-actions {
  display: flex;
  gap: 1rem;
}

@media (min-width: 720px) {
  .story-shell {
    padding-top: 2rem;
    padding-bottom: 1.5rem;
  }
}

@media (max-width: 430px) {
  .story-shell {
    padding-right: 0.85rem;
    padding-left: 0.85rem;
  }

  .composer-row {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }
}
