/* Baby Talk - app styles. One design system: cream canvas, coral accent, big
   rounded cards, Fredoka for the words babies see, Nunito for grown-up text. */

@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/fredoka-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/nunito-latin.woff2') format('woff2');
}

:root {
  --canvas: #FFF8EE;
  --card: #FFFFFF;
  --ink: #2B2440;
  --muted: #6E6A80;
  --line: #EFE6DA;
  --primary: #FF6B6B;
  --primary-dark: #E85555;
  --sun: #FFD166;
  --sky: #4ECDC4;
  --lav: #A78BFA;
  --radius: 28px;
  --radius-sm: 18px;
  --shadow: 0 6px 0 rgba(43, 36, 64, .06), 0 14px 32px rgba(43, 36, 64, .10);
  --shadow-press: 0 2px 0 rgba(43, 36, 64, .06), 0 6px 14px rgba(43, 36, 64, .10);
  --display: 'Fredoka', 'Segoe UI Rounded', system-ui, -apple-system, sans-serif;
  --body: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --top-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
img { max-width: 100%; display: block; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible, a:focus-visible, select:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; }
[hidden] { display: none !important; }

/* ---- header ---- */
.top {
  position: sticky; top: 0; z-index: 20;
  height: calc(var(--top-h) + env(safe-area-inset-top, 0px));
  padding-top: env(safe-area-inset-top, 0px);
  display: flex; align-items: center; gap: 8px;
  padding-left: 12px; padding-right: 12px;
  background: rgba(255, 248, 238, .92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; color: var(--ink);
  font-family: var(--display); font-weight: 600; font-size: 24px;
  padding: 4px 8px 4px 4px; border-radius: 16px;
}
.brand .mark { width: 40px; height: 40px; background: var(--primary); border-radius: 14px; padding: 3px; flex: none; }
.brand-t { display: flex; flex-direction: column; line-height: 1; white-space: nowrap; }
.brand-t small { font-size: 11px; font-weight: 600; color: var(--primary-dark); letter-spacing: .12em; text-transform: uppercase; margin-top: 3px; }
.title {
  margin: 0; flex: 1; min-width: 0;
  font-family: var(--display); font-weight: 600; font-size: 24px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.title small { display: block; font-size: 14px; font-weight: 500; color: var(--muted); line-height: 1.1; }
.tools { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.iconbtn {
  width: 48px; height: 48px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--card); box-shadow: var(--shadow-press); color: var(--ink);
  transition: transform .12s ease;
}
.iconbtn svg { width: 24px; height: 24px; }
.iconbtn:active { transform: scale(.92); }
.seg { display: inline-flex; background: var(--card); border-radius: 999px; padding: 4px; box-shadow: var(--shadow-press); }
.segbtn { width: 44px; height: 40px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.segbtn svg { width: 22px; height: 22px; }
.segbtn.on { background: var(--primary); color: #fff; }

/* ---- views ---- */
.view { padding: 16px 16px calc(24px + var(--safe-b)); max-width: 1200px; margin: 0 auto; }

.cats, .grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
@media (max-width: 380px) { .cats, .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; } }
@media (min-width: 700px) { .cats, .grid { gap: 18px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); } }

.cat, .word {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  aspect-ratio: 1 / 1.08;
  padding: 12px 10px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  text-align: center;
  transition: transform .15s ease, box-shadow .15s ease;
  -webkit-user-select: none; user-select: none;
}
.cat { background: var(--tint, var(--card)); color: var(--ink); text-decoration: none; }
.cat:active, .word:active { transform: scale(.95); box-shadow: var(--shadow-press); }
.cat img, .word img { width: 58%; height: auto; aspect-ratio: 1; object-fit: contain; pointer-events: none; }
.word { background: var(--card); border: 4px solid var(--tint, transparent); }
.l1, .l2 { font-family: var(--display); line-height: 1.15; max-width: 100%; overflow-wrap: anywhere; unicode-bidi: plaintext; }
.l1 { font-weight: 600; font-size: clamp(19px, 5.2vw, 24px); }
.l2 { font-weight: 500; font-size: clamp(15px, 4vw, 18px); color: var(--muted); }
.cat .l2 { color: rgba(43, 36, 64, .6); }
.nolabels .word .l1, .nolabels .word .l2 { display: none; }
.nolabels .word img { width: 74%; }

.speaking .l1.now, .speaking .l2.now, .l1.now, .l2.now { color: var(--primary); }
@keyframes pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.12) rotate(-2deg); }
  70% { transform: scale(.98) rotate(1deg); }
  100% { transform: scale(1); }
}
.pop { animation: pop .5s ease; }
.pop img { animation: pop .5s ease; }

/* ---- slide show ---- */
.slides {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: calc(100dvh - var(--top-h) - env(safe-area-inset-top, 0px) - 40px - var(--safe-b));
  gap: 12px;
  touch-action: pan-y;
}
.stage { position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; overflow: hidden; }
.slide {
  width: min(92vw, 70vh, 560px);
  aspect-ratio: 1 / 1.15;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: 24px;
  border-radius: 40px;
  background: var(--card);
  border: 6px solid var(--tint, var(--line));
  box-shadow: var(--shadow);
  -webkit-user-select: none; user-select: none;
  will-change: transform;
}
.slide img { width: 62%; height: auto; aspect-ratio: 1; object-fit: contain; pointer-events: none; }
.slide .l1 { font-size: clamp(34px, 9vw, 60px); }
.slide .l2 { font-size: clamp(22px, 5.6vw, 36px); }
.nolabels .slide .l1, .nolabels .slide .l2 { display: none; }
.nolabels .slide img { width: 80%; }
@keyframes inRight { from { transform: translateX(60px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes inLeft { from { transform: translateX(-60px); opacity: 0; } to { transform: none; opacity: 1; } }
.slide.from-right { animation: inRight .28s ease; }
.slide.from-left { animation: inLeft .28s ease; }

.arrow {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--card); box-shadow: var(--shadow); color: var(--ink);
  display: flex; align-items: center; justify-content: center;
}
.arrow svg { width: 26px; height: 26px; }
.arrow.prev { left: 2px; }
.arrow.next { right: 2px; }
.arrow:active { transform: translateY(-50%) scale(.92); }
@media (max-width: 480px) { .arrow { width: 48px; height: 48px; opacity: .92; } }

.slidebar {
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding-bottom: 4px;
}
.count { font-family: var(--display); font-weight: 500; font-size: 18px; color: var(--muted); min-width: 64px; text-align: center; }
.bigbtn {
  height: 60px; padding: 0 22px; border-radius: 999px;
  display: inline-flex; align-items: center; gap: 10px; white-space: nowrap;
  font-family: var(--display); font-weight: 600; font-size: 20px;
  background: var(--primary); color: #fff; box-shadow: var(--shadow);
  transition: transform .12s ease;
}
@media (max-width: 420px) {
  .bigbtn { height: 54px; padding: 0 16px; font-size: 18px; gap: 8px; }
  .bigbtn svg { width: 22px; height: 22px; }
  .slidebar { gap: 10px; }
  .count { min-width: 52px; font-size: 16px; }
}
.bigbtn svg { width: 26px; height: 26px; }
.bigbtn:active { transform: scale(.95); }
.bigbtn.alt { background: var(--card); color: var(--ink); }
.bigbtn.alt.on { background: var(--sky); color: #fff; }

/* ---- overlays: gate + settings ---- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(43, 36, 64, .45);
  display: flex; align-items: flex-end; justify-content: center;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
@media (min-width: 700px) { .overlay { align-items: center; } }
.gate {
  background: var(--card); border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 24px calc(28px + var(--safe-b)); width: 100%; max-width: 480px; text-align: center;
}
@media (min-width: 700px) { .gate { border-radius: var(--radius); } }
.gate-kicker { margin: 0; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .08em; font-size: 12px; }
.gate h2 { font-family: var(--display); font-weight: 600; font-size: 30px; margin: 8px 0 18px; }
.gate-opts { display: flex; gap: 12px; justify-content: center; margin-bottom: 14px; }
.gate-opts button {
  width: 76px; height: 64px; border-radius: 20px;
  background: var(--canvas); border: 2px solid var(--line);
  font-family: var(--display); font-size: 26px; font-weight: 600;
}
.gate-opts button:active { background: var(--sun); }
.gate-opts button.wrong { animation: shake .35s ease; border-color: var(--primary); }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.linkbtn { color: var(--muted); font-weight: 700; padding: 10px 14px; border-radius: 12px; text-decoration: underline; }

.sheet {
  background: var(--canvas); border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 560px; max-height: calc(100dvh - 24px);
  display: flex; flex-direction: column;
}
@media (min-width: 700px) { .sheet { border-radius: var(--radius); max-height: min(90vh, 860px); } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 8px 24px;
}
.sheet-head h2 { margin: 0; font-family: var(--display); font-weight: 600; font-size: 26px; }
.sheet-body { overflow-y: auto; padding: 0 16px calc(24px + var(--safe-b)); }
.set { background: var(--card); border-radius: var(--radius-sm); padding: 14px 16px; margin: 0 0 12px; box-shadow: var(--shadow-press); }
.set h3 { margin: 0 0 8px; font-family: var(--display); font-weight: 600; font-size: 19px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; font-weight: 600; }
.row + .row { border-top: 1px solid var(--line); }
.row span { flex: 1; }
select {
  font: inherit; font-weight: 700; color: var(--ink);
  padding: 10px 36px 10px 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--canvas);
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'><path d='M6 9l6 6 6-6' fill='none' stroke='%232B2440' stroke-width='3' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 18px;
  max-width: 60%;
}
.toggle input { appearance: none; -webkit-appearance: none; width: 54px; height: 32px; border-radius: 999px; background: #D9D3C8; position: relative; flex: none; margin: 0; transition: background .2s; cursor: pointer; }
.toggle input::after { content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s; }
.toggle input:checked { background: var(--sky); }
.toggle input:checked::after { transform: translateX(22px); }
.hint { margin: 6px 0 4px; color: var(--muted); font-size: 14px; }
.hint.note { background: #FFF6DA; border-radius: 10px; padding: 8px 10px; color: var(--ink); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 20px; border-radius: 999px; margin-top: 6px;
  background: var(--primary); color: #fff; font-weight: 800; box-shadow: var(--shadow-press);
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: var(--card); color: var(--ink); border: 2px solid var(--line); }
.about p { margin: 6px 0; font-size: 14px; color: var(--muted); }
.about a { color: var(--ink); font-weight: 700; }

.voices { display: flex; flex-direction: column; gap: 8px; }
.voice {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px 8px 12px; border-radius: 16px; border: 2px solid var(--line); background: var(--canvas);
  cursor: pointer;
}
.voice.on { border-color: var(--primary); background: #FFF1F1; }
.voice .av {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--display); font-weight: 600; font-size: 18px; color: #fff;
}
.voice .av.f { background: var(--lav); }
.voice .av.m { background: var(--sky); }
.voice .vn { flex: 1; min-width: 0; }
.voice .vn b { display: block; font-family: var(--display); font-weight: 600; font-size: 17px; }
.voice .vn small { color: var(--muted); font-weight: 600; }
.voice .play {
  width: 44px; height: 44px; border-radius: 50%; flex: none;
  background: var(--card); box-shadow: var(--shadow-press);
  display: flex; align-items: center; justify-content: center;
}
.voice .play svg { width: 20px; height: 20px; }
.voice input { position: absolute; opacity: 0; width: 0; height: 0; }

/* ---- Pro ---- */
.pill { display: inline-block; font-size: 11px; font-weight: 800; letter-spacing: .06em; padding: 2px 7px; border-radius: 999px; background: var(--sun); color: var(--ink); vertical-align: middle; margin-left: 4px; }
.voice.locked .av { filter: grayscale(.5); opacity: .8; }
.voice.locked .vn b { color: var(--muted); }
.pro-card { border: 2px solid var(--sun); background: #FFFBEB; border-radius: var(--radius-sm); padding: 14px 16px; margin: 8px 0 14px; }
.pro-price { display: flex; align-items: baseline; gap: 6px; font-family: var(--display); }
.pro-price b { font-size: 34px; font-weight: 600; }
.pro-price span { color: var(--muted); font-weight: 600; }
.pro-list { margin: 8px 0 12px; padding-left: 20px; font-weight: 600; }
.pro-list li { margin: 2px 0; }
.row-title { margin: 8px 0 6px; font-weight: 700; }
.code-entry { display: flex; gap: 8px; }
.code-entry input { flex: 1; min-width: 0; font: inherit; font-family: var(--display); font-weight: 600; font-size: 20px; letter-spacing: .08em; text-transform: uppercase; padding: 8px 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--canvas); color: var(--ink); }
.code-entry .btn { margin-top: 0; flex: none; }
.pro-badge { display: inline-block; margin: 0 0 6px; padding: 6px 12px; border-radius: 999px; background: var(--sky); color: #fff; font-weight: 800; }
.pro-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }
@keyframes flash { 0%, 100% { box-shadow: var(--shadow-press); } 50% { box-shadow: 0 0 0 4px var(--sun); } }
.set.flash { animation: flash .9s ease 2; }
select option:disabled { color: #9a96a8; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + var(--safe-b)); transform: translateX(-50%);
  z-index: 60; max-width: calc(100% - 32px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px;
  font-weight: 700; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px;
}
.toast button { color: var(--sun); font-weight: 800; text-decoration: underline; }

/* ---- empty / loading ---- */
.loading { text-align: center; padding: 60px 20px; color: var(--muted); font-family: var(--display); font-size: 22px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
