/* ==========================================================================
   Kunnskap — mobile-first audio player
   ========================================================================== */

:root {
  --color-bg: #f6f5f1;
  --color-surface: #ffffff;
  --color-surface-2: #f0efe9;
  --color-text: #1f2420;
  --color-text-muted: #5b6560;
  --color-border: #e4e2d9;

  --color-brand: #14532d;
  --color-brand-strong: #0f3d21;
  --color-brand-soft: #e4efe6;
  --color-accent: #c9822a;

  --color-done: #14532d;
  --color-done-bg: #e4efe6;
  --color-progress-bg: #e7e5dc;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --radius-pill: 999px;

  --shadow-sm: 0 1px 2px rgba(20, 24, 20, 0.06), 0 1px 1px rgba(20, 24, 20, 0.04);
  --shadow-md: 0 8px 24px -12px rgba(20, 24, 20, 0.25);
  --shadow-lg: 0 -6px 24px -8px rgba(20, 24, 20, 0.18);

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --player-height: 168px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #14171a;
    --color-surface: #1d2124;
    --color-surface-2: #23282b;
    --color-text: #edf0ee;
    --color-text-muted: #a4aca8;
    --color-border: #2c3134;

    --color-brand: #4ade80;
    --color-brand-strong: #22c55e;
    --color-brand-soft: rgba(74, 222, 128, 0.14);
    --color-accent: #e0a854;

    --color-done: #4ade80;
    --color-done-bg: rgba(74, 222, 128, 0.14);
    --color-progress-bg: #2c3134;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px -12px rgba(0, 0, 0, 0.6);
    --shadow-lg: 0 -6px 24px -8px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

img, svg {
  display: block;
  max-width: 100%;
}

button, select, input {
  font-family: inherit;
}

/* Accessibility helpers -------------------------------------------------- */

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

.skip-link {
  position: absolute;
  top: -48px;
  left: var(--space-3);
  background: var(--color-brand);
  color: #fff;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  z-index: 100;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: var(--space-3);
}

:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

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

/* Top bar ------------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.topbar__inner {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.topbar__logo {
  font-size: 1.25rem;
}

.topbar__title {
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 1.05rem;
  color: var(--color-brand-strong);
}

@media (prefers-color-scheme: dark) {
  .topbar__title { color: var(--color-brand); }
}

/* Page layout --------------------------------------------------------------- */

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-6);
  padding-bottom: calc(var(--space-6) + var(--player-height) + var(--safe-bottom));
}

/* Welcome section ------------------------------------------------------------ */

.welcome {
  padding: var(--space-2) 0 var(--space-5);
}

.welcome h1 {
  margin: 0 0 var(--space-2);
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--color-text);
}

.welcome__lead {
  margin: 0 0 var(--space-5);
  color: var(--color-text-muted);
  font-size: 1.02rem;
}

.progress-summary {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-sm);
}

.progress-summary__text {
  font-weight: 600;
  margin-bottom: var(--space-3);
}

.progress-summary__bar {
  height: 10px;
  border-radius: var(--radius-pill);
  background: var(--color-progress-bg);
  overflow: hidden;
}

.progress-summary__bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--color-brand), var(--color-brand-strong));
  border-radius: var(--radius-pill);
  transition: width 0.4s ease;
}

/* Status panel (loading / empty / error) ------------------------------------ */

.status-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  text-align: center;
  color: var(--color-text-muted);
  padding: var(--space-6) var(--space-4);
}

.status-panel[hidden] {
  display: none;
}

.status-panel__spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-brand);
  animation: spin 0.8s linear infinite;
}

.status-panel.is-error .status-panel__spinner {
  display: none;
}

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

/* Episode list --------------------------------------------------------------- */

.episode-list {
  list-style: none;
  margin: var(--space-5) 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.episode-list[hidden] {
  display: none;
}

.episode-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.episode-card.is-done {
  border-color: var(--color-done);
}

.episode-card__main {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.episode-card__icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #fff;
}

.episode-card__text {
  flex: 1;
  min-width: 0;
}

.episode-card__title {
  margin: 0 0 var(--space-1);
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.episode-card__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  font-size: 0.88rem;
  color: var(--color-text-muted);
}

.episode-card__status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-weight: 600;
}

.episode-card.is-done .episode-card__status {
  background: var(--color-done-bg);
  color: var(--color-done);
}

.episode-card__share {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px var(--space-2);
  border-radius: var(--radius-pill);
  border: 1px solid var(--color-border);
  background: none;
  color: var(--color-text-muted);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.episode-card__share:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

.episode-card__share.is-copied {
  background: var(--color-done-bg);
  color: var(--color-done);
  border-color: var(--color-done);
}

@keyframes episode-highlight-pulse {
  0%, 100% { box-shadow: 0 0 0 0 transparent; }
  30% { box-shadow: 0 0 0 4px var(--color-brand-soft); }
}

.episode-card--highlight {
  animation: episode-highlight-pulse 1.6s ease-out;
}

/* Toast ----------------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: var(--space-5);
  transform: translate(-50%, 0);
  background: var(--color-brand-strong);
  color: #fff;
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  font-size: 0.92rem;
  font-weight: 600;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast[hidden] {
  display: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, -6px);
}

.episode-card__status-icon {
  font-size: 0.9em;
  line-height: 1;
}

.episode-card__play {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--color-brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease, background 0.15s ease;
}

.episode-card__play:hover {
  background: var(--color-brand-strong);
}

.episode-card__play:active {
  transform: scale(0.94);
}

.episode-card__play-icon {
  transform: translateX(1px);
}

.episode-card.is-playing .episode-card__play {
  background: var(--color-accent);
}

.episode-card__progress {
  margin-top: var(--space-3);
}

.episode-card__progress-track {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--color-progress-bg);
  overflow: hidden;
}

.episode-card__progress-fill {
  height: 100%;
  width: 0%;
  background: var(--color-accent);
  border-radius: var(--radius-pill);
}

.episode-card.is-done .episode-card__progress-fill {
  background: var(--color-done);
}

/* Player --------------------------------------------------------------------- */

.player {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  padding-bottom: var(--safe-bottom);
}

.player[hidden] {
  display: none;
}

.player__inner {
  max-width: 720px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-4) var(--space-4);
}

.player__top {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.player__nowplaying {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.player__label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  font-weight: 700;
}

.player__title {
  font-weight: 700;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player__close {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 0.95rem;
}

.player__seek {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.player__time {
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
  color: var(--color-text-muted);
  width: 38px;
  flex-shrink: 0;
}

.player__time#player-time-total {
  text-align: right;
}

.player__seekbar {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--color-progress-bg);
  outline-offset: 4px;
}

.player__seekbar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--color-brand);
  cursor: pointer;
  margin-top: -5px;
}

.player__seekbar::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: var(--color-brand);
  cursor: pointer;
}

.player__seekbar::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--color-progress-bg);
}

.player__controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  margin-top: var(--space-3);
}

.player__btn {
  border: none;
  background: var(--color-surface-2);
  color: var(--color-text);
  border-radius: var(--radius-pill);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.player__btn--skip {
  width: 48px;
  height: 48px;
  font-size: 0.78rem;
}

.player__btn--play {
  width: 60px;
  height: 60px;
  background: var(--color-brand);
  color: #fff;
  font-size: 1.3rem;
}

.player__btn--play:active {
  transform: scale(0.95);
}

.player__speed {
  margin-left: var(--space-2);
}

.player__speed select {
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-2);
  font-weight: 600;
  font-size: 0.85rem;
}

/* Small screens fine-tuning ---------------------------------------------------- */

@media (max-width: 380px) {
  .player__controls { gap: var(--space-3); }
  .player__btn--skip { width: 44px; height: 44px; }
  .player__btn--play { width: 54px; height: 54px; }
  .player__speed select { padding: 6px 4px; font-size: 0.8rem; }
}

/* Larger screens ----------------------------------------------------------------- */

@media (min-width: 640px) {
  .episode-card__play { width: 56px; height: 56px; font-size: 1.2rem; }
}
