@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Serif:ital,wght@0,400;0,600;1,400&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@24,400,0,0&icon_names=add,arrow_split,close,dark_mode,edit_note,group,light_mode,logout,refresh&display=block");

/* AI Adventure components. Every value comes from tokens.css; class prefix aa-. */

/* The hidden attribute always wins over a component's display. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 20px;
}

/* Icon: Material Symbols Rounded ligatures, e.g. <span class="aa-icon" aria-hidden="true">add</span> */
.aa-icon {
  font-family: var(--font-icon);
  font-size: 24px;
  line-height: 1;
  font-weight: normal;
  font-style: normal;
  letter-spacing: normal;
  text-transform: none;
  white-space: nowrap;
  direction: ltr;
  display: inline-block;
  width: 1em;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "liga";
}

/* Page column */
.aa-page {
  box-sizing: border-box;
  width: 100%;
  max-width: var(--page-max);
  margin-inline: auto;
  padding-block: var(--space-6);
  padding-left: max(var(--space-4), env(safe-area-inset-left, 0px));
  padding-right: max(var(--space-4), env(safe-area-inset-right, 0px));
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

/* Top bar */
.aa-bar {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  height: var(--size-bar);
  padding-left: max(var(--space-2), env(safe-area-inset-left, 0px));
  padding-right: max(var(--space-2), env(safe-area-inset-right, 0px));
  background: var(--brand);
  color: var(--on-brand);
  border-bottom: 1px solid var(--brand-hover);
  position: relative;
  z-index: 2;
}
.aa-bar-title {
  margin: 0 auto 0 var(--space-2);
  font-family: var(--font-serif);
  font-size: 20px;
  line-height: 24px;
  font-weight: 600;
}
/* Logo: the wordmark with Pxl's handwriting over it, inlined so it takes the tokens */
.aa-bar-title:has(.aa-logo) { display: flex; align-items: center; }
.aa-logo { display: block; height: 54px; width: auto; overflow: visible; }
.aa-logo-word { fill: var(--on-brand); }
.aa-logo-ink { stroke: var(--scribble); }
.aa-iconbtn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-0);
  background: none;
  color: inherit;
  cursor: pointer;
}
.aa-iconbtn:hover { background: var(--on-brand-wash); }
.aa-iconbtn:focus-visible { outline: 2px solid var(--on-brand); outline-offset: -2px; }

/* Story card */
.aa-story {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 12rem;
  padding: var(--space-8);
  background: var(--surface);
  border-radius: var(--radius-0);
  border: 1px solid var(--line);
}
.aa-story-turn,
.aa-label {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.aa-story-text {
  margin: 0;
  max-width: var(--measure);
  font-family: var(--font-serif);
  font-size: 20px;
  line-height: 32px;
  white-space: pre-line;
  text-wrap: pretty;
}
.aa-story-text.is-pending { color: var(--ink-muted); }

/* Beats: the scene told in short pieces, narration and speech bubbles */
.aa-beats {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  max-width: var(--measure);
  margin: 0;
  padding: 0;
  list-style: none;
}
.aa-beats.is-pending { opacity: 0.55; }
.aa-narration {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 20px;
  line-height: 32px;
  text-wrap: pretty;
}
.aa-narration strong, .aa-bubble strong { font-weight: 600; }
/* Each bubble gets its colors inline (app.js paintBubble): a light and a dark pair, picked by theme. */
.aa-speech {
  --bubble: var(--bubble-light, var(--bubble-violet));
  --bubble-ink: var(--bubble-ink-light, var(--bubble-violet-ink));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
}
[data-theme="dark"] .aa-speech {
  --bubble: var(--bubble-dark, var(--bubble-violet));
  --bubble-ink: var(--bubble-ink-dark, var(--bubble-violet-ink));
}
.aa-speaker {
  margin: 0;
  font: 500 12px/16px var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bubble-ink);
}
.aa-bubble {
  position: relative;
  margin: 0;
  max-width: 100%;
  padding: var(--space-2) var(--space-4);
  background: var(--bubble);
  border: 1px solid var(--bubble-ink);
  border-radius: var(--radius-0);
  color: var(--ink);
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 28px;
  overflow-wrap: anywhere;
}
.aa-bubble::before {
  content: "";
  position: absolute;
  top: -6px;
  left: var(--space-4);
  width: 10px;
  height: 10px;
  background: var(--bubble);
  border-top: 1px solid var(--bubble-ink);
  border-left: 1px solid var(--bubble-ink);
  transform: rotate(45deg);
}

/* Fake progress while the model thinks: a bar that grows along the story card's bottom border */
.aa-progress {
  position: absolute;
  left: -1px;
  right: -1px;
  bottom: -1px;
  z-index: 1;
  height: 2px;
  background: var(--brand-ink);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.2s linear, opacity 0.4s ease-out;
  pointer-events: none;
}
.aa-progress.is-done { opacity: 0; transition: transform 0.25s ease-out, opacity 0.4s ease-out 0.25s; }

/* The story is over: in place of the options */
.aa-ended {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--surface);
  border: 1px solid var(--line);
}
.aa-ended-text { margin: 0; font-family: var(--font-serif); font-size: 18px; line-height: 28px; color: var(--ink); }

/* Story log: a fixed-height card that scrolls; the top edge blurs and fades */
.aa-story.is-log {
  position: relative;
  display: block;
  min-height: 0;
  padding: 0;
}
.aa-story-scroll {
  box-sizing: border-box;
  height: clamp(16rem, 58vh, 36rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  padding: 0 var(--space-8) var(--space-8);
}
.aa-story-veil {
  position: sticky;
  top: 0;
  flex: none;
  height: 6rem;
  margin-bottom: -6rem;
  z-index: 1;
  pointer-events: none;
  background: linear-gradient(to bottom, var(--surface) 10%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  -webkit-mask-image: linear-gradient(to bottom, #000 25%, transparent);
  mask-image: linear-gradient(to bottom, #000 25%, transparent);
}
.aa-log {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin: auto 0 0;
  padding: 6rem 0 0;
  list-style: none;
}
.aa-log > .aa-beat { max-width: var(--measure); }
.aa-pick { align-self: flex-end; max-width: min(100%, 28rem); }
.aa-speech.is-new { animation: aa-pop 0.28s ease-out both; transform-origin: left top; }

/* Steer: a note to the narrator, sent with the next action */
.aa-steer {
  position: absolute;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 3;
  color: var(--ink-muted);
}
.aa-steer:hover { background: var(--brand-soft); color: var(--brand-ink); }
.aa-steer:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.aa-steer[aria-pressed="true"] { background: var(--brand-soft); color: var(--brand-ink); outline: 1px solid var(--brand-ink); outline-offset: -1px; }
.aa-steer-panel {
  position: absolute;
  top: calc(var(--space-3) + 40px);
  left: var(--space-3);
  right: var(--space-3);
  max-width: 26rem;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--control);
  border-radius: var(--radius-0);
}
.aa-steer-text { margin: 0; font-family: var(--font-serif); font-size: 15px; line-height: 24px; color: var(--ink); }

/* Start screen: the theme composer and how many options each turn offers */
.aa-start { display: flex; flex-direction: column; gap: var(--space-4); }
/* The start screen's welcome: serif, like the story it leads into */
.aa-intro { display: flex; flex-direction: column; gap: var(--space-3); max-width: var(--measure); margin-bottom: var(--space-2); }
.aa-intro p { margin: 0; font-family: var(--font-serif); font-size: 18px; line-height: 28px; color: var(--ink); text-wrap: pretty; }
.aa-intro strong { font-weight: 600; }
.aa-count { display: flex; flex-direction: column; gap: var(--space-2); margin: 0; padding: 0; border: 0; min-width: 0; }
.aa-count legend { padding: 0; margin-bottom: var(--space-2); }
.aa-count-row { display: flex; flex-wrap: wrap; }
.aa-count-opt { position: relative; margin-left: -1px; }
.aa-count-opt:first-child { margin-left: 0; }
.aa-count-opt input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.aa-count-opt span {
  display: grid;
  place-items: center;
  width: var(--size-control);
  height: var(--size-control);
  border: 1px solid var(--control);
  background: var(--field);
  color: var(--ink);
  font: 500 14px/20px var(--font-mono);
}
.aa-count-opt input:hover + span { color: var(--brand-ink); border-color: var(--brand-ink); position: relative; }
.aa-count-opt input:checked + span { background: var(--brand); border-color: var(--brand); color: var(--on-brand); position: relative; }
.aa-count-opt input:focus-visible + span { box-shadow: var(--focus-ring); position: relative; z-index: 1; }

/* Two-way switch (faster / better responses): joined cells like the count picker, sized to their words */
.aa-switch { display: flex; }
.aa-switch-opt { position: relative; margin-left: -1px; }
.aa-switch-opt:first-child { margin-left: 0; }
.aa-switch-opt input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.aa-switch-opt span {
  display: grid;
  place-items: center;
  height: var(--size-control);
  padding: 0 var(--space-3);
  border: 1px solid var(--control);
  background: var(--field);
  color: var(--ink);
  font: 500 14px/20px var(--font-mono);
  white-space: nowrap;
}
.aa-switch-opt input:hover + span { color: var(--brand-ink); border-color: var(--brand-ink); position: relative; }
.aa-switch-opt input:checked + span { background: var(--brand); border-color: var(--brand); color: var(--on-brand); position: relative; }
.aa-switch-opt input:focus-visible + span { box-shadow: var(--focus-ring); position: relative; z-index: 1; }

/* Options pop in one after another */
.aa-choices > li { animation: aa-pop 0.22s ease-out both; animation-delay: calc(var(--i, 0) * 70ms); }

/* Gate: the sign-in and no-access screens, inside a story card */
.aa-gate { justify-content: center; align-items: flex-start; gap: var(--space-4); }
.aa-gate-text { margin: 0; max-width: var(--measure); font-family: var(--font-serif); font-size: 18px; line-height: 28px; }

/* Choices */
.aa-choices {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}
.aa-choice {
  --choice-ink: var(--brand-ink);
  --choice-fill: var(--brand);
  box-sizing: border-box;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  width: 100%;
  height: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--choice-ink);
  border-radius: var(--radius-0);
  background: var(--field);
  color: var(--choice-ink);
  font: 400 14px/20px var(--font-mono);
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
/* The last option is the unhinged one: red instead of purple. */
.aa-choice.is-unhinged { --choice-ink: var(--unhinged-ink); --choice-fill: var(--unhinged); }
.aa-choice-key { flex: none; font-weight: 600; }
.aa-choice:hover:not(:disabled),
.aa-choice[aria-pressed="true"] {
  background: var(--choice-fill);
  border-color: var(--choice-fill);
  color: var(--on-brand);
}
.aa-choice:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.aa-choice:disabled { cursor: not-allowed; }
.aa-choice[aria-pressed="true"]:disabled { cursor: progress; }
.aa-choice:disabled:not([aria-pressed="true"]) {
  border-color: var(--control);
  color: var(--ink-muted);
}

/* Buttons */
.aa-btn {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--size-control);
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--brand);
  border-radius: var(--radius-0);
  background: var(--brand);
  color: var(--on-brand);
  font: 500 14px/20px var(--font-mono);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}
.aa-btn:hover:not(:disabled) { background: var(--brand-hover); border-color: var(--brand-hover); }
.aa-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.aa-btn:disabled {
  background: var(--field);
  border-color: var(--control);
  color: var(--ink-muted);
  cursor: not-allowed;
}
.aa-btn-quiet {
  background: none;
  border-color: transparent;
  color: var(--brand-ink);
}
.aa-btn-quiet:hover:not(:disabled) { background: var(--brand-soft); border-color: transparent; }
.aa-btn .aa-icon { font-size: 20px; }

/* Field */
.aa-field { display: flex; flex-direction: column; gap: var(--space-2); }
.aa-input {
  box-sizing: border-box;
  width: 100%;
  min-height: var(--size-control);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--control);
  border-radius: var(--radius-0);
  background: var(--field);
  color: var(--ink);
  font: 400 14px/20px var(--font-mono);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.aa-input::placeholder { color: var(--ink-muted); opacity: 1; }
.aa-input { text-overflow: ellipsis; }
.aa-input:focus { outline: none; border-color: var(--brand-ink); box-shadow: 0 0 0 1px var(--brand-ink); }
.aa-input[aria-invalid="true"] { border-color: var(--danger); }

/* Composer: a field with its action on the right */
.aa-compose { display: flex; gap: var(--space-3); align-items: flex-end; }
.aa-compose .aa-field { flex: 1; min-width: 0; }

/* Modal */
.aa-scrim {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: var(--scrim);
  animation: aa-fade 0.2s ease-out;
}
.aa-modal {
  box-sizing: border-box;
  width: min(100%, 32rem);
  max-height: min(80vh, 40rem);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-6);
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius-0);
  border: 1px solid var(--line);
  animation: aa-rise 0.2s ease-out;
}
.aa-modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.aa-modal-title { margin: 0; font-family: var(--font-serif); font-size: 24px; line-height: 30px; font-weight: 600; }
.aa-modal-text { margin: 0; font-family: var(--font-serif); font-size: 17px; line-height: 26px; text-wrap: pretty; }
.aa-modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); }
.aa-modal .aa-iconbtn { color: var(--ink-muted); }
.aa-modal .aa-iconbtn:hover { background: var(--brand-soft); color: var(--brand-ink); }
.aa-modal .aa-iconbtn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* History */
.aa-history { display: flex; flex-direction: column; gap: var(--space-3); margin: 0; padding: 0; list-style: none; }
.aa-entry {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-4);
  background: var(--bg);
  border-radius: var(--radius-0);
  border: 1px solid var(--line);
}
.aa-entry-text { margin: 0; font-family: var(--font-serif); font-size: 15px; line-height: 24px; }
.aa-chip {
  display: inline-flex;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--brand-ink);
  border-radius: var(--radius-0);
  background: var(--brand-soft);
  color: var(--brand-ink);
  font: 500 14px/20px var(--font-mono);
}
.aa-empty { margin: 0; color: var(--ink-muted); }

/* Status: loading and error */
.aa-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--size-control);
  font: 400 12px/16px var(--font-mono);
  color: var(--ink-muted);
}
.aa-spinner {
  box-sizing: border-box;
  width: 16px;
  height: 16px;
  border: 2px solid var(--brand-ink);
  border-bottom-color: transparent;
  border-radius: var(--radius-full);
  animation: aa-spin 0.6s linear infinite;
}
.aa-status-error {
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border-radius: var(--radius-0);
  background: var(--danger-soft);
  color: var(--danger);
  font: 400 14px/20px var(--font-mono);
}
.aa-status-error .aa-btn-quiet { color: var(--danger); }
.aa-status-error .aa-btn-quiet:hover:not(:disabled) { background: none; text-decoration: underline; }

/* Footer and links */
.aa-footer { text-align: center; font: 400 12px/16px var(--font-mono); color: var(--ink-muted); }
.aa-link { color: var(--brand-ink); text-decoration: none; text-underline-offset: 3px; }
.aa-link:hover { text-decoration: underline; }
.aa-link:focus-visible { outline: none; box-shadow: var(--focus-ring); }

@keyframes aa-spin { to { transform: rotate(1turn); } }
@keyframes aa-fade { from { opacity: 0; } }
@keyframes aa-pop { from { opacity: 0; transform: scale(0.9); } }
@keyframes aa-rise { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

@media (max-width: 560px) {
  .aa-story { padding: var(--space-5); }
  .aa-story-scroll { padding: 0 var(--space-5) var(--space-5); height: clamp(14rem, 55vh, 30rem); }
  .aa-logo { height: 40px; }
  .aa-story-text, .aa-narration { font-size: 18px; line-height: 28px; }
  .aa-bubble { font-size: 17px; line-height: 26px; }
  .aa-choices { grid-template-columns: minmax(0, 1fr); }
  .aa-compose { flex-direction: column; align-items: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  .aa-scrim, .aa-modal { animation: none; }
  .aa-choice, .aa-btn, .aa-input { transition: none; }
  .aa-spinner { animation-duration: 1.6s; }
  .aa-speech.is-new, .aa-choices > li { animation: none; }
}
