/*
 * Calm Story Narrator — the single stylesheet, mirroring DESIGN.md.
 *
 * Warm minimalism: warm neutrals (never blue-gray), whisper borders, restrained
 * shadows, one saturated accent reserved for the primary action. Two modes share
 * these tokens: the dashboard a parent manages, and focus mode, which is
 * deliberately stripped to one button and one sentence.
 *
 * Nothing animates. Transitions are disabled outright rather than merely toned
 * down, because a child's screen should never move on its own.
 */

:root {
  --paper: #fbf9f6;
  --surface: #ffffff;
  --warm: #f6f5f4;
  --ink: #2f2b28;
  --ink-soft: #615d59;
  --ink-muted: #a39e98;
  --border: rgba(0, 0, 0, 0.1);

  --accent: #3f6b8f;
  --accent-dark: #2f5170;
  --accent-tint: #eef4f9;

  --ok: #17743a;
  --ok-tint: #eefaf1;
  --warn: #a34700;
  --warn-tint: #fdf3ea;
  --error: #a3271c;
  --error-tint: #fdefee;

  --speaking: #fdf1dc;
  --speaking-edge: #e6c893;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 9999px;

  --shadow-card: rgba(0, 0, 0, 0.04) 0 4px 18px, rgba(0, 0, 0, 0.027) 0 2px 8px,
    rgba(0, 0, 0, 0.02) 0 1px 3px;

  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Georgia, serif;

  --focus-ring: 0 0 0 3px var(--accent-tint), 0 0 0 5px var(--accent);
}

* {
  transition: none !important;
  animation: none !important;
}

html,
body {
  background: var(--paper);
  color: var(--ink);
}

body {
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.5;
}

.skip-link {
  position: absolute;
  left: -9999px;
}

.skip-link:focus {
  left: var(--space-4);
  top: var(--space-4);
  background: var(--surface);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  z-index: 100;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* ---------------------------------------------------------------- app bar -- */

.app-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-bar-inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.app-brand {
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.app-nav {
  display: flex;
  gap: var(--space-4);
  flex: 1;
}

.app-nav a {
  color: var(--ink-soft);
  text-decoration: none;
  font-weight: 500;
  padding: var(--space-2) 0;
  min-height: 48px;
  display: inline-flex;
  align-items: center;
}

.app-nav a:hover,
.app-nav a[aria-current="page"] {
  color: var(--accent);
}

.app-account {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.app-username {
  color: var(--ink-muted);
  font-size: 0.875rem;
}

/* ------------------------------------------------------------- containers -- */

.app-container {
  max-width: 1040px;
  padding: var(--space-6) var(--space-4) var(--space-7);
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}

.page-head h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.page-head-actions {
  display: flex;
  gap: var(--space-2);
}

.muted {
  color: var(--ink-muted);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}

.panel h2 {
  font-size: 1.0625rem;
  font-weight: 600;
  margin-bottom: var(--space-4);
}

/* --------------------------------------------------------------- buttons -- */

.btn {
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 0.9375rem;
  border-radius: var(--radius-sm);
  padding: var(--space-3) var(--space-4);
  min-height: 48px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
  color: #ffffff;
}

.btn-primary:disabled {
  background: var(--ink-muted);
  border-color: var(--ink-muted);
}

.btn-quiet {
  background: rgba(0, 0, 0, 0.05);
  color: var(--ink);
  border-color: transparent;
}

.btn-quiet:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--ink);
}

.btn-danger-quiet {
  background: var(--error-tint);
  color: var(--error);
  border-color: transparent;
}

.btn-sm {
  min-height: 40px;
  padding: var(--space-2) var(--space-3);
  font-size: 0.875rem;
}

.btn-lg-action {
  font-size: 1.0625rem;
  padding: var(--space-4);
  width: 100%;
}

.btn-block {
  width: 100%;
}

/* ---------------------------------------------------------------- notices -- */

.notice {
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-5);
  border: 1px solid var(--border);
}

.notice p {
  margin: 0;
}

.notice-warn {
  background: var(--warn-tint);
  color: var(--warn);
}

.notice-error {
  background: var(--error-tint);
  color: var(--error);
}

.notice-ok {
  background: var(--ok-tint);
  color: var(--ok);
}

.notice-info {
  background: var(--accent-tint);
  color: var(--accent-dark);
}

.warning-list {
  margin: var(--space-3) 0 0;
  padding-left: var(--space-5);
}

.warning-kind {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.125px;
  text-transform: uppercase;
  color: var(--warn);
}

/* ------------------------------------------------------------------ pills -- */

.pill {
  display: inline-block;
  border-radius: var(--radius-pill);
  padding: 2px var(--space-2);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.125px;
  background: var(--warm);
  color: var(--ink-soft);
}

.pill-succeeded {
  background: var(--ok-tint);
  color: var(--ok);
}

.pill-running {
  background: var(--accent-tint);
  color: var(--accent-dark);
}

.pill-pending {
  background: var(--warm);
  color: var(--ink-soft);
}

.pill-failed {
  background: var(--error-tint);
  color: var(--error);
}

/* ------------------------------------------------------------ story cards -- */

.story-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: var(--space-3);
}

.story-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.story-card-title {
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 var(--space-2);
}

.story-card-title a {
  color: var(--ink);
  text-decoration: none;
}

.story-card-title a:hover {
  color: var(--accent);
}

.story-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin: 0;
  color: var(--ink-muted);
  font-size: 0.875rem;
  align-items: center;
}

.story-card-error {
  margin: var(--space-2) 0 0;
  color: var(--error);
  font-size: 0.875rem;
}

.story-card-actions {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.story-card-actions form {
  margin: 0;
}

/* ----------------------------------------------------------- empty states -- */

.empty-state {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-7) var(--space-5);
  text-align: center;
}

.empty-state h1,
.empty-state h2 {
  font-size: 1.375rem;
  font-weight: 700;
  margin-bottom: var(--space-3);
}

.empty-state p {
  color: var(--ink-soft);
  max-width: 42ch;
  margin: 0 auto var(--space-5);
}

/* --------------------------------------------------------------- skeleton -- */

.skeleton-list {
  display: grid;
  gap: var(--space-3);
}

.skeleton-row {
  height: 84px;
  border-radius: var(--radius-lg);
  background: linear-gradient(90deg, var(--warm), #ecebe9, var(--warm));
}

/* ------------------------------------------------------------------ forms -- */

.field {
  margin-bottom: var(--space-5);
}

.field label {
  display: block;
  font-weight: 600;
  font-size: 0.9375rem;
  margin-bottom: var(--space-2);
}

.field input[type="text"],
.field input[type="password"],
.field textarea {
  width: 100%;
  border: 1px solid #dddddd;
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: var(--surface);
}

.field textarea {
  line-height: 1.7;
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--ink-muted);
}

.field-hint {
  margin: var(--space-2) 0 0;
  color: var(--ink-muted);
  font-size: 0.875rem;
}

.field-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.field-check label {
  margin: 0;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.story-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

/* ------------------------------------------------------------------ login -- */

.login-card {
  max-width: 26rem;
  margin: var(--space-7) auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-6);
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-2);
}

.login-subtitle {
  color: var(--ink-soft);
  margin-bottom: var(--space-5);
}

.login-hint {
  color: var(--ink-muted);
  font-size: 0.875rem;
  margin: var(--space-5) 0 0;
}

/* ----------------------------------------------------------------- player -- */

.story-lines {
  list-style: none;
  margin: 0 0 var(--space-5);
  padding: 0;
}

.sentence {
  font-family: var(--font-serif);
  font-size: clamp(1.35rem, 4.5vw, 1.9rem);
  line-height: 1.7;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border-left: 0.5rem solid transparent;
  cursor: pointer;
}

.sentence + .sentence {
  margin-top: var(--space-1);
}

.sentence.is-speaking {
  background: var(--speaking);
  border-left-color: var(--speaking-edge);
}

.btn-play {
  font-size: 1.75rem;
  padding: var(--space-5) var(--space-4);
  min-height: 5.5rem;
  border-radius: var(--radius-lg);
}

.story-hint {
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.9375rem;
  margin-top: var(--space-4);
}

.danger-zone {
  margin-top: var(--space-7);
  padding-top: var(--space-5);
  border-top: 1px solid var(--border);
}

/* -------------------------------------------------------------- focus mode -- */

.focus-body {
  background: var(--paper);
  min-height: 100vh;
}

.focus-shell {
  max-width: 44rem;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4) var(--space-5);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.focus-title {
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 700;
  text-align: center;
  color: var(--ink-soft);
  margin-bottom: var(--space-6);
}

.focus-sentences {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--space-3);
}

.focus-sentences .sentence {
  font-size: clamp(1.6rem, 6vw, 2.4rem);
  line-height: 1.6;
  border-left-width: 0.4rem;
}

.focus-controls {
  margin-top: var(--space-6);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}

.focus-button {
  width: 100%;
  font-size: 2rem;
  min-height: 7rem;
  border-radius: var(--radius-lg);
}

.focus-exit {
  color: var(--ink-muted);
  font-size: 0.9375rem;
  text-decoration: none;
  padding: var(--space-2) var(--space-3);
}

/* ------------------------------------------------------------------ table -- */

.table-quiet {
  width: 100%;
  border-collapse: collapse;
}

.table-quiet th,
.table-quiet td {
  text-align: left;
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  font-size: 0.9375rem;
  vertical-align: middle;
}

.table-quiet th {
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.125px;
}

.admin-actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
}

.admin-actions form {
  margin: 0;
}

.pw-form {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.pw-form input {
  width: 10rem;
  border: 1px solid #dddddd;
  border-radius: var(--radius-sm);
  padding: var(--space-2);
}

.add-user-form {
  max-width: 28rem;
}

/* ------------------------------------------------------------------ toast -- */

.toast-stack {
  position: fixed;
  bottom: var(--space-4);
  right: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 50;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: var(--space-3) var(--space-4);
  font-size: 0.9375rem;
  max-width: 22rem;
}

.toast-error {
  border-left-color: var(--error);
}

/* --------------------------------------------------------------- responsive -- */

@media (max-width: 600px) {
  .app-bar-inner {
    gap: var(--space-3);
  }

  .app-nav {
    order: 3;
    width: 100%;
    justify-content: space-between;
  }

  .story-card {
    flex-direction: column;
    align-items: stretch;
  }

  .story-card-actions {
    justify-content: stretch;
  }

  .story-card-actions .btn {
    flex: 1;
  }

  .table-quiet {
    display: block;
    overflow-x: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
