:root {
  --bg: #fbfaf8;
  --surface: #fff;
  --border: #e4e0d9;
  --text: #1e1c1a;
  --muted: #6d6862;
  --accent: #a2503c;
  --accent-soft: #f3e7e3;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(30 28 26 / 6%), 0 6px 18px rgb(30 28 26 / 5%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16151a;
    --surface: #201f26;
    --border: #34323c;
    --text: #eceaf0;
    --muted: #a09caa;
    --accent: #e59078;
    --accent-soft: #332624;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 18px rgb(0 0 0 / 25%);
  }
}

:root[data-theme="dark"] {
  --bg: #16151a; --surface: #201f26; --border: #34323c;
  --text: #eceaf0; --muted: #a09caa; --accent: #e59078; --accent-soft: #332624;
  --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 6px 18px rgb(0 0 0 / 25%);
}
:root[data-theme="light"] {
  --bg: #fbfaf8; --surface: #fff; --border: #e4e0d9;
  --text: #1e1c1a; --muted: #6d6862; --accent: #a2503c; --accent-soft: #f3e7e3;
  --shadow: 0 1px 2px rgb(30 28 26 / 6%), 0 6px 18px rgb(30 28 26 / 5%);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", system-ui, sans-serif;
  overflow-wrap: break-word;
}

.skip {
  position: absolute; left: -9999px;
  background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 8px;
}
.skip:focus { left: 12px; top: 12px; z-index: 10; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px 10px;
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
h1 { font-size: clamp(18px, 4.5vw, 22px); margin: 0; letter-spacing: -0.01em; }

#theme {
  background: none; border: 1px solid var(--border); border-radius: 10px;
  width: 40px; height: 40px; font-size: 17px; cursor: pointer; color: inherit;
}

.filters { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 14px; font-size: 14px; cursor: pointer; white-space: nowrap;
  min-height: 38px;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); min-height: 38px; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.count { margin: 6px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- grid ---------- */
.grid {
  display: grid; gap: 16px;
  padding: 16px;
  grid-template-columns: 1fr;
  max-width: 760px; margin: 0 auto;
}
.grid:focus { outline: none; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; scroll-margin-top: 140px;
}
.card[hidden] { display: none; }
.card:target, .card.flash { border-color: var(--accent); }

.card-title { font-size: 19px; margin: 0 0 8px; letter-spacing: -0.01em; }

.parts { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.part {
  font-size: 12px; padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}
.part.warn { background: transparent; border: 1px dashed var(--border); color: var(--muted); font-weight: 400; }

/* ---------- video ---------- */
.videos { display: grid; gap: 10px; margin-bottom: 14px; }
.vwrap { position: relative; }

/* aspect-ratio is set per-video from the data — most clips are portrait.
   Cap portrait height so a phone-shot clip doesn't push the card off screen. */
video {
  width: 100%; height: auto; object-fit: contain;
  background: #000; border-radius: 10px; display: block;
}
video.portrait {
  width: auto; max-width: 100%; max-height: 62vh; margin-inline: auto;
}
.vcap { font-size: 12px; color: var(--muted); margin-top: 4px; }
.novideo {
  border: 1px dashed var(--border); border-radius: 10px;
  padding: 14px; font-size: 13px; color: var(--muted); text-align: center;
}

/* ---------- cues ---------- */
.cues { display: grid; gap: 10px; }
.cue { margin: 0; padding: 12px 14px; background: var(--bg); border-radius: 10px; border: 1px solid var(--border); }
.cue p { margin: 0; font-size: 15px; }
.note {
  margin: 0; padding: 12px 14px; font-size: 13px; color: var(--muted);
  border: 1px dashed var(--border); border-radius: 10px;
}
.cue .when { font-size: 11px; color: var(--muted); display: block; margin-bottom: 4px; letter-spacing: 0.02em; }

/* ---------- study panel ---------- */
.study {
  margin-top: 14px; width: 100%;
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 12px; font-size: 15px; font-weight: 600; cursor: pointer; min-height: 46px;
}
.study[aria-expanded="true"] { background: var(--surface); color: var(--accent); border: 1px solid var(--accent); }

.panel { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 14px; }
.panel h3 { font-size: 14px; margin: 16px 0 6px; color: var(--muted); letter-spacing: 0.02em; }
.panel h3:first-child { margin-top: 0; }
.panel ul { margin: 0; padding-left: 20px; }
.panel li { margin-bottom: 5px; font-size: 15px; }

.disclaimer {
  background: var(--accent-soft); color: var(--accent);
  font-size: 12px; padding: 9px 12px; border-radius: 8px; margin-bottom: 14px;
}

.quiz { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.quiz p { margin: 0 0 8px; font-weight: 600; font-size: 15px; }
.quiz button {
  display: block; width: 100%; text-align: left; margin-bottom: 6px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-size: 14px; cursor: pointer; color: inherit; min-height: 42px;
}
.quiz button.right { border-color: #3f8f5a; background: color-mix(in srgb, #3f8f5a 12%, transparent); }
.quiz button.wrong { border-color: #b4463a; background: color-mix(in srgb, #b4463a 12%, transparent); }
.quiz .explain { font-size: 13px; color: var(--muted); margin: 8px 0 0; }

.foot { padding: 28px 16px 40px; text-align: center; color: var(--muted); font-size: 12px; max-width: 620px; margin: 0 auto; }

.empty { text-align: center; color: var(--muted); padding: 48px 0; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media (min-width: 640px) {
  .grid { grid-template-columns: 1fr 1fr; max-width: 1080px; }
  .card:has(.videos .vwrap + .vwrap) { grid-column: 1 / -1; }
}
