/* Telegram injects --tg-theme-* variables; the fallbacks are for plain browsers. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --surface: var(--tg-theme-secondary-bg-color, #f3f1ee);
  --text: var(--tg-theme-text-color, #16130f);
  --hint: var(--tg-theme-hint-color, #8b857d);
  --line: color-mix(in srgb, var(--text) 10%, transparent);
  --accent: #ff5a36;
  --accent-2: #ffb020;
  --accent-ink: #ffffff;
  --accent-soft: color-mix(in srgb, var(--accent) 12%, transparent);
  --danger: #e5484d;
  --radius: 18px;
  --radius-sm: 12px;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --display: "Unbounded", -apple-system, "SF Pro Display", "Segoe UI", sans-serif;
  --body: -apple-system, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root:not(.tg) {
    --bg: #121110;
    --surface: #1d1b19;
    --text: #f4f1ec;
    --hint: #8f8880;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; background: var(--bg); color: var(--text); }

body {
  font: 16px/1.45 var(--body);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px 16px calc(120px + env(safe-area-inset-bottom));
}

/* ---------- progress ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 12px 16px 10px;
}
.steps { display: flex; gap: 6px; max-width: 560px; margin: 0 auto; }
.steps span {
  flex: 1; height: 4px; border-radius: 4px;
  background: var(--line);
  overflow: hidden; position: relative;
}
.steps span::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transform: scaleX(0); transform-origin: left;
  transition: transform 0.5s var(--ease);
}
.steps span.on::after { transform: scaleX(1); }

/* ---------- screens ---------- */
.screen { animation: enter 0.42s var(--ease) both; }
.screen.back { animation-name: enter-back; }
@keyframes enter { from { opacity: 0; transform: translateX(18px); } }
@keyframes enter-back { from { opacity: 0; transform: translateX(-18px); } }

.eyebrow {
  margin: 14px 0 6px;
  font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--accent);
}
h1 {
  margin: 0 0 8px;
  font: 700 27px/1.15 var(--display);
  letter-spacing: -0.01em;
}
.lead { margin: 0 0 22px; color: var(--hint); font-size: 15px; }
h2 {
  margin: 26px 0 10px;
  font-size: 13px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--hint);
}

/* ---------- occasion cards ---------- */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  position: relative;
  display: flex; flex-direction: column; align-items: flex-start; gap: 18px;
  min-height: 104px; padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  transition: transform 0.18s var(--ease), box-shadow 0.25s var(--ease);
}
.tile:active { transform: scale(0.97); }
.tile .emoji { font-size: 30px; line-height: 1; }
.tile .label { font-weight: 600; font-size: 15px; line-height: 1.2; }
.tile.selected {
  box-shadow: inset 0 0 0 2px var(--accent);
  background: var(--accent-soft);
}
.tile.selected::after {
  content: "✓"; position: absolute; top: 12px; right: 12px;
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700;
  color: var(--accent-ink); background: var(--accent);
}

/* ---------- mode picker ---------- */
.modes { display: flex; flex-direction: column; gap: 12px; }
.mode {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  text-align: left;
  transition: transform 0.18s var(--ease), box-shadow 0.25s var(--ease);
}
.mode:active { transform: scale(0.98); }
.mode-emoji {
  flex: none; width: 52px; height: 52px; border-radius: 16px;
  display: grid; place-items: center; font-size: 28px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 20px -10px var(--accent);
}
.mode-body { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.mode-title { font: 700 17px/1.2 var(--display); }
.mode-text { font-size: 14px; line-height: 1.4; color: var(--hint); }
.mode-arrow { flex: none; font-size: 28px; color: var(--hint); }

.free-panels { margin-top: 16px; }
/* ---------- song builder ---------- */
.builder-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.builder-head .field-label { margin: 0 0 0 4px; }
.link-btn { color: var(--accent); font-weight: 600; font-size: 14px; padding: 4px 2px; }
.blocks { display: flex; flex-direction: column; gap: 10px; }
.block {
  padding: 10px 12px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  animation: enter 0.3s var(--ease) both;
}
.block-chorus { box-shadow: inset 3px 0 0 var(--accent); }
.block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.block-pill {
  position: relative; display: inline-flex; align-items: center;
  border-radius: 999px; background: var(--accent-soft);
}
.block-type {
  appearance: none; -webkit-appearance: none;
  border: 0; background: transparent;
  padding: 6px 26px 6px 12px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--accent); cursor: pointer;
}
.block-caret { position: absolute; right: 10px; font-size: 11px; color: var(--accent); pointer-events: none; }
.block-tools { display: flex; gap: 2px; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 10px;
  display: grid; place-items: center;
  font-size: 15px; color: var(--hint);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:active { background: var(--line); color: var(--text); }
.icon-btn:disabled { opacity: 0.25; pointer-events: none; }
.block .textarea.block-text {
  min-height: 72px; padding: 10px 12px;
  background: var(--bg); overflow: hidden; line-height: 1.5;
}
.block-break { margin: 0; padding: 4px 2px; font-size: 14px; color: var(--hint); }
.add-label { margin: 14px 0 8px 4px; font-size: 13px; color: var(--hint); }
.add-row .chip-add { font-size: 14px; padding: 8px 12px; background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
.add-row .chip-repeat { font-size: 14px; padding: 8px 12px; color: var(--accent); background: var(--accent-soft); }
.field-foot .over { color: var(--danger); font-weight: 600; }
.sheet-lead { margin: 0 0 12px; font-size: 14px; }
.sheet .textarea.paste-input { min-height: 200px; }

/* ---------- chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--surface);
  font-size: 15px; font-weight: 500;
  transition: transform 0.15s var(--ease), background 0.2s, color 0.2s;
}
.chip:active { transform: scale(0.95); }
.chip.selected { background: var(--text); color: var(--bg); }

.segmented {
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 4px; gap: 4px;
  border-radius: 14px; background: var(--surface);
}
.segmented button {
  padding: 10px 6px; border-radius: 10px;
  font-weight: 600; font-size: 15px;
  transition: background 0.2s, box-shadow 0.2s;
}
.segmented button.selected {
  background: var(--bg);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.12), 0 0 0 1px var(--line);
}

/* ---------- fields ---------- */
.field { display: block; margin-bottom: 14px; }
.field-label { display: block; margin: 0 0 6px 4px; font-size: 14px; font-weight: 600; }
.input, .textarea {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid transparent; border-radius: 14px;
  background: var(--surface);
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}
.input:focus, .textarea:focus { border-color: var(--accent); background: var(--bg); }
.textarea { min-height: 150px; resize: none; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--hint); opacity: 0.85; }
.shake { animation: shake 0.4s var(--ease); border-color: var(--danger) !important; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.field-foot > span:last-child:not(:first-child) { flex: none; white-space: nowrap; }
.screen h1 + .segmented { margin-top: 18px; }
.segmented button { white-space: nowrap; }
.field-foot { display: flex; justify-content: space-between; gap: 12px; margin: 6px 4px 0; font-size: 13px; color: var(--hint); }
.other-input { margin-top: 10px; }

.tip {
  display: flex; gap: 10px; align-items: flex-start;
  margin-top: 18px; padding: 12px 14px;
  border-radius: 14px; background: var(--accent-soft);
  font-size: 14px; line-height: 1.4;
}

/* ---------- lyrics ---------- */
.song-head { display: flex; align-items: center; gap: 14px; margin: 14px 0 18px; }
.cover {
  flex: none; width: 64px; height: 64px; border-radius: 16px;
  display: grid; place-items: center; font-size: 28px;
  background: var(--cover, linear-gradient(135deg, var(--accent), var(--accent-2)));
  box-shadow: 0 8px 22px -10px var(--accent);
}
.song-head h1 { font-size: 21px; margin: 0; }
.song-head .lead { margin: 4px 0 0; }

.lyrics { display: flex; flex-direction: column; gap: 10px; }
.section {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
}
.section.chorus { box-shadow: inset 3px 0 0 var(--accent); }
.section-name {
  display: inline-block; margin-bottom: 6px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--accent);
}
.section p { margin: 0; white-space: pre-line; font-size: 16px; line-height: 1.6; }
.section.instrumental {
  padding: 10px 16px;
  background: transparent; border: 1.5px dashed var(--line);
  color: var(--hint); font-size: 14px;
}
.section .textarea { min-height: 0; padding: 10px 12px; background: var(--bg); overflow: hidden; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 14px; border-radius: 14px;
  background: var(--surface);
  font-weight: 600; font-size: 15px;
  transition: transform 0.15s var(--ease), opacity 0.2s;
}
.btn:active { transform: scale(0.97); }
a.btn { color: inherit; text-decoration: none; }
.btn.wide { grid-column: 1 / -1; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--accent); }
.btn:disabled { opacity: 0.5; pointer-events: none; }

/* ---------- skeleton ---------- */
.skeleton { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.skeleton .section { display: flex; flex-direction: column; gap: 9px; }
.bar {
  height: 12px; border-radius: 6px;
  background: linear-gradient(90deg, var(--line) 0%, color-mix(in srgb, var(--text) 18%, transparent) 50%, var(--line) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- studio (generation) ---------- */
.studio { display: flex; flex-direction: column; align-items: center; text-align: center; padding-top: 28px; }
.vinyl {
  position: relative; width: 220px; height: 220px; border-radius: 50%;
  background:
    radial-gradient(circle at center, var(--bg) 0 7%, transparent 7.5%),
    radial-gradient(circle at center, var(--cover-solid, var(--accent)) 0 30%, transparent 30.5%),
    repeating-radial-gradient(circle at center, #1a1816 0 2px, #26231f 2px 4px);
  box-shadow: 0 24px 50px -20px rgb(0 0 0 / 0.55);
  animation: spin 2.6s linear infinite;
}
.vinyl::after {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  background: conic-gradient(from 30deg, transparent 0 20%, rgb(255 255 255 / 0.10) 25%, transparent 32% 70%, rgb(255 255 255 / 0.07) 75%, transparent 82%);
}
@keyframes spin { to { transform: rotate(360deg); } }
.vinyl.paused { animation-play-state: paused; }

.eq { display: flex; align-items: flex-end; gap: 5px; height: 34px; margin: 30px 0 18px; }
.eq i {
  width: 6px; border-radius: 3px;
  background: linear-gradient(var(--accent-2), var(--accent));
  animation: eq 1s var(--ease) infinite alternate;
}
.eq i:nth-child(1) { animation-delay: -0.2s; }
.eq i:nth-child(2) { animation-delay: -0.7s; }
.eq i:nth-child(3) { animation-delay: -0.4s; }
.eq i:nth-child(4) { animation-delay: -0.9s; }
.eq i:nth-child(5) { animation-delay: -0.1s; }
@keyframes eq { from { height: 6px; } to { height: 34px; } }

.studio h1 { font-size: 22px; }
.phase { min-height: 24px; color: var(--hint); transition: opacity 0.3s; }
.timer { margin-top: 6px; font-variant-numeric: tabular-nums; font-size: 14px; color: var(--hint); }
.studio .tip { text-align: left; margin-top: 30px; }

/* ---------- player ---------- */
.player {
  margin-top: 18px; padding: 22px 20px 20px;
  border-radius: 26px;
  background: var(--cover, linear-gradient(135deg, var(--accent), var(--accent-2)));
  color: #fff;
  box-shadow: 0 26px 50px -24px var(--cover-solid, var(--accent));
}
.player .badge { font-size: 13px; font-weight: 600; opacity: 0.85; letter-spacing: 0.04em; text-transform: uppercase; }
.player h1 { margin: 6px 0 22px; font-size: 24px; color: #fff; }
.player-row { display: flex; align-items: center; gap: 14px; }
.play {
  flex: none; width: 60px; height: 60px; border-radius: 50%;
  display: grid; place-items: center;
  background: #fff; color: #16130f;
  box-shadow: 0 8px 20px -8px rgb(0 0 0 / 0.5);
  transition: transform 0.15s var(--ease);
}
.play:active { transform: scale(0.93); }
.play svg { width: 24px; height: 24px; }
.scrub { flex: 1; }
.track {
  position: relative; height: 6px; border-radius: 3px;
  background: rgb(255 255 255 / 0.3);
  touch-action: none;
}
.track .fill { position: absolute; inset: 0 auto 0 0; border-radius: 3px; background: #fff; width: 0; }
.track .knob {
  position: absolute; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px;
  border-radius: 50%; background: #fff; left: 0;
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.3);
}
.wave {
  display: flex; align-items: center; gap: 2px;
  height: 44px;
  touch-action: none;
}
.wave i {
  flex: 1; min-width: 2px; border-radius: 2px;
  background: rgb(255 255 255 / 0.35);
  transition: background 0.15s;
}
.wave i.played { background: #fff; }

.karaoke { margin-top: 6px; }
.karaoke-lines {
  position: relative;
  max-height: 232px; overflow-y: auto;
  padding: 6px 2px;
  scrollbar-width: none;
  mask-image: linear-gradient(transparent, #000 14%, #000 86%, transparent);
  -webkit-mask-image: linear-gradient(transparent, #000 14%, #000 86%, transparent);
}
.karaoke-lines::-webkit-scrollbar { display: none; }
.karaoke p {
  margin: 0; padding: 5px 0;
  font-size: 18px; font-weight: 600; line-height: 1.4;
  color: var(--hint);
  opacity: 0.55;
  transition: opacity 0.3s, transform 0.3s var(--ease);
  transform-origin: left center;
}
.karaoke p.active { opacity: 1; transform: scale(1.03); }
.karaoke span { transition: color 0.15s; }
.karaoke span.sung { color: var(--text); }
.karaoke span.now { color: var(--accent); }

.times { display: flex; justify-content: space-between; margin-top: 8px; font-size: 12px; opacity: 0.85; font-variant-numeric: tabular-nums; }

.delivered {
  display: flex; align-items: center; gap: 10px;
  margin-top: 14px; padding: 12px 14px;
  border-radius: 14px; background: var(--surface);
  font-size: 14px;
}

/* ---------- error ---------- */
.empty { text-align: center; padding-top: 60px; }
.empty .emoji { font-size: 54px; }

/* ---------- bottom CTA (browser fallback for Telegram MainButton) ---------- */
.cta-wrap {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 35%);
}
.cta {
  display: block; width: 100%; max-width: 528px; margin: 0 auto;
  padding: 16px; border-radius: 16px;
  background: linear-gradient(100deg, var(--accent), color-mix(in srgb, var(--accent) 70%, var(--accent-2)));
  color: var(--accent-ink);
  font-weight: 700; font-size: 16px;
  box-shadow: 0 12px 26px -12px var(--accent);
  transition: transform 0.15s var(--ease), opacity 0.2s, filter 0.2s;
}
.cta:active { transform: scale(0.98); }
.cta:disabled { filter: grayscale(0.7); opacity: 0.45; box-shadow: none; }

/* ---------- bottom sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 20;
  background: rgb(0 0 0 / 0.4);
  animation: fade 0.25s both;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-width: 560px; margin: 0 auto;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: var(--bg);
  box-shadow: 0 -12px 40px rgb(0 0 0 / 0.25);
  animation: rise 0.35s var(--ease) both;
}
@keyframes rise { from { transform: translateY(100%); } }
.sheet .grabber { width: 38px; height: 5px; margin: 0 auto 14px; border-radius: 3px; background: var(--line); }
.sheet h1 { font-size: 20px; }
.sheet .chips { margin: 12px 0; }
.sheet .chip { font-size: 14px; padding: 8px 12px; }
.sheet .textarea { min-height: 96px; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translateX(-50%);
  width: max-content; max-width: min(calc(100% - 32px), 420px);
  padding: 12px 16px; border-radius: 14px;
  text-align: center; line-height: 1.35;
  box-shadow: 0 10px 30px -10px rgb(0 0 0 / 0.4);
  background: var(--text); color: var(--bg);
  font-size: 14px; font-weight: 500;
  animation: rise-small 0.3s var(--ease) both;
}
@keyframes rise-small { from { opacity: 0; transform: translate(-50%, 10px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
