:root {
  --bg: #0d1020;
  --surface: #161a30;
  --surface-2: #20253f;
  --border: rgba(255, 255, 255, 0.08);
  --text: #e9e6f2;
  --muted: #9396b0;
  --accent: #f2c46d;
  --accent-ink: #231a06;
  --danger: #ff8f85;
  --skip: #ff4d4d;
  --fav: #ff7eb0;
  --radius: 14px;
  --player-h: 150px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  overscroll-behavior-y: none;
}
body.has-player main { padding-bottom: calc(var(--player-h) + var(--safe-bottom) + 16px); }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
[hidden] { display: none !important; }

svg { width: 24px; height: 24px; display: block; }
svg.stroke { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
svg.fill { fill: currentColor; }

/* --- Zgornja vrstica --- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 8px) 12px 8px;
  background: rgba(13, 16, 32, 0.92);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 {
  flex: 1; margin: 0 4px; font-size: 20px; font-weight: 650;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; color: var(--text);
}
.icon-btn:active { background: var(--surface-2); }

main { padding: 16px; max-width: 720px; margin: 0 auto; }

.hint { color: var(--muted); text-align: center; padding: 24px 12px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* --- Domača stran --- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.card {
  display: flex; flex-direction: column; gap: 8px; text-align: left;
  border-radius: var(--radius);
}
.card .art { width: 100%; aspect-ratio: 1; border-radius: var(--radius); }
.card-title { font-size: 15px; font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card:active .art { transform: scale(0.97); }
.add-card .art {
  display: grid; place-items: center; color: var(--muted);
  background: transparent; border: 2px dashed var(--surface-2);
}
.add-card svg { width: 40px; height: 40px; }
.card-sub { font-size: 13px; margin-top: -6px; }
.card .playlist-art { color: var(--fav); background: linear-gradient(135deg, #4a2a55, #1f1a3a); }
.card .playlist-art svg { width: 58%; height: 58%; fill: currentColor; }
.card .shuffle-art { color: var(--accent); background: linear-gradient(135deg, #2a3f5a, #1a1d36); }
.card .shuffle-art svg { width: 62%; height: 62%; }

.art {
  background: linear-gradient(135deg, #2a2f55, #1a1d36) center / cover no-repeat;
  overflow: hidden; flex-shrink: 0;
  display: grid; place-items: center;
  color: var(--accent); font-weight: 700; font-size: 28px;
}
.art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.art-lg { width: 112px; height: 112px; border-radius: var(--radius); }
.art-sm { width: 48px; height: 48px; border-radius: 10px; font-size: 18px; }

/* --- Podcast --- */
.pod-head { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 8px; }
.pod-meta { min-width: 0; flex: 1; }
.pod-meta h2 { margin: 2px 0 4px; font-size: 20px; line-height: 1.25; }
.pod-meta p { margin: 0 0 10px; font-size: 14px; }
.pod-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-btn {
  padding: 7px 12px; border-radius: 999px; font-size: 14px;
  background: var(--surface-2); color: var(--text);
}

.episodes { list-style: none; margin: 0; padding: 0; }
.ep {
  display: grid; grid-template-columns: 1fr; grid-auto-flow: column; grid-auto-columns: auto; align-items: stretch;
  border-bottom: 1px solid var(--border); border-radius: 10px;
}
.ep:active { background: var(--surface); }
.ep-main {
  min-width: 0; text-align: left;
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  padding: 12px 4px 12px 10px;
}
.ep-date { font-size: 13px; color: var(--muted); }
.ep-title { font-weight: 550; line-height: 1.3; }
.ep-dur {
  display: flex; align-items: center; justify-content: flex-end;
  padding: 0 10px 0 4px; min-width: 56px;
  font-size: 13px; color: var(--muted); white-space: nowrap; cursor: pointer;
}
.skip-btn {
  align-self: center; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--muted); opacity: 0.55; transition: color 0.15s, opacity 0.15s;
}
.skip-btn svg { width: 20px; height: 20px; }
.skip-btn:active { background: var(--surface-2); }
.skip-btn.on { color: var(--skip); opacity: 1; }
.ep.skipped .ep-main, .ep.skipped .ep-dur { opacity: 0.4; }
.fav-btn {
  align-self: center; width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center;
  color: var(--muted); opacity: 0.55; transition: color 0.15s, opacity 0.15s;
}
.fav-btn svg { width: 20px; height: 20px; }
.fav-btn:active { background: var(--surface-2); }
.fav-btn.on { color: var(--fav); opacity: 1; }
.fav-btn.on svg { fill: currentColor; }
.player .fav-btn svg { width: 22px; height: 22px; }
.ep.removed .ep-main, .ep.removed .ep-dur { opacity: 0.4; pointer-events: none; }
.playlist-status { padding: 0 4px 8px; text-align: left; font-size: 14px; }.ep.current { background: var(--surface); }
.ep.current .ep-title { color: var(--accent); }
.ep.current .ep-date::after {
  content: "  ♪ zdaj"; color: var(--accent);
}

/* --- Predvajalnik --- */
.player {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 10px 16px calc(var(--safe-bottom) + 10px);
  background: rgba(22, 26, 48, 0.97);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.player > * { max-width: 688px; margin-left: auto; margin-right: auto; }
.player-row { display: flex; align-items: center; gap: 12px; }
.player-titles { flex: 1; min-width: 0; }
.player-title, .player-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player-title { font-weight: 600; }
.player-sub { font-size: 13px; }

.sleep-chip {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--accent); font-size: 14px; font-variant-numeric: tabular-nums;
}
.sleep-chip svg { width: 16px; height: 16px; }

#seek {
  display: block; width: 100%; margin: 10px auto 2px; height: 28px;
  -webkit-appearance: none; appearance: none; background: transparent;
  --pct: 0%;
}
#seek::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--pct), var(--surface-2) var(--pct));
}
#seek::-webkit-slider-thumb {
  -webkit-appearance: none; width: 16px; height: 16px; margin-top: -6px;
  border-radius: 50%; background: var(--text); border: 0;
}
#seek::-moz-range-track { height: 4px; border-radius: 2px; background: var(--surface-2); }
#seek::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--accent); }
#seek::-moz-range-thumb { width: 16px; height: 16px; border-radius: 50%; background: var(--text); border: 0; }

.controls { justify-content: space-between; }
.time { width: 64px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.time.right { text-align: right; }
.buttons { display: flex; align-items: center; gap: 18px; }
.play-btn {
  width: 58px; height: 58px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
}
.play-btn svg { width: 36px; height: 36px; }
.buttons .icon-btn { width: 52px; height: 52px; }
.buttons .icon-btn svg { width: 34px; height: 34px; }
.play-btn:active { transform: scale(0.95); }

/* --- Dialogi --- */
dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - var(--safe-top) - var(--safe-bottom) - 40px);
  margin: auto; padding: 8px 18px 20px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 20px;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin-right: -10px; }
.dlg-head h2 { margin: 0; font-size: 20px; }
dialog h3 { font-size: 15px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 22px 0 8px; }

input[type="search"], input[type="url"], input[type="time"], textarea {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 16px; /* 16px prepreči povečavo na iOS */
  min-width: 0;
}
input[type="time"] { min-width: 110px; text-align: center; }
textarea { width: 100%; resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 13px; margin-top: 8px; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.row-form { display: flex; gap: 8px; margin: 12px 0; }
.row-form input { flex: 1; }
.row-buttons { display: flex; gap: 8px; }

.btn {
  padding: 10px 16px; border-radius: 10px; font-weight: 600;
  background: var(--accent); color: var(--accent-ink); white-space: nowrap;
}
.btn.secondary { background: var(--surface-2); color: var(--text); }
.btn.wide { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: 0.5; }

.results, .manage { list-style: none; margin: 0; padding: 0; }
.results li, .manage li {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.results .art, .manage .art { width: 48px; height: 48px; border-radius: 8px; font-size: 18px; }
.item-text { flex: 1; min-width: 0; }
.item-text div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-text .muted { font-size: 13px; }
.remove-btn { color: var(--danger); padding: 8px; font-size: 14px; }

.setting-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.setting-label { flex: 1; }

.switch { position: relative; width: 50px; height: 30px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: var(--surface-2);
  transition: background 0.2s;
}
.switch span::before {
  content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px;
  border-radius: 50%; background: #fff; transition: transform 0.2s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.segmented {
  display: flex; gap: 4px; padding: 4px; margin: 4px 0;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
}
.segmented label { flex: 1; position: relative; }
.segmented input { position: absolute; opacity: 0; width: 0; height: 0; }
.segmented span {
  display: block; padding: 9px 12px; border-radius: 9px; text-align: center;
  cursor: pointer; color: var(--muted); font-weight: 600; transition: background 0.15s, color 0.15s;
}
.segmented input:checked + span { background: var(--accent); color: var(--accent-ink); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- Obvestila --- */
.toast {
  position: fixed; left: 50%; z-index: 20;
  bottom: calc(var(--safe-bottom) + 24px);
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 32px); width: max-content;
  padding: 10px 16px; border-radius: 12px;
  background: #2b3156; color: var(--text); font-size: 15px; text-align: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
body.has-player .toast { bottom: calc(var(--player-h) + var(--safe-bottom) + 12px); }

.spinner {
  width: 22px; height: 22px; margin: 24px auto; border-radius: 50%;
  border: 3px solid var(--surface-2); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 380px) {
  main { padding: 12px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .art-lg { width: 88px; height: 88px; }
}
