/*
 * Game shell — title, roster, profile and credits (SPEC-REALM-012).
 * The in-game styles live in the other sheets; this covers everything a player
 * sees before the table.
 */

.game-shell {
  min-height: 100dvh;
  background: var(--bg-main);
  color: var(--text-primary);
  font-family: var(--font-body);
}

/* Reduced motion is a preference, not only an OS setting (§2.3). */
.game-shell.shell-reduced-motion *,
.game-shell.shell-reduced-motion *::before,
.game-shell.shell-reduced-motion *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
}

.game-shell.shell-high-contrast {
  --text-secondary: #d7dee6;
  --text-muted: #b6c0cc;
  --border-subtle: rgba(255, 255, 255, 0.45);
}

.game-shell[data-text-size='small'] { font-size: 14px; }
.game-shell[data-text-size='medium'] { font-size: 16px; }
.game-shell[data-text-size='large'] { font-size: 18px; }

/* ---------- Title ---------- */

.title-screen-scroller {
  position: relative;
  height: 100dvh;
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1200px) 500px;
  justify-content: center;
  overflow: hidden;
  background: var(--bg-main);
}

.title-cover-page {
  position: relative;
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: #000;
  overflow: hidden;
}

.title-cover-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain; /* Don't crop on ultrawides */
  object-position: center;
  opacity: 0.9;
}

.title-scroll-prompt {
  display: none; /* Hidden on desktop */
}

.title-screen {
  width: 100%;
  height: 100dvh;
  position: relative;
  display: grid;
  place-items: center;
  background: var(--bg-main);
  border-left: 1px solid var(--border-subtle);
  overflow-y: auto;
}

/* Mobile full width stacked layout */
@media (max-width: 1024px) {
  .title-screen-scroller {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    scroll-snap-type: y mandatory;
  }

  .title-cover-page {
    height: 100dvh;
    flex: 0 0 100dvh;
    scroll-snap-align: start;
  }
  
  .title-cover-image {
    object-fit: cover;
    object-position: top center;
  }

  .title-scroll-prompt {
    position: absolute;
    bottom: 2rem;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    padding: 0.75rem 1.5rem;
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
  }

  .title-scroll-prompt:hover {
    background: rgba(0, 0, 0, 0.8);
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-2px);
  }

  .title-scroll-prompt svg {
    animation: bounce 2s infinite;
  }

  .title-screen {
    flex: 0 0 100dvh;
    width: 100%;
    border-left: none;
    scroll-snap-align: start;
  }
}
  position: relative;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.title-hero {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(168, 85, 247, 0.22), transparent 60%),
    radial-gradient(ellipse at 20% 80%, rgba(59, 130, 246, 0.16), transparent 55%),
    var(--bg-main);
}

.title-content {
  position: relative;
  text-align: center;
  padding: 3rem 1.5rem;
  max-width: 34rem;
  width: 100%;
}

.title-wordmark {
  font-family: var(--font-title);
  font-size: clamp(2.5rem, 8vw, 4rem);
  letter-spacing: 0.04em;
  margin: 0;
  color: var(--text-primary);
  text-shadow: var(--glow-arcane);
  /* Keep the wordmark on one line wherever it fits; it only breaks on narrow
     screens, where breaking is better than shrinking further. */
  white-space: normal;
}

.title-tagline {
  color: var(--text-secondary);
  margin: 0.5rem 0 2.5rem;
  font-size: 0.95rem;
}

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

.title-menu-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.9rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface-translucent);
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.title-menu-item:hover:not(.is-disabled) {
  border-color: var(--border-hover);
  transform: translateX(2px);
}

.title-menu-item.is-primary {
  border-color: var(--border-active);
  box-shadow: var(--glow-arcane);
}

/* Disabled, never hidden — a menu that changes shape between visits is harder
   to learn than one with a dimmed entry (§2.1). */
.title-menu-item.is-disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.title-menu-label {
  font-family: var(--font-title);
  font-size: 1.1rem;
}

.title-menu-hint {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ---------- Shared screen chrome ---------- */

.shell-screen {
  max-width: 52rem;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.shell-screen-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 2rem;
}

.shell-screen-header h2 {
  font-family: var(--font-title);
  margin: 0;
}

.shell-back,
.shell-btn {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
}

.shell-back:hover,
.shell-btn:hover {
  border-color: var(--border-hover);
}

.shell-btn-primary {
  border-color: var(--border-active);
}

.shell-btn-danger {
  border-color: rgba(239, 68, 68, 0.5);
  color: var(--color-crimson);
}

/* ---------- Roster ---------- */

.roster-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.roster-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}

.roster-portrait {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid var(--border-active);
  font-family: var(--font-title);
  font-size: 1.4rem;
  color: var(--text-accent);
}

.roster-identity {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  flex: 1 1 auto;
  min-width: 0;
}

.roster-name {
  font-family: var(--font-title);
  font-size: 1.05rem;
}

.roster-detail { color: var(--text-secondary); font-size: 0.85rem; }
.roster-played { color: var(--text-muted); font-size: 0.75rem; }
.roster-actions { display: flex; gap: 0.5rem; flex: 0 0 auto; flex-wrap: wrap; }
.roster-empty { color: var(--text-secondary); }

/* Restore (#347). Below the list, because it makes a row rather than acts on one. */
.roster-restore {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.5rem;
}

.roster-restore-note {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: 0;
  max-width: 46ch;
}

/* ---------- Profile ---------- */

.profile-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.profile-tab {
  padding: 0.6rem 1rem;
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-secondary);
  font: inherit;
  cursor: pointer;
}

.profile-tab.is-active {
  color: var(--text-primary);
  border-bottom-color: var(--border-active);
}

.profile-group {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem 1.25rem;
  margin: 0 0 1.25rem;
}

.profile-group legend {
  font-family: var(--font-title);
  padding: 0 0.5rem;
  color: var(--text-accent);
}

.profile-choices { display: flex; flex-wrap: wrap; gap: 0.6rem; }

.profile-choice {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.profile-choice.is-selected { border-color: var(--border-active); box-shadow: var(--glow-arcane); }
.profile-choice-hint { color: var(--text-muted); font-size: 0.75rem; }

.profile-toggle {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.4rem 0;
  cursor: pointer;
}

.profile-toggle input[type='checkbox'] {
  accent-color: var(--color-purple);
  width: 1rem;
  height: 1rem;
}

.profile-toggle.is-disabled { opacity: 0.45; cursor: not-allowed; }
.profile-toggle-hint { flex: 1 0 100%; color: var(--text-muted); font-size: 0.75rem; }
.profile-note { color: var(--text-muted); font-size: 0.8rem; margin: 0.75rem 0 0; }

/*
 * The text controls, which had NO RULES AT ALL until now.
 *
 * `.profile-field`, `.profile-input`, `.profile-actions` and `.profile-button`
 * were referenced by `profile-screen.ts` from the day the API key field shipped
 * (#229) and defined nowhere, so the key input, the model input and their two
 * buttons rendered as bare browser controls -- white background, black text,
 * Arial -- on a dark themed screen.
 *
 * NOTHING CAUGHT IT, and the reason is worth writing down: every test on this
 * screen asserts visibility, values and routing. `toBeVisible()` passes on an
 * unstyled control, and so does `toHaveValue()`. The gap was found by opening
 * the page and looking at it.
 */
.profile-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.9rem 0 0;
}

.profile-field-label {
  font-family: var(--font-title);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  color: var(--text-accent);
}

.profile-input {
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  /* `font: inherit` rather than a stack: the same choice `.profile-choice` and
     `.shell-btn` make, so one theme change moves every control together. */
  font: inherit;
  width: 100%;
  box-sizing: border-box;
}

.profile-input:focus {
  outline: none;
  border-color: var(--border-active);
  box-shadow: var(--glow-arcane);
}

.profile-input::placeholder { color: var(--text-muted); }

/* Diagnostics is the one multi-line control, and it is READ-ONLY: a monospace
   face is what makes a pasted fault log legible, and the resize handle is left
   on deliberately so an operator can open it up rather than scroll a six-row box. */
textarea.profile-input {
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 0.78rem;
  line-height: 1.45;
  resize: vertical;
}

.profile-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.6rem 0 0;
}

.profile-button {
  padding: 0.45rem 0.9rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
}

.profile-button:hover { border-color: var(--border-hover); }

.profile-unreadable-note { color: var(--text-muted); font-size: 0.8rem; }

/* The campaign validator's findings, in the editor (#400). */
.library-issues {
  margin: 0.9rem 0 0;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--color-purple);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
}

.library-issues p { margin: 0 0 0.4rem; }
.library-issues ul { margin: 0 0 0.6rem; padding-left: 1.1rem; }
.library-issues li { font-size: 0.82rem; color: var(--text-muted); margin: 0 0 0.25rem; }
.library-issues li code { color: var(--text-accent); font-size: 0.78rem; }
.library-issues > :last-child { margin-bottom: 0; }

/* An ERROR means New Game will not start. That is a different sentence from a
   warning, and it is coloured so an author can tell at a glance. */
.library-issues-error { color: var(--text-primary); }
.library-issues:has(.library-issues-error) { border-left-color: #fb7185; }



/* Dice skins. Each preview carries its own --die-* variables. */
.skin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 0.75rem;
}

.skin-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
  padding: 0.9rem 0.6rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--text-primary);
  font: inherit;
  cursor: pointer;
}

.skin-card.is-selected { border-color: var(--border-active); box-shadow: var(--glow-arcane); }
.skin-card.is-locked { opacity: 0.5; cursor: not-allowed; }

.skin-preview {
  display: grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  border-radius: var(--radius-sm);
  background: var(--die-face);
  border: 2px solid var(--die-edge);
  box-shadow: 0 0 10px var(--die-glow);
}

.skin-preview-die {
  font-family: var(--font-stats);
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--die-numeral);
}

.skin-name { font-family: var(--font-title); font-size: 0.9rem; }
.skin-description { color: var(--text-muted); font-size: 0.7rem; text-align: center; }

/* ---------- Credits ---------- */

.credits-section { margin-bottom: 2rem; }

.credits-section h3 {
  font-family: var(--font-title);
  color: var(--text-accent);
  margin: 0 0 0.6rem;
}

.credits-text { color: var(--text-secondary); line-height: 1.65; margin: 0 0 0.75rem; }

.credits-entries { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.9rem; }

.credits-entry {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding-left: 0.9rem;
  border-left: 2px solid var(--border-subtle);
}

.credits-holder { font-weight: 600; }
.credits-what { color: var(--text-secondary); font-size: 0.9rem; }
.credits-meta { color: var(--text-muted); font-size: 0.78rem; display: flex; gap: 0.6rem; flex-wrap: wrap; }
.credits-licence { color: var(--text-accent); font-family: var(--font-stats); }

/* ── The content library (#255) ─────────────────────────────────────────── */

.library-list {
  display: grid;
  gap: 6px;
  margin-bottom: 4px;
}

.library-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: 'title kind' 'summary edited';
  gap: 2px 12px;
  text-align: left;
  background: rgba(148, 163, 184, 0.08);
  border: 1px solid var(--border-active);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: inherit;
  cursor: pointer;
  transition: background 0.15s ease;
}

.library-row:hover,
.library-row.is-open {
  background: rgba(168, 85, 247, 0.18);
}

.library-row-title { grid-area: title; font-weight: 700; }
.library-row-kind { grid-area: kind; font-size: 11px; opacity: 0.7; letter-spacing: 0.04em; }
.library-row-summary { grid-area: summary; font-size: 12px; opacity: 0.8; }
.library-row-edited {
  grid-area: edited;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-gold, #e6ca65);
}

/*
 * Monospace, because these are prompt slots read by a compiler rather than
 * prose read by a person: the `**Field:**` lines are the content, and a
 * proportional face makes a misaligned one hard to see.
 */
.library-editor {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  background: rgba(7, 9, 14, 0.75);
  color: #e8eaf0;
  border: 1px solid var(--border-active);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  resize: vertical;
}

/* ── The turn in flight (#359) ──────────────────────────────────────────────
   The table used to say nothing between Send and the narration, and this
   endpoint has been measured between 2.2s and 23s (#355). Motion is the
   acknowledgement; the elapsed count only appears once the wait is worth
   naming. */

.feed-item-thinking {
  opacity: 0.85;
}

.feed-thinking-body {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.feed-thinking-label {
  font-style: italic;
}

.feed-thinking-elapsed {
  font-variant-numeric: tabular-nums;
  opacity: 0.6;
  font-size: 0.9em;
}

.feed-thinking-dots {
  display: inline-flex;
  gap: 0.22rem;
}

.feed-thinking-dots i {
  width: 0.38rem;
  height: 0.38rem;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.35;
  animation: feed-thinking-pulse 1.2s ease-in-out infinite;
}

.feed-thinking-dots i:nth-child(2) { animation-delay: 0.18s; }
.feed-thinking-dots i:nth-child(3) { animation-delay: 0.36s; }

@keyframes feed-thinking-pulse {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40%           { opacity: 1;    transform: translateY(-0.16rem); }
}

.custom-action-send-btn.is-busy {
  cursor: progress;
  opacity: 0.75;
}

/* A player who has asked for less motion still gets the acknowledgement -- the
   row, the label and the count are all still there. Only the movement stops. */
@media (prefers-reduced-motion: reduce) {
  .feed-thinking-dots i {
    animation: none;
    opacity: 0.55;
  }
}

/* ---------- Ending (#337) ---------- */

.ending-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  padding: 1rem;
}

.ending-panel {
  max-width: 34rem;
  width: 100%;
  text-align: center;
  padding: 2rem 1.5rem;
  border: 1px solid var(--border-subtle);
  border-radius: 0.75rem;
  background: var(--surface-raised, rgba(0, 0, 0, 0.2));
}

.ending-heading {
  font-family: var(--font-title);
  font-size: 1.75rem;
  margin: 0 0 0.35rem;
}

.ending-campaign {
  color: var(--text-secondary);
  margin: 0 0 1rem;
}

.ending-body {
  color: var(--text-secondary);
  margin: 0 0 1.75rem;
  max-width: 40ch;
  margin-inline: auto;
}

.ending-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* A lost campaign reads differently from a won one without a second layout. */
.ending-screen[data-outcome='DEFEAT'] .ending-heading {
  color: var(--text-danger, #e06c75);
}
