:root {
  --bg: #fff8ef;
  --ink: #2b2140;
  --muted: #6d6480;
  --card: #ffffff;
  --line: #eadfce;
  --accent: #5b4bdb;
  --word: #ffffff;
  --folder: #fff1c9;
  --starter: #d6f5df;
  --learn: #e9e2ff;
  --name: #ffe0ec;
  --call: #d9f0ff;
  --tile: 170px;
  --gap: 16px;
  --radius: 26px;
  color-scheme: light;
}
:root[data-size="s"] { --tile: 135px; --gap: 12px; }
:root[data-size="l"] { --tile: 220px; --gap: 20px; }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, "Segoe UI", sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
  min-height: 100vh;
}
button, a.tile, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
.noscript { padding: 40px; font-size: 22px; }

/* ---------- top bar with the sentence strip ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 2px solid var(--line);
}
.nav-btn {
  flex: none; width: 72px; height: 72px;
  font-size: 36px; border: 0; border-radius: 22px;
  background: var(--card); box-shadow: 0 3px 0 var(--line);
}
.nav-btn:active { transform: translateY(2px); box-shadow: none; }
.strip {
  flex: 1; min-width: 0; min-height: 84px;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 24px;
  background: var(--card); border: 3px dashed var(--line);
}
.strip.has-words { border: 3px solid var(--accent); }
.strip-words { flex: 1; display: flex; gap: 10px; overflow-x: auto; align-items: center; scrollbar-width: none; }
.strip-hint { color: var(--muted); font-size: 22px; padding-left: 6px; }
.strip-play { font-size: 40px; flex: none; opacity: .35; }
.strip.has-words .strip-play { opacity: 1; animation: pulse 1.6s ease-in-out infinite; }
.chip {
  display: flex; align-items: center; gap: 8px; flex: none;
  padding: 6px 14px 6px 6px; border-radius: 18px; background: var(--starter);
  font-size: 24px; font-weight: 700;
}
.chip + .chip { background: var(--folder); }
.chip .lbl2 { display: none; }
.chip-pic { width: 52px; height: 52px; display: grid; place-items: center; font-size: 38px; }
.chip-pic img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; }

/* ---------- tile grid ---------- */
.grid {
  display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr));
  padding: 20px 20px calc(env(safe-area-inset-bottom) + 110px);
}
.folder-title {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 12px;
  font-size: 30px; font-weight: 800;
}
.folder-title .emoji { font-size: 40px; }
.folder-title img { width: 54px; height: 54px; object-fit: cover; border-radius: 14px; }
.folder-title .lbl2 { color: var(--muted); font-weight: 600; font-size: 22px; }
.tile {
  position: relative; aspect-ratio: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 10px; border: 0; border-radius: var(--radius);
  background: var(--word); color: var(--ink); text-decoration: none;
  box-shadow: 0 6px 0 var(--line), 0 10px 24px rgba(60, 40, 20, .06);
  transition: transform .08s;
}
.tile:active { transform: translateY(4px) scale(.98); box-shadow: 0 2px 0 var(--line); }
.tile.pop { animation: pop .35s ease; }
.t-folder { background: var(--folder); }
.t-starter { background: var(--starter); }
.t-numbers, .t-letters, .t-colors { background: var(--learn); }
.t-name { background: var(--name); }
.t-call { background: var(--call); }
.pic { position: relative; flex: 1; width: 100%; min-height: 0; display: grid; place-items: center; }
.pic .emoji { font-size: calc(var(--tile) * .46); line-height: 1; }
.pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: calc(var(--radius) - 10px); }
.lbls { display: flex; flex-direction: column; align-items: center; line-height: 1.1; text-align: center; }
.lbl { font-size: calc(var(--tile) * .14); font-weight: 800; }
.lbl2 { font-size: calc(var(--tile) * .105); font-weight: 600; color: var(--muted); }
.more {
  position: absolute; top: 8px; right: 12px;
  font-size: 34px; font-weight: 900; color: rgba(0, 0, 0, .25);
}

/* ---------- learning ---------- */
.learn-title { margin: 0; font-size: 34px; }
.learn .tile.num .big { font-size: calc(var(--tile) * .5); font-weight: 900; line-height: 1; }
.learn .tile.num .big small { font-size: .55em; margin-left: .1em; opacity: .7; }
.tile.num.c0 { background: #ffe0e0; } .tile.num.c1 { background: #ffeccc; } .tile.num.c2 { background: #fff7c2; }
.tile.num.c3 { background: #dcf7dc; } .tile.num.c4 { background: #dbeeff; } .tile.num.c5 { background: #eee0ff; }
.swatch { flex: 1; width: 78%; max-height: 70%; aspect-ratio: 1; border-radius: 50%; border: 4px solid rgba(0, 0, 0, .08); }

.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center; gap: 16px;
  padding: calc(env(safe-area-inset-top) + 20px) 16px 20px;
  background: rgba(43, 33, 64, .55);
  animation: fade .15s ease;
}
.ov-close {
  position: absolute; top: calc(env(safe-area-inset-top) + 16px); right: 16px;
  width: 72px; height: 72px; border: 0; border-radius: 50%; font-size: 32px; background: var(--card);
}
.ov-arrow {
  flex: none; width: 88px; height: 88px; border: 0; border-radius: 50%;
  font-size: 40px; background: var(--card); color: var(--accent);
}
.ov-arrow:disabled { opacity: .25; }
.card {
  width: min(560px, 100%); max-height: 100%; overflow: auto;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 28px; border-radius: 36px; background: var(--card); text-align: center;
  animation: pop .3s ease;
}
.card-big { border: 0; background: none; font-size: 150px; font-weight: 900; line-height: 1; color: var(--accent); }
.card-big small { font-size: .55em; margin-left: .1em; opacity: .7; }
.card-emoji { border: 0; background: none; font-size: 130px; line-height: 1.1; }
.card-word { font-size: 46px; font-weight: 800; display: flex; flex-direction: column; }
.card-word small { font-size: 28px; font-weight: 600; opacity: .75; }
.card-hint { color: var(--muted); font-size: 20px; }
.dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 480px; }
.dot { width: 72px; height: 72px; border: 0; border-radius: 20px; font-size: 44px; background: #f3eee6; filter: grayscale(.6); opacity: .6; }
.dot.on { background: #fff2b8; filter: none; opacity: 1; }
.color-card { min-height: 360px; justify-content: center; border: 4px solid rgba(0, 0, 0, .08); }

/* ---------- grown-up button ---------- */
.gear {
  position: fixed; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px); z-index: 10;
  width: 64px; height: 64px; border-radius: 50%; border: 0;
  font-size: 30px; background: var(--card); opacity: .45;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .12);
  touch-action: none;
}
.gear::after {
  content: ""; position: absolute; inset: -6px; border-radius: 50%;
  background: conic-gradient(var(--accent) var(--p, 0%), transparent 0);
  -webkit-mask: radial-gradient(circle, transparent 60%, #000 61%); mask: radial-gradient(circle, transparent 60%, #000 61%);
  pointer-events: none;
}
.gear.holding { opacity: 1; animation: hold 2s linear forwards; }
@property --p { syntax: "<percentage>"; inherits: true; initial-value: 0%; }

/* ---------- grown-up settings ---------- */
.parent-bar { justify-content: space-between; }
.parent-bar h1 { margin: 0; font-size: 28px; }
.parent { max-width: 860px; margin: 0 auto; padding: 20px 16px 60px; -webkit-user-select: text; user-select: text; }
.card-p { background: var(--card); border-radius: 22px; padding: 18px 20px 22px; margin-bottom: 18px; box-shadow: 0 3px 0 var(--line); }
.card-p h2 { margin: 0 0 8px; font-size: 24px; }
.parent label, .sheet label { display: block; margin: 14px 0 6px; font-weight: 700; }
.parent label.check, .sheet label.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; }
.check input { width: 24px; height: 24px; flex: none; margin-top: 1px; }
.tip { color: var(--muted); margin: 6px 0; line-height: 1.4; }
.warn { background: #fff0c2; padding: 12px 16px; border-radius: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; }
.row.end { justify-content: flex-end; margin-top: 22px; }
.grow { flex: 1; }
.row input[type="range"] { flex: 1; }
select, .parent input:not([type]), .sheet input:not([type]), .sheet input[type="text"] {
  width: 100%; padding: 12px 14px; font-size: 18px; border-radius: 12px;
  border: 2px solid var(--line); background: #fff;
  -webkit-user-select: text; user-select: text;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 18px; border-radius: 14px;
  border: 2px solid var(--line); background: #fff; font-weight: 700; font-size: 17px;
  margin: 0 !important;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: #c62828; border-color: #f3c4c4; }
.btn.rec-on { background: #e53935; border-color: #e53935; color: #fff; animation: pulse 1s infinite; }
.seg { display: inline-flex; border: 2px solid var(--line); border-radius: 14px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: 0; padding: 12px 18px; background: #fff; font-weight: 700; font-size: 17px; }
.seg button.on { background: var(--accent); color: #fff; }
.crumbs { margin: 8px 0 10px; font-size: 18px; }
.crumb { border: 0; background: none; font-weight: 700; color: var(--accent); padding: 6px 2px; }
.elist { border-top: 2px solid var(--line); }
.erow { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 2px solid var(--line); }
.erow.hidden .ethumb, .erow.hidden .etext { opacity: .35; }
.ethumb { width: 56px; height: 56px; flex: none; display: grid; place-items: center; font-size: 38px; }
.ethumb img { width: 100%; height: 100%; object-fit: cover; border-radius: 12px; }
.etext { flex: 1; min-width: 0; font-size: 18px; }
.etext small { display: block; color: var(--muted); font-size: 14px; margin-top: 2px; }
.eact { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.ib { width: 46px; height: 46px; border-radius: 12px; border: 2px solid var(--line); background: #fff; font-size: 20px; padding: 0; }

.sheet-wrap { align-items: flex-start; overflow-y: auto; }
.sheet {
  width: min(620px, 100%); margin: auto 0; padding: 22px 22px 24px;
  background: var(--card); border-radius: 26px; animation: pop .25s ease;
  -webkit-user-select: text; user-select: text;
}
.sheet h2 { margin: 0 0 14px; }
.sheet h3 { margin: 22px 0 0; }
.pic-edit { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.tile.preview { width: 150px; flex: none; --tile: 150px; box-shadow: 0 4px 0 var(--line); }
.pic-actions { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.pic-actions label.inline { display: flex; align-items: center; gap: 8px; margin: 0; }
.emoji-in { width: 90px !important; font-size: 30px !important; text-align: center; }
.recrow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.recrow > span { width: 110px; font-weight: 700; }

@keyframes pop { 0% { transform: scale(.92); } 60% { transform: scale(1.04); } 100% { transform: scale(1); } }
@keyframes pulse { 50% { transform: scale(1.12); } }
@keyframes fade { from { opacity: 0; } }
@keyframes hold { to { --p: 100%; } }

@media (max-width: 600px) {
  :root { --tile: 120px; --gap: 10px; }
  .nav-btn { width: 56px; height: 56px; font-size: 28px; }
  .strip { min-height: 64px; }
  .ov-arrow { width: 56px; height: 56px; font-size: 26px; }
  .overlay { gap: 6px; padding-left: 6px; padding-right: 6px; }
  .card-big { font-size: 100px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
