/* Colors follow the Telegram theme; the fallbacks are for testing in a normal browser. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2481cc);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --line: color-mix(in srgb, var(--hint) 25%, transparent);
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --bg: #101014; --card: #1c1c22; --text: #f2f2f5; --hint: #8d8d96;
    --accent: #4aa3ff; --link: #4aa3ff; --danger: #ff6b6b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
main { max-width: 640px; margin: 0 auto; padding: 12px 16px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 20px 4px 8px; font-weight: 600; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
button:disabled { opacity: .4; cursor: default; }

.hint { color: var(--hint); font-size: 14px; }
.small-text { font-size: 13px; margin: 8px 0 0; }
.center { text-align: center; }
.warn { color: var(--danger); margin-top: 6px; }
.empty { color: var(--hint); text-align: center; padding: 24px 8px; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.row { display: flex; align-items: center; gap: 10px; }

/* Now playing */
.now { display: flex; gap: 14px; align-items: center; margin-top: 4px; }
.now-kind {
  width: 64px; height: 64px; flex: none; border-radius: 12px; display: grid; place-items: center;
  font-size: 32px; background: color-mix(in srgb, var(--accent) 15%, transparent);
}
.now-text { min-width: 0; }
.now-title { font-size: 18px; font-weight: 600; overflow-wrap: anywhere; }
.progress { margin: 4px 4px 8px; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); transition: width .9s linear; }
.bar.seekable { height: 10px; border-radius: 5px; cursor: pointer; }
.times { display: flex; justify-content: space-between; margin-top: 4px; font-variant-numeric: tabular-nums; }
.controls { display: flex; justify-content: center; align-items: center; gap: 24px; margin: 8px 0 12px; }
.controls.small { gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.round {
  width: 56px; height: 56px; border-radius: 50%; font-size: 22px;
  background: var(--card); display: grid; place-items: center;
}
.round.big { width: 76px; height: 76px; font-size: 30px; background: var(--accent); color: var(--accent-text); }
.pill { padding: 8px 14px; border-radius: 999px; background: var(--card); font-size: 15px; white-space: nowrap; }
.pill.primary { background: var(--accent); color: var(--accent-text); }
.pill.danger, .danger { color: var(--danger); }
.link { color: var(--link); padding: 8px 4px; font-size: 15px; }
.volume input { flex: 1; accent-color: var(--accent); }
.volume-value { width: 48px; text-align: right; font-variant-numeric: tabular-nums; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.list:empty { display: none; }
.item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; min-height: 56px; }
.item + .item { border-top: 1px solid var(--line); }
.item .icon { font-size: 20px; width: 28px; text-align: center; flex: none; }
.item .body { flex: 1; min-width: 0; }
.item .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { color: var(--hint); font-size: 13px; }
.item.playing .title { color: var(--accent); font-weight: 600; }
.item.tappable { cursor: pointer; }
.item .actions { display: flex; gap: 2px; flex: none; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; font-size: 16px; color: var(--hint); }
.icon-btn:not(:disabled):active { background: var(--line); }
.item input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar.between { justify-content: space-between; margin: 4px 4px 6px; }
#search, .search { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 0; background: var(--card); }
.upload-btn { cursor: pointer; }
.upload { background: var(--card); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; font-size: 14px; }
.upload .bar { margin-top: 6px; }
.upload.failed { color: var(--danger); }

.select-bar {
  position: fixed; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom));
  display: flex; justify-content: space-between; align-items: center; padding: 10px 16px;
  background: var(--card); border-top: 1px solid var(--line);
}

/* Setlists */
.search { display: block; width: 100%; margin-bottom: 10px; }
.wide { display: block; width: 100%; padding: 12px; margin: 10px 0; }
.form-row { margin-top: 12px; }
.form-row input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 0; background: var(--card); }

/* Settings */
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; }
.setting + .setting { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 6px; }
.label { font-weight: 600; }
select { max-width: 50%; padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
.plain { list-style: none; margin: 0 0 10px; padding: 0; }
.plain li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; }
#manager-form input { flex: 1; min-width: 0; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: transparent; }
#schedule-form select, #schedule-setlist { max-width: none; flex: 1; min-width: 0; }
.schedule-entry { flex-wrap: wrap; gap: 4px 10px; }
.schedule-entry .when { flex: 1; min-width: 0; }
#schedule-time { padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); }
#cleanup-days { max-width: none; flex: 1; }
.cleanup-list { max-height: 260px; overflow-y: auto; font-size: 14px; }
#storage-bar { transition: none; }
#storage-text { margin-bottom: 8px; }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { flex: 1; padding: 8px 0 10px; font-size: 12px; color: var(--hint); display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; }
.tabs button span { font-size: 20px; line-height: 1.2; }
.tabs button.active { color: var(--accent); }
.badge { position: absolute; top: 4px; left: 55%; background: var(--accent); color: var(--accent-text); font-size: 11px; border-radius: 999px; padding: 0 6px; }

/* Action sheet, toast, notice */
.backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / .35); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; background: var(--card);
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto;
}
.sheet-title { font-weight: 600; text-align: center; overflow-wrap: anywhere; }
.sheet-btn { display: block; width: 100%; padding: 14px; font-size: 17px; border-radius: 12px; margin-top: 8px; background: var(--bg); }
.sheet-btn.cancel { color: var(--hint); }
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom));
  max-width: 480px; margin: 0 auto; padding: 12px 16px; border-radius: 12px;
  background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--card); text-align: center; font-size: 15px;
}
.toast.error { background: var(--danger); color: #fff; }
.notice { background: var(--danger); color: #fff; padding: 12px 16px; text-align: center; font-size: 15px; }
