:root {
  color-scheme: light;
  --bg: #f6f1e4;
  --panel: #ffffff;
  --ink: #1f1f1f;
  --muted: #6c6c6c;
  --accent: #f0843d;
  --border: #e6dac7;
  --shadow: rgba(0, 0, 0, 0.08);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: radial-gradient(circle at top, #fbe6c8, #f6f1e4 45%, #efe7d4 100%);
}

body.auth-locked {
  overflow: hidden;
}

.auth-gate {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 20% 20%, rgba(240, 132, 61, 0.2), transparent 45%),
    rgba(15, 15, 15, 0.7);
  place-items: center;
  padding: 24px;
  z-index: 100;
  display: none;
}

.auth-gate.is-open {
  display: grid;
}

.auth-card {
  width: min(420px, 100%);
  background: #fff7ea;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: 0 22px 45px rgba(0, 0, 0, 0.25);
  display: grid;
  gap: 12px;
}

.auth-title {
  font-size: 1.4rem;
  font-weight: 700;
}

.auth-subtitle {
  margin: 0;
  color: var(--muted);
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.auth-form input {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 1rem;
}

.auth-form button {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

.auth-error {
  min-height: 1.1em;
  color: #b24a2f;
  font-size: 0.9rem;
}

.hero {
  padding: 20px 4vw 16px;
  border-bottom: 1px solid var(--border);
}

.topbar {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.topbar-meta {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

.search-inline {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.9rem;
  width: 240px;
  background: #fff;
}

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

.system-status {
  padding: 6px 10px;
  border-radius: 999px;
  background: #fff7ea;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.brand {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.4rem);
  letter-spacing: -0.02em;
}

.logout-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}

/* ===== Filter Bar ===== */

.filter-bar {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 4vw 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}

.filter-row:last-child {
  border-bottom: none;
}

.filter-row-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  width: 64px;
  flex-shrink: 0;
  text-align: right;
  padding-right: 4px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 36px;
  align-items: center;
}

/* Standard filter chips (variant, tag) */

.filter-chip {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.filter-chip:hover:not(.active) {
  border-color: var(--accent);
  background: #fff7ea;
}

.filter-chip:focus-visible,
.recent-item:focus-visible,
.logout-btn:focus-visible,
.resume-btn:focus-visible,
.search-inline:focus-visible,
.video-card:focus-visible .course-card-parent {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

/* Class filter chips — larger with circular icons */

.filters-classes .filter-chip {
  flex-direction: column;
  padding: 8px 10px 6px;
  border-radius: 12px;
  gap: 4px;
  min-width: 64px;
  text-align: center;
}

.filters-classes .filter-chip .chip-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(0, 0, 0, 0.12);
  background: #1b1b1b;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.filters-classes .filter-chip.active .chip-icon {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.filters-classes .filter-chip span {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* Spec filter chips — similar to class but smaller */

.filters-specs .filter-chip {
  flex-direction: column;
  padding: 6px 8px 4px;
  border-radius: 10px;
  gap: 3px;
  min-width: 56px;
  text-align: center;
}

.filters-specs .filter-chip .chip-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(0, 0, 0, 0.12);
  background: #1b1b1b;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.filters-specs .filter-chip.active .chip-icon {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.filters-specs .filter-chip span {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* ===== Main Layout ===== */

.layout {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 24px;
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 4vw 48px;
}

.content-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.video-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.status-banner {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff7ea;
  color: var(--ink);
  font-size: 0.9rem;
}

.status-banner[data-tone="error"] {
  border-color: #f0a08a;
  background: #ffe8e2;
  color: #8d2f1f;
}

.debug-only {
  display: none;
}

.debug-enabled .debug-only {
  display: inline-flex;
}

.chip-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(0, 0, 0, 0.15);
  background: #1b1b1b;
}

.video-card {
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  text-align: left;
}

.course-card-parent {
  position: relative;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #1b1b1b;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
}

.course-card-image {
  width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
}

.course-card-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.course-card-spacer {
  height: 55%;
}

.course-card-bottom {
  padding: 10px;
  color: #fff;
  display: grid;
  gap: 8px;
}

.course-card-bottom .course-title {
  font-size: 0.85rem;
  font-weight: 700;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

.course-card-info-row {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
  flex-wrap: wrap;
}

.info-cell {
  position: relative;
  height: 28px;
  display: flex;
  align-items: center;
  padding-left: 24px;
  padding-right: 10px;
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.9);
}

.info-cell .chip-shape {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.info-cell .chip-icon {
  position: absolute;
  left: 8px;
  width: 14px;
  height: 14px;
  fill: #fff;
  border-radius: 0;
  border: none;
  background: none;
}

.info-cell .chip-text {
  position: relative;
  z-index: 1;
}

.info-cell.rating {
  width: 54px;
}

.info-cell.views {
  width: 72px;
}

.info-cell.progress {
  width: 117px;
  padding-left: 10px;
  padding-right: 10px;
}

.info-cell.progress .progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  overflow: hidden;
}

.info-cell.progress .progress-fill {
  height: 100%;
  background: var(--accent);
}

.info-cell.favorite {
  width: 70px;
  padding-left: 28px;
}

.info-cell.favorite .chip-icon.heart {
  filter: drop-shadow(rgba(0, 0, 0, 0.6) 0px 3px 4px);
  fill: rgba(255, 255, 255, 0.5);
}

.cache-caption {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.6);
}

.empty {
  color: var(--muted);
  padding: 12px;
}

/* ===== Viewer (video player) ===== */

.viewer {
  display: grid;
  gap: 12px;
  align-content: start;
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

.viewer-meta {
  background: var(--panel);
  border-radius: 14px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  box-shadow: 0 8px 24px var(--shadow);
  min-height: 0;
}

.viewer-meta h2 {
  margin: 0 0 6px;
  font-size: 1.2rem;
}

.viewer-meta p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 6px;
  grid-auto-rows: min-content;
}

.meta-grid span {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.meta-grid strong {
  font-size: 0.85rem;
}

.viewer video {
  width: 100%;
  border-radius: 14px;
  background: #111;
  min-height: 200px;
  border: 1px solid var(--border);
  display: block;
}

.video-actions {
  display: flex;
  justify-content: flex-end;
}

.download-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9rem;
  transition: opacity 0.2s;
}

.download-btn:hover {
  opacity: 0.9;
}

.player-status {
  background: #fff7ea;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

/* ===== Recent, Debug, etc ===== */

.recent-section {
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.recent-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.recent-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.resume-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.recent-list {
  display: grid;
  gap: 6px;
}

.recent-search {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
  background: #fff;
  font-size: 0.85rem;
  cursor: pointer;
}

.recent-item small {
  color: var(--muted);
  font-size: 0.75rem;
}

.filter-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 6px;
}

.help-panel {
  max-width: 1400px;
  margin: 0 auto 12px;
  padding: 0 4vw;
}

.help-panel summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
}

.help-body {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.85rem;
}

.help-body p {
  margin: 0 0 6px;
}

.help-body ul {
  margin: 0;
  padding-left: 18px;
}

.help-links {
  margin-top: 8px;
}

.help-links a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.help-links a:hover {
  text-decoration: underline;
}

.cache-settings {
  max-width: 1400px;
  margin: 0 auto 12px;
  padding: 0 4vw;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  background: #fff;
}

.cache-form {
  display: flex;
  gap: 8px;
}

.cache-form input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.9rem;
}

.cache-form button {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 8px 12px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

.cache-hint {
  margin-top: 6px;
  min-height: 1em;
  color: var(--muted);
  font-size: 0.75rem;
}

.cache-hint[data-tone="error"] {
  color: #b24a2f;
}

.debug-bar {
  max-width: 1400px;
  margin: 0 auto;
  padding: 8px 4vw;
  display: flex;
  gap: 8px;
}

.debug-bar button {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

.debug-panel {
  background: #0f0f0f;
  color: #f0e6d2;
  border-radius: 12px;
  padding: 12px;
  border: 1px solid #2b2b2b;
  font-size: 0.85rem;
}

.debug-title {
  font-weight: 600;
  margin-bottom: 8px;
}

.debug-log {
  margin: 0;
  white-space: pre-wrap;
  max-height: 220px;
  overflow: auto;
}

/* ===== Responsive ===== */

@media (max-width: 1000px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 12px 4vw 32px;
    gap: 16px;
  }

  .viewer {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .filter-bar {
    padding: 12px 4vw 4px;
  }

  .filter-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .filter-row-label {
    width: auto;
    text-align: left;
    padding-right: 0;
  }

  .filters {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 4px;
  }

  .search-inline {
    width: 160px;
  }

  .video-list {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
  }
}

@media (max-width: 600px) {
  .hero {
    padding: 14px 4vw 10px;
  }

  .topbar {
    flex-wrap: wrap;
    gap: 10px;
  }

  .topbar-meta {
    width: 100%;
    justify-content: flex-end;
  }

  .search-inline {
    flex: 1;
    min-width: 0;
  }

  .filter-chip {
    padding: 6px 10px;
    font-size: 0.8rem;
  }

  .filters-classes .filter-chip .chip-icon {
    width: 36px;
    height: 36px;
  }

  .filters-specs .filter-chip .chip-icon {
    width: 30px;
    height: 30px;
  }
}
