:root {
  --night: #0f1622;      /* фон: ночное небо */
  --night-2: #161f2e;    /* поверхности */
  --fog: #273246;        /* границы, неактивное */
  --ash: #8f97a6;        /* второстепенный текст */
  --bone: #e9e2cf;       /* лунный свет: основной текст, луна */
  --window: #f0b86e;     /* свет в окне: единственный тёплый акцент */
  --serif: "Old Standard TT", "Times New Roman", serif;
  --sans: "Golos Text", system-ui, -apple-system, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--night); color: var(--bone); }
body {
  font: 400 16px/1.5 var(--sans);
  min-height: 100vh;
  overscroll-behavior-y: none;
  /* лёгкое зерно, как на обложках */
  background-image: 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='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--window); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* ---------- главная ---------- */
.home { max-width: 560px; margin: 0 auto; padding: 28px 18px calc(48px + var(--safe-b)); }

.greet h1 {
  font: 400 40px/1.05 var(--serif);
  letter-spacing: -0.01em;
  margin: 8px 0 10px;
}
.greet-sub { margin: 0 0 26px; color: var(--ash); font-size: 15px; max-width: 32ch; }

.composer {
  border-radius: 22px;
  padding: 20px 16px 18px;
  background:
    radial-gradient(120% 70% at 85% -10%, rgba(233, 226, 207, .09), transparent 60%),
    var(--night-2);
  border: 1px solid var(--fog);
}
.composer-q { font: 400 22px/1.2 var(--serif); margin: 0 0 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--fog);
  background: transparent;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 15px;
  color: var(--bone);
  transition: background .15s, border-color .15s, color .15s;
}
.chip[aria-checked="true"] { background: var(--bone); border-color: var(--bone); color: var(--night); }
.chips.small .chip { padding: 6px 12px; font-size: 14px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.row-label { color: var(--ash); font-size: 14px; }
.seg { display: inline-flex; background: var(--night); border-radius: 12px; padding: 3px; border: 1px solid var(--fog); }
.seg button {
  border: 0; background: transparent; padding: 7px 12px; border-radius: 9px; font-size: 14px; color: var(--ash);
}
.seg button[aria-checked="true"] { background: var(--fog); color: var(--bone); }

.idea textarea {
  width: 100%; margin-top: 18px; resize: none;
  background: var(--night); border: 1px solid var(--fog); border-radius: 14px;
  padding: 12px 14px; font-size: 15px; line-height: 1.4;
}
.idea textarea::placeholder { color: #5f6878; }

.btn-primary {
  width: 100%; margin-top: 14px; border: 0; border-radius: 14px; padding: 15px;
  background: var(--bone); color: var(--night); font-weight: 600; font-size: 16px;
}
.btn-primary:active { transform: scale(.99); }
.btn-ghost { border: 1px solid var(--fog); background: transparent; border-radius: 12px; padding: 10px 14px; }

/* идёт сочинение */
.composing { display: flex; align-items: center; gap: 18px; }
.moon-wait { width: 92px; height: 92px; flex: none; }
.composing-title { font: 400 22px/1.2 var(--serif); margin: 0 0 4px; }
.composing-stage { margin: 0; color: var(--window); font-size: 15px; }
.composing-note { margin: 8px 0 0; color: var(--ash); font-size: 13px; line-height: 1.4; }
.composing-error p { margin: 0 0 12px; }

/* библиотека */
.section-title { font: 400 26px/1.2 var(--serif); margin: 36px 0 8px; }
.story-list { list-style: none; margin: 0; padding: 0; }
.story {
  display: grid; grid-template-columns: 64px 1fr; gap: 14px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid rgba(39, 50, 70, .7);
  width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left;
}
.story img { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; background: var(--night-2); }
.story-title { font: 400 19px/1.2 var(--serif); margin: 0 0 3px; }
.story-meta { color: var(--ash); font-size: 13px; margin: 0; }
.story-meta .new { color: var(--window); }
.empty { color: var(--ash); max-width: 36ch; }

/* ---------- луна ---------- */
.moon-dark { fill: rgba(233, 226, 207, .07); stroke: rgba(233, 226, 207, .16); stroke-width: 1; }
.moon-lit { fill: var(--bone); }
.moon { filter: drop-shadow(0 0 22px rgba(233, 226, 207, .18)); }

/* ---------- плеер ---------- */
.player {
  position: fixed; inset: 0; z-index: 10; overflow-y: auto; background: var(--night);
  animation: rise .28s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .player { animation: none; } }

.player-cover { position: relative; max-width: 560px; margin: 0 auto; }
.player-cover img {
  display: block; width: 100%; aspect-ratio: 1; object-fit: cover;
  -webkit-mask-image: linear-gradient(to bottom, #000 55%, transparent);
  mask-image: linear-gradient(to bottom, #000 55%, transparent);
}
.icon-btn { border: 0; background: none; padding: 0; display: grid; place-items: center; }
.icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
.back {
  position: absolute; top: 14px; left: 14px; width: 40px; height: 40px; border-radius: 50%;
  background: rgba(15, 22, 34, .55); backdrop-filter: blur(6px);
}
.tg .back { display: none; } /* в Telegram используется системная кнопка «Назад» */

.player-body { max-width: 560px; margin: -88px auto 0; padding: 0 20px calc(40px + var(--safe-b)); position: relative; }
.p-genre { color: var(--window); font-size: 14px; margin: 0 0 6px; }
.p-title { font: 400 34px/1.08 var(--serif); margin: 0 0 10px; }
.p-logline { font: italic 400 18px/1.4 var(--serif); color: #c9c2b0; margin: 0; max-width: 34ch; }

.transport { display: flex; align-items: center; justify-content: center; gap: 30px; margin: 30px 0 18px; }
.skip { position: relative; width: 48px; height: 48px; color: var(--ash); }
.skip svg { width: 34px; height: 34px; stroke-width: 1.4; }
.skip span { position: absolute; font-size: 11px; font-weight: 600; top: 50%; left: 50%; transform: translate(-50%, -45%); }
.moon-btn { position: relative; width: 132px; height: 132px; border: 0; padding: 0; background: none; border-radius: 50%; }
.moon-btn .moon { width: 100%; height: 100%; }
.play-icon {
  position: absolute; inset: 0; margin: auto; width: 34px; height: 34px;
  fill: #fff; mix-blend-mode: difference;
}

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; background: transparent; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 3px;
  background: linear-gradient(to right, var(--bone) var(--fill, 0%), var(--fog) var(--fill, 0%)); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--bone); margin-top: -6.5px; border: 0; }
input[type="range"]::-moz-range-track { height: 3px; background: var(--fog); border-radius: 3px; }
input[type="range"]::-moz-range-progress { height: 3px; background: var(--bone); border-radius: 3px; }
input[type="range"]::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--bone); border: 0; }
.seek { height: 24px; }
.times { display: flex; justify-content: space-between; color: var(--ash); font-size: 13px;
  font-variant-numeric: tabular-nums; margin-top: 2px; }

.setting { margin-top: 26px; }
.setting-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; font-size: 15px; }
.setting-note { color: var(--window); font-size: 13px; font-variant-numeric: tabular-nums; }
.vol { margin-top: 14px; height: 24px; }

.btn-dim {
  margin-top: 28px; width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  border: 1px solid var(--fog); background: transparent; border-radius: 14px; padding: 13px; font-size: 15px;
}
.btn-dim svg { width: 18px; height: 18px; fill: var(--bone); }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.action {
  border: 0; background: var(--night-2); border-radius: 12px; padding: 12px 10px; font-size: 14px; color: var(--bone);
}
.action[aria-pressed="true"] { background: var(--fog); color: var(--window); }
.action.danger { width: 100%; margin-top: 18px; background: transparent; color: #b8796f; }
.hint { color: var(--ash); font-size: 13px; line-height: 1.45; margin: 14px 0 0; }

.story-text { margin-top: 22px; font: 400 19px/1.65 var(--serif); color: #d8d1bf; }
.story-text p { margin: 0 0 1em; }

/* затемнение экрана */
.dim {
  position: fixed; inset: 0; z-index: 30; background: #000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
.dim-moon { width: 56px; height: 56px; opacity: .35; filter: none; }
.dim p { color: #3c3c3c; font-size: 13px; margin: 0; transition: opacity 1.2s; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translate(-50%, 20px);
  background: var(--bone); color: var(--night); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 40; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
