/* ── Reset & base ─────────────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #f8f7f4;
  --color-surface: #ffffff;
  --color-border: #e2ddd8;
  --color-text: #1a1814;
  --color-text-muted: #6b6560;
  --color-accent: #2563c8;
  --color-accent-hover: #1a4fa0;
  --color-badge: #dcfce7;
  --color-badge-text: #166534;
  --color-mark: #fef08a;
  --color-panel-bg: #ffffff;

  --font-sans: "Poppins", system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --radius: 8px;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-panel: -4px 0 24px rgba(0,0,0,0.12);
  --max-width: 680px;
  --transition: 200ms ease;
}

/* Ensure the HTML hidden attribute always wins over CSS display rules */
[hidden] { display: none !important; }

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

header {
  background: #fff;
  color: var(--color-text);
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.header-logo {
  height: 56px;
  width: auto;
  flex-shrink: 0;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

/* ── Main layout ─────────────────────────────────────────────────────────── */

main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

/* ── Search bar ──────────────────────────────────────────────────────────── */

.search-section {
  padding: 1.5rem 0 1rem;
  position: sticky;
  top: 0;
  background: var(--color-bg);
  z-index: 10;
}

.search-wrapper {
  position: relative;
}

#search-input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  outline: none;
  transition: border-color var(--transition);
}

#search-input:focus {
  border-color: var(--color-accent);
}

#search-input::placeholder {
  color: var(--color-text-muted);
}

.search-status {
  display: block;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-top: 0.4rem;
  min-height: 1.2em;
}

/* ── Browse section ──────────────────────────────────────────────────────── */

.browse-label {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Result / Browse cards ───────────────────────────────────────────────── */

.results-count {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
  font-weight: 500;
}

.results-list,
.browse-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.result-card,
.browse-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem 1.125rem;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow-card);
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.card-body {
  flex: 1;
  min-width: 0;
}

.card-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}

.result-card:hover,
.browse-card:hover {
  border-color: var(--color-accent);
  box-shadow: 0 2px 8px rgba(37,99,200,0.12);
}

.result-card:focus,
.browse-card:focus {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.card-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.card-title {
  font-weight: 600;
  font-size: 0.9375rem;
  flex: 1;
}

.card-date {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  margin-top: 0.2rem;
}

.card-snippet {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-top: 0.4rem;
  line-height: 1.5;
}

.no-results {
  color: var(--color-text-muted);
  padding: 1rem 0;
  font-size: 0.9rem;
  list-style: none;
}

/* ── Badge ───────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.15em 0.55em;
  border-radius: 4px;
  white-space: nowrap;
  vertical-align: middle;
}

.badge-transcript {
  background: var(--color-badge);
  color: var(--color-badge-text);
}

/* ── Highlight ───────────────────────────────────────────────────────────── */

mark {
  background: var(--color-mark);
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* ── Episode detail panel ────────────────────────────────────────────────── */

.panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 100;
}

.episode-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(520px, 100vw);
  background: var(--color-panel-bg);
  z-index: 101;
  overflow-y: auto;
  box-shadow: var(--shadow-panel);
  display: flex;
  flex-direction: column;
}

body.panel-open {
  overflow: hidden;
}

.panel-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  background: var(--color-panel-bg);
  z-index: 1;
}

.panel-close {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--color-accent);
  cursor: pointer;
  padding: 0.25rem 0;
  font-weight: 500;
}

.panel-close:hover {
  color: var(--color-accent-hover);
}

.panel-close:focus {
  outline: 2px solid var(--color-accent);
  border-radius: 3px;
}

.panel-content {
  padding: 1.5rem 1.25rem 2rem;
  flex: 1;
}

.panel-artwork {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 1rem;
}

.panel-loading,
.panel-error {
  color: var(--color-text-muted);
  padding: 2rem 0;
}

.panel-title {
  font-size: 1.1875rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.panel-meta {
  display: flex;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  margin-top: 0.35rem;
}

.panel-actions {
  margin-top: 1.25rem;
}

.btn-listen {
  display: inline-block;
  background: var(--color-accent);
  color: #fff;
  text-decoration: none;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius);
  font-size: 0.9375rem;
  font-weight: 600;
  transition: background var(--transition);
}

.btn-listen:hover {
  background: var(--color-accent-hover);
}

.panel-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--color-border);
}

.panel-section h3 {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: 0.5rem;
}

.panel-section p {
  font-size: 0.9375rem;
  line-height: 1.65;
  color: var(--color-text);
}

.panel-transcript p {
  font-size: 0.875rem;
  color: var(--color-text-muted);
  font-style: italic;
}

.no-transcript {
  color: var(--color-text-muted) !important;
  font-style: italic;
}

/* ── Footer ──────────────────────────────────────────────────────────────── */

footer {
  padding: 1.5rem;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
}

footer a {
  color: var(--color-accent);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  header { padding: 1rem 1rem; }
  main { padding: 0 1rem 3rem; }
  .search-section { padding: 1rem 0 0.75rem; }
  .episode-panel { width: 100vw; }
  .header-logo { height: 40px; }
  .card-thumb { width: 44px; height: 44px; }
}
