:root {
  --bg: #fff7df;
  --paper: #fffefd;
  --ink: #20242a;
  --muted: #637083;
  --line: #e8d5a8;
  --soft: #fff1bd;
  --accent: #e54d2e;
  --accent-dark: #a83622;
  --teal: #167a76;
  --teal-soft: #e8f8f3;
  --gold: #ffbd2e;
  --sky: #4d97ff;
  --leaf: #5fbf45;
  --pink: #f577b8;
  --active: #fff1a8;
  --shadow: 0 14px 40px rgba(32, 36, 42, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "Noto Sans JP", Arial, sans-serif;
  line-height: 1.58;
}

.site-header {
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 255, 255, .55), transparent 22%),
    linear-gradient(135deg, #ffbd2e 0%, #ff7d4d 38%, #4d97ff 100%);
  color: white;
}

.header-inner {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  gap: 22px;
  align-items: center;
  max-width: 1180px;
  margin: 0 auto;
  padding: 30px 22px;
}

.site-logo {
  width: 140px;
  height: 140px;
  object-fit: contain;
  border-radius: 50%;
  background: white;
  box-shadow: 0 10px 26px rgba(90, 45, 20, .2);
}

.kicker,
.section-label {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.2rem, 6vw, 5rem);
  line-height: 1.08;
  letter-spacing: 0;
  text-shadow: 0 3px 12px rgba(90, 40, 20, .22);
}

h2 {
  margin: 0 0 12px;
  font-size: clamp(1.45rem, 2.6vw, 2.3rem);
  letter-spacing: 0;
}

.subtitle {
  max-width: 720px;
  margin: 10px 0 0;
  color: #fffaf0;
  font-size: 1.22rem;
  font-weight: 700;
}

.roman-title {
  margin: 8px 0 0;
  color: #fff;
  font-size: clamp(1.35rem, 3vw, 2.25rem);
  font-weight: 800;
}

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px;
}

.content-layout {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.overview {
  display: block;
}

.media-panel,
.meta-panel,
.toolbar,
.study-sidebar,
.phrase {
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.media-panel {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

video,
audio {
  display: block;
  width: 100%;
  background: #101316;
  border-radius: 6px;
}

video {
  aspect-ratio: 16 / 9;
  object-fit: contain;
}

audio {
  height: 38px;
  margin-top: 10px;
}

.transport {
  display: grid;
  grid-template-columns: 44px 1fr 44px 72px;
  gap: 8px;
  margin-top: 10px;
}

button {
  border: 2px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.transport button {
  min-height: 48px;
  font-weight: 700;
  font-size: 1.15rem;
}

#playBtn,
.toggle.active {
  border-color: var(--teal);
  background: var(--teal);
  color: white;
}

.meta-panel {
  padding: 18px;
}

.kid-note {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #e8f8f3;
  color: #145553;
  font-size: 1.06rem;
  font-weight: 700;
}

.learn-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.learn-card {
  min-height: 94px;
  padding: 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff6d6;
}

.learn-card:nth-child(2) {
  background: #e8f8f3;
}

.learn-card:nth-child(3) {
  background: #fff0f6;
}

.learn-card strong,
.learn-card span {
  display: block;
}

.learn-card strong {
  margin-bottom: 6px;
  color: var(--accent-dark);
  font-size: 1.08rem;
}

.learn-card span {
  color: #394455;
  font-weight: 700;
}

.reading-note {
  margin: 0 0 14px;
  color: #475467;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.meta-item {
  min-height: 70px;
  padding: 10px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: #fff9e8;
}

.meta-name {
  display: block;
  color: var(--muted);
  font-size: .83rem;
}

.meta-value {
  display: block;
  margin-top: 4px;
  font-weight: 700;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto auto;
  gap: 12px;
  align-items: end;
  margin: 18px 0;
  padding: 14px;
}

.search span {
  display: block;
  color: var(--muted);
  font-size: .84rem;
  margin-bottom: 4px;
}

.search input {
  width: 100%;
  min-height: 46px;
  border: 2px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
}

.toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.toggle {
  min-height: 46px;
  padding: 7px 10px;
  font-weight: 700;
}

.stats {
  color: var(--muted);
  font-size: .9rem;
  white-space: nowrap;
}

.study-sidebar {
  position: sticky;
  top: 14px;
  max-height: calc(100vh - 28px);
  overflow: auto;
}

.current-card {
  padding: 16px;
}

.current-line .tx {
  font-size: 1.65rem;
}

.phrase-list {
  display: grid;
  gap: 12px;
}

.phrase {
  padding: 16px;
}

.phrase.active {
  background: var(--active);
  border-color: var(--gold);
}

.phrase-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: .88rem;
}

.jump {
  min-width: 48px;
  min-height: 42px;
  border-color: var(--teal);
  color: var(--teal);
  font-weight: 800;
  font-size: 1.1rem;
}

.tx {
  margin: 8px 0 5px;
  font-size: 1.35rem;
  font-weight: 800;
}

.seg {
  color: var(--teal);
  font-weight: 700;
}

.translation {
  margin: 6px 0;
  color: #364151;
  font-size: 1.02rem;
}

.words {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.word {
  padding: 10px;
  border: 2px solid #c7dcdb;
  border-radius: 6px;
  background: var(--teal-soft);
  cursor: pointer;
}

.word .han {
  display: block;
  font-weight: 800;
  font-size: 1.22rem;
}

.word span:not(.han) {
  display: block;
  color: #3f5361;
  font-size: .84rem;
  overflow-wrap: anywhere;
}

.word .gloss {
  color: var(--teal);
  font-weight: 700;
}

.hidden {
  display: none !important;
}

.hide-ch .line-ch,
.hide-jp .line-jp,
.hide-en .line-en,
.hide-words .words {
  display: none;
}

.mini-player {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  display: none;
  width: min(360px, calc(100vw - 32px));
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .42);
  border-radius: 8px;
  background: #101316;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .28);
}

.segment-playing .mini-player {
  display: block;
}

@media (min-width: 881px) {
  .segment-playing .mini-player {
    display: none;
  }
}

.mini-head {
  display: grid;
  grid-template-columns: 1fr 34px;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  color: white;
  background: rgba(16, 19, 22, .92);
  font-size: .88rem;
}

.mini-head span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-head button {
  min-height: 28px;
  border-color: rgba(255, 255, 255, .28);
  background: rgba(255, 255, 255, .1);
  color: white;
  font-weight: 800;
}

.mini-player video {
  width: 100%;
  border-radius: 0;
}

footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 22px 34px;
  color: var(--muted);
  text-align: center;
}

.footer-brand {
  color: var(--accent-dark);
  font-size: 1.05rem;
  font-weight: 800;
}

@media (max-width: 880px) {
  .header-inner {
    grid-template-columns: 84px minmax(0, 1fr);
    gap: 12px;
  }

  .site-logo {
    width: 84px;
    height: 84px;
  }

  main {
    padding: 14px;
  }

  .overview,
  .content-layout,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .learn-cards {
    grid-template-columns: 1fr;
  }

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

  .stats {
    white-space: normal;
  }

  .mini-player {
    right: 10px;
    bottom: 10px;
    width: min(300px, calc(100vw - 20px));
  }
}
