@import url('./tokens.css');
@import url('./screens.css');
@import url('./player.css');
@import url('./nowplaying.css');
@import url('./art.css');

/* ============================================================ reset ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--t-md);
  line-height: 1.42;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

input {
  font: inherit;
}

button:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/*
 * Text inputs are the exception, and this is the rule the Search defect came from.
 *
 * A default `input:focus-visible` outline is a RECTANGLE. On a rounded capsule that paints
 * a square frame inside the pill — the owner's screenshot. Inputs in this app therefore
 * never draw their own outline; the focus indicator belongs to the rounded container
 * (.search-bar, .modal-input), where it follows the real radius.
 *
 * Kept here, next to the rule it corrects, rather than only in the component sheet: this
 * is the place someone will come to change global focus behaviour.
 */
.search-bar input:focus-visible,
.modal-input:focus-visible {
  outline: none;
}

.ic {
  width: 22px;
  height: 22px;
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ========================================================== shell ======= */
/*
 * A fixed-height column: chrome / scrolling content / bottom stack. 100dvh plus
 * safe-area insets, because Telegram's WebView reports a different visual
 * viewport than 100vh describes and a hard 100vh bar lands under the home bar.
 */
.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: var(--shell);
  margin: 0 auto;
  overflow: hidden;
  isolation: isolate;
  background: var(--bg);
  box-shadow: 0 0 0 1px var(--wash-2), 0 40px 120px -30px var(--shadow-ink);
}

/* Ambient warmth behind everything: the reference glows rather than sits flat. */
.app::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(90% 50% at 50% -12%, var(--accent-ambient), transparent 62%),
    radial-gradient(70% 40% at 100% 100%, var(--accent-ambient), transparent 66%);
  pointer-events: none;
}

.main {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: calc(var(--mini-h) + var(--nav-h) + var(--safe-bottom) + 26px);
}

.main::-webkit-scrollbar {
  display: none;
}

.screen {
  display: none;
  padding: 0 0 8px;
}

.screen.is-active {
  display: block;
  animation: screen-in var(--base) var(--ease-out);
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translate3d(0, 10px, 0);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ========================================================= chrome ======= */
/*
 * No device chrome.
 *
 * Run 08 removed the drawn status bar entirely: eight copies of a 9:41 clock, cellular
 * bars, Wi-Fi and a battery glyph, plus their CSS. In a Telegram Mini App the client owns
 * that region; in a plain browser this is a web app and drawing an iPhone status bar is a
 * fake. What remains is the safe-area inset, which is a real layout requirement.
 */

/* ========================================================== header ====== */
.hdr {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  /*
   * The top inset is the app's own, applied ONCE, now that no drawn status bar sits above
   * it. In Telegram the host draws the real status area and reports it through
   * safeAreaInset; `--safe-top` reads env(safe-area-inset-top) and is updated by prefs.js
   * when the Mini App is embedded. Double padding was the specific risk called out in the
   * handoff, so the only top inset in the app is this one.
   */
  padding: calc(10px + var(--safe-top)) 20px 12px;
}

.hdr-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  flex: 0 0 auto;
  padding: 2px;
  background: var(--accent-grad);
  box-shadow: 0 6px 18px -8px var(--accent-glow);
}

.avatar > span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--surface-2);
  background-size: cover;
  box-shadow: inset 0 0 0 2px var(--scrim-strong);
}

.hdr-greet {
  min-width: 0;
}

.hdr-hello {
  font-size: var(--t-xs);
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
}

.hdr-name {
  font-size: var(--t-lg);
  font-weight: 700;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.round-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 1px solid var(--hairline);
  background: var(--wash-2);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  color: var(--text);
  transition: background var(--fast) var(--ease), transform var(--fast) var(--ease);
}

.round-button:hover {
  background: var(--wash-3);
}

.round-button:active {
  transform: scale(0.94);
}

.round-button .ic {
  width: 19px;
  height: 19px;
}

.round-button--accent {
  background: var(--accent-grad);
  border-color: transparent;
  color: var(--on-accent);
  box-shadow: 0 10px 24px -10px var(--accent-glow);
}

/* Small "live" tag used on demo surfaces. */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 9px;
  border-radius: var(--r-pill);
  border: 1px solid var(--hairline);
  background: var(--wash-2);
  font-size: var(--t-2xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.tag--accent {
  border-color: var(--accent-glow);
  background: var(--accent-ambient);
  color: var(--accent-2);
}

.tag i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 7px currentColor;
}

/* ========================================================= section ====== */
.section {
  margin-top: 26px;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  margin-bottom: 12px;
}

.section-title {
  margin: 0;
  font-size: var(--t-lg);
  font-weight: 700;
  letter-spacing: -0.015em;
}

.section-link {
  font-size: var(--t-xs);
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.section-link:hover {
  color: var(--text);
}

/* ========================================================= chips ======== */
.chips {
  display: flex;
  gap: 9px;
  overflow-x: auto;
  padding: 0 20px 4px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  height: 36px;
  padding: 0 16px;
  border-radius: var(--r-pill);
  border: 1px solid var(--hairline);
  background: var(--wash-2);
  color: var(--text-dim);
  font-size: var(--t-sm);
  font-weight: 600;
  white-space: nowrap;
  transition: background var(--fast) var(--ease), color var(--fast) var(--ease),
    border-color var(--fast) var(--ease);
}

.chip:hover {
  border-color: var(--hairline);
  background: var(--wash-3);
}

.chip.is-active {
  background: var(--accent-grad);
  border-color: transparent;
  color: var(--on-accent);
  box-shadow: 0 10px 22px -12px var(--accent-glow);
}

/* ===================================================== bottom stack ===== */
.bottom-stack {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  padding: 0 14px calc(8px + var(--safe-bottom));
  pointer-events: none;
}

.bottom-stack > * {
  pointer-events: auto;
}

/* ---------------------------------------------------- mini player ----- */
/*
 * A raised, glossy bar. The progress line sits inside the bar's lower edge so the
 * element reads as one object, not a strip with a decoration attached.
 */
.mini {
  position: relative;
  display: none;
  align-items: center;
  gap: 12px;
  height: var(--mini-h);
  margin-bottom: 8px;
  padding: 0 8px 0 8px;
  border-radius: var(--r-lg);
  border: 1px solid var(--wash-4);
  background:
    linear-gradient(180deg, var(--wash-3), var(--wash-1)),
    var(--glass-strong);
  -webkit-backdrop-filter: blur(26px) saturate(150%);
  backdrop-filter: blur(26px) saturate(150%);
  box-shadow: 0 22px 44px -22px var(--shadow-ink), inset 0 1px 0 var(--wash-4);
  overflow: hidden;
}

.mini.is-visible {
  display: flex;
  animation: mini-in var(--slow) var(--ease-out);
}

@keyframes mini-in {
  from {
    opacity: 0;
    transform: translate3d(0, 18px, 0);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.mini-art {
  position: relative;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--wash-4), 0 8px 18px -8px var(--shadow-ink);
}

.mini-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-height: var(--touch);
  text-align: left;
}

.mini-title {
  font-size: var(--t-sm);
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-artist {
  font-size: var(--t-xs);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-play {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--accent-grad);
  color: var(--on-accent);
  box-shadow: 0 10px 22px -10px var(--accent-glow);
  transition: transform var(--fast) var(--ease), filter var(--fast) var(--ease);
}

.mini-play:hover {
  filter: brightness(1.08);
}

.mini-play:active {
  transform: scale(0.93);
}

.mini-play .ic {
  width: 18px;
  height: 18px;
}

.mini-progress {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 0;
  height: 2px;
  border-radius: 2px;
  background: var(--wash-3);
  overflow: hidden;
}

.mini-progress > i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent-grad);
  box-shadow: 0 0 10px var(--accent-glow);
  transition: width 420ms linear;
}

/* ------------------------------------------------------------ nav ----- */
/*
 * Floating capsule with one expanded active item, exactly as the reference does:
 * the active tab grows into a pill with its label, the others stay circular.
 */
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  height: var(--nav-h);
  padding: 7px;
  border-radius: var(--r-pill);
  border: 1px solid var(--wash-4);
  background:
    linear-gradient(180deg, var(--wash-3), var(--wash-1)),
    var(--glass-nav);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  backdrop-filter: blur(28px) saturate(160%);
  box-shadow: 0 24px 50px -24px var(--shadow-ink), inset 0 1px 0 var(--hairline);
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 52px;
  min-width: 52px;
  padding: 0 15px;
  border-radius: var(--r-pill);
  color: var(--muted);
  font-size: var(--t-sm);
  font-weight: 650;
  white-space: nowrap;
  transition: color var(--fast) var(--ease), background var(--fast) var(--ease),
    padding var(--base) var(--ease), flex-basis var(--base) var(--ease);
}

.nav-item .ic {
  width: 21px;
  height: 21px;
  flex: 0 0 auto;
}

.nav-item span {
  display: none;
}

.nav-item.is-active {
  color: var(--on-accent);
  background: var(--accent-grad);
  box-shadow: 0 12px 26px -12px var(--accent-glow), inset 0 1px 0 var(--wash-5);
}

.nav-item.is-active span {
  display: inline;
}

.nav-item.is-active .ic {
  width: 19px;
  height: 19px;
}

.nav-item:not(.is-active):hover {
  color: var(--text);
  background: var(--hairline-soft);
}

/* ==================================================== shared primitives == */
.glass {
  border: 1px solid var(--hairline);
  background: linear-gradient(180deg, var(--wash-2), var(--wash-1));
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 46px;
  padding: 0 20px;
  border-radius: var(--r-pill);
  font-size: var(--t-sm);
  font-weight: 650;
  transition: filter var(--fast) var(--ease), transform var(--fast) var(--ease),
    background var(--fast) var(--ease);
}

.btn .ic {
  width: 18px;
  height: 18px;
}

.btn--primary {
  background: var(--accent-grad);
  color: var(--on-accent);
  box-shadow: 0 16px 32px -16px var(--accent-glow), inset 0 1px 0 var(--wash-5);
}

.btn--primary:hover {
  filter: brightness(1.07);
}

.btn--primary:active {
  transform: scale(0.98);
}

.btn--ghost {
  border: 1px solid var(--hairline);
  background: var(--wash-2);
  color: var(--text);
}

.btn--ghost:hover {
  background: var(--wash-3);
}

/* ---------------------------------------------------- player error (S2B-01) -----
   A failed recording reports itself in the now-playing panel, in the same
   typographic register as the rest of the panel. Hidden by default; the engine
   reveals it only in the `error` state, and the existing Play button becomes
   the retry. */
#screen-welcome .np-error,
.np-error {
  margin: 10px 0 0;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 12.5px;
  line-height: 1.4;
  color: rgb(255 226 214);
  background: rgb(120 32 40 / 0.42);
  border: 1px solid rgb(255 140 120 / 0.35);
}

.np-error[hidden] {
  display: none;
}

/* ------------------------------------------------- Run S2B-02: API states -----
   Search latency, the signed-out banner and the "no recording" row are all new
   because the UI now talks to a real API. They use the existing palette and type
   scale so the accepted composition is unchanged; the fox, logo, hemisphere, wave,
   arcs, equalizer, carousel and slider are not touched by any rule below. */

.search-meta {
  margin: 2px 0 10px;
  font-size: 11.5px;
  letter-spacing: 0.02em;
  color: var(--muted, rgb(255 255 255 / 0.52));
}

.auth-banner {
  margin: 0 0 12px;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 12.5px;
  line-height: 1.45;
  color: rgb(255 232 219);
  background: rgb(120 60 40 / 0.34);
  border: 1px solid rgb(255 150 110 / 0.28);
}

.auth-banner[hidden] { display: none; }

/* A row without a recording is visibly inert, not a dead live button. */
.rcard.is-unavailable { opacity: 0.55; }

.rcard.is-unavailable .rcard-play {
  cursor: not-allowed;
  color: var(--muted, rgb(255 255 255 / 0.5));
  background: rgb(255 255 255 / 0.05);
}

.tag--muted {
  color: var(--muted, rgb(255 255 255 / 0.55));
  background: rgb(255 255 255 / 0.06);
  border-color: rgb(255 255 255 / 0.10);
}

button.is-locked {
  opacity: 0.45;
  cursor: not-allowed;
}
