:root {
  --bg: #0f1117;
  --surface: #1a1d29;
  --surface2: #232735;
  --border: #2c3142;
  --text: #eef1f8;
  --text2: #aeb6cc;
  --text3: #717892;
  --accent: #4f8cff;
  --accent2: #7c5cff;
  --good: #34d399;
  --warn: #fbbf24;
  --hi: #ffd36b;
  --hi-bg: rgba(255, 211, 107, .16);
  --shadow: 0 8px 30px rgba(0, 0, 0, .45);
  --radius: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
[data-theme="light"] {
  --bg: #f3f5fa; --surface: #ffffff; --surface2: #f0f3fa;
  --border: #e2e7f0; --text: #161a26; --text2: #4a5268; --text3: #8a93a8;
  --hi-bg: rgba(255, 180, 0, .18); --shadow: 0 8px 30px rgba(20, 30, 60, .12);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Hiragino Sans", "Yu Gothic", "Meiryo", "Segoe UI", "PingFang HK", "Microsoft JhengHei", sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
  display: flex; flex-direction: column; min-height: 100dvh;
}

/* TOP BAR */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(140%) blur(12px); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 17px; letter-spacing: .5px; }
.brand span { color: var(--text3); font-weight: 600; font-size: 12px; margin-left: 4px; }
.icon-btn {
  margin-left: auto; width: 38px; height: 38px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 20px; cursor: pointer; display: grid; place-items: center;
}
#backBtn { margin-left: 0; font-size: 26px; line-height: 1; }
.icon-btn:active { transform: scale(.93); }

.view { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 16px 16px 40px; }
.hidden { display: none !important; }
.muted { color: var(--text3); }

/* CATALOG */
.hero { padding: 14px 4px 22px; }
.hero h1 { font-size: 30px; letter-spacing: 1px; }
.hero p { color: var(--text2); margin-top: 8px; font-size: 14px; }
.cat-group { margin-bottom: 26px; }
.cat-title { display: flex; align-items: baseline; gap: 8px; margin: 0 4px 12px; }
.cat-title b { font-size: 16px; }
.cat-title span { font-size: 12px; color: var(--text3); }
.lesson-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .lesson-grid { grid-template-columns: 1fr; } }
.lesson-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; cursor: pointer; transition: transform .12s, border-color .15s; position: relative; overflow: hidden;
}
.lesson-card::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: linear-gradient(var(--accent), var(--accent2));
}
.lesson-card:active { transform: scale(.98); }
.lesson-card .lc-ja { font-size: 18px; font-weight: 700; }
.lesson-card .lc-zh { color: var(--text2); font-size: 13px; margin-top: 4px; }
.lesson-card .lc-meta { display: flex; gap: 8px; margin-top: 12px; }
.pill { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--surface2); color: var(--text2); border: 1px solid var(--border); }
.empty-cat { color: var(--text3); font-size: 13px; padding: 10px 6px; border: 1px dashed var(--border); border-radius: 12px; }

.upload-card { border: 1px dashed var(--border); border-radius: var(--radius); padding: 18px; margin-top: 8px; background: var(--surface); }
.upload-head { font-weight: 700; margin-bottom: 6px; }
.badge-soon { display: inline-block; margin-top: 6px; font-size: 11px; color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 50%, transparent); padding: 2px 8px; border-radius: 999px; }

/* PLAYER */
.lesson-head { padding: 6px 4px 14px; }
.lesson-title { display: flex; flex-direction: column; gap: 2px; }
#pTitle { font-size: 22px; font-weight: 800; }
#pTitleZh { font-size: 13px; }
.lesson-meta { display: flex; gap: 8px; margin-top: 10px; }

.script { display: flex; flex-direction: column; gap: 14px; padding-bottom: 230px; }
.line { display: flex; gap: 10px; }
.line .avatar {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 800; color: #fff; margin-top: 4px;
}
.line.spk-female .avatar { background: linear-gradient(135deg, #ff7eb3, #ff5e8a); }
.line.spk-male .avatar { background: linear-gradient(135deg, #4f8cff, #5b6dff); }
.line.spk-neutral .avatar { background: linear-gradient(135deg, #34d399, #10b981); }
.bubble {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; flex: 1; min-width: 0;
}
.spk-name { font-size: 11px; color: var(--text3); margin-bottom: 6px; font-weight: 700; }
.ja-line { font-size: 21px; line-height: 2.35; word-break: break-word; }
.seg {
  cursor: pointer; padding: 1px 2px; border-radius: 6px; transition: background .15s, color .15s;
  border-bottom: 2px solid transparent;
}
.seg:hover { background: var(--surface2); }
.seg.active { background: color-mix(in srgb, var(--accent) 26%, transparent); border-bottom-color: var(--accent); }
.seg.spoken { color: var(--text2); }
.line { cursor: pointer; border-radius: 16px; transition: background .15s; }
.line.active .bubble { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); }
.line.active .avatar { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
ruby rt { font-size: .5em; color: var(--accent); font-weight: 600; letter-spacing: 0; }
[data-theme="light"] ruby rt { color: var(--accent2); }
.vocab { color: var(--hi); background: var(--hi-bg); border-radius: 5px; padding: 0 2px; }
[data-theme="light"] .vocab { color: #b26a00; }
.vocab::after { content: ""; }
.zh-line { margin-top: 10px; font-size: 14px; color: var(--text2); padding-top: 9px; border-top: 1px dashed var(--border); }
.zh-line.hidden-tr { display: none; }
.zh-reveal { font-size: 12px; color: var(--text3); cursor: pointer; margin-top: 8px; display: inline-block; }

/* DOCK */
.player-dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(16px) saturate(140%);
  border-top: 1px solid var(--border);
  padding: 10px 14px calc(12px + var(--safe-b));
  box-shadow: var(--shadow);
}
.player-dock > * { max-width: 760px; margin-inline: auto; }
.now-playing { display: flex; justify-content: space-between; font-size: 12px; color: var(--text3); margin-bottom: 8px; }
.np-speaker { font-weight: 700; color: var(--text2); }
.transport { display: flex; justify-content: center; align-items: center; gap: 14px; }
.t-btn {
  width: 50px; height: 50px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); font-size: 19px; cursor: pointer; display: grid; place-items: center;
}
.t-btn:active { transform: scale(.9); }
.t-btn.play { width: 64px; height: 64px; font-size: 25px; background: linear-gradient(135deg, var(--accent), var(--accent2)); border: none; color: #fff; box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 45%, transparent); }
.t-btn.on { outline: 2px solid var(--accent); color: var(--accent); }
.t-btn.busy { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.controls { margin-top: 12px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.ctl.speed { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text2); }
.ctl.speed b { color: var(--accent); }
input[type="range"] { -webkit-appearance: none; appearance: none; height: 6px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--border); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); cursor: pointer; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
input[type="range"]::-moz-range-thumb { width: 22px; height: 22px; border: none; border-radius: 50%; background: var(--accent); cursor: pointer; }
.toggles { display: flex; gap: 8px; }
.chip { font-size: 13px; font-weight: 700; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface2); color: var(--text3); cursor: pointer; }
.chip.on { background: color-mix(in srgb, var(--accent) 18%, transparent); border-color: var(--accent); color: var(--accent); }

/* SHEET */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.sheet-card {
  position: relative; width: 100%; max-width: 560px; background: var(--surface);
  border-radius: 22px 22px 0 0; border: 1px solid var(--border); border-bottom: none;
  padding: 8px 20px calc(26px + var(--safe-b)); animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } }
.sheet-handle { width: 44px; height: 5px; border-radius: 999px; background: var(--border); margin: 8px auto 16px; }
.dict-word { font-size: 30px; font-weight: 800; }
.dict-reading { font-size: 16px; color: var(--accent); margin-top: 2px; }
.dict-row { display: flex; gap: 10px; margin-top: 16px; align-items: flex-start; }
.dict-row .k { flex: 0 0 64px; color: var(--text3); font-size: 13px; padding-top: 2px; }
.dict-row .v { flex: 1; font-size: 15px; }
.dict-pos { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--border); color: var(--text2); }

.toast { position: fixed; bottom: 110px; left: 50%; transform: translateX(-50%); background: var(--surface2); color: var(--text); border: 1px solid var(--border); padding: 10px 16px; border-radius: 12px; font-size: 13px; z-index: 60; box-shadow: var(--shadow); }
