:root {
  --clay: #C67D64;
  --clay-deep: #A9604A;
  --ink: #221A16;
  --ink-2: #5E514A;
  --ink-3: #8F817A;
  --paper: #F7F1EB;
  --card: #FFFDFB;
  --line: #E9DDD3;
  --ok: #4F8A5B;
  --radius: 16px;
  --font: "Source Sans 3", "Noto Sans SC", system-ui, -apple-system, "PingFang SC", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: inherit; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 999px; padding: 12px 22px; font-weight: 600; font-size: 16px;
  transition: transform .12s ease, background .2s ease, box-shadow .2s ease;
  text-decoration: none; display: inline-flex; align-items: center; gap: 8px; justify-content: center;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--ink); color: #fff; }
.btn.primary:hover { background: #3a2d26; }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 1.5px currentColor; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.sm { padding: 8px 14px; font-size: 14px; }
.link-btn { background: none; border: 0; text-decoration: underline; text-underline-offset: 3px; color: var(--ink-2); padding: 8px; }

/* ============ LIBRARY ============ */
.library { max-width: 1120px; margin: 0 auto; padding: 0 20px 48px; }
.lib-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.brand-dot { width: 22px; height: 22px; border-radius: 7px; background: var(--clay); box-shadow: inset 0 -6px 0 rgba(0,0,0,.08); }
.admin-link { color: var(--ink-2); text-decoration: none; font-size: 14px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); }
.admin-link:hover { background: var(--card); }
.head-links { display: flex; gap: 8px; align-items: center; flex: none; }
.head-links a { white-space: nowrap; }
@media (max-width: 480px) {
  .lib-head { gap: 10px; }
  .brand { font-size: 16px; min-width: 0; }
  .head-links { gap: 6px; }
  .head-links .hl-txt { display: none; }
  .head-links a { padding: 6px 10px; }
}
.kids-link { color: #fff; background: var(--clay); text-decoration: none; font-size: 14px; font-weight: 600; padding: 6px 14px; border-radius: 999px; }
.kids-link:hover { background: var(--clay-deep); }
.cal-link { color: var(--clay-deep); background: #F6E3DA; text-decoration: none; font-size: 14px; font-weight: 600; padding: 6px 14px; border-radius: 999px; white-space: nowrap; }
.cal-link:hover { background: #F0D5C8; }
a.stat { color: inherit; text-decoration: none; transition: background .15s; }
a.stat:hover { background: rgba(255,255,255,.34); }
.finish-checkin { display: block; margin: -6px 0 16px; padding: 10px 14px; border-radius: 12px; background: #EEF5EF; color: var(--ok); font-weight: 600; text-decoration: none; }
.finish-checkin:hover { background: #E2EFE4; }

.hero {
  display: grid; grid-template-columns: 1.5fr 1fr; gap: 28px; align-items: end;
  background: var(--clay); color: var(--ink); border-radius: 28px; padding: 44px 44px 36px;
  position: relative; overflow: hidden;
}
.hero::after {
  content: "Hello everyone. Welcome back to our slow English."; position: absolute; right: -40px; top: 18px;
  font-size: 15px; line-height: 1.75; width: 250px; text-align: center; opacity: .18; transform: rotate(-4deg); pointer-events: none;
}
.eyebrow { margin: 0 0 10px; font-weight: 600; font-size: 14px; letter-spacing: .08em; opacity: .75; }
.hero h1 { margin: 0; font-size: clamp(34px, 5vw, 56px); line-height: 1.02; letter-spacing: -.02em; font-weight: 700; }
.hero .sub { max-width: 46ch; margin: 16px 0 24px; font-size: 16px; line-height: 1.6; color: #3b2a23; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.hero .btn.ghost { color: var(--ink); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: rgba(255,255,255,.22); border-radius: 16px; padding: 14px 12px; text-align: center; }
.stat b { display: block; font-size: 30px; line-height: 1; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; opacity: .8; }

.today { margin: 18px 0 8px; }
.today-card {
  display: flex; align-items: center; gap: 18px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; cursor: pointer; transition: border-color .2s;
}
.today-card:hover { border-color: var(--clay); }
.today-tag { font-size: 12px; font-weight: 700; color: var(--clay-deep); letter-spacing: .06em; white-space: nowrap; }
.today-title { font-size: 20px; font-weight: 600; flex: 1; }
.today-go { color: var(--ink-3); font-size: 14px; white-space: nowrap; }

.browse { margin-top: 28px; }
.browse-bar { display: flex; gap: 10px; flex-wrap: wrap; }
.browse-bar input, .browse-bar select {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 14px; font-size: 15px; outline: none;
}
.browse-bar input { flex: 1; min-width: 200px; }
.browse-bar input:focus, .browse-bar select:focus { border-color: var(--clay); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 18px; }
.chip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 14px; font-size: 14px; color: var(--ink-2);
}
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip small { opacity: .6; margin-left: 4px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; cursor: pointer;
  display: flex; flex-direction: column; gap: 10px; transition: transform .15s ease, border-color .2s, box-shadow .2s; text-align: left;
}
.card:hover { transform: translateY(-2px); border-color: #dcc7b9; box-shadow: 0 8px 24px -16px rgba(80,40,20,.35); }
.card-top { display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--ink-3); }
.lv { font-weight: 700; color: var(--clay-deep); background: #F6E6DF; padding: 2px 8px; border-radius: 6px; }
.card h3 { margin: 0; font-size: 18px; line-height: 1.3; font-weight: 600; }
.card p { margin: 0; font-size: 14px; line-height: 1.55; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-foot { margin-top: auto; display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-3); }
.done-mark { color: var(--ok); font-weight: 600; }
.card.is-done h3 { color: var(--ink-2); }
.empty { text-align: center; color: var(--ink-3); padding: 40px 0; }
.lib-foot { margin-top: 40px; text-align: center; color: var(--ink-3); font-size: 14px; }
.lib-foot a { color: var(--ink-2); }

@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; padding: 30px 22px 22px; border-radius: 22px; }
  .hero::after { display: none; }
  .library { padding: 0 16px 40px; }
  .today-card { flex-wrap: wrap; gap: 6px 12px; }
  .today-title { flex-basis: 100%; order: 3; }
}

/* ============ PLAYER ============ */
.player {
  --bg: #C67D64; --fg: #1C1512; --hl: rgba(255,255,255,.28);
  position: fixed; inset: 0; background: #1a1412; color: var(--fg); overflow: hidden; z-index: 10;
  user-select: none; -webkit-user-select: none;
}
.player.frame-full, .player.frame-phone.portrait { background: var(--bg); }
.frame {
  position: absolute; top: 0; bottom: 0; left: 50%; transform: translateX(-50%);
  width: min(100vw, calc(100vh * 9 / 16)); background: var(--bg); overflow: hidden;
  box-shadow: 0 0 80px rgba(0,0,0,.4);
}
.player.frame-full .frame, .player.portrait .frame { width: 100vw; box-shadow: none; }
.stage { position: absolute; inset: 0; overflow: hidden; cursor: pointer; }
.scroller { position: absolute; left: 0; right: 0; top: 0; will-change: transform; }

.p-title {
  margin: 0; font-weight: 600; text-align: center;
  font-size: calc(var(--fs) * 1.38); line-height: 1.3;
  padding: calc(var(--sh) * .095) 8% 0;
  height: calc(var(--sh) * .76);
}
.p-text {
  width: var(--col); margin: 0 auto; text-align: center;
  font-size: var(--fs); line-height: 1.76; font-weight: 500;
  padding-bottom: var(--sh);
}
.p-text p { margin: 0 0 1.76em; }
.p-text .s { border-radius: .2em; transition: background .3s ease; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.p-text .s.cur { background: var(--hl); }
.p-text .intro, .p-text .outro { }

.progress { position: absolute; left: 0; right: 0; top: 0; height: 3px; background: rgba(0,0,0,.08); }
.progress i { display: block; height: 100%; width: 0; background: var(--fg); opacity: .5; }

.tap-hint {
  position: absolute; left: 50%; top: 44%; transform: translateX(-50%);
  background: rgba(0,0,0,.72); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 15px;
  pointer-events: none; animation: pulse 2s ease-in-out infinite; white-space: nowrap;
}
@keyframes pulse { 50% { opacity: .65; } }

/* HUD */
.hud { position: absolute; left: 0; right: 0; z-index: 3; transition: opacity .35s ease, transform .35s ease; color: #fff; }
.player.hud-hidden .hud, .player.clean .hud, .player.clean .progress, .player.clean .tap-hint { opacity: 0; pointer-events: none; }
.player.hud-hidden .hud-top { transform: translateY(-10px); }
.player.hud-hidden .hud-bottom { transform: translateY(10px); }
.player.hud-hidden { cursor: none; }
.player.hud-hidden .stage { cursor: none; }
.hud-top {
  top: 0; display: flex; align-items: center; gap: 12px; padding: 12px 16px calc(28px);
  padding-top: max(12px, env(safe-area-inset-top));
  background: linear-gradient(rgba(0,0,0,.45), transparent);
}
.hud-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hud-title span { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-title small { font-size: 12px; opacity: .75; }
.hud-time { font-variant-numeric: tabular-nums; font-size: 14px; opacity: .9; }
.hud-bottom {
  bottom: 0; padding: 40px 12px 18px; padding-bottom: max(18px, env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0,0,0,.55));
}
.ctrl-row { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: nowrap; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.14);
  display: grid; place-items: center; color: #fff; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,.24); }
.icon-btn.sm { width: 36px; height: 36px; background: transparent; }
.icon-btn.sm:hover { background: rgba(255,255,255,.16); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn circle { fill: currentColor; stroke: none; }
.aa { font-weight: 700; font-size: 13px; }
.aa.big { font-size: 19px; }
.speed { display: flex; align-items: center; background: rgba(255,255,255,.14); border-radius: 999px; padding: 4px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.speed-val { min-width: 50px; text-align: center; line-height: 1; }
.speed-val b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.speed-val span { font-size: 10px; opacity: .75; }
.play-btn {
  width: 62px; height: 62px; border-radius: 50%; border: 0; background: #fff; color: #1C1512; display: grid; place-items: center;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); transition: transform .12s; flex-shrink: 0;
}
.play-btn:active { transform: scale(.94); }
.play-btn svg { width: 26px; height: 26px; fill: currentColor; }
.play-btn .i-pause, .player.playing .play-btn .i-play { display: none; }
.player.playing .play-btn .i-pause { display: block; }
@media (max-width: 400px) {
  .ctrl-row { gap: 6px; }
  .icon-btn { width: 40px; height: 40px; }
  .play-btn { width: 56px; height: 56px; }
}

/* more sheet */
.sheet {
  position: absolute; z-index: 5; left: 50%; bottom: 104px; transform: translateX(-50%);
  width: min(440px, calc(100vw - 24px)); background: rgba(28,22,19,.94); color: #fff; border-radius: 20px;
  padding: 18px; display: flex; flex-direction: column; gap: 14px; backdrop-filter: blur(10px);
  box-shadow: 0 20px 50px rgba(0,0,0,.4); font-size: 14px;
}
.sheet-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sheet-row > label:first-child:not(.tog) { width: 36px; opacity: .7; }
.sheet .btn.ghost { color: #fff; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); position: relative; }
.swatch::after { content: "A"; position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: var(--sfg); }
.swatch.on { border-color: #fff; }
.seg { display: inline-flex; background: rgba(255,255,255,.1); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; color: #fff; font-size: 13px; }
.seg button.on { background: #fff; color: #1C1512; }
.toggles { flex-direction: column; align-items: flex-start; gap: 8px; }
.tog { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.tog input { width: 18px; height: 18px; accent-color: var(--clay); }
.keys { margin: 0; font-size: 12px; opacity: .55; line-height: 1.6; }

/* finish */
.finish { position: absolute; inset: 0; z-index: 6; display: grid; place-items: center; background: rgba(20,14,12,.55); backdrop-filter: blur(4px); padding: 20px; }
.finish-card {
  background: var(--paper); color: var(--ink); border-radius: 26px; padding: 30px 26px 18px; width: min(380px, 100%); text-align: center;
  animation: pop .4s cubic-bezier(.2,1.4,.4,1);
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.finish-badge { display: inline-block; background: var(--clay); color: var(--ink); font-weight: 700; font-size: 26px; padding: 6px 22px; border-radius: 999px; transform: rotate(-3deg); }
.finish-card h2 { margin: 14px 0 18px; font-size: 22px; }
.finish-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.finish-stats div { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 4px; }
.finish-stats b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.finish-stats span { font-size: 12px; color: var(--ink-3); }
.rec-box { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.rec-box p { margin: 0; font-size: 13px; color: var(--ink-2); }
.rec-box audio { width: 100%; }
.finish-actions { display: flex; gap: 10px; justify-content: center; }
.finish-actions .btn { flex: 1; }
.finish .btn.ghost { color: var(--ink); }

.rec-dot { position: absolute; top: 14px; right: 14px; z-index: 2; width: 10px; height: 10px; border-radius: 50%; background: #e5484d; box-shadow: 0 0 0 4px rgba(229,72,77,.25); animation: pulse 1.2s infinite; }

.toast {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); z-index: 50;
  background: rgba(20,14,12,.9); color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 14px; max-width: 90vw; text-align: center;
}
