/* ============================================================
   Loopkins — shared design system: hand-drawn sketchbook.
   Warm paper, ink linework, sticker buttons, colored-pencil
   accents. Every feature stylesheet (mixer/creator/soundlab.css)
   consumes these :root tokens so the app reads as one system.
   ============================================================ */
:root {
  /* ---- paper & ink core ---- */
  --paper: #f5efe1;            /* page background — warm cream */
  --paper-soft: #efe4cd;       /* appbar / footer / recessed wash */
  --card: #fffaf2;             /* sticker / index-card fill */
  --ink: #2c2622;              /* primary hand-ink text + strokes */
  --ink-soft: #5b534a;         /* faded-pencil muted text (~6.6:1 on paper) */
  --line: #2c2622;             /* solid drawn borders */
  --line-soft: #a89678;        /* lighter pencil/dash lines (decorative) */
  --dot-grid: rgba(44, 38, 34, .1); /* faint graph-paper dots */
  --paper-noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch' result='t'/%3E%3CfeColorMatrix in='t' type='matrix' values='0 0 0 0 0.173 0 0 0 0 0.149 0 0 0 0 0.129 0 0 0 0.045 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");

  /* ---- fonts: system-only, CSP forbids web fonts ---- */
  --font-hand: 'Chalkboard SE', 'Bradley Hand', 'Marker Felt', 'Comic Sans MS', 'Comic Neue', cursive;
  --font-body: -apple-system, "Segoe UI", system-ui, sans-serif;

  /* ---- category colored-pencil accents (red beats / teal effects / yellow tunes / purple voices) ---- */
  --cat-beat: #d1495b;
  --cat-effect: #2f9e8f;
  --cat-melody: #d9a520;
  --cat-voice: #7c5cbf;
  --cat-fallback: #8a8172;     /* warm graphite — replaces cold gray fallback */

  /* ---- action colors ---- */
  --accent: #ffd23f;           /* warm marker highlight — primary/save */
  --accent-ink: #2c2622;       /* text on accent */
  --danger: #d1495b;           /* record / delete pencil-red */
  --focus: #1d6fe0;            /* focus ring — clear on both paper & ink */

  /* ---- hand-drawn shape language ---- */
  --radius-card: 20px 24px 22px 26px;
  --radius-tab: 14px 18px 16px 20px;
  --radius-btn: 16px 20px 18px 22px;
  --radius-pill: 999px;

  --target: 76px;

  /* ---- legacy aliases: pwa.js injects an inline <style> for .about-*
     and #pwa-install-banner that reads these exact var names with hex
     fallbacks. Keeping them mapped to the paper tokens re-themes that
     JS-owned markup without editing pwa.js. Do not rename. ---- */
  --bg: var(--paper);
  --bg2: var(--paper-soft);
  --panel: var(--card);
  --panel-line: var(--line);
  --text: var(--ink);
  --muted: var(--ink-soft);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background-color: var(--paper);
  background-image: var(--paper-noise), radial-gradient(var(--dot-grid) .8px, transparent .8px);
  background-size: auto, 25px 25px;
  background-attachment: fixed, fixed;
  min-height: 100dvh; display: flex; flex-direction: column;
  overscroll-behavior: none; user-select: none; -webkit-user-select: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* headings, labels & buttons get the handwriting stack; small print stays sans for legibility */
h1, h2, h3,
button, .tab, .brand,
.charrow-label, .col h2, .mychar span, .char .name,
label { font-family: var(--font-hand); }

/* ---------- start overlay ---------- */
.overlay { position: fixed; inset: 0; z-index: 50;
  background-color: var(--paper);
  background-image: var(--paper-noise), radial-gradient(var(--dot-grid) .8px, transparent .8px);
  background-size: auto, 25px 25px;
  display: none; place-items: center; text-align: center; }
.overlay.visible { display: grid; }
.overlay-card { padding: 32px; max-width: 460px; }
.logo-big { font-size: 88px; animation: float 2.4s ease-in-out infinite; filter: drop-shadow(3px 4px 0 rgba(44,38,34,.14)); }
.overlay h1 { font-size: 54px; margin: 4px 0 10px; color: var(--ink);
  text-shadow: 3px 3px 0 rgba(44,38,34,.08); }
.tag { font-family: var(--font-body); color: var(--ink-soft); font-size: 19px; line-height: 1.5; margin: 0 0 30px; }
.start-btn { font-family: var(--font-hand); font-size: 28px; font-weight: 700; color: var(--accent-ink);
  background: var(--accent); border: 2.5px solid var(--line); border-radius: var(--radius-btn);
  padding: 20px 44px; cursor: pointer; box-shadow: 4px 5px 0 var(--line);
  transition: transform .08s, box-shadow .08s; }
.start-btn:active { transform: translate(4px, 5px); box-shadow: 0 0 0 var(--line); }
.start-btn:disabled { filter: saturate(.5) brightness(1.05); cursor: default; }
.overlay-text { font-family: var(--font-body); color: var(--ink-soft); margin-top: 20px; font-size: 16px; min-height: 20px; }

/* ---------- app bar + nav ---------- */
.appbar { display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px; border-bottom: 2.5px solid var(--line);
  position: sticky; top: 0; z-index: 10; background: var(--paper-soft);
  box-shadow: 0 2px 0 rgba(44,38,34,.06); }
.brand { font-size: 23px; font-weight: 700; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.brand .logo { font-size: 25px; }
.nav { display: flex; gap: 10px; }
.tab { font-size: 17px; font-weight: 700; color: var(--ink); background: var(--card);
  border: 2px solid var(--line); border-radius: var(--radius-tab); padding: 10px 16px; cursor: pointer;
  min-height: 48px; display: flex; align-items: center; gap: 6px;
  box-shadow: 2px 2px 0 var(--line); transition: transform .08s, box-shadow .08s, background .1s; }
.tab:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }
.tab.active { background: var(--accent); border-color: var(--line); color: var(--accent-ink); }

/* ---------- screen container ---------- */
.screen { flex: 1; padding: 16px 20px 10px; }

/* ---------- mix transport (legacy — superseded by mixer.css's mx- classes,
   kept var-driven for consistency in case it's ever rendered again) ---------- */
.mix-transport { display: flex; align-items: center; gap: 10px; justify-content: flex-end; margin-bottom: 12px; }
.beatbar { display: flex; gap: 5px; margin-right: auto; }
.beatbar .pip { width: 12px; height: 12px; border-radius: 50%; background: var(--line-soft);
  transition: transform .05s, background .05s; }
.beatbar .pip.on { background: var(--accent); transform: scale(1.5); box-shadow: 0 0 0 2px var(--line); }
.beatbar .pip.downbeat.on { background: var(--cat-beat); box-shadow: 0 0 0 2px var(--line); }
.tbtn { font-size: 17px; font-weight: 700; color: var(--ink); background: var(--card);
  border: 2px solid var(--line); border-radius: var(--radius-tab); padding: 12px 18px; cursor: pointer; min-height: 48px;
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  box-shadow: 2px 2px 0 var(--line); transition: transform .08s, box-shadow .08s; }
.tbtn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }
.tbtn.rec { border-color: var(--danger); color: var(--danger); }
.tbtn.rec.recording { background: var(--danger); color: #fff; border-color: var(--danger); animation: pulse 1s infinite; }

/* ---------- stage (legacy) ---------- */
.stage-wrap { min-height: 140px; border: 3px dashed var(--line-soft); border-radius: var(--radius-card);
  background: var(--card); margin-bottom: 16px; display: grid; place-items: center; padding: 14px; }
.stage { display: flex; flex-wrap: wrap; gap: 18px; justify-content: center; align-items: flex-end; width: 100%; }
.stage-empty { font-family: var(--font-body); color: var(--ink-soft); font-size: 18px; text-align: center; margin: 0; }
.sprite { display: flex; flex-direction: column; align-items: center; gap: 6px; animation: pop .25s ease; }
.sprite .bubble { width: 84px; height: 84px; border-radius: 26px; display: grid; place-items: center;
  font-size: 44px; background: var(--c); border: 2.5px solid var(--line); box-shadow: 3px 3px 0 var(--line);
  animation: bob .6s ease-in-out infinite; }
.sprite span { font-size: 14px; font-weight: 700; color: var(--ink); }

/* ---------- my loopkins row (legacy) ---------- */
.charrow { margin-bottom: 16px; }
.charrow-label { font-size: 14px; text-transform: uppercase; letter-spacing: 1px; color: var(--ink-soft); margin: 0 2px 8px; }
.charrow-strip { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 4px; }
.mychar { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius-tab); padding: 8px 10px;
  cursor: pointer; color: var(--ink); min-width: 84px; box-shadow: 2px 2px 0 var(--line); }
.mychar[disabled] { opacity: .45; cursor: default; box-shadow: none; }
.mychar.on { border-color: var(--line); background: var(--accent); }
.mychar-art { width: 64px; height: 64px; display: grid; place-items: center; font-size: 40px; }
.mychar span { font-size: 13px; font-weight: 700; }

/* ---------- palette (legacy) ---------- */
.palette { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.col { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius-card); padding: 12px; }
.col h2 { margin: 4px 4px 12px; font-size: 15px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--c); display: flex; align-items: center; gap: 8px; }
.col h2::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--c); border: 1.5px solid var(--line); }
.grid { display: grid; gap: 12px; }
.char { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; min-height: var(--target); padding: 12px 6px; cursor: pointer; background: var(--card);
  color: var(--ink); border: 2px solid var(--line); border-radius: var(--radius-tab); transition: transform .08s, background .1s; }
.char .emoji { font-size: 34px; line-height: 1; filter: grayscale(.15); transition: filter .1s; }
.char .name { font-size: 14px; font-weight: 700; opacity: .8; }
.char:active { transform: scale(.94); }
.char.on { background: color-mix(in srgb, var(--c, var(--cat-fallback)) 28%, var(--card));
  box-shadow: 0 0 0 3px var(--c, var(--cat-fallback)); }
.char.on .emoji { filter: none; animation: bob .6s ease-in-out infinite; }
.char.on .name { opacity: 1; }
.char.custom::after { content: "★"; position: absolute; top: 6px; right: 8px; font-size: 12px; color: var(--accent); text-shadow: 0 0 0 var(--line); -webkit-text-stroke: .5px var(--line); }

/* ---------- save area (legacy) ---------- */
.save-area { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 16px;
  padding: 14px 18px; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius-card); }
.save-area audio { height: 40px; }

/* ---------- placeholder ---------- */
.placeholder { text-align: center; color: var(--ink-soft); padding: 60px 20px; font-family: var(--font-body); }
.ph-emoji { font-size: 64px; }
.placeholder h2 { color: var(--ink); margin: 12px 0 6px; }

/* ---------- parental gate ---------- */
.gate-overlay { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(44,38,34,.45); backdrop-filter: blur(2px); }
.gate-card { background: var(--card); border: 2.5px solid var(--line); border-radius: var(--radius-card);
  padding: 26px; width: min(90vw, 380px); text-align: center; box-shadow: 5px 6px 0 var(--line); }
.gate-emoji { font-size: 52px; }
.gate-card h2 { margin: 6px 0; color: var(--ink); }
.gate-reason { font-family: var(--font-body); color: var(--ink-soft); margin: 0 0 10px; }
.gate-q { font-size: 20px; margin: 8px 0; color: var(--ink); }
.gate-input { font-family: var(--font-hand); font-size: 26px; text-align: center; width: 120px; padding: 10px; border-radius: 12px;
  border: 2.5px dashed var(--line); background: var(--paper); color: var(--ink); }
.gate-err { font-family: var(--font-body); color: var(--danger); }
.gate-row { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.gate-row button { font-size: 17px; font-weight: 700; padding: 12px 22px; border-radius: var(--radius-btn); cursor: pointer;
  min-height: 48px; border: 2px solid var(--line); transition: transform .08s, box-shadow .08s; }
.gate-cancel { background: var(--card); color: var(--ink-soft); box-shadow: 2px 2px 0 var(--line); }
.gate-cancel:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }
.gate-ok { background: var(--accent); color: var(--accent-ink); box-shadow: 2px 2px 0 var(--line); }
.gate-ok:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }

/* ---------- footer ---------- */
.foot { display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 20px; border-top: 2px solid var(--line); font-size: 14px; flex-wrap: wrap;
  font-family: var(--font-body); background: var(--paper-soft); }
.foot .muted { color: var(--ink-soft); }

/* ---------- about panel + install banner (rendered by pwa.js, which injects its
   own <style> reading --panel/--panel-line/--text/--muted/--accent — those are
   aliased above so the paper theme flows through automatically. The rules below
   use higher-specificity selectors (#screen ancestor / #pwa-install-banner id)
   so they win the cascade over that later-inserted <style> for the few
   properties it hardcodes, all without touching pwa.js.) ---------- */
#screen .about-panel { max-width: 640px; margin: 0 auto; }
#screen .about-card { background: var(--card); border: 2.5px solid var(--line);
  border-radius: var(--radius-card); padding: 22px 22px 26px; color: var(--ink);
  box-shadow: 4px 5px 0 var(--line); }
#screen .about-emoji { font-size: 40px; margin-bottom: 4px; }
#screen .about-card h2 { color: var(--ink); }
#screen .about-card h3 { color: var(--ink); }
#screen .about-list { font-family: var(--font-body); }
#screen .about-list li { color: var(--ink); }
#screen .about-disclaimer { font-family: var(--font-body); color: var(--ink-soft); border-top: 2px dashed var(--line-soft); }
#screen .about-danger { border-top: 2px dashed var(--line-soft); }
#screen .about-danger p { font-family: var(--font-body); color: var(--ink-soft); }
#screen .about-delete-btn { font-family: var(--font-hand); color: #fff; background: var(--danger);
  border: 2px solid var(--line); border-radius: var(--radius-btn); box-shadow: 2px 2px 0 var(--line);
  transition: transform .08s, box-shadow .08s; }
#screen .about-delete-btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }
#screen .about-delete-status { color: var(--ink-soft); }

#pwa-install-banner.pwa-install-banner { background: var(--card); border: 2.5px solid var(--line);
  border-radius: var(--radius-card); color: var(--ink); font-family: var(--font-body);
  box-shadow: 4px 5px 0 var(--line); }
#pwa-install-banner .pwa-banner-action { font-family: var(--font-hand); color: var(--accent-ink);
  background: var(--accent); border: 2px solid var(--line); box-shadow: 2px 2px 0 var(--line);
  transition: transform .08s, box-shadow .08s; }
#pwa-install-banner .pwa-banner-action:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--line); }
#pwa-install-banner .pwa-banner-dismiss { font-family: var(--font-hand); color: var(--ink-soft);
  background: var(--paper); border: 2px solid var(--line-soft); }

/* ---------- animations ---------- */
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes float { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-12px) rotate(4deg); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

@media (max-width: 720px) {
  .palette { grid-template-columns: repeat(2, 1fr); }
  .brand span:not(.logo) { display: none; }
  .tab span { display: none; }
  .foot .muted { font-size: 12px; }
}
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 10px; }
.char:focus-visible, .tab:focus-visible, .mychar:focus-visible, .start-btn:focus-visible { outline-offset: 3px; }

@media (prefers-reduced-motion: reduce) {
  .sprite .bubble, .char.on .emoji, .logo-big, .tbtn.rec.recording, .start-btn { animation: none !important; }
}
