:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #15171c;
  --muted: #6b6f78;
  --line: #e4e4e0;
  --accent: #1f6feb;
  --accent-text: #ffffff;
  --ok: #1a7f37;
  --err: #c62828;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --text: #eceef2;
    --muted: #9399a5;
    --line: #262a32;
    --accent: #4c8dff;
    --accent-text: #0f1115;
    --ok: #3fb950;
    --err: #ff6b6b;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}

header {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg);
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  border-bottom: 1px solid var(--line);
}

#search-form { display: flex; gap: 8px; max-width: 720px; margin: 0 auto; }

input, select, button { font: inherit; color: inherit; }

#q {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  /* 16px+ zabrání zoomu na iOS */
  font-size: 17px;
}

#q:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 24px);
}

#qobuz-banner {
  display: block;
  width: 100%;
  margin: 12px 0 0;
  padding: 10px 12px;
  border: 1px solid var(--err);
  border-radius: 10px;
  background: transparent;
  color: var(--err);
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}

#qobuz-banner[hidden] { display: none; }

.status { color: var(--muted); text-align: center; margin: 32px 0; }
.status.error { color: var(--err); }

.results { list-style: none; margin: 0; padding: 0; }

section h2 {
  margin: 20px 0 4px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

section .status { margin: 12px 0; text-align: left; }

#settings-btn {
  flex: none;
  width: 46px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
}

#settings-btn svg { width: 22px; height: 22px; display: block; margin: auto; fill: currentColor; }

.tag.library { color: var(--ok); border-color: currentColor; }

.dl.open { background: transparent; color: var(--accent); box-shadow: inset 0 0 0 1px currentColor; }

.track {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.play {
  position: relative;
  flex: none;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--line);
  cursor: pointer;
}

.cover { width: 100%; height: 100%; object-fit: cover; display: block; }

.play .icon {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(0 0 0 / 0.35);
  color: #fff;
  font-size: 20px;
}

.play .icon::before { content: "▶"; padding-left: 3px; }
.track.playing .play .icon::before { content: "❚❚"; padding-left: 0; font-size: 15px; letter-spacing: -2px; }
.track.loading .play .icon::before { content: ""; width: 20px; height: 20px; border: 2px solid #fff; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; padding: 0; }

.ring {
  position: absolute;
  inset: 4px;
  width: calc(100% - 8px);
  height: calc(100% - 8px);
  transform: rotate(-90deg);
  pointer-events: none;
  z-index: 1;
  opacity: 0;
}

.ring circle {
  fill: none;
  stroke: #fff;
  stroke-width: 2.5;
  stroke-dasharray: 100.53;
  stroke-dashoffset: calc(100.53 * (1 - var(--p, 0)));
  stroke-linecap: round;
}

.track.playing .ring { opacity: 1; }

.meta { flex: 1; min-width: 0; }

.title, .sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title { font-weight: 600; }
.sub { color: var(--muted); font-size: 14px; }

.tags { display: flex; gap: 6px; margin-top: 3px; font-size: 11px; color: var(--muted); }

.tag {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
}

.tag.hires { color: var(--accent); border-color: currentColor; }

.dl {
  flex: none;
  min-width: 92px;
  padding: 9px 12px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.dl:disabled { opacity: 0.6; cursor: default; }
.dl.busy .dl-label::before { content: ""; display: inline-block; width: 11px; height: 11px; margin-right: 6px; vertical-align: -1px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
.dl.done { background: transparent; color: var(--ok); box-shadow: inset 0 0 0 1px currentColor; }
.dl.failed { background: transparent; color: var(--err); box-shadow: inset 0 0 0 1px currentColor; }

.track.unavailable { opacity: 0.45; }

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  width: min(360px, calc(100vw - 32px));
  padding: 20px;
}

dialog::backdrop { background: rgb(0 0 0 / 0.5); }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
dialog p { margin: 0 0 12px; color: var(--muted); }
dialog input + input { margin-top: 8px; }

#settings { width: min(420px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }

.account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0 14px;
  border-bottom: 1px solid var(--line);
}

dialog button.secondary {
  width: auto;
  margin: 0;
  padding: 8px 14px;
  background: transparent;
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}

fieldset { margin: 14px 0 0; padding: 0; border: 0; }
legend { padding: 0; font-weight: 600; }
fieldset label { display: block; margin-top: 10px; font-size: 14px; color: var(--muted); }
fieldset label input, fieldset label textarea, fieldset label select { margin-top: 4px; color: var(--text); }
dialog textarea, dialog select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  font-size: 15px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  resize: vertical;
}
dialog select { font-family: inherit; font-size: 17px; }
.hint { margin: 8px 0 0 !important; font-size: 13px; }
.qstatus { margin: 6px 0 0 !important; font-size: 14px; }
.qstatus.ok { color: var(--ok) !important; }
.qstatus.bad { color: var(--err) !important; }

.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#settings-close { margin-right: auto !important; }

.secret { display: flex; gap: 6px; margin-top: 4px; }
.secret input { flex: 1; min-width: 0; margin-top: 0 !important; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 15px; }
.secret button { flex: none; }
.actions button { margin: 0 !important; }
#settings-save { width: auto; padding: 8px 14px; }
.login-error { color: var(--err) !important; margin: 10px 0 0 !important; font-size: 14px; }
dialog input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 17px; }
dialog button { margin-top: 12px; width: 100%; padding: 10px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-text); font-weight: 600; }

@keyframes spin { to { transform: rotate(360deg); } }
