/* Global tokens + shared primitives. Each view owns its own stylesheet with its own prefix. */
:root {
  /* type */
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-hand: "Segoe Print", "Bradley Hand", "Noteworthy", "Comic Neue", "Comic Sans MS", cursive;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* search-engine look (light) */
  --c-bg: #ffffff;
  --c-text: #202124;
  --c-muted: #5f6368;
  --c-border: #dfe1e5;
  --c-surface: #f8f9fa;
  --c-link: #1a0dab;
  --c-link-visited: #681da8;
  --c-url: #188038;
  --c-focus: #5b8def;
  /* playful logo colours */
  --c-logo-1: #5b8def;
  --c-logo-2: #e8574a;
  --c-logo-3: #f5b82e;
  --c-logo-4: #3fae5b;

  /* gram (dark) */
  --g-bg: #000000;
  --g-text: #ffffff;
  --g-muted: rgba(255, 255, 255, 0.7);
  --g-accent: #ff3b5c;
  --g-gradient: linear-gradient(45deg, #f9ce34, #ee2a7b, #6228d7);

  /* letter (paper) */
  --l-paper: #fbf5e9;
  --l-paper-edge: #efe3c8;
  --l-ink: #3a2e2a;
  --l-accent: #b8433a;
  --l-desk: #e9d8c4;

  /* shape + motion */
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 24px;
  --radius-pill: 999px;
  --shadow-1: 0 1px 6px rgba(32, 33, 36, 0.28);
  --shadow-2: 0 8px 30px rgba(0, 0, 0, 0.18);
  --gutter: 16px;
  --maxw: 680px;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur: 280ms;

  /* layering */
  --z-overlay: 50;
  --z-music: 60;
  --z-fx: 70;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--c-bg);
  color: var(--c-text);
  font: 16px/1.5 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
#app { min-height: 100dvh; }
.view { min-height: 100dvh; }
img, video, canvas { max-width: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 3px solid var(--c-focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

.center-screen {
  min-height: 100dvh; display: grid; place-items: center; align-content: center;
  gap: 12px; padding: var(--gutter); text-align: center;
}

/* spinner */
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--c-border); border-top-color: var(--c-logo-1);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* generic buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px; border-radius: var(--radius-pill);
  border: 1px solid var(--c-border); background: var(--c-surface); color: var(--c-text);
  font-size: 15px; transition: transform var(--dur) var(--ease-out), box-shadow var(--dur);
}
.btn:hover { box-shadow: var(--shadow-1); }
.btn:active { transform: scale(0.97); }

/* Shared "← Back" button used at the bottom of chapter / gram / letter */
.btn-back-wrap { display: flex; justify-content: center; padding: 32px var(--gutter) calc(32px + env(safe-area-inset-bottom)); }
/* use as: class="btn btn-back" */
.btn-back::before { content: "\2190"; }

/* message screens (no link / errors) */
.msg-emoji { font-size: 56px; }
.msg-title { margin: 0; font-size: 22px; }
.msg-body { margin: 0; color: var(--c-muted); max-width: 32ch; }

/* entrance animations */
@keyframes fade-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.fade-up { animation: fade-up 480ms var(--ease-out) both; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
