*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; box-sizing: border-box; }
body {
  height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
/* the overlays set their own display; hiding must still win, whatever the host page adds */
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute !important; /* must win over any layout rule to stay off-screen */
  width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}

.app {
  height: 100%;
  max-width: 1680px;
  margin-inline: auto;
  padding-inline: 16px;
  padding-block: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 32px; }
.brand {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: var(--step-1);
  line-height: 1.1;
  letter-spacing: -0.01em;
}
.brand-dot {
  width: 0.9em; height: 0.9em; flex: none;
  border: var(--stroke) solid var(--line);
  border-radius: 4px;
  background: linear-gradient(135deg, var(--mille) 0 33%, var(--million) 33% 66%, var(--milliard) 66%);
}

/* ---------- the player ---------- */
.player {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: var(--stroke) solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--lift) var(--lift) 0 var(--shadow);
  background: var(--stage-frame);
  overflow: hidden;
}
.app:fullscreen { max-width: none; padding: 8px; background: var(--paper); }
.app:fullscreen .player { border-radius: 10px; box-shadow: none; }
.stage { position: relative; flex: 1; min-height: 0; background: var(--stage-bg); overflow: hidden; container: stage / size; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hud {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: baseline;
  gap: 0.45em;
  max-width: calc(100% - 24px);
  padding: 0.1em 0.8em;
  border: var(--stroke) solid var(--stage-ink);
  border-radius: 999px;
  background: var(--stage-card);
  color: var(--stage-ink);
  box-shadow: 3px 3px 0 var(--stage-ink);
  font-family: var(--font-display);
  white-space: nowrap;
  pointer-events: none;
}
.hud-n { font-weight: 800; font-size: clamp(1.1rem, 0.8rem + 1.8vw, 2.3rem); font-variant-numeric: tabular-nums; color: var(--hud-color, var(--stage-ink)); }
.hud-unit { font-weight: 700; font-size: clamp(0.8rem, 0.7rem + 0.6vw, 1.15rem); overflow: hidden; text-overflow: ellipsis; }
.hud[data-level="1"] { --hud-color: var(--stage-mille-ink); }
.hud[data-level="2"] { --hud-color: var(--stage-million-ink); }
.hud[data-level="3"] { --hud-color: var(--stage-milliard-ink); }

.chapter-flag {
  display: none;
  position: absolute;
  top: 10px;
  left: 10px;
  margin: 0;
  padding: 0.15em 0.7em;
  border-radius: 999px;
  background: var(--stage-flag);
  color: var(--stage-bg);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--step--1);
  pointer-events: none;
}
.chapter-flag .older-badge { margin-inline-start: 0.5em; padding: 0 0.5em; border-radius: 999px; background: var(--stage-mille); color: var(--stage-ink); }

/* ---------- captions ---------- */
.captions {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(2 * 1.35em + 14px);
  padding: 6px 16px;
  background: var(--caption-bg);
  color: var(--caption-ink);
  font-size: clamp(1rem, 0.85rem + 0.9vw, 1.6rem);
  line-height: 1.35;
  text-align: center;
}
.captions[data-off="true"] { min-height: 0; padding-block: 0; }
.caption { margin: 0; max-width: 42ch; text-wrap: balance; }
.caption.sound { font-style: italic; opacity: 0.85; }

/* ---------- controls ---------- */
/* phones first: the seek bar gets its own row above the buttons */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0;
  padding: 2px 4px 4px;
  background: var(--surface);
  border-top: var(--stroke) solid var(--line);
}
.icon {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
}
.icon svg { width: 24px; height: 24px; fill: currentColor; }
.icon:hover { background: var(--surface-2); }
.icon[aria-pressed="true"], .icon[aria-expanded="true"] { background: var(--surface-2); color: var(--accent); }
.icon.play { width: 42px; height: 42px; border: var(--stroke) solid var(--line); border-radius: 50%; background: var(--accent); color: var(--accent-ink); }
.icon.play svg { width: 26px; height: 26px; }
.icon.play .i-pause, .icon.play[data-state="playing"] .i-play { display: none; }
.icon.play[data-state="playing"] .i-pause { display: block; }
#mute .i-muted, #mute[aria-pressed="true"] .i-sound { display: none; }
#mute[aria-pressed="true"] .i-muted { display: block; }
.lang-btn { font-family: var(--font-display); font-weight: 800; font-size: 0.95rem; letter-spacing: 0.04em; }
.time { order: -1; flex: none; min-width: 4.8em; font-family: var(--font-display); font-weight: 700; font-size: var(--step--1); font-variant-numeric: tabular-nums; text-align: center; color: var(--muted); }

.seek { order: -1; position: relative; flex: 1 1 calc(100% - 5.5em); min-width: 0; height: 34px; margin-inline: 0 4px; }
.seek input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; background: transparent; cursor: pointer; accent-color: var(--accent); }
.marks { position: absolute; inset-inline: 0; top: 50%; height: 0; pointer-events: none; }
.mark { position: absolute; top: -9px; width: 3px; height: 18px; margin-inline-start: -1.5px; border-radius: 2px; background: var(--muted); opacity: 0.55; }

/* ---------- side panels ---------- */
.panel {
  position: fixed;
  z-index: 10;
  top: 12px;
  inset-inline-end: 16px;
  width: min(26rem, calc(100% - 32px));
  max-height: calc(100% - 24px);
  overflow-y: auto;
  padding: 14px 18px 18px;
  border: var(--stroke) solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--lift) var(--lift) 0 var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel h2 { margin: 0; font-family: var(--font-display); font-size: var(--step-2); line-height: 1.1; }
.panel h3 { margin: 1.1em 0 0.3em; font-family: var(--font-display); font-size: var(--step-1); }
.panel-intro { margin: 0.2em 0 0; color: var(--muted); }
.panel p { margin: 0.35em 0; }
.chapter-list { margin: 10px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; counter-reset: ch; }
.chapter-list a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: var(--stroke) solid transparent;
  border-radius: 12px;
  color: inherit;
  text-decoration: none;
  font-family: var(--font-display);
  font-weight: 700;
  counter-increment: ch;
}
.chapter-list a::before {
  content: counter(ch);
  display: inline-grid; place-items: center;
  width: 1.9em; height: 1.9em; flex: none;
  border: var(--stroke) solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
}
.chapter-list a:hover { border-color: var(--line); }
.chapter-list a[aria-current="true"] { background: var(--surface-2); border-color: var(--line); }
.chapter-list .older-badge { margin-inline-start: auto; padding: 0 0.6em; border-radius: 999px; background: var(--warn-bg); color: var(--mille-ink); font-size: var(--step--1); }

@media (min-width: 421px) {
  .controls { gap: 2px; padding-inline: 8px; }
  .icon { width: 36px; }
}
@media (min-width: 641px) {
  .controls { flex-wrap: nowrap; justify-content: flex-start; padding: 6px 8px; }
  .icon { width: 40px; height: 40px; }
  .icon.play { width: 46px; height: 46px; }
  .seek, .time { order: 0; }
  .seek { flex: 1; height: 40px; margin-inline: 6px; }
  .chapter-flag { display: block; }
}
@media (max-height: 520px) {
  .topbar { display: none; }
  .app { padding-block: 6px; }
  .captions { font-size: 0.95rem; min-height: calc(1.35em + 10px); padding-block: 4px; }
  .icon { width: 34px; height: 34px; }
  .icon.play { width: 38px; height: 38px; }
  .controls { padding-block: 3px; }
}
