:root {
  --bg: #120f0c;
  --bg-2: #181410;
  --surface: #1d1915;
  --card: #251f19;
  --card-hover: #2d261e;
  --border: #3c342b;
  --text: #f4ebe1;
  --muted: #b5a898;
  --faint: #7d7266;
  --accent: #e0b44b;
  --accent-2: #c45c3e;
  --accent-dim: rgba(224, 180, 75, 0.16);
  --practiced: #7d9a6a;
  --danger: #c45c3e;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --header-h: 64px;
  --font: "Segoe UI", "Helvetica Neue", system-ui, -apple-system, sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body { min-height: 100vh; }
button, input, select { font-family: inherit; }
button { cursor: pointer; }

.app-header {
  position: sticky; top: 0; z-index: 20;
  height: var(--header-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 20px;
  background: linear-gradient(180deg, #1a1612 0%, rgba(18,15,12,0.92) 100%);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(10px);
}
.brand { display: flex; flex-direction: column; min-width: 180px; }
.brand h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: 0.02em; }
.brand h1 span { color: var(--accent); }
.brand p { margin: 0; font-size: 11px; color: var(--muted); }

.search-wrap { flex: 1; position: relative; max-width: 640px; }
.search-wrap input {
  width: 100%; height: 40px; padding: 0 16px 0 40px;
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 14px; outline: none;
}
.search-wrap input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.search-wrap .icon { position: absolute; left: 14px; top: 11px; color: var(--faint); pointer-events: none; }
.header-actions { display: flex; gap: 8px; margin-left: auto; }
.chip-btn {
  height: 36px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 13px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.chip-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.chip-btn .count { background: var(--card); border-radius: 999px; padding: 1px 7px; font-size: 11px; color: var(--muted); }
.chip-btn.active .count { background: rgba(0,0,0,0.25); color: var(--accent); }

.layout { display: grid; grid-template-columns: 300px 1fr; min-height: calc(100vh - var(--header-h)); }
.layout.player-open { grid-template-columns: 300px minmax(280px, 1fr) minmax(380px, 46vw); }

.sidebar {
  border-right: 1px solid var(--border); background: var(--bg-2);
  padding: 16px 16px 32px; overflow-y: auto; position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h));
}
.sidebar h2 { margin: 18px 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: var(--faint); }
.sidebar h2:first-child { margin-top: 0; }
.sidebar label, .filter-label { display: block; font-size: 12px; color: var(--muted); margin: 8px 0 4px; }
select, .date-input {
  width: 100%; height: 34px; padding: 0 8px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px;
}
.date-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cat-list { display: flex; flex-direction: column; gap: 4px; }
.cat-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 10px; border-radius: 8px; border: 0; background: transparent; color: var(--text);
  text-align: left; font-size: 13px; width: 100%;
}
.cat-item:hover { background: var(--card); }
.cat-item.active { background: var(--accent-dim); color: var(--accent); }
.cat-item .n { color: var(--faint); font-variant-numeric: tabular-nums; font-size: 11px; }
.diff-row { display: flex; gap: 6px; flex-wrap: wrap; }
.diff-pill {
  flex: 1; min-width: 36px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 600;
}
.diff-pill.active { color: var(--bg); background: var(--accent); border-color: var(--accent); }
.diff-pill.unrated.active { background: var(--faint); border-color: var(--faint); color: var(--bg); }
.reset-btn { margin-top: 16px; width: 100%; }

.results { padding: 16px 20px 48px; min-width: 0; }
.results-meta { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; gap: 12px; }
.results-meta h2 { margin: 0; font-size: 15px; font-weight: 600; }
.results-meta span { color: var(--muted); font-size: 13px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; text-align: left; color: inherit; padding: 0;
  display: flex; flex-direction: column; transition: transform 0.15s ease, border-color 0.15s, background 0.15s;
}
.card:hover { transform: translateY(-2px); border-color: #5a4e40; background: var(--card-hover); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.thumb-wrap { position: relative; aspect-ratio: 16/10; background: #0a0908; overflow: hidden; }
.thumb-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-wrap .badge {
  position: absolute; left: 8px; bottom: 8px; background: rgba(0,0,0,0.7);
  color: #fff; font-size: 11px; padding: 2px 6px; border-radius: 6px; font-variant-numeric: tabular-nums;
}
.thumb-wrap .kind {
  position: absolute; right: 8px; top: 8px; background: rgba(0,0,0,0.65);
  color: var(--accent); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  padding: 2px 6px; border-radius: 6px;
}
.card-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-body h3 { margin: 0; font-size: 13.5px; line-height: 1.35; font-weight: 600; }
.meta-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pill { font-size: 10.5px; padding: 2px 7px; border-radius: 999px; background: #322b23; color: var(--muted); }
.pill.cat { color: var(--accent); background: var(--accent-dim); }
.diff { display: inline-flex; gap: 2px; }
.diff i { width: 7px; height: 7px; border-radius: 50%; background: #3a332c; display: inline-block; }
.diff i.on { background: var(--accent); }
.diff.unrated { color: var(--faint); font-size: 10px; font-style: italic; }
.icons-row { display: flex; gap: 8px; color: var(--faint); font-size: 12px; margin-top: auto; }
.icons-row .on-fav { color: var(--accent); }
.icons-row .on-prac { color: var(--practiced); }

.player-pane {
  border-left: 1px solid var(--border); background: var(--surface);
  display: none; flex-direction: column; min-width: 0;
  position: sticky; top: var(--header-h); height: calc(100vh - var(--header-h)); overflow: hidden;
}
.layout.player-open .player-pane { display: flex; }
.player-toolbar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.player-toolbar h2 { margin: 0; font-size: 14px; flex: 1; line-height: 1.3; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); display: grid; place-items: center; font-size: 15px;
}
.icon-btn.active-fav { color: var(--accent); border-color: var(--accent); }
.icon-btn.active-prac { color: var(--practiced); border-color: var(--practiced); }
.video-box { background: #000; width: 100%; aspect-ratio: 16/9; max-height: 42vh; display: flex; align-items: center; justify-content: center; }
.video-box video, .video-box img.photo { width: 100%; height: 100%; object-fit: contain; background: #000; }
.video-box .placeholder { color: var(--muted); font-size: 13px; padding: 24px; text-align: center; }
.lesson-info { padding: 12px 16px; border-bottom: 1px solid var(--border); overflow-y: auto; max-height: 28vh; }
.lesson-info .summary { margin: 8px 0; font-size: 13.5px; line-height: 1.5; color: #ddd4c8; }
.lesson-info .rationale { font-size: 12px; color: var(--muted); font-style: italic; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { font-size: 11px; padding: 3px 8px; border-radius: 999px; background: #322b23; color: var(--muted); border: 0; cursor: pointer; }
.tag:hover { color: var(--accent); border-color: var(--accent); }
.facts { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.conf { text-transform: capitalize; }

.transcript { flex: 1; overflow-y: auto; padding: 12px 16px 32px; }
.transcript h3 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--faint); }
.seg { display: grid; grid-template-columns: 52px 1fr; gap: 8px; padding: 4px 0; font-size: 13px; line-height: 1.45; }
.seg button.ts {
  border: 0; background: none; color: var(--accent); font-family: var(--mono);
  font-size: 11px; padding: 0; text-align: left; height: fit-content;
}
.seg button.ts:hover { text-decoration: underline; }
.seg p { margin: 0; color: #e8dfd4; }
.seg.active p { color: var(--accent); }

.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.about { font-size: 12px; color: var(--muted); line-height: 1.45; margin-top: 18px; }
.about strong { color: var(--text); font-weight: 600; }

@media (max-width: 1100px) {
  .layout, .layout.player-open { grid-template-columns: 1fr; }
  .sidebar { position: relative; top: 0; height: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .filters-collapsible { display: none; }
  .sidebar.open .filters-collapsible { display: block; }
  .player-pane {
    position: relative; top: 0; height: auto; max-height: none; border-left: 0; border-bottom: 1px solid var(--border);
  }
  .layout.player-open .player-pane { display: flex; }
  .video-box { max-height: 50vh; }
  .lesson-info { max-height: none; }
  .app-header { flex-wrap: wrap; height: auto; padding: 10px 12px; gap: 10px; }
  .search-wrap { min-width: 100%; order: 3; max-width: none; }
}

/* Date chips + year histogram */
.year-histo {
  display: flex; align-items: flex-end; gap: 3px;
  height: 56px; margin: 6px 0 8px; padding: 0 2px;
}
.year-histo button {
  flex: 1; min-width: 0; height: 100%; padding: 0;
  border: 0; background: transparent; display: flex; flex-direction: column;
  justify-content: flex-end; align-items: center; gap: 2px; color: var(--faint);
}
.year-histo button .bar {
  width: 100%; border-radius: 2px 2px 0 0; background: #3a332c; min-height: 2px;
}
.year-histo button.active .bar, .year-histo button:hover .bar { background: var(--accent); }
.year-histo button .yl { font-size: 8px; letter-spacing: -0.02em; transform: rotate(-60deg); transform-origin: center; height: 14px; }
.year-chips, .month-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.year-chips button, .month-chips button {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 3px 8px; font-size: 11px;
}
.year-chips button.active, .month-chips button.active {
  background: var(--accent-dim); border-color: var(--accent); color: var(--accent);
}
.year-chips button .n, .month-chips button .n { color: var(--faint); margin-left: 3px; }

.card-date { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
.player-date {
  font-size: 13px; color: var(--accent); margin: 0 0 6px; font-weight: 600;
}
.video-box iframe {
  width: 100%; height: 100%; border: 0; background: #000;
}
a.icon-btn { text-decoration: none; line-height: 32px; text-align: center; }
a.download-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--accent); font-size: 13px; margin-top: 8px;
}
.not-hosted { color: var(--muted); font-size: 13px; padding: 24px; text-align: center; }


/* Phone/tablet: player opens as a full-screen sheet over the list */
@media (max-width: 1100px) {
  .layout.player-open .player-pane {
    position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column;
    height: 100dvh; max-height: 100dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
    background: var(--bg, #14110f); border: 0;
    padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
  }
  .layout.player-open .player-toolbar { position: sticky; top: 0; z-index: 2; background: var(--bg, #14110f); }
  .video-box { flex: none; aspect-ratio: 16 / 9; max-height: none; }
  .video-box video, .video-box iframe { width: 100%; height: 100%; }
  body.sheet-open { overflow: hidden; }
}
