:root {
  --bg: #f6efe4;
  --card: #fffaf2;
  --ink: #3b2f25;
  --muted: #7a6a5a;
  --accent: #a85a24;
  --accent-ink: #ffffff;
  --line: #e3d5c1;
  --field: #ffffff;
  --danger: #a3361f;
  --ok: #3f6a2b;
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1f1a16;
    --card: #2a231d;
    --ink: #f3e9dc;
    --muted: #b9a893;
    --accent: #e59a62;
    --accent-ink: #1f1a16;
    --line: #3f362d;
    --field: #1f1a16;
    --danger: #f08a74;
    --ok: #9cc47f;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  place-items: center;
  padding: 24px 16px;
  background: var(--bg);
  color: var(--ink);
  font: 18px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.card {
  width: min(440px, 100%);
  padding: 36px 28px;
  border-radius: 28px;
  background: var(--card);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .04), 0 12px 40px rgba(59, 47, 37, .08);
}
.card.medium { width: min(640px, 100%); }
.card.wide { width: min(900px, 100%); }

.brand { text-align: center; margin-bottom: 24px; }
.teddy { display: block; width: 112px; height: 112px; margin: 0 auto; filter: drop-shadow(0 10px 18px rgba(59, 47, 37, .18)); }
h1 { margin: 12px 0 4px; font-size: 36px; line-height: 1.15; letter-spacing: -.02em; }
h2 { margin: 0 0 4px; font-size: 24px; line-height: 1.2; }
p { margin: 0; }
.muted { color: var(--muted); }

form, .stack { display: grid; gap: 14px; }

label { display: grid; gap: 6px; font-size: 16px; font-weight: 600; }
input[type="email"], input[type="password"], input[type="text"], textarea {
  min-height: 56px;
  padding: 12px 16px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--field);
  color: var(--ink);
  font: inherit;
}
input.code {
  font-size: 28px;
  letter-spacing: .35em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

button, .button {
  min-height: 56px;
  padding: 12px 20px;
  border: 0;
  border-radius: var(--radius);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.primary { background: var(--accent); color: var(--accent-ink); }
.secondary { background: transparent; color: var(--ink); border: 2px solid var(--line); }
.link {
  min-height: 44px;
  padding: 8px 4px;
  background: none;
  color: var(--accent);
  font-weight: 600;
}
button[disabled] { opacity: .6; cursor: progress; }

.links { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

.status { margin-top: 16px; padding: 12px 16px; border-radius: 12px; font-size: 16px; }
.status.error { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.status.info { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }

.pill {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
}
.stack .pill { justify-self: center; text-align: center; }

textarea { resize: vertical; line-height: 1.45; }

.helper { padding-top: 20px; border-top: 1px solid var(--line); }
.dialog { display: grid; gap: 10px; }
.dialog:empty { display: none; }
.msg {
  max-width: 92%;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 17px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user {
  justify-self: end;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border-bottom-right-radius: 6px;
}
.msg.assistant {
  justify-self: start;
  background: var(--field);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.msg.pending { color: var(--muted); font-style: italic; }

.table-wrap { overflow-x: auto; margin-top: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 16px; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-weight: 600; }
td button { min-height: 40px; padding: 6px 12px; font-size: 15px; }
.blocked { color: var(--danger); font-weight: 600; }

/* --- главная: дети и курс --- */
h3 { margin: 0; font-size: 19px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 48px;
  padding: 8px 16px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  gap: 8px;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip.add { color: var(--accent); border-style: dashed; }
.week { gap: 8px; }
.episode-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 12px 16px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}
.episode-link:hover { border-color: var(--accent); }
.episode-link .done { color: var(--ok); white-space: nowrap; }
.account { padding-top: 20px; border-top: 1px solid var(--line); }
.swatch {
  display: inline-block;
  width: 20px;
  height: 20px;
  flex: none;
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15);
}

/* --- пульт занятия --- */
.back { align-self: start; padding-left: 0; }
main > h1 { margin-top: 4px; }
main > p + p, main > h1 + p { margin-top: 6px; }
main > .chips { margin: 16px 0 8px; }
.lesson-start, [data-steps], [data-finish] { margin-top: 16px; }
.mode-choice { display: grid; gap: 12px; }
.mode {
  display: grid;
  gap: 4px;
  justify-items: start;
  padding: 16px 18px;
  border: 2px solid var(--line);
  background: transparent;
  color: var(--ink);
  text-align: left;
  font-weight: 400;
}
.mode:hover { border-color: var(--accent); }
.mode b { font-size: 19px; }
.mode .muted { font-size: 16px; }
.step {
  display: grid;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--field);
}
.step-icon { width: 64px; height: 64px; }
.step-text { font-size: 20px; line-height: 1.5; }
.audio-buttons { display: flex; flex-wrap: wrap; gap: 10px; }
.sound { min-height: 52px; font-weight: 600; }
.step-nav { display: grid; grid-template-columns: 1fr 2fr; gap: 10px; }
.observe-row { display: grid; gap: 8px; padding-top: 10px; border-top: 1px solid var(--line); }
.observe-word { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.levels { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.level {
  min-height: 48px;
  padding: 6px 4px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
}
.level[aria-pressed="true"] { background: var(--ok); border-color: var(--ok); color: var(--card); }
@media (max-width: 420px) { .levels { grid-template-columns: repeat(2, 1fr); } }

/* --- сцена для ребёнка: один герой, одна задача, крупные карточки --- */
.scene {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: center;
  align-items: center;
  gap: 16px;
  padding: 24px 16px 32px;
  background: var(--bg);
}
.scene-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 48px;
  min-height: 48px;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
}
.scene-teddy { width: clamp(110px, 26vw, 160px); height: auto; }
.scene-teddy.hop { animation: hop .6s ease; }
.scene-options { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(16px, 5vw, 48px); }
.option {
  width: clamp(150px, 40vw, 260px);
  aspect-ratio: 1;
  padding: 0;
  border: 6px solid transparent;
  border-radius: 32px;
  background: var(--card);
  box-shadow: 0 10px 30px rgba(59, 47, 37, .12);
  display: grid;
  place-items: center;
}
.option img { width: 72%; height: auto; pointer-events: none; }
.option.right { border-color: var(--ok); animation: pop .5s ease; }
.option.wiggle { animation: wiggle .4s ease; }
.scene-repeat {
  width: 96px;
  min-height: 96px;
  padding: 0;
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 6px 20px rgba(59, 47, 37, .12);
  font-size: 40px;
}
@keyframes hop { 40% { transform: translateY(-28px); } }
@keyframes pop { 50% { transform: scale(1.06); } }
@keyframes wiggle { 25% { transform: rotate(-4deg); } 75% { transform: rotate(4deg); } }
@media (prefers-reduced-motion: reduce) {
  .scene-teddy.hop, .option.right, .option.wiggle { animation: none; }
}

/* --- картинки (Fluent Emoji 3D, MIT) --- */
.chip img, .observe-word img { width: 28px; height: 28px; flex: none; }
.week-head { display: flex; align-items: center; gap: 12px; }
.week-head img { width: 56px; height: 56px; flex: none; }
.play-link { gap: 10px; justify-self: start; padding-left: 14px; }
.play-link img { width: 36px; height: 36px; }
.episode-name { display: flex; align-items: center; gap: 12px; }
.episode-name img { width: 40px; height: 40px; flex: none; }
.lesson-head { display: flex; align-items: center; gap: 16px; margin-top: 4px; }
.lesson-head h1 { margin: 0; }
.lesson-head p { margin-top: 6px; }
.cover { width: 96px; height: 96px; flex: none; filter: drop-shadow(0 8px 14px rgba(59, 47, 37, .16)); }
.scene-repeat img { width: 56px; height: 56px; pointer-events: none; }
@media (max-width: 420px) {
  .lesson-head { align-items: flex-start; }
  .cover { width: 72px; height: 72px; }
}
