:root {
  --bg: #0e1230;
  --bg-2: #151a42;
  --surface: #1c2254;
  --surface-2: #262d68;
  --line: rgba(255, 255, 255, 0.08);
  --text: #eef0ff;
  --muted: #a4abd8;
  --dim: #6f76a8;
  --gold: #ffd27a;
  --gold-2: #ffb85c;
  --mint: #8fe3cf;
  --rose: #ff9fb2;
  --danger: #ff7a7a;
  --radius: 20px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(120% 60% at 50% 0%, #232a66 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  font: 17px/1.5 Nunito, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

.stars {
  position: fixed; inset: 0; pointer-events: none; z-index: -1; opacity: 0.55;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff, transparent),
    radial-gradient(1px 1px at 28% 42%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 44% 12%, #fff, transparent),
    radial-gradient(1px 1px at 63% 30%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 78% 8%, #fff, transparent),
    radial-gradient(1px 1px at 88% 36%, #fff, transparent),
    radial-gradient(1px 1px at 18% 70%, #fff, transparent),
    radial-gradient(1px 1px at 52% 64%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 82% 76%, #fff, transparent),
    radial-gradient(1px 1px at 35% 88%, #fff, transparent);
}

main {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 20px) 16px calc(var(--tabs-h) + var(--safe-b) + 96px);
  outline: none;
}

h1 { font-size: 30px; line-height: 1.15; margin: 4px 0 6px; font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: 21px; margin: 28px 0 12px; font-weight: 800; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.hello { color: var(--gold); font-weight: 700; font-size: 15px; margin: 0; }

/* ---------- кнопки ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 56px; padding: 12px 20px; border: 0; border-radius: 16px;
  background: var(--surface-2); font-weight: 700; font-size: 17px; text-decoration: none; cursor: pointer;
  transition: transform 0.15s, filter 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: linear-gradient(135deg, var(--gold), var(--gold-2)); color: #2b1d00; }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); }
.btn.danger { background: rgba(255, 122, 122, 0.12); color: var(--danger); }
.btn .sub { display: block; font-weight: 600; font-size: 13px; opacity: 0.75; }
.btn-stack { display: grid; gap: 12px; margin: 20px 0; }
.icon-btn {
  display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: 50%;
  border: 0; background: var(--surface); cursor: pointer; font-size: 18px; flex: none;
}
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; font-weight: 700; margin-bottom: 12px; padding: 8px 0; }

/* ---------- обложки и карточки ---------- */
.cover {
  position: relative; display: grid; place-items: center; overflow: hidden;
  border-radius: var(--radius); aspect-ratio: 1; font-size: 44px;
  background: linear-gradient(145deg, var(--c1, #3b3f8f), var(--c2, #1d2160));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.cover::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(1px 1px at 20% 25%, #fff, transparent), radial-gradient(1px 1px at 75% 20%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 60% 75%, rgba(255,255,255,.8), transparent);
  opacity: 0.7;
}
.cover.big { font-size: 96px; border-radius: 28px; }

.cards { display: grid; gap: 12px; }
.card {
  display: grid; grid-template-columns: 88px 1fr; gap: 14px; align-items: center;
  padding: 12px; border-radius: var(--radius); background: var(--surface); text-decoration: none;
  border: 1px solid var(--line);
}
.card h3 { margin: 0 0 4px; font-size: 18px; line-height: 1.2; }
.card .meta { color: var(--muted); font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; background: rgba(255, 255, 255, 0.07); color: var(--muted); }
.chip.gold { background: rgba(255, 210, 122, 0.15); color: var(--gold); }

.promo {
  display: block; margin: 20px 0; padding: 18px; border-radius: var(--radius); text-decoration: none;
  background: linear-gradient(135deg, rgba(255, 159, 178, 0.18), rgba(255, 210, 122, 0.14));
  border: 1px solid rgba(255, 210, 122, 0.25);
}
.promo b { display: block; font-size: 18px; margin-bottom: 4px; }

/* ---------- экран сказки ---------- */
.tale-head { display: grid; gap: 16px; text-align: center; }
.tale-head .cover { width: min(62vw, 240px); margin: 0 auto; }
.tale-head .chips { justify-content: center; }
.about { color: var(--muted); text-align: center; }

/* ---------- плеер ---------- */
.player { display: grid; gap: 18px; text-align: center; }
.player .cover { width: min(58vw, 230px); margin: 8px auto 0; }
.player h1 { font-size: 24px; }
.lyrics { min-height: 150px; display: grid; gap: 8px; align-content: center; padding: 0 4px; }
.lyrics .l { color: var(--dim); font-size: 16px; transition: color 0.3s; }
.lyrics .l.now { color: var(--text); font-size: 21px; font-weight: 700; }
.lyrics .who { display: block; font-size: 13px; color: var(--gold); font-weight: 800; }
.progress { display: grid; gap: 6px; }
.progress input { width: 100%; accent-color: var(--gold); }
.times { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; }
.controls { display: flex; align-items: center; justify-content: center; gap: 22px; }
.play-btn {
  width: 84px; height: 84px; border-radius: 50%; border: 0; font-size: 30px; cursor: pointer;
  background: linear-gradient(135deg, var(--gold), var(--gold-2)); color: #2b1d00;
  box-shadow: 0 10px 30px rgba(255, 184, 92, 0.25);
}
.sleep { padding: 16px; border-radius: var(--radius); background: var(--surface); text-align: left; }
.sleep b { display: block; margin-bottom: 10px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  flex: 1; min-width: 56px; min-height: 44px; border-radius: 12px; border: 1.5px solid var(--line);
  background: transparent; font-weight: 700; font-size: 15px; cursor: pointer;
}
.seg button.on { background: var(--surface-2); border-color: var(--gold); color: var(--gold); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ---------- «Читаю сам» ---------- */
.reader { padding-bottom: 180px; }
.reader-top {
  position: sticky; top: 0; z-index: 5; margin: 0 -16px 8px; padding: 10px 16px;
  background: linear-gradient(var(--bg) 70%, transparent); display: flex; align-items: center; gap: 10px;
}
.reader-top .title { flex: 1; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dim); }
.dot.live { background: var(--mint); box-shadow: 0 0 0 4px rgba(143, 227, 207, 0.2); animation: pulse 1.6s infinite; }
.dot.rec { background: var(--danger); box-shadow: 0 0 0 4px rgba(255, 122, 122, 0.25); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

.text { font-size: var(--reader-size, 22px); line-height: 1.6; }
.text .ln { padding: 6px 10px; margin: 0 -10px; border-radius: 12px; color: var(--muted); cursor: pointer; transition: color 0.3s, background 0.3s; }
.text.started .ln { color: var(--dim); }
.text.started .ln.done { color: #585f92; }
.text.started .ln.now { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.text .ln .who { display: block; font-size: 0.62em; font-weight: 800; color: var(--gold); letter-spacing: 0.02em; }
.text .ln .mood { font-weight: 600; color: var(--muted); }
.text .gap { height: 14px; }
.text .mark {
  display: inline-flex; align-items: center; gap: 6px; margin: 4px 0; padding: 4px 12px; border-radius: 99px;
  font-size: 14px; font-weight: 700; border: 1px dashed rgba(255, 255, 255, 0.18); color: var(--muted); background: none; cursor: pointer;
}
.text .mark.fired { border-style: solid; border-color: rgba(143, 227, 207, 0.5); color: var(--mint); }
.text .mark.fon { border: 0; padding-left: 0; color: var(--dim); cursor: default; }
.name { color: var(--gold); }

.reader-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: linear-gradient(transparent, var(--bg) 30%);
}
.reader-bar .in { max-width: 560px; margin: 0 auto; display: grid; gap: 10px; }
.reader-bar .row .btn { flex: 1; }
.hint { font-size: 14px; color: var(--muted); text-align: center; margin: 0; }
body.reading .tabs, body.reading .mini { display: none; }

/* ---------- мои записи и настройки ---------- */
.rec {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center;
  padding: 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line);
}
.rec .cover { font-size: 26px; border-radius: 14px; }
.rec b { display: block; line-height: 1.25; }
.empty { text-align: center; padding: 40px 12px; color: var(--muted); }
.empty .big { font-size: 56px; }

.field { display: grid; gap: 8px; margin: 18px 0; }
.field label { font-weight: 700; }
.input {
  min-height: 52px; padding: 12px 16px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--surface); outline: none;
}
.input:focus { border-color: var(--gold); }
input[type=range] { accent-color: var(--gold); width: 100%; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.toggle input { width: 22px; height: 22px; accent-color: var(--gold); }

.sheet-bg { position: fixed; inset: 0; background: rgba(5, 7, 25, 0.7); z-index: 40; display: grid; align-items: end; }
.sheet {
  background: var(--bg-2); border-radius: 26px 26px 0 0; padding: 22px 16px calc(22px + var(--safe-b));
  max-width: 560px; width: 100%; margin: 0 auto; border-top: 1px solid var(--line);
}
.sheet h2 { margin-top: 0; }
.progress-msg { text-align: center; padding: 24px 0; }
.spinner { width: 42px; height: 42px; margin: 0 auto 14px; border-radius: 50%; border: 4px solid var(--surface-2); border-top-color: var(--gold); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.soon { list-style: none; padding: 0; margin: 16px 0; display: grid; gap: 10px; }
.soon li { padding: 14px 16px; border-radius: 16px; background: var(--surface); }

/* ---------- мини-плеер и вкладки ---------- */
.mini {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + var(--safe-b) + 10px); z-index: 25;
  width: min(560px, calc(100% - 24px)); display: flex; align-items: center; gap: 8px;
  padding: 8px; border-radius: 18px; background: var(--surface-2); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
.mini-open { flex: 1; display: flex; align-items: center; gap: 10px; background: none; border: 0; text-align: left; cursor: pointer; min-width: 0; }
.mini-cover { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 22px; background: var(--surface); flex: none; }
.mini-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: center;
  padding-bottom: var(--safe-b); background: rgba(14, 18, 48, 0.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabs a {
  flex: 1; max-width: 186px; height: var(--tabs-h); display: grid; place-items: center; align-content: center; gap: 2px;
  text-decoration: none; font-size: 12px; font-weight: 700; color: var(--dim);
}
.tabs a span { font-size: 20px; filter: grayscale(1) opacity(0.6); }
.tabs a.on { color: var(--gold); }
.tabs a.on span { filter: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + var(--safe-b) + 80px); transform: translateX(-50%);
  background: var(--surface-2); padding: 12px 18px; border-radius: 14px; z-index: 50; font-weight: 700;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); width: max-content; max-width: min(520px, calc(100% - 32px)); text-align: center;
}

/* ---------- возраст, свои сказки ---------- */
.seg.ages { margin: 14px 0 4px; }
.seg.ages button { min-width: 0; padding: 0 6px; font-size: 14px; }
.add-card {
  display: grid; grid-template-columns: 56px 1fr; gap: 12px; align-items: center; margin: 14px 0;
  padding: 14px; border-radius: var(--radius); border: 1.5px dashed rgba(255, 210, 122, 0.35);
  text-decoration: none; background: rgba(255, 210, 122, 0.05);
}
.add-card > span {
  width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center;
  font-size: 28px; background: rgba(255, 210, 122, 0.12); color: var(--gold);
}
.add-card b { display: block; }
textarea.input { resize: vertical; line-height: 1.5; min-height: 220px; }
.file-btn { cursor: pointer; }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-pick button {
  width: 46px; height: 46px; font-size: 24px; border-radius: 12px; cursor: pointer;
  border: 1.5px solid var(--line); background: var(--surface);
}
.emoji-pick button.on { border-color: var(--gold); background: var(--surface-2); }
.note { margin: 20px 0; padding: 16px; border-radius: var(--radius); background: var(--surface); }
.note p { margin: 8px 0 0; }

/* ---------- мой голос ---------- */
.voice-row { grid-template-columns: 56px 1fr auto; }
.voice-row audio { width: 100%; height: 36px; margin-top: 6px; }
.consent { align-items: flex-start; font-size: 15px; margin-bottom: 16px; }
.consent input { margin-top: 4px; flex: none; }
.sample {
  font-size: 20px; line-height: 1.6; padding: 16px; margin: 12px 0 200px;
  border-radius: var(--radius); background: var(--surface);
}
.sample p { margin: 0 0 10px; }
.rec-panel {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + var(--safe-b)); z-index: 20;
  padding: 12px 16px; background: linear-gradient(transparent, var(--bg) 25%); display: grid; gap: 10px;
  max-width: 560px; margin: 0 auto;
}
.meter { height: 8px; border-radius: 99px; background: var(--surface); overflow: hidden; }
.meter div { height: 100%; width: 0; background: var(--mint); transition: width 0.08s; }
.meter div.hot { background: var(--danger); }

/* ---------- панель звуков в «Читаю сам» ---------- */
.reader.pal { padding-bottom: 330px; }
.palette { display: grid; gap: 8px; padding: 10px; border-radius: 18px; background: var(--bg-2); border: 1px solid var(--line); }
.pal-row { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.pal-row::-webkit-scrollbar { display: none; }
.pal {
  flex: none; min-width: 64px; padding: 6px 8px; border-radius: 14px; border: 1.5px solid var(--line);
  background: var(--surface); font-size: 12px; font-weight: 700; cursor: pointer; display: grid; justify-items: center; gap: 2px;
}
.pal span { font-size: 22px; }
.pal.on { border-color: var(--mint); color: var(--mint); }
.pal.flash { border-color: var(--gold); background: var(--surface-2); }
.pal-toggle.on { background: var(--surface-2); box-shadow: inset 0 0 0 1.5px var(--gold); }

/* ---------- вход и аккаунт ---------- */
.btn.yandex { background: #fff; color: #000; }
.btn.yandex b { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: #fc3f1d; color: #fff; font-size: 15px; }
.code-input { font-size: 28px; letter-spacing: 0.4em; text-align: center; font-weight: 800; }
.consent a { color: var(--gold); }
.policy h3 { font-size: 17px; margin: 18px 0 6px; }
.policy p { color: var(--muted); font-size: 15px; }

/* ---------- админка ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { padding: 14px; border-radius: 16px; background: var(--surface); display: grid; gap: 2px; }
.stat b { font-size: 28px; color: var(--gold); line-height: 1.1; }
.stat span { font-size: 13px; color: var(--muted); }
.admin-user { margin: 0; }
.admin-user .row b { word-break: break-all; }
.admin-actions { gap: 8px; margin-top: 8px; }
.admin-actions .btn { min-height: 42px; font-size: 14px; padding: 8px 10px; }
