/* Keyboard-only focus ring. :focus-visible never fires on touch/mouse, so the
   phone visuals are unchanged, but keyboard / switch users can see focus. */
:focus-visible { outline: 2px solid var(--kk-acc-line, #5cc8ff); outline-offset: 2px; }

/* Otoyomi v2 — Phase 1b: Kiku Dark Refined.
   All theming via --kk-* tokens so Phase 6 can re-skin cleanly.
   Mobile-first; primary target is 360x800 Chrome Android. */

/* Web fonts are loaded NON-blocking via a <link media="print" onload> in
   index.html (was a render-blocking @import here, which stalled first paint by
   ~0.5s while Google Fonts CSS was fetched, and hung offline). System fonts show
   instantly; the web fonts swap in when ready (display=swap). */

:root,
[data-theme="dark"] {
  --kk-bg:        #14171a;
  --kk-bg-2:      #181c20;
  --kk-surface:   #1f2429;
  --kk-surface-2: #262c32;
  --kk-line:      #2a3138;
  --kk-line-2:    #353d45;
  --kk-text:      #e8ebe6;
  --kk-text-2:    #a3a99f;
  --kk-text-3:    #6b7166;
  --kk-text-4:    #444842;
  --kk-active:    #ffffff;
  --kk-acc:       #9bbf7a;
  --kk-acc-soft:  rgba(155, 191, 122, 0.16);
  --kk-acc-line:  rgba(155, 191, 122, 0.36);
  --kk-acc-glow:  rgba(155, 191, 122, 0.55);
  --kk-warn:      #d8a96b;
  --kk-danger:    #d57676;
  --kk-done:      #7aaf5a;

  --kk-r-2xs: 2px;
  --kk-r-xs: 3px;
  --kk-r-sm: 6px;
  --kk-r-md: 10px;
  --kk-r-lg: 16px;
  --kk-r-pill: 999px;

  /* Spacing scale (values match the ones already used across the app, so
     swapping a hardcoded px for one of these never changes the layout). */
  --kk-space-2xs: 2px;
  --kk-space-xs:  4px;
  --kk-space-sm:  6px;
  --kk-space-md:  8px;
  --kk-space-lg:  10px;
  --kk-space-xl:  12px;
  --kk-space-2xl: 14px;
  --kk-space-3xl: 16px;
  --kk-space-4xl: 24px;

  /* Font-size scale (UI text). Body workhorse is 13px; reader font is set
     separately by the font settings, not from these. */
  --kk-text-2xs:  10px;
  --kk-text-xs:   11px;
  --kk-text-sm:   12px;
  --kk-text-base: 13px;
  --kk-text-md:   14px;
  --kk-text-lg:   16px;
  --kk-text-xl:   18px;
  --kk-text-2xl:  22px;

  /* Named stacking layers — mirror the z-map noted in index.html comments. */
  --kk-z-content:   8;
  --kk-z-fnbar:     10;
  --kk-z-util:      11;
  --kk-z-pomocap:   14;
  --kk-z-float:     15;
  --kk-z-sheet-dim: 19;
  --kk-z-sheet:     20;
  --kk-z-chap:      21;
  --kk-z-confirm:   25;

  /* Shadow colors (themeable: tweak once instead of editing every shadow). */
  --kk-shadow:        rgba(0, 0, 0, 0.25);
  --kk-shadow-strong: rgba(0, 0, 0, 0.45);

  --kk-font-jp: 'Klee One', 'Shippori Mincho', 'Hiragino Mincho ProN', 'Yu Mincho', serif;
  --kk-font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --kk-font-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top:    env(safe-area-inset-top, 0px);
}

/* Smooth book-accent swap on the highest-impact consumers. Listing them
   individually (instead of using @property on --kk-acc) avoids the registered
   custom-property quirk where inline style.setProperty stops cascading. */
.kk-bot-main,
.kk-mini-pp,
.kk-mini-bar > i,
.kk-m4b-controls .kk-m4b-play,
.kk-m4b-prog > i,
.kk-mini-badge,
.kk-study-clear-pill,
.kk-srch-sel-check.is-on,
.kk-card-sel-badge,
.kk-srch-card-sel-badge,
.kk-srch-card.is-selected {
  transition: background-color 300ms ease, color 300ms ease, border-color 300ms ease;
}

[data-theme="light"] {
  --kk-bg:        #f0ebe4;
  --kk-bg-2:      #e8e1d8;
  --kk-surface:   #f5f2ed;
  --kk-surface-2: #ece7df;
  --kk-line:      #ddd6cc;
  --kk-line-2:    #ccc4b8;
  --kk-text:      #2a2a28;
  --kk-text-2:    #5a5a55;
  --kk-text-3:    #8a8a82;
  --kk-text-4:    #b0aca4;
  --kk-active:    #1a1a18;
  --kk-acc:       #5a8c4a;
  --kk-acc-soft:  rgba(90, 140, 74, 0.12);
  --kk-acc-line:  rgba(90, 140, 74, 0.28);
  --kk-warn:      #b8863a;
  --kk-danger:    #c05050;
  --kk-done:      #4a8a3a;
}

[data-theme="matcha"] {
  --kk-bg:        #1a2318;
  --kk-bg-2:      #1f2a1c;
  --kk-surface:   #242f20;
  --kk-surface-2: #2a3726;
  --kk-line:      #2f3d2a;
  --kk-line-2:    #3a4a33;
  --kk-text:      #d4dcc9;
  --kk-text-2:    #a8b59a;
  --kk-text-3:    #7a8a6a;
  --kk-text-4:    #5a6a4a;
  --kk-active:    #e8f0da;
  --kk-acc:       #8ab86a;
  --kk-acc-soft:  rgba(138, 184, 106, 0.16);
  --kk-acc-line:  rgba(138, 184, 106, 0.36);
  --kk-warn:      #c4a060;
  --kk-danger:    #b06060;
  --kk-done:      #6aaa4a;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html, body, * {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}
input, textarea, [contenteditable="true"] {
  user-select: text;
  -webkit-user-select: text;
}
body {
  margin: 0;
  background: var(--kk-bg);
  color: var(--kk-text);
  font: 14px/1.5 var(--kk-font-ui);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: contain;
  overflow: hidden;
}

/* Hide scrollbars */
::-webkit-scrollbar { display: none; }
* { scrollbar-width: none; }
button { font: inherit; color: inherit; background: none; border: none; padding: 0; cursor: pointer; touch-action: manipulation; }

.hidden { display: none !important; }
.muted { color: var(--kk-text-3); }
.gpu-layer { transform: translateZ(0); will-change: transform, opacity; }

/* Home scroll — initial CSS variable defaults */
.kk-lib-scroll {
  --sy: 0; --hero-o: 1; --title-o: 1; --bar-a: 0; --blur: none;
  --stats-o: 0; --resume-o: 1; --s1: 0; --s2: 0; --s3: 0; --s4: 0;
}

/* Japanese rendering — single rule used by every screen.
   Phase 2 will add <ruby><rt> children; data-furigana toggles their visibility. */
.kk-jp {
  font-family: var(--kk-font-jp);
  line-height: 1.65;
  letter-spacing: 0.02em;
  color: inherit;
}
.kk-jp ruby { ruby-align: center; }
.kk-jp ruby rt {
  font-family: var(--kk-font-jp);
  font-size: 0.63em;
  color: var(--kk-text-3);
  letter-spacing: 0.05em;
  line-height: 1.1;
  font-weight: 400;
}
[data-furigana="off"] .kk-jp ruby rt { display: none; }
[data-furigana="off"] .kk-jp ruby { display: inline; }

/* P+ — Furigana display modes (only while furigana is on).
   Dim: readings blurred until a word is tapped (67-furi-display.js adds
   .furi-revealed). Auto: readings hidden on words already known
   (.status-known set by 61-word-marks.js on the active line). */
#kk-read[data-furigana="on"][data-furi-mode="dim"] .kk-jp ruby rt,
#view-m4b[data-furigana="on"][data-furi-mode="dim"] .kk-jp ruby rt {
  filter: blur(4px);
  transition: filter 0.2s ease;
}
#kk-read[data-furigana="on"][data-furi-mode="dim"] .kk-jp .word.furi-revealed ruby rt,
#view-m4b[data-furigana="on"][data-furi-mode="dim"] .kk-jp .word.furi-revealed ruby rt {
  filter: none;
}
#kk-read[data-furigana="on"][data-furi-mode="auto"] .kk-jp .word.status-known ruby rt,
#view-m4b[data-furigana="on"][data-furi-mode="auto"] .kk-jp .word.status-known ruby rt {
  opacity: 0;
}

#app {
  position: fixed;
  inset: 0;
  background: var(--kk-bg);
  color: var(--kk-text);
  /* `overflow: clip` (not hidden) — `hidden` still lets programmatic scrollers
     like `Element.scrollIntoView({block:'center'})` walk up the DOM and shift
     #app's scrollTop, which translates the entire view upward (root cause of
     the "reader pushed up" bug). `clip` disables all scrolling, programmatic
     included, so scrollIntoView is confined to the actual scroll container
     (sub-list). */
  overflow: clip;
}
.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  transition: transform 280ms cubic-bezier(0.25, 0.46, 0.45, 0.94), opacity 200ms ease;
}

#view-library {
  background: transparent;
}

/* ====================================================================
   LIBRARY
   ==================================================================== */

.kk-lib {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 8px) 22px 0;
  overflow: hidden;
  position: relative;
}

.kk-lib-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 18px;
  flex-shrink: 0;
}
.kk-lib-greet {
  font-family: var(--kk-font-jp);
  font-size: 22px;
  font-weight: 600;
}
.kk-lib-greet-s {
  font-size: 11px;
  color: var(--kk-text-3);
  margin-top: 2px;
  font-family: var(--kk-font-mono);
  letter-spacing: 0.5px;
}
.kk-lib-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--kk-surface);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--kk-font-jp);
  color: var(--kk-acc);
  font-weight: 600;
  font-size: 14px;
}

.kk-lib-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1px;
  background: var(--kk-line);
  margin-bottom: 22px;
  border-radius: var(--kk-r-md);
  overflow: hidden;
  flex-shrink: 0;
}
.kk-lib-stat {
  background: var(--kk-bg);
  padding: 12px 10px;
}
.kk-lib-stat-v {
  font-family: var(--kk-font-mono);
  font-size: 18px;
  color: var(--kk-text);
  font-weight: 600;
  line-height: 1;
}
.kk-lib-stat-v span {
  font-size: 10px;
  color: var(--kk-text-3);
  margin-left: 2px;
  font-weight: 400;
}
.kk-lib-stat-l {
  font-size: 10px;
  color: var(--kk-text-3);
  margin-top: 4px;
}


.kk-lib-section {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
  flex-shrink: 0;
}
.kk-lib-section-t {
  font-family: var(--kk-font-mono);
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--kk-text-3);
  text-transform: uppercase;
}

.kk-lib-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--kk-line);
  border-radius: var(--kk-r-md);
  margin-bottom: calc(var(--safe-bottom) + 86px);
}
.kk-lib-row {
  display: grid;
  grid-template-columns: 36px 1fr 36px;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  background: var(--kk-bg);
  cursor: pointer;
  position: relative;
}
.kk-lib-row:active { background: var(--kk-bg-2); }
.kk-lib-row:first-child { border-radius: var(--kk-r-md) var(--kk-r-md) 0 0; }
.kk-lib-row:last-child  { border-radius: 0 0 var(--kk-r-md) var(--kk-r-md); }
.kk-lib-cover {
  width: 36px; height: 48px;
  background: var(--kk-surface);
  border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--kk-font-jp);
  font-size: 16px;
  font-weight: 600;
  color: var(--kk-text-2);
  overflow: hidden;
}
.kk-lib-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kk-lib-row-inner { min-width: 0; }
.kk-lib-row-t {
  font-family: var(--kk-font-jp);
  font-size: 14px;
  font-weight: 600;
  color: var(--kk-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kk-lib-row-meta {
  display: flex; gap: 8px; align-items: center;
  font-size: 10px;
  color: var(--kk-text-3);
  margin-top: 2px;
  font-family: var(--kk-font-mono);
}
.kk-lib-row-meta .dot { width: 2px; height: 2px; background: var(--kk-text-3); border-radius: 50%; }
.kk-lib-row-prog {
  width: 36px; height: 36px;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--kk-font-mono);
  font-size: 9px;
  color: var(--kk-text-2);
}
.kk-ring {
  width: 36px; height: 36px;
  transform: rotate(-90deg);
  position: absolute; inset: 0;
}
.kk-ring circle { fill: none; stroke-width: 2; }
.kk-ring .bg { stroke: var(--kk-line-2); }
.kk-ring .fg { stroke: var(--kk-acc); stroke-linecap: round; }

.kk-lib-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: var(--kk-text-3);
}
.kk-lib-empty .kk-lib-empty-h {
  font-family: var(--kk-font-jp);
  font-size: 18px;
  color: var(--kk-text-2);
}

.kk-lib-fab {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 22px);
  right: 22px;
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--kk-acc);
  color: var(--kk-bg);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 14px rgba(155, 191, 122, 0.25);
  z-index: 5;
}
.kk-lib-fab svg { width: 22px; height: 22px; }
.kk-lib-fab.fab-shown:active { transform: scale(0.96); transition: transform 0.1s ease; }

/* ====================================================================
   LIBRARY v2 — P7 LAYOUT OVERRIDE
   ==================================================================== */

/* Scroll container replaces old flex column */
.kk-lib {
  position: absolute !important;
  inset: 0 !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch;
  display: block !important;
  padding: 0 !important;
}

/* FAB floats above scroll inside #view-library */
.kk-lib-fab {
  position: absolute;
  bottom: 88px;
  right: 16px;
  z-index: 15;
}

/* FAB arc menu */
.kk-fab-dim {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 13;
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms ease;
}
.kk-fab-dim.is-open { opacity: 1; pointer-events: auto; }

.kk-fab-arc-btn {
  position: absolute;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--kk-surface-2);
  border: 1px solid var(--kk-line-2);
  color: var(--kk-text);
  display: flex; align-items: center; justify-content: center;
  z-index: 14;
  opacity: 0;
  transform: scale(0);
  pointer-events: none;
  transition: transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1), opacity 200ms ease;
}
.kk-fab-arc-btn svg { width: 18px; height: 18px; }
.kk-fab-arc-btn.is-open { opacity: 1; transform: scale(1); pointer-events: auto; }

#kk-fab-folder { bottom: 147px; right: 75px; transition-delay: 50ms; }
#kk-fab-file   { bottom: 94px; right: 97px; transition-delay: 100ms; }

.kk-fab-arc-label {
  position: absolute;
  font-size: 10px;
  font-family: var(--kk-font-ui);
  font-weight: 500;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.7);
  white-space: nowrap;
  z-index: 14;
  opacity: 0;
  transform: translateX(8px);
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
}
.kk-fab-arc-label.is-open { opacity: 1; transform: translateX(0); }

#kk-fab-folder-lbl { bottom: 164px; right: 131px; transition-delay: 50ms; }
#kk-fab-file-lbl   { bottom: 111px; right: 153px; transition-delay: 100ms; }

.kk-fab-plus {
  transition: transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
#kk-fab.is-open .kk-fab-plus { transform: rotate(45deg); }

/* Sticky morphing top bar — transparent at top, frosted glass as --bar-a grows */
.kk-lib-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: rgba(20, 23, 26, var(--bar-a, 0));
  border-bottom: 1px solid rgba(255,255,255,calc(var(--bar-a, 0) * 0.1));
  transition: background 300ms ease, border-color 300ms ease;
}
.kk-lib-bar-l {
  flex: 1;
  opacity: var(--stats-o, 0);
  transition: opacity 300ms ease;
}
.kk-lib-bar-streak {
  font-family: var(--kk-font-mono);
  font-size: 11px;
  color: var(--kk-text-2);
  letter-spacing: 0.06em;
  display: block;
}
.kk-lib-bar-title {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
  opacity: var(--title-o, 1);
  transition: opacity 300ms ease;
  pointer-events: none;
  white-space: nowrap;
}
.kk-lib-bar-r {
  flex: 1;
  display: flex;
  justify-content: flex-end;
  gap: 14px;
  opacity: var(--stats-o, 0);
  transition: opacity 300ms ease;
}
.kk-lib-bar-stat {
  font-family: var(--kk-font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--kk-text);
  padding: 0 8px;
  text-align: center;
}
.kk-lib-bar-stat em {
  font-style: normal;
  color: var(--kk-text-3);
  font-size: 9px;
  margin-left: 1px;
}

/* Hero block */
.kk-hero {
  position: relative;
  min-height: calc(100vh - 64px); /* fallback for browsers without svh */
  /* svh = the SHORT (URL-bar-visible) viewport height on Chrome Android.
     Subtract the full tab-bar height incl. safe area so the Resume button
     + drag pill always sit ABOVE the bottom bar, never hidden behind it,
     no matter the screen or whether the address bar is showing. */
  min-height: calc(100svh - 64px - var(--safe-bottom));
  margin-top: -52px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  overflow: hidden;
}
.kk-hero-bg {
  position: absolute;
  inset: 0;
  opacity: 1;
  background-size: cover;
  background-position: center;
}
.kk-hero-grad {
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(20,23,26,0.75) 0%, rgba(20,23,26,0.55) 25%, rgba(20,23,26,0.70) 50%, rgba(20,23,26,0.88) 75%, var(--kk-bg) 100%);
}
.kk-hero-body {
  position: relative;
  padding: 0 20px 20px;
  opacity: var(--hero-o, 1);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kk-hero-greet {
  font-family: var(--kk-font-jp);
  font-size: 28px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0,0,0,0.5);
  margin-bottom: 2px;
}
.kk-hero-label {
  font-family: var(--kk-font-mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--kk-acc);
  margin-top: 6px;
}
.kk-hero-title {
  font-family: var(--kk-font-jp);
  font-size: 26px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 6px rgba(0,0,0,0.5);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kk-hero-prog {
  height: 3px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  overflow: hidden;
  margin: 2px 0;
}
.kk-hero-prog i {
  display: block;
  height: 100%;
  background: var(--kk-acc);
  border-radius: 2px;
  width: 0;
}
.kk-hero-meta {
  font-size: 11px;
  color: var(--kk-text-2);
  font-family: var(--kk-font-mono);
}
.kk-hero-resume {
  margin-top: 4px;
  width: 100%;
  height: 48px;
  border-radius: 24px;
  background: var(--kk-acc);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  color: #0a0d08;
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  opacity: var(--resume-o, 1);
  -webkit-tap-highlight-color: transparent;
  transition: filter 0.1s;
}
.kk-hero-resume:active { filter: brightness(0.9); }
.kk-hero-pill-wrap {
  display: flex;
  justify-content: center;
  padding: 12px 0 8px;
  position: relative;
}
.kk-hero-pill {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--kk-line-2);
}


/* Horizontal strips */
.kk-strip { padding: 16px 0 4px; }
.kk-strip-hd {
  font-family: var(--kk-font-mono);
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--kk-text-3);
  padding: 0 16px 10px;
}
.kk-strip-row {
  display: flex;
  gap: 10px;
  padding: 0 16px 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.kk-strip-row::-webkit-scrollbar { display: none; }
.kk-strip-item {
  flex-shrink: 0;
  width: 64px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.kk-strip-cover {
  width: 64px;
  height: 90px;
  border-radius: var(--kk-r-sm);
  background: var(--kk-surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--kk-font-jp);
  font-size: 18px;
  font-weight: 600;
  color: var(--kk-text-2);
  overflow: hidden;
  margin-bottom: 6px;
  background-size: cover;
  background-position: center;
}
.kk-strip-title {
  font-size: 10px;
  color: var(--kk-text-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.3;
}

/* Your Series section */
.kk-series-section {
  padding: 16px 0 calc(80px + var(--safe-bottom));
}
.kk-series-card {
  margin: 0 16px;
  border-radius: 10px;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  overflow: hidden;
}
.kk-series-item + .kk-series-item { border-top: 1px solid var(--kk-line); }
.kk-series-row {
  display: flex;
  align-items: stretch;
  gap: 12px;
  padding: 12px 16px;
}
.kk-series-cover {
  width: 32px;
  height: 44px;
  border-radius: 4px;
  background: var(--kk-surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--kk-font-jp);
  font-size: 13px;
  font-weight: 600;
  color: var(--kk-text-2);
  flex-shrink: 0;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}
.kk-series-row-right {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 12px 12px 12px 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.kk-series-row-right:active { background: var(--kk-surface-2); }
.kk-series-cover { cursor: pointer; }
.kk-series-info { flex: 1; min-width: 0; }
.kk-series-title {
  font-family: var(--kk-font-jp);
  font-size: 14px;
  font-weight: 600;
  color: var(--kk-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kk-series-meta { font-size: 11px; color: var(--kk-text-2); margin-top: 2px; }
.kk-series-caret { color: var(--kk-text-3); transition: transform 0.2s; flex-shrink: 0; }
.kk-series-caret.open { transform: rotate(180deg); color: var(--kk-acc); }

/* Volume sub-rows */
.kk-series-panel {
  background: var(--kk-bg-2);
  border-top: 1px solid var(--kk-line);
  max-height: 0;
  overflow: hidden;
  transition: max-height 300ms cubic-bezier(0.25,0.46,0.45,0.94);
}
.kk-series-panel.is-open {
  max-height: 2000px;
}
.kk-series-panel.is-open .kk-ch-row {
  animation: indentIn 300ms ease both;
}
.kk-series-panel.is-open .kk-ch-row:nth-child(1) { animation-delay: 30ms; }
.kk-series-panel.is-open .kk-ch-row:nth-child(2) { animation-delay: 60ms; }
.kk-series-panel.is-open .kk-ch-row:nth-child(3) { animation-delay: 90ms; }
.kk-series-panel.is-open .kk-ch-row:nth-child(4) { animation-delay: 120ms; }
.kk-series-panel.is-open .kk-ch-row:nth-child(5) { animation-delay: 150ms; }
.kk-series-panel.is-open .kk-ch-row:nth-child(6) { animation-delay: 180ms; }
.kk-series-panel.is-open .kk-ch-row:nth-child(7) { animation-delay: 210ms; }
.kk-series-panel.is-open .kk-ch-row:nth-child(8) { animation-delay: 240ms; }
.kk-series-panel.is-open .kk-ch-row:nth-child(9) { animation-delay: 270ms; }
.kk-series-panel.is-open .kk-ch-row:nth-child(10) { animation-delay: 300ms; }
.kk-vol-cover {
  width: 32px; height: 32px; border-radius: 6px;
  background: var(--kk-acc-soft);
  color: var(--kk-acc);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; flex-shrink: 0; overflow: hidden;
  background-size: cover; background-position: center;
}
.kk-vol-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--kk-line);
  -webkit-tap-highlight-color: transparent;
}
.kk-vol-row:last-child { border-bottom: none; }
.kk-vol-row:active { background: var(--kk-surface); }
.kk-vol-row.is-open { background: var(--kk-acc-soft); }
.kk-vol-caret { color: var(--kk-text-4); transition: transform 0.2s; flex-shrink: 0; }
.kk-vol-caret.open { transform: rotate(180deg); color: var(--kk-acc); }
.kk-vol-info { flex: 1; min-width: 0; }
.kk-vol-title { font-size: 14px; color: var(--kk-text-2); display: block; }
.kk-vol-meta { font-size: 10px; color: var(--kk-text-2); font-family: var(--kk-font-mono); }

/* Chapter rows */
.kk-ch-panel { background: var(--kk-bg); }
.kk-ch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--kk-line);
  border-left: 2px solid transparent;
  -webkit-tap-highlight-color: transparent;
  transition: background 150ms ease, border-color 150ms ease;
}
.kk-ch-row:last-child { border-bottom: none; }
.kk-ch-row:active { background: var(--kk-surface); }
.kk-ch-row.active {
  background: var(--kk-acc-soft);
  border-left-color: var(--kk-acc);
}
.kk-ch-row.active .kk-ch-title { color: var(--kk-acc); }
.kk-ch-num {
  font-family: var(--kk-font-mono);
  font-size: 10px;
  color: var(--kk-text-3);
  flex-shrink: 0;
  width: 22px;
}
.kk-ch-title {
  font-size: 13px;
  color: var(--kk-text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kk-missing-badge {
  font-size: 10px;
  color: #ff4444;
  background: rgba(255, 68, 68, 0.15);
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: auto;
  flex-shrink: 0;
  font-weight: 600;
}
.kk-ch-row.is-missing { opacity: 0.55; }

.kk-missing-section { padding: 0 16px 8px; }
.kk-missing-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 68, 68, 0.1);
  border: 1px solid rgba(255, 68, 68, 0.3);
  border-radius: 8px;
  padding: 10px 14px;
}
.kk-missing-count { font-size: 13px; color: var(--kk-text-2); }
.kk-missing-fix-btn {
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 6px;
  border: none;
  background: var(--kk-acc);
  color: #000;
  font-weight: 600;
  cursor: pointer;
}

/* Stagger opacity for strips/series via scroll CSS vars */
#kk-strip-progress { opacity: var(--s2, 1); transform: translateY(calc((1 - var(--s2, 1)) * -12px)) scale(calc(0.96 + var(--s2, 1) * 0.04)); transition: opacity 300ms ease, transform 300ms cubic-bezier(0.25,0.46,0.45,0.94); }
#kk-strip-recent   { opacity: var(--s3, 1); transform: translateY(calc((1 - var(--s3, 1)) * -12px)) scale(calc(0.96 + var(--s3, 1) * 0.04)); transition: opacity 300ms ease, transform 300ms cubic-bezier(0.25,0.46,0.45,0.94); }
#kk-series-section { opacity: var(--s4, 1); transform: translateY(calc((1 - var(--s4, 1)) * -12px)) scale(calc(0.96 + var(--s4, 1) * 0.04)); transition: opacity 300ms ease, transform 300ms cubic-bezier(0.25,0.46,0.45,0.94); }

/* Scroll padding for library tab bar */
#view-library .kk-lib { padding-bottom: 0 !important; }

/* ====================================================================
   ACTIVE READING (overlay-led)
   ==================================================================== */

.kk-read {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* Reader background painted by parent .kk-m4b::before so the gradient
   is continuous from under the top bar — no own background here to avoid
   a visible cutoff line at the morph-stage boundary. */
.kk-read > * { position: relative; z-index: 1; }

/* z=11 progress hairline */
.kk-read-prog {
  position: absolute; left: 0; right: 0; top: 0;
  height: 2px;
  z-index: 11;
}
.kk-read-prog::before {
  content: '';
  position: absolute; left: 0; top: 0; bottom: 0; width: 100%;
  background: var(--kk-line);
  opacity: 0.6;
}
.kk-read-prog > i {
  display: block;
  height: 100%;
  background: var(--kk-acc);
  position: relative;
  z-index: 2;
  width: 0%;
}

/* Old bottom scrubber (#kk-scrub) removed — replaced by the pill scrubber
   .kk-m4b-prog. It used to flash during the play-controls ↔ util-strip toggle. */

/* === COMPONENT: Sleep timer sheet (Phase 2 Task D) === */
.kk-sleep-card { max-width: 480px; }
.kk-sleep-opts {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 16px 20px;
}
.kk-sleep-opt {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  border-radius: var(--kk-r-md, 12px);
  border: 1px solid var(--kk-line);
  background: var(--kk-surface-2);
  color: var(--kk-text);
  font-family: var(--kk-font-mono);
  font-size: 14px;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.kk-sleep-opt:active { background: var(--kk-bg-2); }
.kk-sleep-opt.kk-sleep-off {
  color: var(--kk-warn, #d66);
  border-color: var(--kk-acc-line, var(--kk-line));
  background: transparent;
}
.kk-sleep-mins {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--kk-r-md, 12px);
  border: 1px solid var(--kk-line);
  background: var(--kk-surface-2);
}
.kk-sleep-mins-val {
  text-align: center;
  font-family: var(--kk-font-mono);
  font-size: 20px;
  color: var(--kk-text);
}
.kk-sleep-mins-val span { color: var(--kk-acc); font-weight: 600; }
.kk-sleep-opt.kk-sleep-start {
  background: var(--kk-acc);
  color: var(--kk-bg);
  border-color: var(--kk-acc);
  text-align: center;
  font-weight: 600;
}

/* === COMPONENT: A–B loop (Phase 2 Task E) === */
.kk-loop-menu {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 92px);
  transform: translateX(-50%) translateY(8px);
  z-index: 12;
  display: none;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border-radius: var(--kk-r-md, 12px);
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
  opacity: 0;
  transition: opacity .15s ease, transform .15s ease;
}
.kk-loop-menu.show {
  display: flex;
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.kk-loop-menu button {
  padding: 12px 18px;
  border-radius: var(--kk-r-sm, 8px);
  border: 1px solid var(--kk-line);
  background: var(--kk-surface-2);
  color: var(--kk-text);
  font-family: var(--kk-font-mono);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.kk-loop-menu button:active { background: var(--kk-bg-2); }
.kk-loop-badge {
  position: absolute;
  left: 50%;
  top: calc(var(--safe-top) + 64px);
  transform: translateX(-50%);
  z-index: 9;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--kk-acc-soft);
  color: var(--kk-acc);
  border: 1px solid var(--kk-acc-line, var(--kk-line));
  font-family: var(--kk-font-mono);
  font-size: 11px;
  letter-spacing: .5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
}
.kk-loop-badge.show { opacity: 1; }
.kk-read[data-mode="focus"] .kk-loop-menu,
.kk-read[data-mode="focus"] .kk-loop-badge { display: none; }

/* z=10 top bar — inset pill with surface background so it separates from subtitle text */
.kk-top {
  position: absolute;
  top: calc(var(--safe-top) + 12px);
  left: 12px; right: 12px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 6px 6px 14px;
  z-index: 10;
  transition: opacity 0.25s, transform 0.25s;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-lg);
}
.kk-top-l, .kk-top-r {
  width: 44px; height: 44px;
  background: var(--kk-surface-2);
  border: 1px solid var(--kk-line);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--kk-text-2);
  flex-shrink: 0;
}
.kk-top-l:active, .kk-top-r:active { background: var(--kk-line); }
.kk-top-c {
  flex: 1;
  text-align: center;
  padding: 0 12px;
  min-width: 0;
}
.kk-top-c-t {
  font-family: var(--kk-font-jp);
  font-size: 13px;
  color: var(--kk-text);
  font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kk-top-c-s {
  font-family: var(--kk-font-mono);
  font-size: 9px;
  color: var(--kk-text-3);
  margin-top: 2px;
  letter-spacing: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* base layer: scrollable subtitle list */
.kk-read-text {
  flex: 1;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  will-change: scroll-position;
}
.kk-read-text::-webkit-scrollbar { display: none; }
.kk-read[data-no-scroll="on"] .kk-read-text { touch-action: none; }

/* N3 — Instant Transcript: while paused (data-scan="on") the transcript is
   freely scrollable (no scroll-snap) and the text can be selected/copied.
   Resume clears data-scan, restoring the locked, snapping sync view. */
.kk-read[data-scan="on"] .kk-read-text {
  scroll-snap-type: none;
  user-select: text;
  -webkit-user-select: text;
}
.kk-read[data-scan="on"] .kk-read-line,
.kk-read[data-scan="on"] .kk-read-line .kk-jp {
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
}
.kk-read-text {
  padding: calc(var(--safe-top) + 80px) 26px 130px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  contain: layout paint;
}
/* Anchor the scroll list so the shared glow box (#kk-hl-box) positions itself
   against the list's own content box and scrolls with the lines. */
#sub-list { position: relative; }

/* ONE shared glow box. Lives behind the lines, rides the active line, and
   slides + fades on the GPU (transform + opacity only). Replaces the old
   per-line .is-active::before glow so the glow can fade OUT on its own clock
   instead of getting cut when the line deactivates/scrolls/hides. */
#kk-hl-box {
  position: absolute;
  top: 0; left: 0;
  width: 0; height: 0;
  background: var(--kk-acc-soft);
  border-radius: var(--kk-r-md);
  pointer-events: none;
  opacity: 0;
  z-index: 0;                 /* lines paint on top (later in DOM, relative) */
  transform: translate(0, 0);
  transition: transform 0.22s ease, opacity 0.22s ease;
  will-change: transform, opacity;
}
#kk-hl-box.is-on  { opacity: 1; }
#kk-hl-box.is-fav { background: rgba(213, 118, 118, 0.18); }
.kk-read-line {
  text-align: center;
  font-size: var(--kk-read-fs, 17px);
  color: var(--kk-text-3);
  cursor: pointer;
  padding: 4px 0;
  position: relative;
  transition: color 0.25s, opacity 0.25s, transform 0.2s;
}
.kk-read-line .kk-jp {
  line-height: 1.65;
  color: inherit;
  font-family: var(--kk-read-family, var(--kk-font-jp));
}
/* O — single "Now playing" snap-back pill. One fixed node; shows only when
   the active line is scrolled off-screen; tap recenters. */
#kk-np-pill {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 140px);
  transform: translate(-50%, 14px);
  z-index: 12;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--kk-acc-line);
  background: var(--kk-acc);
  color: var(--kk-bg);
  font: 600 12px/1 var(--kk-font-ui);
  letter-spacing: 0.02em;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
#kk-np-pill.show {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

/* N7 — Dynamic density: long cues (.is-long set once in render) get gentle
   readability. CSS-only, no extra nodes. text-wrap:balance softly splits a
   long line into evenly-weighted rows instead of one cramped run. */
.kk-read-line.is-long .kk-jp {
  line-height: 1.95;
  text-wrap: balance;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.kk-read-line.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.kk-read-line.is-far  { opacity: 0.55; }
.kk-read-line.is-near {
  opacity: 0.85;
  color: var(--kk-text-2);
}
.kk-read-line.is-active {
  color: var(--kk-active);
  font-size: calc(var(--kk-read-fs, 17px) * 1.29 * var(--kk-active-scale, 1));
  transform: none;
  opacity: 1;
  position: relative;
  will-change: transform;
}
/* The active-line glow now lives in the shared #kk-hl-box (see above), so it can
   fade OUT smoothly. The old per-line ::before glow is retired. */
/* Gap hold state: readable but not focused */
.kk-read-line.is-held-readable {
  opacity: 1;
  transform: scale(1);
  transition: opacity 220ms ease-out, transform 180ms ease-out;
}
.kk-read:not([data-mode="focus"]) .kk-read-line.is-active.is-favorited::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 36px; height: 36px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='%23d57676' d='M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z'/%3E%3C/svg%3E") center/contain no-repeat;
  opacity: 0.1;
  pointer-events: none;
  z-index: -1;
  animation: heartPop 0.5s cubic-bezier(.34,1.56,.64,1) forwards;
}
@keyframes heartPop {
  0%   { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  50%  { transform: translate(-50%, -50%) scale(1.3); opacity: 0.16; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0.1; }
}
.kk-read-line.is-active .kk-jp {
  color: var(--kk-active);
  background: none;
  border-radius: 0;
  padding: 0;
  display: inline;
  font-weight: var(--kk-active-weight, 400);
  text-shadow: var(--kk-bold-shadow, none);
}
.kk-read-line.kk-chap-marker {
  font-family: var(--kk-font-mono);
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--kk-acc);
  text-transform: uppercase;
  border-bottom: 1px solid var(--kk-line);
  padding-bottom: 8px;
  margin-top: 8px;
  cursor: default;
  opacity: 1;
}
.kk-read-line.kk-chap-marker::before { content: none; }

/* Stamp shake on double-tap */
.kk-read-line.stamp {
  animation: kkStampShake 0.4s ease-out;
}
@keyframes kkStampShake {
  0%   { transform: translateX(0); }
  20%  { transform: translateX(-5px); }
  40%  { transform: translateX(5px); }
  60%  { transform: translateX(-3px); }
  80%  { transform: translateX(2px); }
  100% { transform: translateX(0); }
}

.kk-read-empty {
  text-align: center;
  color: var(--kk-text-3);
  margin-top: 80px;
  font-size: 13px;
  padding: 0 22px;
  line-height: 1.6;
}

/* z=9 right tools rail */
.kk-rail {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 9;
  transition: opacity 0.25s, transform 0.25s;
}
.kk-rail-btn {
  width: 44px; height: 44px;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--kk-text-2);
  font-size: 14px;
  font-family: var(--kk-font-jp);
  font-weight: 600;
}
.kk-rail-btn:active { background: var(--kk-surface-2); }
.kk-rail-btn.is-on {
  background: var(--kk-acc-soft);
  color: var(--kk-acc);
  border-color: var(--kk-acc-line);
}
.kk-rail-btn svg { width: 16px; height: 16px; }

/* z=10 bottom transport pill */
.kk-bot {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 16px);
  left: 12px; right: 12px;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-pill);
  padding: 8px 14px;
  display: grid;
  grid-template-columns: 50px 1fr 50px;
  align-items: center;
  z-index: 10;
  transition: opacity 0.25s, transform 0.25s;
}
.kk-bot-time {
  font-family: var(--kk-font-mono);
  font-size: 10px;
  color: var(--kk-text-2);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  user-select: none;
}
.kk-bot-time:active { color: var(--kk-acc); }
.kk-bot-time.r { text-align: right; }
.kk-bot-c {
  display: flex; justify-content: center; align-items: center;
  gap: 12px;
}
.kk-bot-btn {
  width: 44px; height: 44px;
  background: var(--kk-surface-2);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--kk-text);
}
.kk-bot-btn svg { width: 22px; height: 22px; }
.kk-bot-btn:active { color: var(--kk-acc); }
.kk-bot-main {
  width: 48px; height: 48px;
  background: var(--kk-text);
  color: var(--kk-bg);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.kk-bot-main svg { width: 18px; height: 18px; fill: currentColor; }
.kk-bot-main:active { background: var(--kk-text-2); }

/* Auto-hide overlay band: a single class toggle, no remount of base layer. */
.kk-read[data-overlays="hidden"] .kk-top,
.kk-read[data-overlays="hidden"] .kk-bot {
  opacity: 0;
  pointer-events: none;
}
.kk-read[data-overlays="hidden"] .kk-top { transform: translateY(-8px); }
.kk-read[data-overlays="hidden"] .kk-bot { transform: translateY(8px); }
/* M4B unified view: mirror the auto-hide for .kk-m4b-top / .kk-m4b-bot */
#view-m4b[data-overlays="hidden"] .kk-m4b-top {
  opacity: 0;
  pointer-events: none;
  transform: translateY(-8px);
}
#view-m4b[data-overlays="hidden"] .kk-m4b-bot {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}
/* util-strip hides via its own close logic (JS removes .open class) */

/* N9 Immersion: deliberate sticky distraction-free reading. Pure class toggle
   on #kk-read — the subtitle list (#sub-list) stays fully interactive. */
.kk-read[data-immersion="on"] .kk-top,
.kk-read[data-immersion="on"] .kk-bot,
.kk-read[data-immersion="on"] .kk-fn-bar {
  opacity: 0;
  pointer-events: none;
}
.kk-read[data-immersion="on"] .kk-top { transform: translateY(-8px); }
.kk-read[data-immersion="on"] .kk-bot,
.kk-read[data-immersion="on"] .kk-fn-bar { transform: translateY(8px); }
.kk-read[data-immersion="on"] .kk-util-strip,
.kk-read[data-immersion="on"] .kk-read-prog,
.kk-read[data-immersion="on"] #kk-tap-zone { display: none; }

.kk-immersion-exit {
  position: absolute; z-index: 16;
  width: 36px; height: 36px; display: none;
  align-items: center; justify-content: center;
  border: 1px solid var(--kk-line); border-radius: 50%;
  background: var(--kk-surface); color: var(--kk-fg);
  opacity: 0.32; transition: opacity .2s ease;
}
.kk-immersion-exit svg { width: 18px; height: 18px; }
.kk-immersion-exit:active { opacity: 0.9; }
.kk-read[data-immersion="on"] .kk-immersion-exit,
#view-m4b[data-immersion="on"] .kk-immersion-exit { display: flex; }
.kk-read[data-mode="focus"] .kk-immersion-exit,
.kk-read[data-mode="word"] .kk-immersion-exit,
#view-m4b:has(.kk-read[data-mode="focus"]) .kk-immersion-exit,
#view-m4b:has(.kk-read[data-mode="word"]) .kk-immersion-exit { display: none !important; }

/* Hide bottom controls when word lookup card is open — matches overlay auto-hide behavior */
.kk-read[data-mode="word"] .kk-util-strip,
.kk-read[data-mode="word"] .kk-fn-bar {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}
#view-m4b[data-word-mode="word"] .kk-m4b-bot {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}

/* N2: one fixed non-blocking "difficult line" chip (never per-cue) */
.kk-diff-chip {
  position: absolute; left: 50%; bottom: calc(var(--safe-bottom) + 140px); transform: translate(-50%, 8px);
  z-index: 12; max-width: 86%;
  padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--kk-line); background: var(--kk-surface); color: var(--kk-fg);
  font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
}
.kk-diff-chip.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.kk-read[data-mode="focus"] .kk-diff-chip,
.kk-read[data-mode="word"] .kk-diff-chip,
.kk-read[data-immersion="on"] .kk-diff-chip { display: none; }

/* N14: one fixed "Continue" cue for Study Session (never per-cue).
   Kept visible in focus/word/immersion — it is functional, not chrome. */
.kk-study-cue {
  position: absolute; left: 50%; bottom: 132px; transform: translate(-50%, 8px);
  z-index: 13; max-width: 86%;
  padding: 10px 22px; border-radius: 999px;
  border: 1px solid var(--kk-line); background: var(--kk-surface); color: var(--kk-fg);
  font-size: 14px; font-weight: 600; letter-spacing: .02em;
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.kk-study-cue.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.kk-study-cue:active { background: var(--kk-bg-2); }

/* ====================================================================
   FOCUS MODE
   ==================================================================== */

.kk-focus-meta {
  position: absolute;
  top: calc(var(--safe-top) + 36px);
  left: 0; right: 0;
  text-align: center;
  font-family: var(--kk-font-mono);
  font-size: 9px;
  color: var(--kk-text-4);
  letter-spacing: 2px;
  text-transform: uppercase;
  z-index: 8;
  display: none;
}
.kk-focus-foot {
  position: absolute;
  left: 0; right: 0;
  bottom: 40px;
  text-align: center;
  font-family: var(--kk-font-mono);
  font-size: 9px;
  color: var(--kk-text-4);
  letter-spacing: 2px;
  z-index: 8;
  display: none;
}

.kk-read[data-mode="focus"] .kk-top,
.kk-read[data-mode="focus"] .kk-bot,
.kk-read[data-mode="focus"] .kk-util-strip,
.kk-read[data-mode="focus"] .kk-read-prog { display: none; }
.kk-read[data-mode="focus"] .kk-focus-meta,
.kk-read[data-mode="focus"] .kk-focus-foot { display: block; }
.kk-read[data-mode="focus"] .kk-read-text {
  padding: 80px 32px;
  justify-content: center;
}
.kk-read[data-mode="focus"] .kk-read-line { display: none; }
.kk-read[data-mode="focus"] .kk-read-line.is-active {
  display: block;
  font-size: 30px;
  transform: none;
  color: var(--kk-active);
  padding: 28px 0;
  position: relative;
}
.kk-read[data-mode="focus"] .kk-read-line.is-active::before {
  /* Re-purpose the highlight box as a top hairline in focus mode. */
  content: '';
  background: var(--kk-line-2);
  width: 36px; height: 1px;
  border-radius: 0;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 0;
}
.kk-read[data-mode="focus"] .kk-read-line.is-active::after {
  content: '';
  position: absolute;
  left: 50%; transform: translateX(-50%);
  bottom: 0;
  width: 36px; height: 1px;
  background: var(--kk-line-2);
}
.kk-read[data-mode="focus"] .kk-read-line.is-active .kk-jp {
  font-size: 30px;
  line-height: 1.55;
  background: none;
  padding: 0;
  display: inline;
}

/* Reading toggle CSS controls */
.kk-read.vertical .kk-read-text { writing-mode: vertical-rl; }
.kk-read.vertical .kk-read-line.is-active .kk-jp .word.status-known { border-bottom: none; border-right: 2px solid var(--kk-acc); }
.kk-read.vertical .kk-read-line.is-active .kk-jp .word.status-learning { border-bottom: none; border-right: 2px dashed var(--kk-warn); }
.kk-read.vertical .kk-read-line.is-active .kk-jp .word.status-new { border-bottom: none; border-right: 1px dotted var(--kk-text-3); }

.kk-read[data-sub-anim="off"] .kk-read-line,
.kk-read[data-sub-anim="off"] .kk-read-line.is-held-readable,
.kk-read[data-sub-anim="off"] .kk-read-line.stamp,
.kk-read[data-sub-anim="off"] .kk-read-line.is-active::before,
.kk-read[data-sub-anim="off"] .kk-read-line.is-active.is-favorited::after,
.kk-read[data-sub-anim="off"] .kk-read-line * {
  transition: none !important;
  animation: none !important;
}

/* ====================================================================
   CHAPTER SHEET (kept from Phase 1a, restyled into the surface palette)
   ==================================================================== */

.sheet {
  position: fixed; inset: 0;
  z-index: 50;
}
.sheet-bg {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  opacity: 0;
  transition: opacity 0.25s ease-out;
}
.sheet.open .sheet-bg { opacity: 1; }
.sheet.closing .sheet-bg { opacity: 0; transition: opacity 0.2s ease-in; }

.sheet-card {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 70%;
  background: var(--kk-surface);
  border-top-left-radius: var(--kk-r-lg);
  border-top-right-radius: var(--kk-r-lg);
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-bottom);
  transform: translateY(100%);
  opacity: 0;
  transition: transform 0.25s ease-out, opacity 0.25s ease-out;
}
.sheet.open .sheet-card { transform: translateY(0); opacity: 1; }
.sheet.closing .sheet-card { transform: translateY(100%); opacity: 0; transition: transform 0.2s ease-in, opacity 0.2s ease-in; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--kk-line);
}
.sheet-head h2 {
  margin: 0;
  font-size: 11px;
  font-family: var(--kk-font-mono);
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--kk-text-3);
  font-weight: 500;
}
.sheet-close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  color: var(--kk-text-2);
}
.sheet-close svg { width: 16px; height: 16px; }
.chap-list {
  overflow-y: auto;
  padding: 8px 8px 16px;
}
.chap-list .chap {
  padding: 12px;
  border-radius: var(--kk-r-sm);
  cursor: pointer;
  font-size: 13px;
  display: flex; gap: 12px; align-items: center;
}
.chap-list .chap:active { background: var(--kk-surface-2); }
.chap-list .chap .t {
  color: var(--kk-text-3);
  font-size: 11px;
  font-family: var(--kk-font-mono);
  min-width: 60px;
  text-align: right;
}
.chap-list .chap.active { color: var(--kk-acc); }
.chap-list .empty {
  padding: 16px;
  color: var(--kk-text-3);
  font-size: 12px;
}

/* ====================================================================
   STATS SHEET
   ==================================================================== */
#kk-stats-sheet .sheet-card {
  max-height: 85%;
  background: var(--kk-surface);
}
.kk-stats-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Hero */
.kk-stats-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 8px 0 4px;
}
.kk-hero-ring-wrap {
  position: relative;
  width: 200px; height: 200px;
}
.kk-hero-ring-wrap svg { transform: rotate(-90deg); }
.kk-hero-inner {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.kk-hero-val { font-size: 40px; font-weight: 800; color: var(--kk-text); line-height: 1; letter-spacing: -0.5px; }
.kk-hero-label { font-size: 14px; color: var(--kk-text-3); margin-top: 3px; font-weight: 500; }
.kk-hero-goal { font-size: 13px; color: var(--kk-acc); margin-top: 5px; font-weight: 600; }

/* Flowing highlight arc */
.flowing-arc { animation: flowArc 3.5s linear infinite; }
@keyframes flowArc {
  0% { stroke-dashoffset: 0; }
  100% { stroke-dashoffset: -830; }
}

/* Metric rings */
.kk-metric-row {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin-top: 6px;
}
.kk-metric-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.kk-metric-ring-wrap {
  position: relative;
  width: 80px; height: 80px;
}
.kk-metric-ring-wrap svg { transform: rotate(-90deg); }
.kk-metric-inner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--kk-text);
}
.kk-metric-name { font-size: 11px; color: var(--kk-text-3); font-weight: 600; }

/* Tab bar */
.kk-stats-tabbar {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--kk-bg-2);
  border: 1px solid var(--kk-line);
  border-radius: 14px;
}
.kk-stats-tab {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--kk-text-3);
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.25s ease, color 0.25s ease;
}
.kk-stats-tab.is-active {
  background: var(--kk-surface-2);
  color: var(--kk-acc);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
}

/* Panels */
.kk-stats-panels { position: relative; }
.kk-stats-panel {
  display: none;
  flex-direction: column;
  gap: 16px;
}
.kk-stats-panel.is-active { display: flex; }

/* Section cards inside panels */
.kk-stats-section {
  background: var(--kk-bg-2);
  border: 1px solid var(--kk-line);
  border-radius: 16px;
  padding: 18px;
}
.kk-stats-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--kk-text-2);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 16px;
}

/* Bars */
.kk-bars-wrap {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
  height: 120px;
  padding: 0 4px;
}
.kk-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.kk-bar-track {
  width: 100%;
  height: 90px;
  background: var(--kk-surface-2);
  border-radius: 6px 6px 0 0;
  position: relative;
  overflow: hidden;
}
.kk-bar-fill {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  border-radius: 6px 6px 0 0;
  transition: height 0.8s cubic-bezier(.4,0,.2,1);
  background: linear-gradient(180deg, var(--kk-acc), #3d8b3d);
}
.kk-bar-fill.kk-bar-missed {
  background: linear-gradient(180deg, var(--kk-danger), #b85a5a);
}
.kk-bar-day { font-size: 11px; color: var(--kk-text-3); font-weight: 600; }
.kk-bar-val {
  font-size: 10px;
  color: var(--kk-text-2);
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.3s;
  position: absolute;
  bottom: 4px; left: 0; right: 0;
  text-align: center;
}
.kk-bar-col:hover .kk-bar-val { opacity: 1; }

/* Peak hour */
.kk-peak-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 60px;
  margin-top: 12px;
}
.kk-peak-bar {
  flex: 1;
  background: var(--kk-surface-2);
  border-radius: 3px 3px 0 0;
  transition: height 0.3s ease, background 0.3s ease;
}
.kk-peak-bar.is-active {
  background: linear-gradient(180deg, var(--kk-acc), #4dd0e1);
}
.kk-peak-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 10px;
  color: var(--kk-text-3);
}

/* Heatmap */
.kk-heatmap-wrap {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}
.kk-heatmap-cell {
  aspect-ratio: 1;
  border-radius: 4px;
  transition: transform 0.15s;
}
.kk-heatmap-cell:active { transform: scale(0.9); }
.kk-heatmap-labels {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  margin-top: 8px;
}
.kk-heatmap-labels span {
  text-align: center;
  font-size: 10px;
  color: var(--kk-text-3);
}

/* Timeline */
.kk-timeline-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.kk-timeline-scroll::-webkit-scrollbar { display: none; }
.kk-timeline-card {
  flex: 0 0 150px;
  background: var(--kk-surface-2);
  border: 1px solid var(--kk-line);
  border-radius: 12px;
  padding: 14px;
}
.kk-timeline-time { font-size: 11px; color: var(--kk-text-3); margin-bottom: 6px; }
.kk-timeline-book { font-size: 13px; font-weight: 600; color: var(--kk-text); line-height: 1.3; }
.kk-timeline-dur { font-size: 14px; font-weight: 700; color: var(--kk-acc); margin-top: 8px; }

/* Pills */
.kk-pill-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.kk-pill {
  background: var(--kk-surface-2);
  border: 1px solid var(--kk-line);
  border-radius: 12px;
  padding: 14px 16px;
  min-width: 90px;
  flex: 1;
  position: relative;
  overflow: hidden;
  transition: transform 0.15s;
}
.kk-pill:active { transform: scale(0.97); }
.kk-pill::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: 12px 12px 0 0;
}
.kk-pill-green::before { background: linear-gradient(90deg, var(--kk-acc), #4dd0e1); }
.kk-pill-amber::before { background: linear-gradient(90deg, var(--kk-warn), var(--kk-danger)); }
.kk-pill-rose::before { background: linear-gradient(90deg, var(--kk-danger), #b388ff); }
.kk-pill-cyan::before { background: linear-gradient(90deg, #4dd0e1, var(--kk-acc)); }
.kk-pill-val { font-size: 22px; font-weight: 800; color: var(--kk-text); letter-spacing: -0.5px; }
.kk-pill-label { font-size: 11px; color: var(--kk-text-3); margin-top: 3px; }

/* Empty state */
.kk-stats-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px 16px;
  color: var(--kk-text-3);
  text-align: center;
}
.kk-stats-empty svg { opacity: 0.5; }
.kk-stats-empty p { font-size: 13px; line-height: 1.5; max-width: 260px; }

/* ====================================================================
   TOAST
   ==================================================================== */

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 110px);
  transform: translateX(-50%);
  background: var(--kk-surface-2);
  color: var(--kk-text);
  padding: 10px 16px;
  border-radius: var(--kk-r-pill);
  border: 1px solid var(--kk-line);
  font-size: 12px;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  max-width: calc(100% - 40px);
  text-align: center;
}
.toast.show { opacity: 1; }
.toast.err {
  border-color: var(--kk-danger);
  color: var(--kk-danger);
}

input[type="file"][hidden] { display: none; }

/* ====================================================================
   ANIMATED BACKGROUND LAYER (P4 mounts canvas here)
   ==================================================================== */

#kk-trans-cover {
  position: absolute;
  inset: 0;
  background: var(--kk-bg);
  pointer-events: none;
  display: none;
}
#app.animating #kk-trans-cover {
  display: block;
}

/* M — View Transition: the library hero cover+gradient wrapper morphs into
   the reader title (and back). #kk-hero-morph wraps ONLY the background image
   and gradient overlay — text/buttons are excluded. This keeps cover and
   gradient locked together so they never flash out of sync. The root old/new
   crossfade is hidden instantly (no full-screen flash). Durations under 300ms. */
#kk-hero-morph { position: absolute; inset: 0; view-transition-name: kk-cover-morph; will-change: transform, opacity; }
#kk-title      { view-transition-name: kk-cover-morph; will-change: transform, opacity; }
::view-transition-group(*) { animation-duration: 200ms; }
::view-transition-group(kk-cover-morph) { animation-timing-function: cubic-bezier(0.4, 0.0, 0.2, 1); }
::view-transition-old(kk-cover-morph),
::view-transition-new(kk-cover-morph) { animation-timing-function: cubic-bezier(0.4, 0.0, 0.2, 1); }
::view-transition-old(root),
::view-transition-new(root) { animation-duration: 0s; opacity: 0; }

/* ====================================================================
   BOTTOM TAB BAR
   ==================================================================== */

#kk-tab-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(64px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--kk-surface);
  border-top: 1px solid var(--kk-line);
  display: flex;
  align-items: stretch;
  z-index: 20;
}

/* Tab bar hidden on player and volume-detail (full-screen screens) */
#app[data-view="player"] #kk-tab-bar,
#app[data-view="volume-detail"] #kk-tab-bar { display: none; }

.kk-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--kk-text-3);
  font-family: var(--kk-font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.kk-tab svg { flex-shrink: 0; }
.kk-tab.is-active { color: var(--kk-acc); }
.kk-tab.is-locked { pointer-events: none; opacity: 0.35; position: relative; }
.kk-tab.is-locked::after {
  content: '';
  position: absolute;
  top: 6px;
  right: calc(50% - 14px);
  width: 8px;
  height: 8px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7166' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='11' width='18' height='11' rx='2'/%3E%3Cpath d='M7 11V7a5 5 0 0110 0v4'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

/* Search view needs bottom padding so content isn't hidden behind the tab bar */
#view-search { padding-bottom: calc(64px + var(--safe-bottom) + 8px); }

/* ====================================================================
   PLACEHOLDER VIEWS (content added in later phases)
   ==================================================================== */

#view-search {
  background: var(--kk-bg);
  z-index: 1;
}

/* Volume detail slides up over everything */
#view-volume-detail {
  background: var(--kk-bg);
  z-index: 30;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  pointer-events: none;
  display: flex;
  flex-direction: column;
}
#view-volume-detail.hidden {
  display: none;
}
#view-volume-detail.is-open {
  transform: translateY(0);
  pointer-events: auto;
}

/* Volume detail top bar */
.kk-vd-bar {
  height: calc(52px + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  padding-left: 8px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--kk-line);
}
.kk-vd-back {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  color: var(--kk-acc);
  font-size: 14px;
  font-weight: 500;
  -webkit-tap-highlight-color: transparent;
}

/* Volume detail header: cover + info */
.kk-vd-header {
  display: flex;
  gap: 16px;
  padding: 20px 16px;
  flex-shrink: 0;
}
.kk-vd-cover {
  width: 90px;
  height: 126px;
  border-radius: var(--kk-r-md);
  background: var(--kk-surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--kk-font-jp);
  font-size: 28px;
  font-weight: 600;
  color: var(--kk-text-2);
  flex-shrink: 0;
  overflow: hidden;
}
.kk-vd-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; padding-top: 4px; }
.kk-vd-title {
  font-family: var(--kk-font-jp);
  font-size: 17px;
  font-weight: 600;
  color: var(--kk-text);
  line-height: 1.3;
}
.kk-vd-author { font-size: 11px; color: var(--kk-text-2); }
.kk-vd-desc { font-size: 11px; color: var(--kk-text-3); line-height: 1.5; }

/* Volume count label */
.kk-vd-vol-label {
  font-family: var(--kk-font-mono);
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--kk-text-3);
  padding: 0 16px 10px;
  flex-shrink: 0;
}

/* Scrollable volume list */
.kk-vd-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.kk-vd-vol-list {
  border-radius: var(--kk-r-lg);
  margin: 0 16px calc(var(--safe-bottom) + 20px);
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  overflow: hidden;
}
.kk-vd-vol-item + .kk-vd-vol-item { border-top: 1px solid var(--kk-line); }
.kk-vd-vol-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.kk-vd-vol-row:active,
.kk-vd-vol-row.is-open { background: var(--kk-acc-soft); }

#view-firstlaunch {
  background: transparent;
  z-index: 1;
}

/* ====================================================================
   FIRST LAUNCH SCREEN (P5)
   ==================================================================== */

#view-firstlaunch {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 0;
}

.kk-fl {
  flex: 1;
  width: 100%;
  max-width: 340px;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.kk-fl-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.kk-fl-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  width: 100%;
}

.kk-fl-badge {
  font-family: var(--kk-font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--kk-acc);
  border: 1px solid var(--kk-acc-line);
  border-radius: var(--kk-r-pill);
  padding: 3px 10px;
}

.kk-fl-foot {
  padding-bottom: calc(100px + var(--safe-bottom));
}

.kk-fl-headline {
  font-family: var(--kk-font-jp);
  font-size: 28px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--kk-text);
  margin: 0;
}

.kk-fl-desc {
  font-size: 13px;
  line-height: 1.55;
  color: var(--kk-text-2);
  margin: 0;
}

.kk-fl-btns {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
  width: 100%;
}
.kk-fl-btns-row {
  display: flex;
  flex-direction: row;
  gap: 10px;
}
.kk-fl-btns-row .kk-fl-btn { flex: 1; }
.kk-fl-btns > .kk-fl-btn { width: 100%; }

.kk-fl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--kk-line);
  background: color-mix(in srgb, var(--kk-surface) 30%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--kk-text-2);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}
.kk-fl-btn:active { background: color-mix(in srgb, var(--kk-surface) 40%, transparent); }

.kk-fl-btn.pri {
  background: var(--kk-acc-soft), color-mix(in srgb, var(--kk-surface) 30%, transparent);
  border-color: var(--kk-acc-line);
  color: var(--kk-acc);
}
.kk-fl-btn.pri:active { background: var(--kk-acc-line), color-mix(in srgb, var(--kk-surface) 40%, transparent); }

.kk-fl-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 36px 20px;
  border-radius: var(--kk-r-md);
  border: 1px solid var(--kk-line);
  text-align: center;
  background: color-mix(in srgb, var(--kk-surface) 30%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.kk-fl-card-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--kk-bg-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--kk-text-3);
  flex-shrink: 0;
}
.kk-fl-card-title { font-size: 13px; color: var(--kk-text-2); margin-bottom: 3px; }
.kk-fl-card-desc { font-size: 11px; color: var(--kk-text-3); margin: 0; }

.kk-fl-formats {
  font-family: var(--kk-font-mono);
  font-size: 11px;
  color: var(--kk-text-3);
  text-align: center;
  letter-spacing: 0.04em;
  margin: 0;
}

/* Glassy nav when library is empty (P5.6) */
#kk-tab-bar.is-glassy {
  background: color-mix(in srgb, var(--kk-bg) 35%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* ====================================================================
   SEARCH SCREEN (P10)
   ==================================================================== */

#view-search {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.kk-srch-head {
  flex-shrink: 0;
  background: var(--kk-bg);
  padding: 12px 16px;
  border-bottom: 1px solid var(--kk-line);
  z-index: 10;
}

.kk-srch-bar-wrap { margin-bottom: 10px; }

.kk-srch-input {
  width: 100%;
  height: 40px;
  border-radius: 20px;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  color: var(--kk-text);
  padding: 0 16px;
  font-size: 14px;
  font-family: var(--kk-font-ui);
  outline: none;
  box-sizing: border-box;
}
.kk-srch-input::placeholder { color: var(--kk-text-3); }

.kk-srch-pills {
  display: flex;
  gap: 8px;
  overflow-x: hidden;
  padding-bottom: 2px;
  scrollbar-width: none;
  margin-bottom: 10px;
}
.kk-srch-pills.is-expanded { overflow-x: auto; }
.kk-srch-pills::-webkit-scrollbar { display: none; }

.kk-srch-pill {
  flex-shrink: 0;
  height: 32px;
  padding: 0 14px;
  border-radius: 16px;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  color: var(--kk-text-2);
  font-size: 12px;
  font-family: var(--kk-font-ui);
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms, color 150ms;
}
.kk-srch-pill.is-active {
  background: var(--kk-acc);
  border-color: var(--kk-acc);
  color: #000;
}
.kk-srch-pill.kk-srch-pill-more {
  font-weight: 600;
  color: var(--kk-text);
}

.kk-srch-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.kk-srch-sort-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.kk-srch-sort {
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  color: var(--kk-text);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-family: var(--kk-font-ui);
  cursor: pointer;
  outline: none;
}

.kk-srch-view-btns { display: flex; gap: 4px; }

.kk-srch-view-btn {
  width: 32px; height: 32px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid var(--kk-line);
  color: var(--kk-text-3);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background 150ms, color 150ms;
}
.kk-srch-view-btn.is-active {
  background: var(--kk-surface);
  color: var(--kk-text);
}
/* Sort dropdown in search toolbar */
.kk-srch-toolbar .dropdown-trigger {
  height: 32px;
  padding: 0 24px 0 8px;
  font-size: 11px;
}
.kk-srch-toolbar .dropdown-wrap {
  width: 120px;
}
.kk-srch-toolbar .dropdown-menu {
  max-height: none;
  overflow-y: visible;
}

/* ---- Body ---- */
.kk-srch-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(64px + var(--safe-bottom));
}

.kk-srch-body-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 12px;
  align-content: start;
  grid-auto-rows: min-content;
}

/* ---- List row ---- */
.kk-srch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--kk-line);
  cursor: pointer;
  transition: background 100ms;
}
.kk-srch-row:active { background: var(--kk-surface); }

.kk-srch-row-cover {
  width: 36px; height: 50px;
  border-radius: 4px;
  background: var(--kk-surface-2);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--kk-font-jp);
  font-size: 16px;
  color: var(--kk-text-3);
  overflow: hidden;
}

.kk-srch-row-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }

.kk-srch-row-title {
  font-family: var(--kk-font-jp);
  font-size: 14px;
  font-weight: 600;
  color: var(--kk-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kk-srch-row-meta  { font-size: 11px; color: var(--kk-text-2); }
.kk-srch-row-status { font-size: 10px; color: var(--kk-text-3); font-family: var(--kk-font-mono); }

.kk-srch-ring-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.kk-srch-ring-pct {
  font-family: var(--kk-font-mono);
  font-size: 11px;
  color: var(--kk-text-2);
  min-width: 30px;
  text-align: right;
}

/* ---- Grid card ---- */
.kk-srch-card { border-radius: 8px; overflow: hidden; cursor: pointer; }

.kk-srch-card-cover {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  background: var(--kk-surface-2);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--kk-font-jp);
  font-size: 28px;
  color: var(--kk-text-3);
  border-radius: 8px;
  overflow: hidden;
}

.kk-srch-card-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(20,23,26,0.92) 0%, rgba(20,23,26,0.5) 35%, transparent 65%);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 10px;
  z-index: 2;
}
.kk-srch-card-title {
  font-family: var(--kk-font-jp);
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}
.kk-srch-card-meta {
  font-size: 9px;
  color: rgba(255,255,255,0.7);
  margin-top: 2px;
  font-family: var(--kk-font-mono);
}

.kk-srch-card-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: rgba(255,255,255,0.15);
  z-index: 3;
}
.kk-srch-card-fill {
  height: 100%;
  background: var(--kk-acc);
  transition: width 300ms ease;
}

/* Card selection styling */
.kk-srch-card {
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.kk-srch-card.is-selected {
  box-shadow: 0 8px 24px rgba(155,191,122,0.25);
  outline: 2px solid var(--kk-acc);
}
.kk-srch-card-sel-badge {
  position: absolute;
  top: 6px; right: 6px;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  border-radius: 9999px;
  padding: 0 24px;
  background: var(--kk-acc);
  animation: pop 200ms ease;
}
.kk-srch-card-sel-badge.empty {
  width: 22px;
  height: 22px;
  min-width: 0;
  padding: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.2);
  border: 2px solid rgba(255,255,255,0.4);
  animation: none;
}
/* Circle check that sits to the LEFT of the cover in list rows.
   Replaces the old in-cover badge. Hidden unless wrap is in select mode.
   When .is-on the circle shows the selection-order number (1, 2, 3...). */
.kk-srch-sel-check {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(127,127,127,0.4);
  background: transparent;
  flex-shrink: 0;
  display: none;
  align-items: center;
  justify-content: center;
  color: var(--kk-bg);
  font-family: var(--kk-font-ui);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  transition: background 150ms, border-color 150ms, color 150ms;
}
.kk-srch-row-wrap.is-select-mode .kk-srch-sel-check { display: inline-flex; }
.kk-srch-sel-check.is-on {
  background: var(--kk-acc);
  border-color: var(--kk-acc);
  color: var(--kk-bg);
}

/* List-row variant of the OLD in-cover badge (still used elsewhere/no-op) */
.kk-srch-row-cover .kk-srch-card-sel-badge {
  top: 2px; right: 2px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
}
.kk-srch-row-cover .kk-srch-card-sel-badge.empty {
  width: 18px; height: 18px;
}
/* Badge is build-time present on every row; only show when the wrap is in
   select-mode. is-selected rows always show (numbered). */
.kk-srch-row-wrap:not(.is-select-mode) .kk-srch-row-cover .kk-srch-card-sel-badge {
  display: none;
}

/* ── Search book favorite mark — sits in row flow between info and ring ── */
.kk-srch-fav-mark {
  flex-shrink: 0;
  font-size: 22px;
  line-height: 1;
  color: var(--kk-text-2);
  opacity: 0.9;
  margin: 0 8px 0 4px;
  user-select: none;
  pointer-events: none;
}
.kk-srch-card.is-book-fav .kk-srch-card-cover::after {
  content: '★';
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  font-size: 240px;
  color: #fff;
  opacity: var(--star-opacity, 0.2);
  pointer-events: none;
  z-index: 5;
}

/* ---- Empty state ---- */
.kk-srch-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 32px;
  text-align: center;
}
.kk-srch-empty.hidden { display: none; }
.kk-srch-empty-icon {
  width: 120px; height: 120px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(155,191,122,0.08) 0%, transparent 70%);
  animation: breathe 3s ease-in-out infinite;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 20px;
  color: var(--kk-text-3);
}
.kk-srch-empty-icon svg { width: 40px; height: 40px; }
.kk-srch-empty-t {
  font-family: var(--kk-font-jp);
  font-size: 22px;
  font-weight: 600;
  color: var(--kk-text);
  margin-bottom: 10px;
}
.kk-srch-empty-s {
  font-size: 13px;
  color: var(--kk-text-2);
  line-height: 1.6;
  margin-bottom: 28px;
}
.kk-srch-browse-btn {
  height: 48px;
  padding: 0 24px;
  border-radius: 24px;
  background: var(--kk-acc);
  color: #000;
  font-weight: 600;
  font-size: 13px;
  border: none;
  cursor: pointer;
}

/* ====================================================================
   READER — P11: TAP ZONE + UTIL STRIP + FOCUS OVERLAY + SHEETS + POMO
   ==================================================================== */

/* Tap zone: bottom third, below player control */
.kk-tap-zone {
  position: absolute;
  left: 0; right: 0;
  top: 67%;
  bottom: 0;
  z-index: 5;
  background: transparent;
  border: none;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

/* Util strip */
.kk-util-strip {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 16px);
  left: 12px; right: 12px;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-lg);
  padding: 8px 6px;
  z-index: 11;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transform: translateY(calc(100% + 30px));
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease;
  pointer-events: none;
}
.kk-util-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
}
.kk-util-row-more {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.3s ease, margin 0.3s ease;
  margin: 0;
}
.kk-util-strip.has-more .kk-util-row-more {
  max-height: 80px;
  opacity: 1;
  margin-bottom: 2px;
}
.kk-util-strip.open {
  transform: translateY(0);
  pointer-events: auto;
}
.kk-bot.is-util-hidden {
  transform: translateY(calc(100% + 20px));
  opacity: 0;
  pointer-events: none;
}
.kk-m4b-bot.is-util-hidden {
  transform: translateY(calc(100% + 20px));
  opacity: 0;
  pointer-events: none;
}

.kk-util-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 48px;
  padding: 4px;
  border-radius: var(--kk-r-sm);
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.kk-util-item:active .kk-util-icon {
  background: var(--kk-bg-2);
  color: var(--kk-text);
}

.kk-util-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--kk-bg);
  border: 1px solid var(--kk-line);
  display: flex; align-items: center; justify-content: center;
  color: var(--kk-text-2);
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.kk-util-icon svg { width: 18px; height: 18px; }
.kk-util-icon.is-on {
  background: var(--kk-acc-soft);
  color: var(--kk-acc);
  border-color: var(--kk-acc-line);
}

.kk-util-label {
  font-size: 9px;
  color: var(--kk-text-3);
  font-family: var(--kk-font-mono);
  letter-spacing: 0.3px;
  white-space: nowrap;
}

/* Focus overlay */
.kk-focus-overlay {
  position: fixed;
  inset: 0;
  background: var(--kk-bg);
  z-index: 150;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.kk-focus-overlay.on {
  opacity: 1;
  pointer-events: auto;
}

.kk-focus-close {
  position: absolute;
  top: calc(var(--safe-top) + 16px);
  right: 16px;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--kk-bg-2);
  border: 1px solid var(--kk-line);
  color: var(--kk-text-3);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.kk-focus-close:active { background: var(--kk-line); }
.kk-focus-close svg { width: 18px; height: 18px; }

.kk-focus-meta-bar {
  font-family: var(--kk-font-mono);
  font-size: 9px;
  color: var(--kk-text-3);
  letter-spacing: 2px;
  text-transform: uppercase;
  text-align: center;
  margin-bottom: 24px;
}

.kk-focus-line {
  font-family: var(--kk-font-jp);
  /* Scales with the main reading font slider (--kk-read-fs), kept larger for
     focus. Default 17px slider -> ~28px. */
  font-size: calc(var(--kk-read-fs, 17px) * 1.65);
  color: var(--kk-text);
  text-align: center;
  line-height: 1.8;
  max-width: 100%;
  padding: 0 8px;
}
/* Furigana on the focus line: small kana above kanji. */
.kk-focus-line ruby rt {
  font-family: var(--kk-font-jp);
  font-size: 0.45em;
  color: var(--kk-text-3);
  font-weight: 400;
}
/* Honour the furigana on/off toggle. Overlay now lives at #app top level, so
   updateFocusLine() mirrors the current furigana state onto the overlay. */
.kk-focus-overlay[data-furigana="off"] .kk-focus-line rt { display: none; }
/* Strip the reader's word-status underlines/highlights inside focus. */
.kk-focus-line .word {
  border: none !important;
  background: none !important;
}

.kk-focus-hairline {
  width: 40px; height: 1px;
  background: var(--kk-line-2);
  margin: 20px auto;
}

.kk-focus-hint {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 40px);
  left: 0; right: 0;
  text-align: center;
  font-family: var(--kk-font-mono);
  font-size: 9px;
  color: var(--kk-text-4);
  letter-spacing: 1px;
}

/* Generic sheet */
.kk-sheet {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--kk-surface);
  border-top: 1px solid var(--kk-line);
  border-radius: var(--kk-r-lg) var(--kk-r-lg) 0 0;
  padding: 14px 16px calc(var(--safe-bottom) + 24px);
  z-index: 20;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0.35s;
  max-height: 70%;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  visibility: hidden;
}
.kk-sheet.open {
  transform: translateY(0);
  pointer-events: auto;
  visibility: visible;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s;
}

.kk-sheet-grab {
  width: 36px; height: 3px;
  background: var(--kk-line-2);
  border-radius: 2px;
  margin: 0 auto 12px;
  border: none;
  padding: 8px 24px;
  cursor: pointer;
  background-clip: content-box;
  display: block;
}

.kk-sheet-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 10px;
  gap: 8px;
}
.kk-sheet-head > .kk-sheet-title { grid-column: 2; justify-self: center; }
.kk-sheet-head > .kk-sheet-close { grid-column: 3; justify-self: end; }
.kk-sheet-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--kk-text);
  text-align: center;
}
.kk-sheet-close {
  background: none;
  border: none;
  color: var(--kk-text-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 6px 10px;
  cursor: pointer;
  border-radius: var(--kk-r-sm);
}
.kk-sheet-close:active { background: var(--kk-bg-2); }

.kk-sheet-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.kk-sheet-row {
  padding: 14px 0;
  border-bottom: 1px solid var(--kk-line);
  font-size: 14px;
  color: var(--kk-text-2);
  cursor: pointer;
}
.kk-sheet-row:active { color: var(--kk-text); }

.kk-sheet-empty {
  padding: 32px 0;
  text-align: center;
  font-size: 13px;
  color: var(--kk-text-3);
  font-family: var(--kk-font-mono);
}

/* Sheet dim overlay */
.kk-sheet-dim {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 19;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.kk-sheet-dim.on { opacity: 1; pointer-events: auto; }

/* Pomodoro badge */
.kk-pomo-cap {
  position: absolute;
  bottom: calc(var(--safe-bottom) + 90px);
  left: 50%;
  transform: translateX(-50%) scaleX(0.3);
  opacity: 0;
  z-index: 14;
  background: var(--kk-bg-2);
  border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-pill);
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--kk-font-mono);
  font-size: 11px;
  color: var(--kk-text-2);
  pointer-events: none;
  transform-origin: center;
  transition: transform 380ms cubic-bezier(0.22, 1, 0.36, 1), opacity 200ms ease-out;
  box-shadow: 0 4px 14px rgba(0,0,0,0.3);
  white-space: nowrap;
}
.kk-pomo-cap.show {
  opacity: 1;
  transform: translateX(-50%) scaleX(1);
  pointer-events: auto;
}
.kk-pomo-content {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 200ms ease-out 80ms, transform 200ms ease-out 80ms;
  display: flex;
  align-items: center;
  gap: 8px;
}
.kk-pomo-cap.show .kk-pomo-content {
  opacity: 1;
  transform: translateY(0);
}
.kk-pomo-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--kk-acc);
  animation: pulse-dot 2s infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Import overlay ───────────────────────────────────────────────── */
.kk-import {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: rgba(20,23,26,0.82);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: kkFadeIn 300ms ease;
}
.kk-import[hidden] { display: none; }
@keyframes kkFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes kkSlideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.kk-import-head {
  flex-shrink: 0;
  height: 52px;
  padding: 0 16px;
  display: flex;
  align-items: center;
}
.kk-import-head-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--kk-text);
}
.kk-import-body {
  flex: 1;
  overflow: auto;
  padding: 0 20px 32px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.kk-import-state[hidden] { display: none; }
.kk-import-spinner {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 3px solid var(--kk-line);
  border-top-color: var(--kk-acc);
  margin: 0 auto 16px;
  animation: kkSpin 1s linear infinite;
}
.kk-import-spinner.sm {
  width: 44px;
  height: 44px;
  border-width: 2.5px;
  margin: 0;
  flex-shrink: 0;
}
@keyframes kkSpin { to { transform: rotate(360deg); } }
@keyframes sheetUp   { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes sheetDown { from { transform: translateY(0); opacity: 1; } to { transform: translateY(20px); opacity: 0; } }
@keyframes breathe   { 0%,100% { transform: scale(1); opacity: 0.9; } 50% { transform: scale(1.03); opacity: 1; } }
@keyframes indentIn  { from { opacity: 0; transform: translateX(-12px); } to { opacity: 1; transform: translateX(0); } }
@keyframes pop       { 0% { transform: scale(1); } 50% { transform: scale(0.92); } 100% { transform: scale(1); } }
@keyframes scaleIn   { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes slideRight { from { opacity: 0; transform: translateX(-12px); } to { opacity: 1; transform: translateX(0); } }
@keyframes slideDown  { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.kk-import-hd {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.kk-import-ttl {
  font-family: var(--kk-font-jp);
  font-size: 18px;
  font-weight: 600;
  color: var(--kk-text);
  text-align: center;
}
.kk-import-hd .kk-import-ttl { text-align: left; }
.kk-import-sub {
  font-size: 12px;
  color: var(--kk-text-2);
  margin-top: 6px;
  text-align: center;
}
.kk-import-hd .kk-import-sub { text-align: left; margin-top: 2px; }
.kk-import-flist {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  max-height: 250px;
  overflow-y: auto;
  position: relative;
}
.kk-import-frow {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--kk-surface);
  border-radius: 8px;
  border: 1px solid var(--kk-line);
  opacity: 0.45;
  transition: opacity 300ms ease;
}
.kk-import-frow.processing,
.kk-import-frow.done,
.kk-import-frow.error,
.kk-import-frow.conflict { opacity: 1; }
.kk-import-fdot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--kk-line-2);
  flex-shrink: 0;
  transition: background 300ms ease;
}
.kk-import-frow.done .kk-import-fdot { background: var(--kk-acc); }
.kk-import-frow.processing .kk-import-fdot { background: var(--kk-warn); }
.kk-import-frow.error .kk-import-fdot { background: var(--kk-danger); }
.kk-import-frow.conflict .kk-import-fdot { background: var(--kk-text-3); }
.kk-import-fname {
  font-size: 12px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kk-import-fstatus {
  font-size: 10px;
  color: var(--kk-text-3);
  font-family: var(--kk-font-mono);
  flex-shrink: 0;
}
.kk-import-frow.done .kk-import-fstatus { color: var(--kk-acc); }
.kk-import-frow.processing .kk-import-fstatus { color: var(--kk-warn); }
.kk-import-frow.error .kk-import-fstatus { color: var(--kk-danger); }
.kk-import-bar-wrap {
  height: 3px;
  background: var(--kk-line);
  border-radius: 2px;
  overflow: hidden;
}
.kk-import-bar {
  height: 100%;
  background: var(--kk-acc);
  width: 0%;
  transition: width 150ms linear;
}
.kk-import-pct {
  font-size: 10px;
  color: var(--kk-text-3);
  margin-top: 6px;
  font-family: var(--kk-font-mono);
}
/* done state */
.kk-import-done .kk-import-ttl { font-size: 20px; margin-bottom: 4px; text-align: left; }
.kk-import-done .kk-import-sub { text-align: left; margin-top: 0; margin-bottom: 16px; }
.kk-import-conflict {
  background: rgba(216,169,107,0.08);
  border: 1px solid rgba(216,169,107,0.25);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: kkSlideUp 400ms ease;
}
.kk-import-conflict[hidden] { display: none; }
.kk-import-resolved[hidden] { display: none; }
.kk-import-conflict-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(216,169,107,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--kk-warn);
  flex-shrink: 0;
  margin-top: 2px;
}
.kk-import-conflict-body { flex: 1; min-width: 0; }
.kk-import-conflict-ttl { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.kk-import-conflict-sub { font-size: 11px; color: var(--kk-text-3); margin-bottom: 10px; }
.kk-import-conflict-btns { display: flex; gap: 6px; }
.kk-import-conflict-btn {
  flex: 1;
  height: 32px;
  border-radius: 16px;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  color: var(--kk-text);
  font-size: 12px;
  cursor: pointer;
}
.kk-import-conflict-btn.pri {
  background: var(--kk-acc);
  color: #000;
  font-weight: 600;
  border: none;
}
.kk-import-conflict-btn.danger { color: var(--kk-danger); }
.kk-import-conflict-x {
  background: none;
  border: none;
  color: var(--kk-text-3);
  cursor: pointer;
  padding: 4px;
  font-size: 12px;
  line-height: 1;
  flex-shrink: 0;
}
.kk-import-resolved {
  background: var(--kk-surface);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--kk-line);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--kk-text-2);
  animation: kkFadeIn 300ms ease;
}
.kk-import-resolved-icon {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--kk-acc-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--kk-acc);
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}
.kk-import-start {
  width: 100%;
  height: 44px;
  border-radius: 22px;
  background: var(--kk-acc);
  color: #000;
  font-weight: 600;
  border: none;
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
}

/* ── Settings system ─────────────────────────────────────────────── */
.kk-sheet-dim {
  position: absolute;
  inset: 0;
  z-index: 19;
  background: rgba(0,0,0,0.55);
  opacity: 0;
  pointer-events: none;
  transition: opacity 280ms ease;
}
.kk-sheet-dim.on { opacity: 1; pointer-events: auto; }

/* Sub-panel sheet — base z-index 20, raised to 22 only while open so chapter panel (z-index 21) isn't covered during settings close animation */
.kk-sheet-sub {
  z-index: 20;
  max-height: 85%;
  overflow: hidden;
}
/* Chapter sheet above mine sheet (both .kk-sheet = 20, but chapters must win) */
#kk-chap-sheet { z-index: 24; }
.kk-sheet-sub.open {
  z-index: 22;
}
#kk-settings-sheet,
.kk-sheet-sub {
  background: var(--kk-bg);
  padding-left: 14px;
  padding-right: 14px;
}
.kk-sheet-sub {
  padding-top: 0;
  padding-bottom: 0;
}
#kk-settings-sheet .kk-sheet-head {
  padding: 10px 0 6px;
  flex-shrink: 0;
  margin-bottom: 0;
}
#kk-settings-sheet {
  padding-top: 0;
  padding-bottom: 0;
}
#kk-settings-sheet .settings-list {
  flex: 1;
  min-height: 0;
}

/* Settings row */
.settings-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 0 24px;
}

.settings-group { margin-top: 16px; }
.settings-group:first-child { margin-top: 8px; }
.settings-group-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--kk-text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 8px 6px;
}

.settings-card {
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-md);
  overflow: hidden;
}

.settings-row {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--kk-line);
  cursor: pointer;
  width: 100%;
  text-align: left;
  gap: 10px;
  color: var(--kk-text);
  -webkit-tap-highlight-color: transparent;
}
.settings-row:last-child { border-bottom: none; }
.settings-row:active { background: var(--kk-bg-2); }
.settings-row-l { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.settings-row-t { font-size: 13px; color: var(--kk-text); }
.settings-row-s { font-size: 10px; color: var(--kk-text-3); font-family: var(--kk-font-mono); }
.settings-row-r { display: flex; align-items: center; gap: 6px; flex-shrink: 0; margin-left: auto; }
.settings-row-v { font-size: 12px; color: var(--kk-text-2); font-family: var(--kk-font-mono); }
.settings-row-ch { font-size: 13px; color: var(--kk-text-3); line-height: 1; }

.settings-row-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--kk-bg-2);
  flex-shrink: 0;
}
.settings-row-icon svg { width: 16px; height: 16px; stroke: var(--kk-text-2); }

/* Panel sections inside sub-panels */
.panel-section { margin-top: 16px; }
.panel-section:first-child { margin-top: 8px; }

.panel-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--kk-text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 8px 6px;
}

/* Custom dropdown */
.dropdown-wrap {
  position: relative;
  flex: 1;
  max-width: 160px;
}
.dropdown-trigger {
  width: 100%;
  height: 36px;
  padding: 0 28px 0 12px;
  background: var(--kk-bg);
  border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-sm);
  color: var(--kk-text);
  font-size: 12px;
  font-family: var(--kk-font-mono);
  display: flex;
  align-items: center;
  cursor: pointer;
  position: relative;
}
.dropdown-trigger::after {
  content: '▼';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 8px;
  color: var(--kk-text-3);
}
.dropdown-menu {
  position: fixed;
  width: 160px;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-sm);
  z-index: 100;
  max-height: 200px;
  overflow-y: auto;
  display: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.dropdown-menu.open { display: block; }
.dropdown-item {
  padding: 10px 12px;
  font-size: 12px;
  color: var(--kk-text);
  cursor: pointer;
  border-bottom: 1px solid var(--kk-line);
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:active { background: var(--kk-bg-2); }
.dropdown-item.on { color: var(--kk-acc); }

/* Buttons inside cards */
.btn-row { padding: 10px 14px; }
.btn-full {
  width: 100%;
  height: 44px;
  border-radius: var(--kk-r-sm);
  background: var(--kk-bg);
  border: 1px solid var(--kk-line);
  color: var(--kk-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.btn-full:active { background: var(--kk-bg-2); }
.btn-full.pri {
  background: var(--kk-acc);
  color: var(--kk-bg);
  border: none;
}
.btn-full.pri:active { opacity: 0.85; }
.btn-full.danger {
  background: rgba(213,118,118,0.12);
  color: var(--kk-danger);
  border-color: rgba(213,118,118,0.25);
}

/* Tip box */
.tip-box {
  margin: 8px 14px 0;
  padding: 12px;
  background: var(--kk-bg-2);
  border-radius: var(--kk-r-sm);
  font-size: 11px;
  color: var(--kk-text-3);
  line-height: 1.5;
  text-align: center;
}

/* Slider header (used inside cards) */
.slider-hd {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.slider-hd-label { font-size: 13px; color: var(--kk-text); }
.slider-hd-val { font-size: 12px; color: var(--kk-text-2); font-family: var(--kk-font-mono); }

/* Progress bar (batch translate) */
.progress-hd {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--kk-text-3);
  margin-bottom: 6px;
}
.progress-track {
  width: 100%;
  height: 6px;
  background: var(--kk-line);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--kk-acc);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s;
}

/* ===== PROTOTYPE SETTINGS PORT ===== */

/* Theme card inner (prototype names) */
.theme-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--kk-line-2);
}
.theme-dot.auto {
  background: linear-gradient(135deg, #1f2429 50%, #f0ebe4 50%);
}
.theme-card.active .theme-dot { border-color: var(--kk-acc); }
.theme-label { width: 25.34px; height: 14px; font-size: 12px; color: var(--kk-text); }

/* Font list rows (prototype names) */
.font-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--kk-line);
  cursor: pointer;
  background: transparent;
  border: none;
  width: 100%;
  color: var(--kk-text);
  text-align: left;
}
.font-row:last-child { border-bottom: none; }
.font-row:active { background: var(--kk-bg-2); }
.font-row.on { background: var(--kk-bg-2); }
.font-name { font-size: 13px; }
.font-sub { font-size: 10px; color: var(--kk-text-3); }

/* Voice row inner (prototype names) */
.voice-info { flex: 1; min-width: 0; }
.voice-name { font-size: 13px; color: var(--kk-text); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.voice-desc { font-size: 10px; color: var(--kk-text-3); margin-top: 2px; }
.voice-play {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--kk-line);
  background: var(--kk-bg-2);
  color: var(--kk-text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.voice-play:active { background: var(--kk-line); }
.voice-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.voice-check { font-size: 14px; color: var(--kk-accent); width: 20px; text-align: center; }
.voice-row.on { background: var(--kk-surface-2); }

/* Dictionary status header (prototype) */
.dict-status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
}
.dict-status-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.dict-status-icon svg { width: 20px; height: 20px; stroke: var(--kk-text-2); }
.dict-status-t { font-size: 13px; color: var(--kk-text); }
.dict-status-s { font-size: 11px; color: var(--kk-text-3); }

/* Dictionary grid (prototype) */
.dict-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px;
}
.dict-cell {
  background: var(--kk-bg);
  border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-sm);
  padding: 12px;
  text-align: center;
}
.dict-cell-v { font-size: 14px; font-weight: 600; color: var(--kk-text); font-family: var(--kk-font-mono); }
.dict-cell-l { font-size: 10px; color: var(--kk-text-3); margin-top: 4px; }

/* Upload zone text (prototype) */
.upload-t { font-size: 13px; color: var(--kk-text); }
.upload-s { font-size: 11px; color: var(--kk-text-3); }

/* Explicit import button inside the dictionary dropzone. */
.kk-dict-pick-btn {
  margin-top: 6px;
  padding: 9px 22px;
  border: none;
  border-radius: var(--kk-r-sm);
  background: var(--kk-acc);
  color: var(--kk-bg);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.kk-dict-pick-btn:active { opacity: 0.85; }

/* Panel head */
.panel-head {
  display: flex;
  align-items: center;
  padding: 10px 0 6px;
  flex-shrink: 0;
}
.panel-head::after {
  content: '';
  width: 32px;
  flex-shrink: 0;
}
.panel-back {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--kk-bg-2);
  color: var(--kk-text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.panel-back:active { background: var(--kk-line); }
.panel-title { font-family: var(--kk-font-jp); font-size: 15px; font-weight: 600; flex: 1; text-align: center; }
.panel-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0 24px;
}
.kk-sheet-sub .panel-body {
  padding-bottom: 4px;
}
#kk-set-dict .panel-body {
  overflow: visible;
}
#kk-set-translation .panel-body {
  overflow: visible;
}
#kk-set-reading .panel-body,
#kk-set-translation .panel-body,
#kk-set-voice .panel-body,
#kk-set-fontup .panel-body,
#kk-set-dict .panel-body,
#kk-set-backup .panel-body {
  padding-bottom: 12px;
}

#kk-set-pomo .panel-section:first-child .settings-card {
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  box-sizing: border-box;
}
#kk-set-pomo .panel-section:first-child .settings-card .slider-wrap {
  height: 49.84px;
  padding: 8px 14px;
  box-sizing: border-box;
}
#kk-set-pomo .panel-section:first-child .settings-card .slider-wrap .slider-hd {
  margin-bottom: 0;
}
#kk-set-translation .slider-wrap,
#kk-set-playback .slider-wrap,
#kk-set-wpm .slider-wrap {
  padding: 8px 14px;
}
.panel-foot {
  padding: 12px 0;
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-shrink: 0;
}
.test-btn {
  height: 44px;
  padding: 0 16px;
  border-radius: var(--kk-r-sm);
  background: var(--kk-bg);
  border: 1px solid var(--kk-line);
  color: var(--kk-text);
  font-size: 12px;
  cursor: pointer;
}
.test-btn:active { background: var(--kk-bg-2); }
.test-btn:disabled { opacity: 0.7; cursor: default; }

.test-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2.5px solid var(--kk-line);
  border-top-color: var(--kk-acc);
  border-radius: 50%;
  animation: kk-spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 4px;
}

/* Theme grid */
.theme-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px;
  box-sizing: border-box;
}
.theme-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px;
  background: var(--kk-bg);
  border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-md);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-sizing: border-box;
}
.theme-card:active { background: var(--kk-bg-2); }
.theme-card.active { border-color: var(--kk-acc-line); background: var(--kk-acc-soft); }
.theme-card .dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--kk-line-2);
}
.theme-card .t { font-size: 12px; color: var(--kk-text); }
.theme-card .s { font-size: 10px; color: var(--kk-text-3); font-family: var(--kk-font-mono); }

/* Font panel */
.font-preview {
  padding: 16px;
  background: var(--kk-bg);
  border-bottom: 1px solid var(--kk-line);
  text-align: center;
  font-size: 18px;
  color: var(--kk-text);
  font-family: var(--kk-read-family, var(--kk-font-jp));
}
.font-list {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

/* Font subpanel: compact font list, content sets height */
#kk-set-font {
  max-height: none;
}
#kk-set-font .panel-body {
  overflow-y: auto;
}
#kk-set-font .font-list {
  flex: none;
  min-height: 0;
  max-height: 230px;
}
#kk-set-font .slider-wrap {
  padding: 8px 14px;
}
.font-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--kk-bg);
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
}
.font-option:active { background: var(--kk-bg-2); }
.font-option.active { background: var(--kk-bg-2); }
.font-option .t { font-size: 13px; color: var(--kk-text); }
.font-option .s { font-size: 11px; color: var(--kk-text-3); }
.font-option .check { font-size: 14px; color: var(--kk-acc); }

/* Slider */
.slider-wrap { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; padding: 8px 14px; }
.slider-track {
  position: relative;
  height: 6px;
  background: var(--kk-line);
  border-radius: 2px;
  cursor: pointer;
  touch-action: none;
}
.slider-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--kk-acc);
  border-radius: 2px;
  pointer-events: none;
}
.slider-thumb {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  pointer-events: none;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
}
.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--kk-text-3);
  font-family: var(--kk-font-mono);
}

/* Toggle row */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--kk-surface);
  gap: 12px;
}
.toggle-row .t { font-size: 13px; color: var(--kk-text); }
.toggle-row .s { font-size: 11px; color: var(--kk-text-3); margin-top: 2px; }
.toggle-track {
  width: 40px;
  height: 24px;
  border-radius: 12px;
  background: var(--kk-line-2);
  flex-shrink: 0;
  position: relative;
  cursor: pointer;
  transition: background 200ms ease;
}
.toggle-track.on { background: var(--kk-acc); }
.toggle-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 200ms ease;
}
.toggle-track.on .toggle-knob { transform: translateX(16px); }

/* Speed display */
.speed-display {
  font-size: 28px;
  font-weight: 700;
  font-family: var(--kk-font-mono);
  color: var(--kk-text);
  text-align: center;
  padding: 10px 0;
  flex-shrink: 0;
}
.speed-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.chip {
  height: 32px;
  padding: 0 12px;
  border-radius: var(--kk-r-pill);
  background: var(--kk-surface);
  border: 1px solid var(--kk-line-2);
  color: var(--kk-text-2);
  font-size: 12px;
  font-family: var(--kk-font-mono);
  cursor: pointer;
  transition: all 150ms ease;
}
.chip.on { background: var(--kk-acc-soft); border-color: var(--kk-acc-line); color: var(--kk-acc); }
.chip-row {
  display: flex;
  gap: 6px;
  padding: 8px 14px 12px;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  justify-content: space-between;
}
.chip-row::-webkit-scrollbar { display: none; }

/* Voice list */
.voice-list { display: flex; flex-direction: column; }
.voice-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--kk-surface);
  border: none;
  cursor: pointer;
  width: 100%;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
}
.voice-row:active { background: var(--kk-surface-2); }
.voice-row-l { flex: 1; }
.voice-row-t { font-size: 13px; color: var(--kk-text); }
.voice-row-s { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.voice-lang { font-size: 9px; font-family: var(--kk-font-mono); background: var(--kk-line-2); border-radius: 3px; padding: 1px 5px; color: var(--kk-text-3); }
.font-sep { height: 1px; background: var(--kk-line); margin: 6px 14px; }
.voice-sample { width: 40px; height: 40px; border-radius: 50%; background: var(--kk-bg-2); border: 1px solid var(--kk-line); display: flex; align-items: center; justify-content: center; font-size: 14px; cursor: pointer; color: var(--kk-text-2); flex-shrink: 0; }
.voice-sample:active { background: var(--kk-line); }

/* WPM */
.wpm-display { font-size: 36px; font-weight: 700; font-family: var(--kk-font-mono); color: var(--kk-text); text-align: center; flex-shrink: 0; }
.wpm-label { font-size: 10px; color: var(--kk-text-3); text-align: center; font-family: var(--kk-font-mono); letter-spacing: 0.08em; margin-top: -4px; flex-shrink: 0; }
.wpm-preview { font-size: 12px; color: var(--kk-text-2); text-align: center; padding: 10px 0; flex-shrink: 0; }

/* Input / Status */
.input-wrap { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.input-field {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  background: var(--kk-bg);
  border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-sm);
  color: var(--kk-text);
  font-family: var(--kk-font-mono);
  font-size: 12px;
  outline: none;
  box-sizing: border-box;
}
.input-field:focus { border-color: var(--kk-acc-line); }
.status-row { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--kk-text-2); flex-shrink: 0; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--kk-line-2); flex-shrink: 0; }
.status-dot.ok { background: var(--kk-acc); }
.status-dot.err { background: var(--kk-danger); }

/* Custom Font upload */
.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px;
  background: var(--kk-bg);
  border: 2px dashed var(--kk-line-2);
  border-radius: var(--kk-r-md);
  cursor: pointer;
}
.upload-zone svg { width: 32px; height: 32px; stroke: var(--kk-text-3); }
.upload-zone .t { font-size: 13px; color: var(--kk-text); }
.upload-zone .s { font-size: 11px; color: var(--kk-text-3); }
.upload-zone.drag-over { border-color: var(--kk-accent); background: var(--kk-surface-2); }
.upload-info { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; background: var(--kk-surface); border: 1px solid var(--kk-line); border-radius: var(--kk-r-md); flex-shrink: 0; }
.upload-info .t { font-size: 13px; color: var(--kk-text); }
.upload-info .s { font-size: 11px; color: var(--kk-text-3); }
.upload-rm { font-size: 12px; color: var(--kk-danger); background: none; border: none; cursor: pointer; }

/* Backup */
.backup-actions { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.backup-btn { width: 100%; height: 48px; border-radius: var(--kk-r-md); display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 13px; font-weight: 600; cursor: pointer; border: 1px solid var(--kk-acc); background: var(--kk-acc); color: var(--kk-bg); touch-action: manipulation; }
.backup-btn:active { opacity: 0.9; }
.backup-btn.sec { background: var(--kk-bg); border-color: var(--kk-line); color: var(--kk-text); }
.backup-btn.sec { background: var(--kk-surface); border: 1px solid var(--kk-line-2); color: var(--kk-text); font-weight: 400; }
.backup-hint { font-size: 11px; color: var(--kk-text-3); line-height: 1.5; text-align: center; padding-top: 4px; flex-shrink: 0; }

/* Step list (Dictionary how-to) */
.step-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 14px;
  border-bottom: 1px solid var(--kk-line);
}
.step-item:last-child { border-bottom: none; }
.step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--kk-bg-2);
  border: 1px solid var(--kk-line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--kk-text-2);
  flex-shrink: 0;
}
.step-body { flex: 1; }
.step-t { font-size: 12px; color: var(--kk-text); font-weight: 500; }
.step-s { font-size: 11px; color: var(--kk-text-3); margin-top: 2px; }

/* Separator utility inside settings cards */
.panel-sep { border-top: 1px solid var(--kk-line); }

/* Input label */
.input-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  color: var(--kk-text-3);
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

/* Dictionary panel tip-box inset */
#kk-set-dict .tip-box { margin: 0 14px; }

/* Non-interactive settings row (display only, no pointer) */
.settings-row.is-info { cursor: default; }
.settings-row.is-info:active { background: transparent; }

/* ── P14: Bookmarks + Chapter panel ──────────────────────────────── */
.kk-sheet-act {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--kk-acc-soft); border: 1px solid var(--kk-acc-line);
  color: var(--kk-acc); display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0;
}
.kk-sheet-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 10px; border-top: 1px solid var(--kk-line); flex-shrink: 0;
}
.kk-sheet-foot-btn {
  font-size: 12px; color: var(--kk-danger); background: none;
  border: none; cursor: pointer; font-family: var(--kk-font-mono);
  padding: 4px 8px; border-radius: var(--kk-r-sm);
}
/* Bookmark rows */
.bm-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 0; border-bottom: 1px solid var(--kk-line); cursor: pointer;
}
.bm-row-info { flex: 1; min-width: 0; }
.bm-row-time { font-size: 10px; color: var(--kk-text-3); font-family: var(--kk-font-mono); margin-bottom: 3px; }
.bm-row-text { font-size: 13px; color: var(--kk-text-2); line-height: 1.4; word-break: break-all; }
.bm-row-del { font-size: 18px; color: var(--kk-text-4); background: none; border: none; cursor: pointer; padding: 4px; flex-shrink: 0; line-height: 1; }
.bm-row:active .bm-row-text { color: var(--kk-text); }
/* N12: faint surrounding-context lines around the bookmarked sentence */
.bm-row-ctx { font-size: 11px; color: var(--kk-text-4); line-height: 1.35; word-break: break-all; opacity: .7; margin: 1px 0; }

/* PhoneHybridSheet — chapter panel */
.phone-sheet { max-height: 65%; z-index: 21; }
.chap-rail {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 24px 6px; position: relative; flex-shrink: 0;
}
.chap-rail::before {
  content: ''; position: absolute; left: 24px; right: 24px;
  top: 50%; transform: translateY(-50%); height: 2px;
  background: var(--kk-line); z-index: 0;
}
.dot-node {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  position: relative; z-index: 1; cursor: pointer;
}
.dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--kk-bg);
  border: 2px solid var(--kk-line-2); transition: all 0.2s; flex-shrink: 0;
}
.dot.done { background: var(--kk-text-3); border-color: var(--kk-text-3); }
.dot-node.active .dot { background: var(--kk-acc); border-color: var(--kk-acc); box-shadow: 0 0 0 4px var(--kk-acc-soft); }
.dot-label {
  font-family: var(--kk-font-mono); font-size: 9px; color: var(--kk-text-3);
  transition: color 0.2s; min-width: 20px; text-align: center;
}
.dot-node.active .dot-label { color: var(--kk-acc); font-weight: 600; }
.rail-divider { height: 1px; background: var(--kk-line); flex-shrink: 0; margin: 0 18px 10px; }
.list-label {
  font-family: var(--kk-font-mono); font-size: 9px; letter-spacing: 1.5px;
  color: var(--kk-text-3); text-transform: uppercase; padding: 6px 18px 4px; flex-shrink: 0;
}
.chap-sheet-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.row-c {
  display: flex; align-items: center; gap: 12px; padding: 12px 18px; min-height: 44px;
  cursor: pointer; transition: background 0.15s; border-left: 3px solid transparent;
  background: transparent; border: none; color: inherit; width: 100%; text-align: left;
}
.row-c:hover { background: var(--kk-bg-2); }
.row-c:active { background: var(--kk-bg); }
.row-c.active { background: var(--kk-acc-soft); border-left: 3px solid var(--kk-acc); }
.row-c .num {
  width: 32px; height: 32px; border-radius: 50%; background: var(--kk-bg);
  border: 1px solid var(--kk-line); display: flex; align-items: center;
  justify-content: center; font-family: var(--kk-font-mono); font-size: 11px;
  color: var(--kk-text-3); flex-shrink: 0;
}
.row-c.active .num { background: var(--kk-acc-soft); border-color: var(--kk-acc-line); color: var(--kk-acc); }
.row-c .tt { flex: 1; font-family: var(--kk-font-jp); font-size: 13px; color: var(--kk-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-c .dur { font-family: var(--kk-font-mono); font-size: 10px; color: var(--kk-text-3); flex-shrink: 0; }

/* Confirm dialog — bottom sheet style */
.confirm {
  position: absolute; inset: 0; z-index: 30; background: rgba(0,0,0,0.55);
  display: flex; align-items: flex-end;
  opacity: 0; pointer-events: none;
  transition: opacity 200ms ease;
}
.confirm[hidden] { display: none; }
.confirm.on { opacity: 1; pointer-events: auto; }
.confirm.on .confirm-sheet {
  animation: sheetUp 280ms cubic-bezier(0.22,1,0.36,1);
}
.confirm.closing { opacity: 0; }
.confirm.closing .confirm-sheet {
  animation: sheetDown 200ms ease;
}
.confirm-sheet {
  position: absolute;
  left: 12px; right: 12px; bottom: 16px;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line-2);
  border-radius: var(--kk-r-lg);
  overflow: hidden;
}
.confirm h4 {
  margin: 0;
  padding: 20px 20px 12px; font-size: 15px; color: var(--kk-text); font-weight: 600;
  border-bottom: 1px solid var(--kk-line);
}
.confirm p {
  margin: 0; padding: 12px 20px 16px; font-size: 13px; color: var(--kk-text-2); line-height: 1.5;
}
.confirm .actions {
  padding: 0 12px 12px; display: flex; gap: 8px;
}
.confirm .actions button {
  flex: 1; height: 44px; border-radius: var(--kk-r-pill);
  border: 1px solid var(--kk-line-2); font-size: 13px; cursor: pointer;
  background: var(--kk-surface-2); color: var(--kk-text);
}
.confirm .actions .danger { border-color: var(--kk-danger); color: var(--kk-danger); }

/* ── P15: EPUB/TTS function bar ──────────────────────────────────── */
.kk-fn-bar {
  position: absolute;
  bottom: 16px; left: 12px; right: 12px;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-pill);
  padding: 8px 8px 8px 16px;
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  z-index: 10;
  transition: transform .35s cubic-bezier(.4,0,.2,1), opacity .25s ease;
  /* hidden by default — shown via data-player-mode selector */
  transform: translateY(calc(100% + 20px));
  pointer-events: none;
}
.kk-read[data-player-mode="epub"] .kk-fn-bar,
.kk-read[data-player-mode="tts"]  .kk-fn-bar {
  transform: translateY(0);
  pointer-events: auto;
}
/* Hide audio transport in epub/tts mode */
.kk-read[data-player-mode="epub"] .kk-bot,
.kk-read[data-player-mode="tts"]  .kk-bot { display: none; }
/* Auto-hide applies to fn-bar only in epub/tts mode (not audio — fn-bar stays off-screen in audio) */
.kk-read[data-player-mode="epub"][data-overlays="hidden"] .kk-fn-bar,
.kk-read[data-player-mode="tts"][data-overlays="hidden"]  .kk-fn-bar {
  opacity: 0; pointer-events: none; transform: translateY(8px);
}
/* Focus mode hides fn-bar */
.kk-read[data-mode="focus"] .kk-fn-bar { display: none; }
/* Util strip open hides fn-bar */
.kk-fn-bar.is-util-hidden { transform: translateY(calc(100% + 20px)) !important; opacity: 0; pointer-events: none; }

.kk-fn-timer { font-family: var(--kk-font-mono); font-size: 10px; color: var(--kk-text-3); }
.kk-fn-count { font-family: var(--kk-font-mono); font-size: 10px; color: var(--kk-text-3); text-align: right; }
.kk-fn-speed {
  height: 36px; padding: 0 12px;
  background: var(--kk-bg); border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-sm);
  display: flex; align-items: center;
  font-family: var(--kk-font-mono); font-size: 11px; color: var(--kk-text-2);
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  touch-action: none;
}
.kk-fn-speed.is-wpm {
  background: var(--kk-acc);
  color: var(--kk-bg);
  border-color: var(--kk-acc);
}
.kk-fn-tts {
  width: 48px; height: 48px; flex-shrink: 0;
  background: var(--kk-acc); color: var(--kk-bg);
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 16px; border: none; cursor: pointer;
}
.kk-fn-tts:active { background: var(--kk-warn); }

/* ── P15: Floating word chip ─────────────────────────────────────── */
.kk-float-chip {
  position: absolute; z-index: 15;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-pill);
  padding: 6px 14px;
  display: flex; align-items: center; gap: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
  transform: translate(-50%, -130%);
  opacity: 0; transition: opacity .2s;
  pointer-events: none; white-space: nowrap;
}
.kk-float-chip.show { opacity: 1; pointer-events: auto; }
.kk-float-word {
  font-family: var(--kk-font-jp); font-size: 13px; color: var(--kk-text);
  border-right: 1px solid var(--kk-line); padding-right: 8px;
}
.kk-float-mine {
  background: var(--kk-acc); color: var(--kk-bg);
  border: none; border-radius: var(--kk-r-sm);
  padding: 4px 10px; font-size: 11px; font-weight: 600; cursor: pointer;
  display: none; /* not wired yet */
}

#kk-mine-sheet { display: none !important; /* not wired yet */ }

/* Traffic light badge colors */
.kk-pomo-cap.phase-work { color: var(--kk-acc); border-color: rgba(155,191,122,0.45); }
.kk-pomo-cap.phase-work .kk-pomo-dot { background: var(--kk-acc); animation: pulse-dot 2s infinite; }
.kk-pomo-cap.phase-break { color: var(--kk-warn); border-color: rgba(235,179,79,0.45); }
.kk-pomo-cap.phase-break .kk-pomo-dot { background: var(--kk-warn); animation: pulse-dot 2s infinite; }
.kk-pomo-cap.phase-paused { color: var(--kk-danger); border-color: rgba(229,115,115,0.45); }
.kk-pomo-cap.phase-paused .kk-pomo-dot { background: var(--kk-danger); animation: none; }

/* ── Pomodoro sheet ──────────────────────────────────────────────── */
#kk-pomo-sheet .kk-sheet-head { border-bottom: 1px solid var(--kk-line); }

.kk-pomo-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 20px 32px;
  gap: 16px;
  overflow-y: auto;
}

.kk-pomo-timer {
  font-family: var(--kk-font-mono);
  font-size: 64px;
  font-weight: 300;
  color: var(--kk-text);
  line-height: 1;
  letter-spacing: -1px;
}

.kk-pomo-mode {
  font-size: 13px;
  font-weight: 600;
  padding: 6px 16px;
  border-radius: var(--kk-r-pill);
  border: 1.5px solid var(--kk-line);
  color: var(--kk-text-2);
  background: var(--kk-surface);
}

.kk-pomo-dots {
  display: flex;
  gap: 10px;
  align-items: center;
}
.kk-pomo-dot-item {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--kk-line-2);
  transition: background 200ms ease;
}
.kk-pomo-dot-item.done {
  background: var(--kk-acc);
}
.kk-pomo-dot-item.active {
  background: var(--kk-acc);
  box-shadow: 0 0 0 3px rgba(155,191,122,0.25);
}

.kk-pomo-controls {
  display: flex;
  gap: 12px;
  width: 100%;
  justify-content: center;
  margin-top: 4px;
}
.kk-pomo-btn {
  padding: 10px 20px;
  border-radius: var(--kk-r-pill);
  border: 1px solid var(--kk-line);
  background: var(--kk-bg-2);
  color: var(--kk-text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  min-width: 88px;
  text-align: center;
  transition: background 150ms ease, transform 100ms ease;
}
.kk-pomo-btn:active { transform: scale(0.96); }
.kk-pomo-btn.primary {
  background: var(--kk-acc);
  color: #1a1a1a;
  border-color: var(--kk-acc);
}

.kk-pomo-settings {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--kk-line);
}
.kk-pomo-settings .slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--kk-text);
  margin-bottom: 4px;
}
.kk-pomo-settings .slider-val {
  font-size: 12px;
  color: var(--kk-text-2);
  font-family: var(--kk-font-mono);
}

/* ====================================================================
   POLISH FIXES (2.4.15+)
   ==================================================================== */

/* FAB hidden until scrolled past hero */
.kk-lib-fab {
  opacity: 0;
  pointer-events: none;
  transform: scale(0);
  transition: transform 300ms cubic-bezier(0.34,1.56,0.64,1), opacity 200ms ease-out;
}
.kk-lib-fab.fab-shown { opacity: 1; pointer-events: auto; transform: scale(1); }

/* Settings sheet: hug content when short, cap + scroll when tall.
   % of #app (not vh) so Chrome Android URL bar can't push it off-screen. */
#kk-settings-sheet { max-height: 85%; }

/* Search top bar */
.kk-srch-topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 8px 8px 0 8px;
  height: 52px;
}
.kk-srch-topbar-title {
  grid-column: 2;
  font-size: 18px;
  font-weight: 600;
  color: var(--kk-text);
  letter-spacing: -0.3px;
  text-align: center;
  pointer-events: none;
}
.kk-srch-cancel {
  grid-column: 1;
  justify-self: start;
  background: none;
  border: none;
  color: var(--kk-acc);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
#kk-srch-dots { grid-column: 3; justify-self: end; }
.kk-srch-dots {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--kk-text-2);
  cursor: pointer;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}
.kk-srch-dots:active { background: var(--kk-surface); }

/* Search swipe-to-action rows */
.kk-srch-row-wrap {
  position: relative;
  overflow: hidden;
}
.kk-srch-swipe-pill {
  position: absolute;
  top: 6px; bottom: 6px;
  width: 0;
  border-radius: 16px;
  z-index: 1;
  overflow: hidden;
  opacity: 0;
}
.kk-srch-swipe-pill-l { left: 8px; background: var(--kk-danger, #d55f5f); }
.kk-srch-swipe-pill-r { right: 8px; background: var(--kk-acc); }
.kk-srch-swipe-icon {
  position: absolute;
  top: 50%;
  transform: translateY(-50%) scale(0);
  opacity: 0;
  transition: transform 150ms ease, opacity 100ms ease;
  display: flex; align-items: center; justify-content: center;
}
.kk-srch-swipe-pill-l .kk-srch-swipe-icon { left: 16px; }
.kk-srch-swipe-pill-r .kk-srch-swipe-icon { right: 16px; }
.kk-srch-row { position: relative; z-index: 2; touch-action: pan-y; user-select: none; }

/* Select mode */
.kk-srch-sel-check {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
  flex-shrink: 0; display: none;
  align-items: center; justify-content: center;
  transition: background 150ms, border-color 150ms;
}
.kk-srch-row-wrap.is-select-mode .kk-srch-sel-check { display: flex; }
.kk-srch-row-wrap.is-selected .kk-srch-row { background: rgba(155,191,122,0.10); }
.kk-srch-row-wrap.is-selected .kk-srch-sel-check {
  background: var(--kk-acc); border-color: var(--kk-acc);
}

/* Card select overlay */
.kk-srch-card-sel {
  position: absolute; top: 6px; right: 6px; z-index: 3;
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  background: rgba(0,0,0,0.2);
  display: none; align-items: center; justify-content: center;
}
.kk-srch-card-wrap.is-select-mode .kk-srch-card-sel { display: flex; }
.kk-srch-card-wrap.is-selected .kk-srch-card-sel {
  background: var(--kk-acc); border-color: var(--kk-acc);
}
.kk-srch-card-wrap.is-selected .kk-srch-card { border: 2px solid var(--kk-acc); }
.kk-srch-card { border: 2px solid transparent; transition: border-color 150ms; }

@keyframes pop {
  0%   { transform: scale(0.7); opacity: 0.5; }
  100% { transform: scale(1);   opacity: 1; }
}

/* Multi-select bottom sheet */
.kk-srch-msheet {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 40;
  background: var(--kk-surface);
  border-top: 1px solid var(--kk-line);
  border-radius: 16px 16px 0 0;
  padding: 16px 0 24px;
  animation: kkSlideUp 250ms cubic-bezier(0.25,0.46,0.45,0.94);
}
.kk-srch-msheet-grab {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--kk-line-2); margin: 0 auto 16px;
}
.kk-srch-msheet-row {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 12px 24px; background: none; border: none;
  color: var(--kk-text); font-size: 14px; cursor: pointer;
  text-align: left;
}
.kk-srch-msheet-row.danger { color: var(--kk-danger, #d55f5f); }
.kk-srch-msheet-row:disabled { opacity: 0.4; cursor: default; }
.kk-srch-msheet-div { height: 1px; background: var(--kk-line); margin: 8px 24px; }

/* Mine to Anki sheet */
.mine-head { display: flex; justify-content: space-between; align-items: flex-end; padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px solid var(--kk-line); }
.mine-kana { font-family: var(--kk-font-jp); font-size: 11px; color: var(--kk-text-3); margin-bottom: 1px; letter-spacing: .5px; }
.mine-kanji { font-family: var(--kk-font-jp); font-size: 26px; font-weight: 600; color: var(--kk-text); line-height: 1; }
.mine-kanji ruby rt { font-size: 0.45em; opacity: 0.7; font-weight: 400; }
.mine-form { font-size: 10px; color: var(--kk-acc); margin-top: 4px; letter-spacing: .3px; }
.kk-mchain { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-start; }
.kk-mstep  { display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.kk-mk     { font-size: 15px; font-weight: 700; color: var(--kk-acc); }
.kk-ml     { font-size: 10px; opacity: .6; }
.mine-tags { display: flex; gap: 4px; flex-wrap: wrap; align-items: flex-end; }
.mine-tag { font-family: var(--kk-font-mono); font-size: 9px; padding: 2px 6px; border: 1px solid var(--kk-line-2); border-radius: 3px; color: var(--kk-text-2); letter-spacing: .5px; }
.mine-defns { margin-bottom: 2px; }
.mine-defn { display: grid; grid-template-columns: 18px 1fr; gap: 6px; font-size: 12.5px; line-height: 1.5; color: var(--kk-text); margin-bottom: 4px; }
.mine-defn-n { font-family: var(--kk-font-mono); color: var(--kk-text-3); font-size: 10px; padding-top: 2px; }
.mine-ex { background: var(--kk-bg-2,rgba(255,255,255,0.05)); border-left: 2px solid var(--kk-acc); padding: 8px 10px; border-radius: 3px; margin: 10px 0 12px; }
.mine-ex-jp { font-family: var(--kk-font-jp); font-size: 13px; color: var(--kk-text); margin-bottom: 2px; }
.mine-ex-en { font-size: 11px; color: var(--kk-text-3); font-style: italic; }
.mine-ex-highlight { background: var(--kk-acc-soft); border-bottom: 2px solid var(--kk-acc); }
.kk-wc-note {
  margin: 8px 0 10px;
  padding: 8px 10px;
  background: var(--kk-bg-2);
  border-radius: 6px;
  font-size: 12px;
  color: var(--kk-text-2);
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}
.kk-wc-note-edit { margin-bottom: 10px; }
.kk-wc-note-input {
  width: 100%;
  background: var(--kk-bg);
  border: 1px solid var(--kk-line);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  color: var(--kk-text);
  font-family: inherit;
  resize: none;
  outline: none;
  box-sizing: border-box;
}
.kk-wc-note-input:focus { border-color: var(--kk-acc-line); }
.mine-actions { display: flex; flex-direction: column; gap: 6px; }
.mine-btn { height: 44px; border-radius: var(--kk-r-sm); display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 12px; font-weight: 600; cursor: pointer; border: 1px solid var(--kk-acc); background: var(--kk-acc); color: var(--kk-bg); }
.mine-btn:active { opacity: .9; }
.mine-sec-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mine-sec { height: 40px; border-radius: var(--kk-r-sm); display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 11px; cursor: pointer; border: 1px solid var(--kk-line-2); background: var(--kk-bg); color: var(--kk-text-2); }
.mine-sec:active { background: var(--kk-bg-2,rgba(255,255,255,0.05)); }

/* ============================================================
   DICTIONARY + WORD LOOKUP (Phase 4)
   ============================================================ */

/* Download progress bar (inside word card or settings panel) */
.dict-progress { padding: 16px; text-align: center; }
.dict-progress-label { font-size: 13px; color: var(--kk-text-2); margin-bottom: 10px; }
.dict-progress-track { height: 6px; background: var(--kk-line); border-radius: 999px; overflow: hidden; }
.dict-progress-fill { height: 100%; width: 0%; background: var(--kk-acc); border-radius: 999px; transition: width 0.2s linear; }
.dict-progress-pct { font-size: 12px; color: var(--kk-text-3); margin-top: 8px; font-family: var(--kk-font-mono); }

/* Word lookup card (Mine to Anki sheet) */
.kk-word-card {
  position: fixed; left: 0; right: 0; bottom: 0;
  z-index: 30;
  background: var(--kk-surface);
  border-radius: var(--kk-r-lg) var(--kk-r-lg) 0 0;
  border-top: 1px solid var(--kk-line-2);
  padding: 0 0 calc(var(--safe-bottom) + 16px) 0;
  transform: translateY(100%);
  /* visibility:hidden when closed removes the card AND its buttons from the
     keyboard Tab order + a11y tree (transform alone does not). Delayed 0.25s
     so the slide-out animation still plays before it disappears. */
  visibility: hidden;
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s linear 0.25s;
}
.kk-word-card.open {
  transform: translateY(0);
  visibility: visible;
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s;
}

.kk-word-card .sheet-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 18px; margin-bottom: 10px;
}
.kk-word-card .sheet-title {
  font-family: var(--kk-font-jp); font-size: 15px; font-weight: 600;
}
.kk-word-card .sheet-close {
  font-size: 11px; color: var(--kk-text-3); cursor: pointer;
  font-family: var(--kk-font-mono); background: transparent; border: none;
  padding: 4px 8px; border-radius: var(--kk-r-sm);
}
.kk-word-card .sheet-close:active { background: var(--kk-bg-2); }

.kk-word-card-body { padding: 0 18px 18px; }

.mine-head {
  display: flex; justify-content: space-between; align-items: flex-end;
  padding-bottom: 10px; margin-bottom: 10px;
  border-bottom: 1px solid var(--kk-line);
}
.mine-kana {
  font-family: var(--kk-font-jp); font-size: 11px; color: var(--kk-text-3);
  margin-bottom: 1px; letter-spacing: 0.5px;
}
.mine-kanji {
  font-family: var(--kk-font-jp); font-size: 26px; font-weight: 600;
  color: var(--kk-text); line-height: 1;
}
.mine-tags { display: flex; gap: 4px; }
.mine-tag {
  font-family: var(--kk-font-mono); font-size: 9px;
  padding: 2px 6px; border: 1px solid var(--kk-line-2); border-radius: 3px;
  color: var(--kk-text-2); letter-spacing: 0.5px;
}

.mine-defn {
  display: grid; grid-template-columns: 18px 1fr; gap: 6px;
  font-size: 12.5px; line-height: 1.5; color: var(--kk-text);
  margin-bottom: 4px;
}
.mine-defn-n {
  font-family: var(--kk-font-mono); color: var(--kk-text-3);
  font-size: 10px; padding-top: 2px;
}

.mine-ex {
  background: var(--kk-bg-2); border-left: 2px solid var(--kk-acc);
  padding: 8px 10px; border-radius: 3px;
  margin: 10px 0 12px;
}
.mine-ex-jp {
  font-family: var(--kk-font-jp); font-size: 13px;
  color: var(--kk-text); margin-bottom: 2px;
}
.mine-ex-en {
  font-size: 11px; color: var(--kk-text-3); font-style: italic;
}

.mine-actions {
  display: grid; grid-template-columns: 1fr; gap: 6px;
  /* Mirror the header's 10px breathing room below the divider so the gap above
     the buttons matches the top gap even when the example block is hidden. */
  margin-top: 10px;
}
.mine-btn {
  height: 44px; border-radius: var(--kk-r-sm);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--kk-acc); background: var(--kk-acc);
  color: var(--kk-bg);
}
.mine-btn:active { opacity: 0.9; }
.mine-sec {
  height: 40px; border-radius: var(--kk-r-sm);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 11px; cursor: pointer;
  border: 1px solid var(--kk-line-2); background: var(--kk-bg);
  color: var(--kk-text-2);
}
.mine-sec:active { background: var(--kk-bg-2); }

.kk-word-card-empty {
  text-align: center; padding: 24px 12px;
  font-size: 14px; color: var(--kk-text-3);
}
.kk-word-card-empty b {
  display: block; color: var(--kk-text-2); font-weight: 600;
  margin-bottom: 6px;
}

/* N4 — Compact dictionary mode. Same card, collapsed to the head + first
   meaning for a fast glance. "Full ▾" expands it for the current open. */
.kk-word-card .sheet-head-r {
  display: flex; align-items: center; gap: 4px;
}
.kk-wc-expand {
  font-size: 11px; color: var(--kk-acc); cursor: pointer;
  font-family: var(--kk-font-mono); background: transparent; border: none;
  padding: 4px 8px; border-radius: var(--kk-r-sm);
}
.kk-wc-expand:active { background: var(--kk-bg-2); }

.kk-word-card.is-compact #kk-wc-meanings .mine-defn:nth-of-type(n+2) { display: none; }
.kk-word-card.is-compact #kk-wc-meanings .mine-defn { margin-bottom: 0; }
.kk-word-card.is-compact .mine-head { margin-bottom: 8px; padding-bottom: 8px; }
.kk-word-card.is-compact .mine-ex,
.kk-word-card.is-compact .kk-wc-note,
.kk-word-card.is-compact .kk-wc-note-edit,
.kk-word-card.is-compact .mine-actions { display: none; }

/* K+ — brief colour flash when press-and-hold replays a line. */
.kk-read-line.kk-line-flash {
  border-radius: 8px;
  transition: background-color 0.28s ease;
  background-color: var(--kk-acc-soft);
}

/* Clickable word spans inside active line */
.kk-read-line.is-active .kk-jp .word {
  cursor: pointer;
  transition: transform 0.12s ease;
  display: inline-block;
}
/* NOTE: no .word:active / .word.is-pressing zoom — the whole-box zoom made it
   look like the pressed letter was "grouped" with its box. Box-level zoom is
   kept ONLY for the fallback path (is-pressing/is-selected, used when we can't
   isolate the letters). The normal path zooms the matched letters via .kk-wsel
   below. */
.kk-read-line.is-active .kk-jp .word.is-pressing {
  transform: scale(1.06);
}
.kk-read-line.is-active .kk-jp .word.is-selected {
  transform: scale(1.12);
}
/* Char-level selection — zoom ONLY the matched letters, not the whole box.
   The span is created already at full scale, so a transition won't play; a
   keyframe animation runs on insert instead → smooth grow with no delay. */
@keyframes kk-wsel-zoom {
  from { transform: scale(1); }
  to   { transform: scale(1.18); }
}
.kk-read-line.is-active .kk-jp .kk-wsel {
  display: inline-block;
  transform: scale(1.18);
  transform-origin: center center;
  animation: kk-wsel-zoom 0.12s ease;
  color: var(--kk-acc);
  font-weight: 700;
}

/* Word highlighting — underline only (no background tint) */
.kk-read-line.is-active .kk-jp .word.status-known {
  border-bottom: 2px solid var(--kk-acc);
  border-radius: 2px;
}
.kk-read-line.is-active .kk-jp .word.status-learning {
  border-bottom: 2px dashed var(--kk-warn);
  border-radius: 2px;
}
.kk-read-line.is-active .kk-jp .word.status-new {
  border-bottom: 1px dotted var(--kk-text-3);
}

/* Remove highlights when toggled off */
.kk-read[data-wordhl="off"] .kk-read-line.is-active .kk-jp .word.status-known,
.kk-read[data-wordhl="off"] .kk-read-line.is-active .kk-jp .word.status-learning,
.kk-read[data-wordhl="off"] .kk-read-line.is-active .kk-jp .word.status-new {
  border-bottom: none;
}

/* Dim base text when word card is open */
.kk-read[data-mode="word"] .kk-read-text { opacity: 0.32; }
.kk-read[data-mode="word"] .kk-read-line.is-active { opacity: 1; }

/* ============================================================
   DICTIONARY SETTINGS PANEL (Phase 4c — redesigned)
   ============================================================ */

/* ---- Buttons ---- */
.dict-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; border-radius: var(--kk-r-sm);
  font-size: 13px; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; text-decoration: none;
  font-family: var(--kk-font-ui); width: 100%;
  transition: opacity 0.15s ease;
}
.dict-btn:active { opacity: 0.85; }
.dict-btn-primary { background: var(--kk-acc); color: var(--kk-bg); border-color: var(--kk-acc); }
.dict-btn-outline { background: transparent; color: var(--kk-text-2); border-color: var(--kk-line-2); }
.dict-btn-ghost { background: var(--kk-surface); color: var(--kk-text-2); border-color: var(--kk-line); font-weight: 500; }
.dict-btn-danger { background: transparent; color: var(--kk-danger); border-color: rgba(213,118,118,0.25); font-weight: 500; font-size: 12px; height: 36px; }

/* ---- EMPTY STATE ---- */
.dict-empty-header {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 14px;
}
.dict-empty-icon {
  width: 44px; height: 44px; border-radius: var(--kk-r-md);
  background: var(--kk-surface); border: 1px solid var(--kk-line);
  display: flex; align-items: center; justify-content: center;
  color: var(--kk-text-3); flex-shrink: 0;
}
.dict-empty-info { flex: 1; }
.dict-empty-title { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.dict-empty-desc { font-size: 12px; color: var(--kk-text-3); line-height: 1.4; }

.dict-dropzone {
  padding: 20px;
  border: 2px dashed var(--kk-line-2); border-radius: var(--kk-r-md);
  text-align: center; transition: all 0.2s ease; cursor: pointer;
  margin-bottom: 10px;
}
.dict-dropzone svg { color: var(--kk-text-3); margin-bottom: 6px; }
.dict-dropzone-text { font-size: 13px; color: var(--kk-text-3); margin-bottom: 10px; }
.dict-dropzone.drag-active { border-color: var(--kk-acc) !important; background: var(--kk-acc-soft) !important; }
.dict-dropzone.drag-active svg, .dict-dropzone.drag-active .dict-dropzone-text { color: var(--kk-acc); }

.dict-file-link {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 12px; color: var(--kk-text-3);
  margin-bottom: 16px;
}
.dict-file-link a { color: var(--kk-acc); text-decoration: none; }

.dict-steps-header {
  font-size: 11px; font-weight: 600; color: var(--kk-text-3);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.dict-steps { margin-bottom: 4px; }
.dict-step { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--kk-line); }
.dict-step:last-child { border-bottom: none; }
.dict-step-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--kk-surface); border: 1px solid var(--kk-line);
  color: var(--kk-text-3); font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 1px;
}
.dict-step-title { font-size: 12px; font-weight: 600; margin-bottom: 1px; }
.dict-step-desc { font-size: 11px; color: var(--kk-text-3); line-height: 1.4; }
.dict-step-desc b { color: var(--kk-text-2); font-weight: 600; }

.dict-progress {
  margin-top: 12px; padding: 14px;
  background: var(--kk-surface); border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-md); text-align: center;
}
.dict-progress-label { font-size: 13px; color: var(--kk-text-2); margin-bottom: 8px; }
.dict-progress-track { height: 4px; background: var(--kk-line); border-radius: 999px; overflow: hidden; }
.dict-progress-fill { height: 100%; width: 0%; background: var(--kk-acc); border-radius: 999px; transition: width 0.3s ease; }
.dict-progress-pct { font-size: 12px; color: var(--kk-text-3); margin-top: 6px; font-family: var(--kk-font-mono); }

/* ---- LOADED STATE ---- */
.dict-loaded-header {
  display: flex; align-items: center; gap: 14px; padding: 16px;
  background: var(--kk-surface); border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-md); margin-bottom: 12px;
}
.dict-loaded-icon {
  width: 40px; height: 40px; border-radius: var(--kk-r-sm);
  background: var(--kk-acc-soft); border: 1px solid var(--kk-acc-line);
  display: flex; align-items: center; justify-content: center;
  color: var(--kk-acc); flex-shrink: 0;
}
.dict-loaded-title { font-size: 14px; font-weight: 600; }
.dict-loaded-sub { font-size: 12px; color: var(--kk-text-3); margin-top: 2px; }
.dict-loaded-badge {
  font-size: 11px; font-weight: 600; color: var(--kk-acc);
  background: var(--kk-acc-soft); padding: 4px 10px;
  border-radius: var(--kk-r-pill); border: 1px solid var(--kk-acc-line);
  flex-shrink: 0;
}

.dict-data-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.dict-data-cell { background: var(--kk-surface); border: 1px solid var(--kk-line); border-radius: var(--kk-r-sm); padding: 12px 14px; }
.dict-data-label { font-size: 10px; color: var(--kk-text-3); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 5px; }
.dict-data-value { font-size: 14px; font-weight: 600; }
.dict-data-value.small { font-size: 12px; font-weight: 400; color: var(--kk-text-2); }

.dict-loaded-actions { display: flex; flex-direction: column; gap: 8px; }
.dict-btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.dict-update-row { padding: 10px 14px; background: var(--kk-surface); border: 1px solid var(--kk-line); border-radius: var(--kk-r-sm); text-align: center; }
.dict-update-label { font-size: 12px; color: var(--kk-text-2); }
.dict-update-label a { color: var(--kk-acc); text-decoration: none; }

.dict-meta { margin-top: 10px; font-size: 11px; color: var(--kk-text-3); text-align: center; }

/* ====================================================================
   STUDY LIST (Phase 4a — merged from prototype 6)
   ==================================================================== */

#view-study {
  background: var(--kk-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: calc(64px + var(--safe-bottom));
}

.kk-study {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Header */
.kk-study-head {
  flex-shrink: 0;
  border-bottom: 1px solid var(--kk-line);
}
.kk-study-head-top {
  display: flex;
  align-items: center;
  padding: 12px 16px;
}
.kk-study-back {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  color: var(--kk-text-3); border-radius: 6px;
}
.kk-study-back:active { background: var(--kk-bg-2); }
.kk-study-title {
  flex: 1; text-align: center;
  font-family: var(--kk-font-jp);
  font-size: 16px; font-weight: 600;
}
.kk-study-count {
  font-size: 11px; color: var(--kk-text-3);
  font-family: var(--kk-font-mono); margin-left: 8px;
}

/* Filter tabs */
.kk-study-tabs {
  display: none;
  gap: 8px;
  padding: 0 16px 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.kk-study-tabs::-webkit-scrollbar { display: none; }
.kk-study-tab {
  flex-shrink: 0;
  height: 32px;
  padding: 0 14px;
  border-radius: 16px;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  color: var(--kk-text-2);
  font-size: 12px;
  font-family: var(--kk-font-ui);
  cursor: pointer;
  white-space: nowrap;
  transition: background 150ms, color 150ms;
}
.kk-study-tab.is-active {
  background: var(--kk-acc);
  border-color: var(--kk-acc);
  color: #000;
}
.kk-study-tab:active { background: var(--kk-surface-2); }

/* Body (accordion) — scrolls together with the head inside .kk-study now,
   so it no longer needs its own overflow container. */
.kk-study-body {
  padding: 0 16px 4px;
  overflow-anchor: none;
  flex: 1;
}
.kk-study::-webkit-scrollbar { display: none; }

.kk-study-group-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0;
  cursor: pointer;
  border-bottom: 1px solid var(--kk-line);
  position: sticky;
  top: -1px;
  background-color: var(--kk-surface);
  z-index: 10;
  min-height: 56px;
  border-radius: var(--kk-r-sm) var(--kk-r-sm) 0 0;
}
.kk-study-group-header:active { opacity: 0.7; }
.kk-study-group-header.all-known {
  background-color: var(--kk-surface);
  border-bottom-color: rgba(122, 175, 90, 0.25);
  box-shadow: inset 0 -1px 0 rgba(122, 175, 90, 0.15);
}
.kk-study-group-cover {
  width: 28px; height: 36px;
  border-radius: 4px;
  background: var(--kk-surface-2);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--kk-font-jp); font-size: 13px;
  color: var(--kk-text-3); flex-shrink: 0;
}
.kk-study-group-info { flex: 1; min-width: 0; }
.kk-study-group-title { font-size: 14px; font-weight: 600; color: var(--kk-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kk-study-group-count { font-size: 11px; color: var(--kk-text-3); font-family: var(--kk-font-mono); margin-top: 2px; }
.kk-study-group-caret { color: var(--kk-text-3); transition: transform 0.2s; flex-shrink: 0; font-size: 11px; }
.kk-study-group-header.open .kk-study-group-caret { transform: rotate(180deg); color: var(--kk-acc); }
.kk-study-group-body { overflow: hidden; max-height: 0; transition: max-height 0.3s ease; }
.kk-study-group-header.open + .kk-study-group-body { max-height: 2000px; }

.kk-study-group + .kk-study-group { margin-top: 0; }
.kk-study-group + .kk-study-group::before {
  content: ''; display: block; height: 8px;
}

.kk-study-group-btn {
  flex-shrink: 0;
  height: 36px; padding: 0 14px;
  border-radius: 18px;
  background: var(--kk-acc-soft);
  color: var(--kk-acc);
  font-size: 12px; font-weight: 600;
  border: 1px solid var(--kk-acc-line);
  display: flex; align-items: center; gap: 4px;
  min-width: 44px;
}
.kk-study-group-btn:active { background: var(--kk-acc-l2, rgba(155,191,122,0.25)); }
.kk-study-group-btn.all-known {
  background: rgba(122, 175, 90, 0.15);
  color: var(--kk-done);
  border-color: rgba(122, 175, 90, 0.30);
}

/* Rows */
.kk-study-row-wrap { position: relative; overflow: hidden; }

.kk-study-del-pill {
  position: absolute;
  left: 8px;
  top: 4px;
  bottom: 4px;
  width: 0;
  background: var(--kk-danger, #d55f5f);
  border-radius: 8px;
  z-index: 1;
  overflow: hidden;
  opacity: 0;
}
.kk-study-del-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%) scale(0);
  opacity: 0;
  font-size: 16px;
  color: #fff;
  transition: transform 150ms ease, opacity 100ms ease;
}

.kk-study-row {
  display: flex; align-items: center; gap: 10px;
  padding: 0 0 0 38px;
  border-bottom: 1px solid var(--kk-line);
  cursor: pointer;
  transition: background 0.1s;
  min-height: 52px;
  touch-action: pan-y;
  user-select: none;
  position: relative;
  z-index: 2;
}
.kk-study-row:active { background: var(--kk-bg-2); }
.kk-study-row-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.kk-study-row-dot.known { background: var(--kk-acc); }
.kk-study-row-dot.learning { background: var(--kk-warn); }
.kk-study-row-dot.new { background: var(--kk-text-4); }
.kk-study-row-main { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.kk-study-row-top { display: flex; align-items: baseline; gap: 6px; }
.kk-study-row-word {
  font-family: var(--kk-font-jp); font-size: 15px; font-weight: 600;
  color: var(--kk-text); line-height: 1.3;
}
.kk-study-row-reading {
  font-family: var(--kk-font-jp); font-size: 12px;
  color: var(--kk-text-3);
}
.kk-study-row-gloss {
  font-size: 12px; color: var(--kk-text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kk-study-row-note {
  font-size: 11px; color: var(--kk-text-3);
  margin-top: 4px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Empty state */
.kk-study-empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 24px; text-align: center;
  color: var(--kk-text-3); font-size: 13px;
}
.kk-study-empty-t {
  font-family: var(--kk-font-jp);
  font-size: 18px; color: var(--kk-text-2);
  margin-bottom: 8px;
}

/* Footer */
.kk-study-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--kk-line);
  flex-shrink: 0;
  gap: 12px;
  background: var(--kk-surface);
}
.kk-study-foot-left { display: flex; gap: 4px; }
.kk-study-foot-icon {
  width: 44px; height: 44px;
  border-radius: var(--kk-r-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--kk-text-3);
  border: 1px solid var(--kk-line);
  background: var(--kk-surface);
}
.kk-study-foot-icon:active { background: var(--kk-surface-2); }
.kk-study-foot-icon svg { width: 18px; height: 18px; }
#kk-study-fav { color: var(--kk-danger); }
.kk-study-foot-action {
  height: 44px; padding: 0 20px;
  border-radius: var(--kk-r-md);
  border: none;
  background: var(--kk-acc); color: #000;
  font-size: 13px; font-weight: 700;
  display: flex; align-items: center; gap: 6px;
  flex-shrink: 0;
}
.kk-study-foot-action:active { background: #8aaf6a; }
.kk-study-foot-action.all-done {
  background: var(--kk-done); color: #fff;
}

/* Flashcard overlay */
.kk-study-card-view {
  display: none;
  flex-direction: column;
  position: absolute;
  inset: 0;
  background: var(--kk-surface);
  z-index: 10;
}
.kk-study-card-view.show { display: flex; }
.kk-study-card-top {
  display: flex; align-items: center;
  padding: 12px 16px 8px; flex-shrink: 0;
}
.kk-study-card-back {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--kk-acc);
  padding: 10px 12px; border-radius: var(--kk-r-sm);
  min-height: 44px;
}
.kk-study-card-back:active { background: var(--kk-acc-soft); }
.kk-study-card-back svg { width: 16px; height: 16px; }
.kk-study-card-progress {
  font-size: 12px; color: var(--kk-text-3);
  font-family: var(--kk-font-mono); margin-left: auto;
}
.kk-study-card-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 24px;
}
.kk-study-card {
  width: 100%; max-width: 280px;
  min-height: 240px;
  position: relative;
  cursor: pointer;
  perspective: 800px;
}
.kk-study-card-inner {
  width: 100%; min-height: 240px;
  background: var(--kk-bg);
  border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-lg);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: transform 0.45s cubic-bezier(0.4, 0, 0.2, 1);
  transform-style: preserve-3d;
}
.kk-study-card.is-flipped .kk-study-card-inner { transform: rotateY(180deg); }
.kk-study-card-front, .kk-study-card-back {
  width: 100%;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.kk-study-card-back {
  position: absolute; inset: 0;
  transform: rotateY(180deg);
  padding: 24px 20px;
}
.kk-study-card-word {
  font-family: var(--kk-font-jp);
  font-size: 32px; font-weight: 600;
  color: var(--kk-text);
  line-height: 1.3;
  text-align: center;
}
.kk-study-card-reading {
  font-family: var(--kk-font-jp);
  font-size: 16px; color: var(--kk-text-3);
  margin-top: 8px;
}
.kk-study-card-hint {
  position: absolute;
  bottom: 18px;
  font-size: 10px; color: var(--kk-text-4);
  font-family: var(--kk-font-mono);
}
.kk-study-card-gloss {
  font-size: 18px; color: var(--kk-text-2);
  text-align: center; line-height: 1.5;
}
.kk-study-card-sentence {
  font-family: var(--kk-font-jp);
  font-size: 14px; color: var(--kk-text-3);
  margin-top: 12px; text-align: center; line-height: 1.5;
}
.kk-study-card-book {
  font-size: 11px; color: var(--kk-text-4);
  font-family: var(--kk-font-mono);
  margin-top: 12px;
}
.kk-study-card-actions {
  display: flex;
  gap: 20px;
  padding: 12px 24px calc(64px + var(--safe-bottom) + 12px);
  justify-content: center;
  flex-shrink: 0;
}
.kk-study-card-btnwrap { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.kk-study-card-btn {
  width: 56px; height: 56px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--kk-line);
  font-size: 16px;
}
.kk-study-card-btn:active { transform: scale(0.9); }
.kk-study-card-btn.learn {
  background: var(--kk-bg-2); color: var(--kk-warn);
  border-color: rgba(216,169,107,0.3);
}
.kk-study-card-btn.know {
  background: var(--kk-acc-soft); color: var(--kk-acc);
  border-color: var(--kk-acc-line);
}
.kk-study-card-btn.skip {
  background: var(--kk-bg); color: var(--kk-text-4);
  border-color: var(--kk-line-2);
}
.kk-study-card-blabel {
  font-size: 11px; color: var(--kk-text-4);
  font-family: var(--kk-font-mono);
}

/* ── Toggle icon in header ── */
.kk-study-toggle-icon {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  color: var(--kk-text-3); border-radius: 6px;
  flex-shrink: 0;
}
.kk-study-toggle-icon:active { background: var(--kk-bg-2); }
.kk-study-toggle-icon.is-active { color: var(--kk-acc); }
.kk-study-toggle-icon svg { width: 16px; height: 16px; }

/* ── Calendar strip ── */
.kk-study-cal {
  flex-shrink: 0;
  overflow: hidden;
  max-height: 400px;
  opacity: 1;
  padding: 4px 16px 6px;
  transition: max-height 0.25s ease, opacity 0.2s ease, padding 0.2s ease;
}
.kk-study-cal.is-collapsed {
  max-height: 0;
  opacity: 0;
  padding-top: 0;
  padding-bottom: 0;
}
.kk-study-cal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 6px;
}
.kk-study-streak {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-family: var(--kk-font-mono);
  color: var(--kk-warn);
}
.kk-study-streak svg { width: 14px; height: 14px; flex-shrink: 0; }
.kk-study-streak-num { font-weight: 700; }
.kk-study-cal-total {
  font-size: 11px; color: var(--kk-text-3);
  font-family: var(--kk-font-mono);
}
.kk-study-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  justify-content: center;
  max-width: 280px;
  margin: 0 auto;
}
.kk-study-cal-day-label {
  font-size: 10px; color: var(--kk-text-4);
  font-family: var(--kk-font-mono);
  text-align: center;
  padding: 2px 0;
}
.kk-study-cal-day {
  aspect-ratio: 1;
  border-radius: 6px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-family: var(--kk-font-mono);
  color: var(--kk-text-3);
  border: 1.5px solid transparent;
  transition: all 0.15s;
  position: relative;
}
.kk-study-cal-day:active { transform: scale(0.92); }
.kk-study-cal-day.is-today { border-color: var(--kk-acc-line); }
.kk-study-cal-day.is-selected { background: var(--kk-acc); color: #000; font-weight: 700; border-color: var(--kk-acc); }
.kk-study-cal-day.is-in-range { background: var(--kk-acc-dim); color: var(--kk-text); border-color: var(--kk-acc-line); }
.kk-study-cal-day.is-range-start { background: var(--kk-acc); color: #000; font-weight: 700; border-color: var(--kk-acc); }
.kk-study-cal-day.is-range-end { background: var(--kk-acc); color: #000; font-weight: 700; border-color: var(--kk-acc); }
.kk-study-cal-day.lv-0 { background: var(--kk-bg); color: var(--kk-text-4); }
.kk-study-cal-day.lv-1 { background: var(--kk-acc-l1, rgba(155,191,122,0.10)); color: var(--kk-text-2); }
.kk-study-cal-day.lv-2 { background: var(--kk-acc-l2, rgba(155,191,122,0.22)); color: var(--kk-text); }
.kk-study-cal-day.lv-3 { background: var(--kk-acc-l3, rgba(155,191,122,0.38)); color: var(--kk-text); }
.kk-study-cal-day.lv-4 { background: var(--kk-acc-l4, rgba(155,191,122,0.55)); color: #fff; }
.kk-study-cal-day-status {
  position: absolute;
  bottom: 2px; right: 4px;
  width: 5px; height: 5px;
  border-radius: 50%;
}
.kk-study-cal-day-status.all-known { background: var(--kk-acc); }
.kk-study-cal-day-status.mixed { background: var(--kk-warn); }
.kk-study-cal-day-status.all-new { background: var(--kk-text-4); }

/* ── Compact bar (expanded mode) ── */
.kk-study-compact {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 16px 6px;
  font-size: 12px;
  color: var(--kk-text-3);
  font-family: var(--kk-font-mono);
  border-bottom: 1px solid var(--kk-line);
  cursor: pointer;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s ease, padding 0.2s ease;
}
.kk-study-compact.show {
  max-height: 50px;
  opacity: 1;
}
.kk-study-compact:active { background: var(--kk-bg-2); }
.kk-study-compact-squares {
  display: flex; align-items: center; gap: 4px;
  flex: 1; max-width: 328px;
  margin: 0 auto;
}
.kk-study-compact-day {
  flex: 1; height: 32px;
  max-width: 44px;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-family: var(--kk-font-mono);
  font-weight: 500;
  color: var(--kk-text-4);
  background: transparent;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s;
}
.kk-study-compact-day.in-range {
  background: var(--kk-acc-l2, rgba(155,191,122,0.22));
  color: var(--kk-text);
  border-color: var(--kk-acc-line, rgba(155,191,122,0.36));
}
.kk-study-compact-day.range-start,
.kk-study-compact-day.range-end {
  background: var(--kk-acc);
  color: #000;
  font-weight: 700;
  border-color: var(--kk-acc);
}
.kk-study-compact-day.is-selected {
  background: var(--kk-acc);
  color: #000;
  font-weight: 700;
  border-color: var(--kk-acc);
}
.kk-study-compact-day.overflow {
  color: var(--kk-text-3);
  border-color: var(--kk-line);
  font-weight: 400;
  font-size: 10px;
}
.kk-study-compact-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kk-study-compact-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kk-study-compact-clear:active { background: var(--kk-surface-2); }
.kk-study-compact-clear svg { width: 12px; height: 12px; }

/* ── Clear filter pill ── */
.kk-study-clear-pill-wrap {
  flex-shrink: 0;
  padding: 10px 16px 8px;
  display: none;
  text-align: center;
}
.kk-study-clear-pill-wrap.show { display: block; }
.kk-study-clear-pill {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 32px; padding: 0 14px;
  border-radius: 16px;
  background: var(--kk-acc-soft);
  border: 1px solid var(--kk-acc-line);
  font-size: 12px; line-height: 1; color: var(--kk-acc);
  cursor: pointer;
  font-family: var(--kk-font-ui);
}
.kk-study-clear-pill:active { background: var(--kk-acc-l2, rgba(155,191,122,0.25)); }
.kk-study-clear-pill svg { width: 12px; height: 12px; display: block; flex-shrink: 0; }

/* ── Expanded mode overrides ── */
.kk-study.is-expanded .kk-study-tabs { display: flex; }

/* ====================================================================
   FAVORITES PANEL (Phase 4a — combined B+D+E design)
   ==================================================================== */

#view-favorites {
  position: absolute; inset: 0;
  background: var(--kk-bg);
  z-index: 25;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  pointer-events: none;
  display: flex;
  flex-direction: column;
}
#view-favorites.is-open {
  transform: translateY(0);
  pointer-events: auto;
}

.kk-fav {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.kk-fav-head {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--kk-line);
  flex-shrink: 0;
}
.kk-fav-back {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  color: var(--kk-text-3); border-radius: 6px;
}
.kk-fav-back:active { background: var(--kk-bg-2); }
.kk-fav-title {
  flex: 1; text-align: center;
  font-family: var(--kk-font-jp);
  font-size: 16px; font-weight: 600;
  margin-right: 44px;
}
.kk-fav-count {
  font-size: 11px; color: var(--kk-text-3);
  font-family: var(--kk-font-mono); margin-left: 8px;
}

.kk-fav-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px;
  scrollbar-width: none;
}
.kk-fav-list::-webkit-scrollbar { display: none; }

.kk-fav-date {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 0 10px;
  position: sticky; top: 0;
  background: var(--kk-bg);
  z-index: 2;
}
.kk-fav-date::after {
  content: ''; flex: 1; height: 1px; background: var(--kk-line);
}
.kk-fav-date-label {
  font-size: 11px; color: var(--kk-text-3);
  font-family: var(--kk-font-mono);
  text-transform: uppercase; letter-spacing: 0.5px;
}

.kk-fav-card {
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.kk-fav-card:active { border-color: var(--kk-line-2); background: var(--kk-surface-2); }
.kk-fav-card.is-playing { border-color: var(--kk-acc-line); }

.kk-fav-card-top {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
}
.kk-fav-card-sentence {
  font-family: var(--kk-font-jp);
  font-size: 15px; color: var(--kk-text);
  line-height: 1.4; flex: 1;
}
.kk-fav-card-badge {
  height: 24px; padding: 0 10px; border-radius: 12px;
  background: var(--kk-bg-2); font-size: 11px;
  color: var(--kk-acc); font-family: var(--kk-font-mono);
  display: flex; align-items: center; flex-shrink: 0;
}

.kk-fav-wave {
  display: flex; align-items: center; gap: 8px;
  height: 36px; margin-bottom: 8px;
}
.kk-fav-wave-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--kk-acc); color: #000;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.kk-fav-wave-btn:active { transform: scale(0.92); }
.kk-fav-wave-btn svg { width: 14px; height: 14px; }

.kk-fav-wave-bars {
  flex: 1; display: flex; align-items: center; gap: 2px; height: 28px;
}
.kk-fav-wave-bar {
  flex: 1; background: var(--kk-line); border-radius: 1px;
  transition: background 0.2s;
}
.kk-fav-card.is-playing .kk-fav-wave-bar { background: var(--kk-acc-line); }
.kk-fav-card.is-playing .kk-fav-wave-bar.played { background: var(--kk-acc); }

.kk-fav-card-meta {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; color: var(--kk-text-3); font-family: var(--kk-font-mono);
}
.kk-fav-card-book { display: flex; align-items: center; gap: 8px; }
.kk-fav-card-play {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--kk-text-2);
}
.kk-fav-card-play svg { width: 12px; height: 12px; }

.kk-fav-empty {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 24px; text-align: center;
  color: var(--kk-text-3);
  font-size: 13px;
}
.kk-fav-empty-t {
  font-family: var(--kk-font-jp);
  font-size: 18px; color: var(--kk-text-2);
  margin-bottom: 8px;
}

.kk-fav-foot {
  display: flex; gap: 8px;
  padding: 10px 16px calc(var(--safe-bottom) + 10px);
  border-top: 1px solid var(--kk-line);
  flex-shrink: 0;
}
.kk-fav-foot-btn {
  flex: 1; height: 44px; border-radius: 10px;
  border: 1px solid var(--kk-line);
  background: var(--kk-bg); color: var(--kk-text-2);
  font-size: 13px;
}
.kk-fav-foot-btn.pri {
  background: var(--kk-acc); color: #000;
  border-color: var(--kk-acc); font-weight: 700;
}
.kk-fav-foot-btn:active { opacity: 0.8; }

/* Anki sync badges */
.kk-sync-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  margin-right: 6px;
  flex-shrink: 0;
}
.kk-sync-badge.synced::after {
  content: '✓';
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  color: var(--kk-done);
}
.kk-sync-badge.failed::after {
  content: '';
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--kk-danger);
}
.kk-sync-badge.unsynced::after {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--kk-text-3);
  opacity: 0.4;
}

/* Sync button spinning */
#kk-study-anki.is-syncing .kk-anki-icon {
  animation: kk-spin 1s linear infinite;
}
@keyframes kk-spin {
  to { transform: rotate(360deg); }
}

/* Sync summary in accordion header */
.kk-study-group-sync {
  font-size: 10px;
  color: var(--kk-done);
  margin-top: 1px;
}

/* AnkiConnect help sheet */
#kk-anki-help .sheet-card {
  max-height: 85%;
}
.kk-anki-help-body {
  padding: 6px 14px 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.kk-anki-help-steps {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.kk-anki-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: var(--kk-text-2);
  line-height: 1.4;
}
.kk-anki-step-num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--kk-line);
  color: var(--kk-text-3);
  font-size: 11px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}
.kk-anki-step-text {
  flex: 1;
}
.kk-anki-step-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kk-anki-code {
  font-family: var(--kk-font-mono);
  font-size: 11px;
  line-height: 1.5;
  background: var(--kk-bg);
  border: 1px solid var(--kk-line);
  border-radius: 8px;
  padding: 10px 16px;
  white-space: pre-wrap;
  margin-right: 30px;
}
.kk-anki-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--kk-acc);
  background: rgba(124,200,100,0.1);
  border: 1px solid rgba(124,200,100,0.25);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  align-self: flex-start;
  transition: background 0.15s;
}
.kk-anki-copy-btn:active { background: rgba(124,200,100,0.2); }
.kk-anki-copy-btn.is-copied {
  background: var(--kk-done);
  color: #fff;
  border-color: var(--kk-done);
}
.kk-anki-help-actions {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--kk-line);
}
.kk-anki-help-actions .test-btn {
  width: 100%;
  height: 44px;
  border-radius: 10px;
}
.kk-anki-help-status {
  font-size: 12px;
  text-align: center;
  margin-top: 10px;
  min-height: 18px;
  color: var(--kk-text-3);
  font-family: var(--kk-font-mono);
}
.kk-anki-help-status.ok { color: var(--kk-done); }
.kk-anki-help-status.err { color: var(--kk-danger); }

/* Anki sync error toast in Study List */
.kk-study-anki-toast {
  position: absolute;
  left: 12px; right: 12px; bottom: 70px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--kk-surface-2);
  border: 1px solid var(--kk-line);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  font-size: 13px;
  color: var(--kk-text);
  transform: translateY(100px);
  opacity: 0;
  transition: transform 0.25s cubic-bezier(0.25,0.46,0.45,0.94), opacity 0.25s;
  pointer-events: none;
}
.kk-study-anki-toast.show {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.kk-study-anki-toast.dismissing {
  transform: translateY(100px);
  opacity: 0;
  pointer-events: none;
}
.kk-study-anki-toast-btn {
  background: none;
  border: none;
  color: var(--kk-acc);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
}
.kk-study-anki-toast-btn:active { background: var(--kk-surface); }

/* === Stats strip === */
.kk-lib-bar-stat-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 40px;
  padding: 0 2px;
}
.kk-lib-bar-stat {
  font-size: 13px;
  font-weight: 600;
  color: var(--kk-text);
  font-family: var(--kk-font-mono);
  line-height: 1;
}
.kk-lib-bar-stat em {
  font-style: normal;
  font-size: 10px;
  color: var(--kk-text-3);
  margin-left: 1px;
}
.kk-lib-bar-stat-label {
  font-size: 9px;
  color: var(--kk-text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  line-height: 1;
}

/* ====================================================================
   TRANSLATION CARD (Phase 5c)
   ==================================================================== */

.kk-trans-card {
  position: absolute;
  left: 8px; right: 8px;
  z-index: 4;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  border-radius: 16px 16px 12px 12px;
  padding: 12px 16px 14px;
  max-height: 120px;
  overflow-y: auto;
  scrollbar-width: none;
  pointer-events: auto;
  transform: translateY(calc(100% + 160px));
  transition: transform 280ms cubic-bezier(0.22,1,0.36,1), bottom 280ms cubic-bezier(0.22,1,0.36,1);
}
.kk-trans-card::-webkit-scrollbar { display: none; }
.kk-trans-card.open {
  transform: translateY(0);
}

/* Card position follows overlay + util strip visibility — never overlaps controls.
   Reader transport pill ~103px (with chapter line), util strip ~78px, target gap ~26px.
   When overlays hidden: card drops to bottom edge. */
.kk-read[data-overlays="visible"][data-util="closed"] .kk-trans-card { bottom: calc(var(--safe-bottom) + 145px); }
.kk-read[data-overlays="visible"][data-util="open"] .kk-trans-card { bottom: calc(var(--safe-bottom) + 120px); }
.kk-read[data-overlays="hidden"][data-util="closed"] .kk-trans-card { bottom: calc(var(--safe-bottom) + 16px); }
.kk-read[data-overlays="hidden"][data-util="open"] .kk-trans-card { bottom: calc(var(--safe-bottom) + 118px); }

/* When translation card is open (auto-show or manually), don't let overlay auto-hide push it down */
.kk-read[data-util="closed"] .kk-trans-card.open { bottom: calc(var(--safe-bottom) + 145px) !important; }
.kk-read[data-util="open"] .kk-trans-card.open { bottom: calc(var(--safe-bottom) + 120px) !important; }
.kk-read[data-util="open"][data-util-more="true"] .kk-trans-card.open { bottom: calc(var(--safe-bottom) + 200px) !important; }

/* EPUB/TTS mode: fn-bar is shorter than audio transport, so card sits lower.
   Gap matches audiobook's 26px above the transport top.
   Util strip is the same element in both modes — no override needed for util-open. */
.kk-read[data-player-mode="epub"][data-overlays="visible"][data-util="closed"] .kk-trans-card,
.kk-read[data-player-mode="tts"][data-overlays="visible"][data-util="closed"] .kk-trans-card {
  bottom: calc(var(--safe-bottom) + 108px);
}
.kk-read[data-player-mode="epub"][data-util="closed"] .kk-trans-card.open,
.kk-read[data-player-mode="tts"][data-util="closed"] .kk-trans-card.open {
  bottom: calc(var(--safe-bottom) + 108px) !important;
}

.kk-trans-card .sheet-grab {
  display: block;
  width: 32px;
  height: 4px;
  border-radius: 2px;
  background: var(--kk-line-2);
  margin: 0 auto 10px;
  border: none;
  cursor: pointer;
}

.kk-trans-en {
  font-size: var(--kk-trans-fs, 14px);
  color: var(--kk-text);
  line-height: 1.5;
}
.kk-trans-src {
  font-size: 10px;
  color: var(--kk-text-3);
  text-align: right;
  margin-top: 6px;
  opacity: 0.7;
}

/* Focus mode inline translation */
.kk-focus-tr {
  font-size: var(--kk-trans-fs, 14px);
  color: var(--kk-text-2);
  text-align: center;
  line-height: 1.5;
  margin-top: 12px;
  max-width: 280px;
}
.kk-focus-tr[hidden] {
  display: none !important;
}

/* Translation settings panel */
/* Custom dropdown styles are in the shared settings-card section above */

.trans-tip {
  font-size: 12px;
  color: var(--kk-text-3);
  line-height: 1.5;
  padding: 12px;
  background: var(--kk-bg-2);
  border-radius: var(--kk-r-md);
  margin-top: 8px;
}
.trans-tip strong {
  color: var(--kk-acc);
}
.test-btn.danger {
  background: rgba(213, 95, 95, 0.15);
  color: var(--kk-danger, #d55f5f);
}
.test-btn.danger:active {
  background: rgba(213, 95, 95, 0.25);
}

/* ====================================================================
   RESPONSIVE — tablet & desktop adaptation
   TWO layouts only:
     MOBILE   = the original phone design. Used for every phone (any
                rotation) and every tablet held PORTRAIT. Left UNTOUCHED.
     DESKTOP  = width >=1024px AND orientation landscape. True
                tablet-landscape / laptop / desktop. Left side rail,
                centered content, split hero, centered modals.
   Portrait is always mobile; there is no tablet-portrait tier.
   Every block below gates on (min-width:1024px) and (orientation:landscape);
   ultrawide (>11/5) additionally letterboxes #app.
   ==================================================================== */

:root {
  --kk-side: 0px;       /* left nav rail width; 0 on phone */
  --kk-content: 100%;   /* centered content column width; full on phone */
}

/* ---- STEP 1: SHELL FRAME -------------------------------------------- */

/* Two layouts only. Mobile = the original phone design, used for every
   phone (any rotation) AND tablets held portrait. Desktop = width >=1024px
   AND landscape only (true tablet-landscape / laptop / desktop). There is
   deliberately no in-between tablet-portrait tier: portrait is always the
   phone layout. Every wide block below therefore gates on
   (min-width: 1024px) and (orientation: landscape). */

/* Tablet landscape / laptop / desktop: bottom bar becomes a left rail */
@media (min-width: 1024px) and (orientation: landscape) {
  :root { --kk-side: 84px; --kk-content: 1180px; }

  body { background: #0b0d0f; }

  /* Center the whole app on very wide screens (not a phone strip:
     full desktop width up to --kk-max, then gentle letterbox) */
  #app {
    left: 50%;
    right: auto;
    width: 100vw;             /* fill the window on normal monitors */
    transform: translateX(-50%);
  }

  /* Only ultrawide viewports (21:9, 32:9 ...) get letterbox bars */
  @media (min-aspect-ratio: 11/5) {
    #app {
      width: calc(100vh * 16 / 9);
      box-shadow: 0 0 0 1px var(--kk-line), 0 24px 80px rgba(0,0,0,0.55);
    }
  }

  /* Push every screen clear of the rail */
  .view { left: var(--kk-side); }

  /* Screens that hide the rail (player, volume-detail) run full width */
  #app[data-view="player"] .view,
  #app[data-view="volume-detail"] .view { left: 0; }

  /* Bottom tab bar -> vertical left rail */
  #kk-tab-bar {
    top: 0;
    bottom: 0;
    right: auto;
    width: var(--kk-side);
    height: auto;
    padding-bottom: 0;
    padding-top: calc(var(--safe-top) + 14px);
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    border-top: none;
    border-right: 1px solid var(--kk-line);
  }
  .kk-tab {
    flex: 0 0 auto;
    min-height: 44px;            /* comfortable pointer/touch target */
    padding: 16px 4px;
    border-radius: 12px;
    margin: 0 8px;
    transition: color 0.15s, background 0.15s;
  }
  /* FAB inside the vertical rail: behaves like a regular tab cell so it
     doesn't stretch to fill leftover height. The ::before circle still
     centers in its cell. */
  .kk-tab-fab {
    flex: 0 0 auto;
    min-height: 60px;
    padding: 16px 4px;
    margin: 4px 8px;
  }
  .kk-tab-fab:hover { background: transparent; }
  /* Mouse users get hover feedback; touch gets matching :active */
  .kk-tab:hover { color: var(--kk-text); background: var(--kk-surface-2); }
  .kk-tab:active { background: var(--kk-surface-2); }
  .kk-tab.is-active:hover { color: var(--kk-acc); }
}

/* ---- STEP 2: LIBRARY — banner hero + book grid ---------------------- */

@media (min-width: 1024px) and (orientation: landscape) {

  /* Hero stops being a full-screen cover; it's a banner now */
  .kk-hero { min-height: clamp(360px, 56vh, 560px); }

  /* Post-hero content sits in a centered column instead of smearing */
  .kk-strip,
  .kk-series-section {
    max-width: var(--kk-content);
    margin-inline: auto;
  }

  /* Side-scroll strips -> wrapping grid, larger covers, many per row */
  .kk-strip-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 20px 14px;
    overflow: visible;
    padding: 0 16px 4px;
  }
  .kk-strip-item {
    width: auto;
    transition: transform 180ms cubic-bezier(0.22, 1, 0.36, 1);
  }
  .kk-strip-cover {
    width: 100%;
    height: auto;
    aspect-ratio: 2 / 3;
    font-size: 30px;
    margin-bottom: 8px;
  }
  .kk-strip-title {
    font-size: 12px;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  /* Mouse hover lift (touch devices keep :active behaviour) */
  .kk-strip-item:hover { transform: translateY(-3px); }
  .kk-strip-item:hover .kk-strip-cover { outline: 1px solid var(--kk-acc-line); }
  .kk-strip-item:active .kk-strip-cover { outline: 1px solid var(--kk-acc-line); }
  .kk-series-row-right { transition: background 150ms ease; }
  .kk-series-row-right:hover { background: var(--kk-surface-2); }
}

/* ---- STEP 4: SIMPLE SCREENS — centered comfy columns --------------- */

@media (min-width: 1024px) and (orientation: landscape) {

  /* Search: header + results in a centered column */
  .kk-srch-head,
  .kk-srch-body {
    max-width: var(--kk-content);
    width: 100%;
    margin-inline: auto;
  }
  /* Grid view: more covers per row on wide screens */
  .kk-srch-body-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
  .kk-srch-row { transition: background 150ms ease; }
  .kk-srch-row:hover { background: var(--kk-surface-2); }

  /* Study list */
  .kk-study-head,
  .kk-study-body {
    max-width: var(--kk-content);
    width: 100%;
    margin-inline: auto;
  }
  .kk-study-group-header { transition: opacity 150ms ease; }
  .kk-study-group-header:hover { opacity: 0.75; }

  /* Favorites */
  .kk-fav-head,
  .kk-fav-list,
  .kk-fav-foot {
    max-width: var(--kk-content);
    width: 100%;
    margin-inline: auto;
  }

  /* Series / volume detail */
  .kk-vd-header,
  .kk-vd-vol-label,
  .kk-vd-vol-list {
    max-width: var(--kk-content);
    margin-inline: auto;
  }
  .kk-vd-vol-row { transition: background 150ms ease; }
  .kk-vd-vol-row:hover { background: var(--kk-acc-soft); }
}

/* On the side-rail layout there is no bottom bar, so reclaim the space
   that screens reserved for it */
@media (min-width: 1024px) and (orientation: landscape) {
  #view-search,
  #view-study { padding-bottom: 16px; }
  .kk-srch-body { padding-bottom: 24px; }
}

/* ---- STEP 2b: SEAMLESS SPLIT HERO on desktop ----------------------- */
/* Phone keeps original full-bleed tall hero (untouched).
   Desktop: blurred cover fills the whole hero (aspect-proof), the sharp
   cover floats on the left, text on the right, and the bottom fades into
   the library so the page reads as one continuous surface (like mobile). */

@media (min-width: 1024px) and (orientation: landscape) {
  .kk-hero {
    display: grid;
    grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
    align-items: center;
    min-height: 100vh;  /* fallback for browsers without svh */
    min-height: 100svh; /* Chrome Android: the short, URL-bar-visible height */
    /* full-screen landing hero; library is a deliberate scroll down.
       keep original -52px pull so the morphing top bar floats
       transparently over the hero, exactly like on mobile.
       overflow visible so the blurred backdrop can bleed past the
       hero and dissolve over the library (no boundary line). #app
       still clips sideways spill. */
    position: relative;
    overflow: visible;
  }

  /* Container only; its own image is hidden, layers do the work */
  .kk-hero-bg {
    position: absolute;
    inset: 0;
    grid-column: 1 / -1;
    background-image: none !important;
  }
  /* Ambient: blurred + dim full-bleed cover. Blur hides any crop, so
     every cover aspect ratio looks intentional. */
  .kk-hero-bg::before {
    content: '';
    position: absolute;
    /* extend a short way below the hero so the blur ends just under
       the continue card, fading across the seam (not at it) */
    inset: 0 0 -16vh 0;
    background-image: var(--kk-cover);
    background-size: cover;
    background-position: center;
    filter: blur(17px) saturate(1.2) contrast(1.06);
    transform: scale(1.12);
    /* 100% opaque blur through the whole hero (first page); the
       dissolve only begins at the library top and finishes inside
       the library — no boundary line. */
    -webkit-mask-image: linear-gradient(to bottom,
      #000 0%, #000 78%, rgba(0,0,0,0.4) 90%, transparent 100%);
    mask-image: linear-gradient(to bottom,
      #000 0%, #000 78%, rgba(0,0,0,0.4) 90%, transparent 100%);
  }
  /* Sharp cover, floating on the left, never cropped, soft shadow */
  .kk-hero-bg::after {
    content: '';
    position: absolute;
    left: 5%;
    top: 7%;
    width: 42%;
    height: 86%;
    background-image: var(--kk-cover);
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
  }

  /* Top darken keeps the transparent morphing bar legible (like mobile);
     long bottom ramp melts the hero into the library = seamless */
  .kk-hero-grad {
    display: block;
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom,
      rgba(20, 23, 26, 0.6) 0%,
      rgba(20, 23, 26, 0.28) 16%,
      transparent 33%,
      transparent 100%);
  }

  /* Right: greeting / title / progress / Resume, vertically centered */
  .kk-hero-body {
    grid-column: 2;
    position: relative;
    z-index: 2;
    align-self: center;
    padding: 48px clamp(40px, 5vw, 88px);
    gap: 10px;
    max-width: 580px;
  }
  .kk-hero-greet { font-size: 34px; }
  .kk-hero-title {
    font-size: 30px;
    white-space: normal;
    overflow: visible;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
  }
  .kk-hero-resume {
    width: auto;
    align-self: flex-start;
    padding: 0 40px;
    margin-top: 14px;
    transition: filter 0.12s, transform 0.12s;
  }
  .kk-hero-resume:hover { filter: brightness(1.06); transform: translateY(-1px); }

  /* Mobile drag pill is meaningless on desktop */
  .kk-hero-pill-wrap { display: none; }
}

/* ---- STEP 5: READING SCREEN — comfy centered column ---------------- */
/* CSS-only. The sacred sub-list / sync path is untouched: this only
   constrains line width and centers the floating pills. The pills keep
   left:0/right:0 + margin auto so their show/hide translateY transform
   is never overridden. */

@media (min-width: 1024px) and (orientation: landscape) {
  .kk-read-text { align-items: center; }
  /* Vertical text: keep the mobile behaviour (lines stretch to fill the column
     height) so the active glow box spans the full line like on phone, instead of
     shrinking tight to the characters. align-items:center above is for horizontal. */
  .kk-read.vertical .kk-read-text { align-items: stretch; }
  .kk-read-line {
    width: 100%;
    max-width: 720px;
  }

  .kk-top,
  .kk-bot {
    left: 0;
    right: 0;
    margin-inline: auto;
    width: calc(100% - 24px);
    max-width: 760px;
  }
}

/* ---- STEP 6: READER OVERLAYS + SHEETS ----------------------------- */
/* CSS-only, no JS / forbidden files. Reader bottom bars get the same
   centered cap as the transport pill (consistent). Sheets become
   centered scale-in modals on wide screens; phone keeps the bottom
   slide-up sheet exactly as before. */

@media (min-width: 1024px) and (orientation: landscape) {

  /* Util strip / EPUB-TTS bar / translation card: centered + capped.
     left/right:0 + margin auto preserves each element's own
     show/hide translateY transform. */
  .kk-util-strip,
  .kk-fn-bar,
  .kk-trans-card {
    left: 0;
    right: 0;
    margin-inline: auto;
    width: calc(100% - 24px);
    max-width: 760px;
  }

  /* Focus-mode line matches the reading column */
  .kk-focus-line { max-width: 720px; }

  /* Generic .sheet (chapters, stats, mine) -> centered modal */
  .sheet-card {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    width: min(560px, 92vw);
    max-height: 85%;
    border-radius: var(--kk-r-lg);
    transform: translate(-50%, -50%) scale(0.96);
  }
  .sheet.open .sheet-card {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  .sheet.closing .sheet-card {
    transform: translate(-50%, -50%) scale(0.96);
    opacity: 0;
  }

  /* .kk-sheet (settings + subpanels + generic) -> centered modal */
  .kk-sheet {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    width: min(560px, 92vw);
    max-height: 85%;
    border: 1px solid var(--kk-line);
    border-radius: var(--kk-r-lg);
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.96);
    transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1),
                opacity 0.3s ease, visibility 0.3s;
  }
  .kk-sheet.open {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }

  /* Settings sheet height + inner scroll are now handled by the base
     (#kk-settings-sheet max-height:85%, .settings-list flex:1; min-height:0)
     so it is correct on every screen — no desktop-specific re-cap needed. */
}

/* ---- STEP 6b: LOOKUP CARD / CONFIRM / SELECTION SHEET / TOAST ------ */
/* Consistent with the sheet-modal treatment. Phone untouched.
   Word-card + confirm use CSS class toggles (safe to fully center).
   The search selection sheet toggles transform inline via JS, so it is
   only centered + capped here (its slide-up transform is left alone). */

@media (min-width: 1024px) and (orientation: landscape) {

  /* Word lookup / "Mine to Anki" card: floats like the search
     selection popover — slides up on long-press (transform left to the
     base rules), capped + centered, lifted off the bottom, all corners
     rounded. */
  .kk-word-card {
    left: 0;
    right: 0;
    margin-inline: auto;
    width: calc(100% - 24px);
    max-width: 600px;
    bottom: 28px;
    border: 1px solid var(--kk-line-2);
    border-radius: var(--kk-r-lg);
    /* base hide is translateY(100%); with the 28px lift that leaves a
       28px sliver poking above the bottom edge. Clear the lift too so
       the card is fully hidden until .open (which keeps translateY(0),
       higher specificity, so the slide-up still works). */
    transform: translateY(calc(100% + 28px + var(--safe-bottom)));
  }

  /* Confirm dialog -> centered dialog (not full-width bottom) */
  .confirm {
    align-items: center;
    justify-content: center;
  }
  .confirm-sheet {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    margin: 0;
    width: min(440px, 92vw);
  }

  /* Search multi-select action sheet: centered + capped.
     left/right/width only — JS owns its translateY slide. */
  .kk-msheet {
    left: 0 !important;
    right: 0 !important;
    margin-inline: auto !important;
    width: calc(100% - 24px) !important;
    max-width: 440px !important;
    border: 1px solid var(--kk-line) !important;
  }

  /* Toasts never span the screen */
  .toast { max-width: 460px; }
}

/* ---- STEP 6c: SNACKBARS + SELECTION SHEET POLISH ------------------ */
/* The undo / "Can't reach Anki" snackbars are full-width bottom bars
   built with inline styles (ids) — !important is required to beat the
   inline left/right. Their show/hide transform is left untouched. */

@media (min-width: 1024px) and (orientation: landscape) {
  #kk-undo-toast,
  #kk-study-undo-toast,
  .kk-study-anki-toast {
    left: 0 !important;
    right: 0 !important;
    margin-inline: auto !important;
    width: calc(100% - 24px) !important;
    max-width: 520px !important;
  }

  /* Selection action sheet: drop the mobile drag handle, round all
     corners and lift off the bottom edge so it reads as a deliberate
     centered popover instead of a stuck strip with a stray thumb. */
  .kk-msheet {
    bottom: 28px !important;
    border-radius: var(--kk-r-lg) !important;
    /* inline padding is 16px top / ~80px bottom — even it out */
    padding: 16px 0 !important;
    overflow: hidden;
  }
  .kk-msheet > div:first-child { display: none; }
}

/* ---- A11Y: respect "reduce motion" --------------------------------- */
/* Scoped to the wide-screen polish transitions/lifts added in this
   responsive region only. Does NOT touch the reading sync / active-line
   path or any core animation — purely the decorative hover/scale feedback. */
@media (prefers-reduced-motion: reduce) {
  .kk-tab,
  .kk-strip-item,
  .kk-series-row-right,
  .kk-srch-row,
  .kk-study-group-header,
  .kk-vd-vol-row,
  .kk-hero-resume,
  .kk-sheet,
  .sheet-card,
  .kk-word-card,
  .kk-msheet,
  .kk-trans-card,
  .kk-util-strip,
  .kk-fn-bar,
  #kk-undo-toast,
  #kk-study-undo-toast,
  .kk-study-anki-toast,
  .kk-read-line {
    transition: none !important;
    animation: none !important;
  }
  .kk-strip-item:hover,
  .kk-hero-resume:hover { transform: none !important; }
  /* View Transitions: disable morph when user prefers reduced motion */
  ::view-transition-group(*),
  ::view-transition-old(root),
  ::view-transition-new(root) { animation-duration: 0s !important; }
}

/* ---- STEP 7: KEYBOARD FOCUS RINGS (desktop a11y) ------------------- */
/* The app globally hides focus rings (`*:focus-visible{outline:none}`,
   style.css:1). That is fine on a touch phone but the desktop layout is
   used with a keyboard, so tab/grid/row navigation must be visible.
   Scoped to the wide layout + keyboard focus only (:focus-visible never
   fires on touch/mouse), so the phone is byte-identical. Higher
   specificity than the global rule, so it wins without !important. */
@media (min-width: 1024px) and (orientation: landscape) {
  .kk-tab:focus-visible,
  .kk-hero-resume:focus-visible,
  .kk-series-row-right:focus-visible,
  .kk-srch-row:focus-visible,
  .kk-study-group-header:focus-visible,
  .kk-vd-vol-row:focus-visible {
    outline: 2px solid var(--kk-acc-line);
    outline-offset: 2px;
    border-radius: 8px;
  }
  .kk-strip-item:focus-visible {
    outline: none;
  }
  .kk-strip-item:focus-visible .kk-strip-cover {
    outline: 2px solid var(--kk-acc-line);
    outline-offset: 2px;
  }
}

/* === COMPONENT: Mini Player Popup === */
.kk-mini {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(64px + var(--safe-bottom) + 8px);
  height: 56px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: var(--cover-tint-pop, var(--cover-tint, var(--kk-surface)));
  border: 1px solid var(--kk-acc-line, var(--kk-line));
  border-radius: 14px;
  box-shadow: 0 6px 18px -6px rgba(0,0,0,0.35);
  z-index: 19;
  opacity: 0;
  transform: translateY(16px);
  pointer-events: none;
  transition: opacity 220ms cubic-bezier(0.25,0.46,0.45,0.94),
              transform 220ms cubic-bezier(0.25,0.46,0.45,0.94),
              background 700ms ease,
              border-color 700ms ease;
  overflow: hidden;
}
.kk-mini-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: rgba(255,255,255,0.06);
  z-index: 1;
}
.kk-mini-bar > i {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--kk-acc);
  transition: width 200ms linear, background 700ms ease;
}
.kk-mini-badge {
  font-family: var(--kk-font-mono, monospace);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 6px;
  border-radius: 4px;
  background: var(--kk-acc-soft);
  color: var(--kk-acc);
  border: 1px solid var(--kk-acc-line);
  flex-shrink: 0;
  line-height: 1;
  align-self: center;
  transition: background 700ms ease, color 700ms ease, border-color 700ms ease;
}
.kk-mini-badge[hidden] { display: none; }
.kk-mini.is-open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}
.kk-mini.hidden { display: none; }
/* Hide outside library view */
#app[data-view="player"] .kk-mini,
#app[data-view="m4b"] .kk-mini,
#app[data-view="volume-detail"] .kk-mini,
#app[data-view="search"] .kk-mini,
#app[data-view="study"] .kk-mini,
#app[data-view="favorites"] .kk-mini,
#app[data-view="firstlaunch"] .kk-mini {
  display: none;
}
.kk-mini-body {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 0;
  padding: 0;
  min-width: 0;
  text-align: left;
  color: inherit;
  cursor: pointer;
}
.kk-mini-cover {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  background: var(--kk-surface-2);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--kk-text-2);
}
.kk-mini-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kk-mini-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kk-mini-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--kk-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kk-mini-sub {
  font-size: 11px;
  color: var(--kk-text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kk-mini-pp {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--kk-text);
  color: var(--kk-bg);
  border: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.kk-mini-pp svg { width: 18px; height: 18px; fill: currentColor; }

@media (min-width: 768px) {
  /* Cap the mini-player width on larger screens so it stays "mini" — fixed
     ~520px max, centered between the side rails. */
  .kk-mini {
    left: 50%;
    right: auto;
    transform: translateX(-50%) translateY(16px);
    width: min(520px, calc(100vw - 24px));
  }
  .kk-mini.is-open {
    transform: translateX(-50%) translateY(0);
  }
}
@media (min-width: 1024px) and (orientation: landscape) {
  .kk-mini {
    /* Same 520px cap on desktop landscape. The transform-based centering
       above already takes care of placement; just leave left/right alone. */
  }
}

/* === COMPONENT: M4B Player View (Spec 2) === */
#view-m4b { position: absolute; inset: 0; display: flex; flex-direction: column; }
#view-m4b.hidden { display: none; }
.kk-m4b {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--kk-bg);
  color: var(--kk-text);
  position: relative;
}
/* Cover-tinted glow on the M4B player background. */
.kk-m4b::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(150% 70% at 50% 0%, var(--kk-acc-glow, transparent) 0%, transparent 78%),
    linear-gradient(180deg, var(--cover-tint-deep, var(--kk-bg)) 0%, var(--kk-bg) 50%, var(--kk-bg) 100%);
  transition: background 700ms ease;
  pointer-events: none;
}
.kk-m4b > * { position: relative; z-index: 1; }
.kk-m4b > .kk-pomo-cap { position: absolute; }
.kk-m4b-top {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 14px;
  gap: 10px;
  min-height: 56px;
  transition: opacity .25s, transform .25s;
}
.kk-m4b-top > .kk-m4b-back,
.kk-m4b-top > .kk-m4b-menu,
.kk-m4b-top > .kk-immersion-exit {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}
.kk-m4b-top > .kk-m4b-back { left: 10px; }
.kk-m4b-top > .kk-m4b-menu { right: 10px; }
.kk-m4b-top > .kk-immersion-exit { right: 10px; display: none; background: var(--kk-surface); }
.kk-m4b-top > button {
  background: transparent;
  border: 0;
  color: var(--kk-text);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.kk-m4b-top > button svg { width: 20px; height: 20px; }
.kk-m4b-reader-btn {
  width: auto !important;
  padding: 0 14px;
  gap: 6px;
  border: 1px solid var(--kk-line) !important;
  border-radius: 18px !important;
  font-size: 13px;
  font-weight: 600;
}
.kk-m4b-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 20px 12px 20px;
  gap: 12px;
  overflow: hidden;
}
.kk-m4b-cover {
  width: min(260px, 60vw);
  height: min(260px, 60vw);
  border-radius: 12px;
  background: var(--kk-surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
  font-weight: 700;
  color: var(--kk-text-2);
  overflow: hidden;
  box-shadow: 0 10px 28px -10px rgba(0,0,0,0.4);
}
.kk-m4b-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.kk-m4b-title {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  max-width: 100%;
}
.kk-m4b-sub { font-size: 13px; color: var(--kk-text-2); text-align: center; }
.kk-m4b-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 4px;
}
.kk-m4b-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid var(--kk-line);
  background: transparent;
  color: var(--kk-text);
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}
.kk-m4b-chip.is-static { cursor: default; }
.kk-m4b-chip.is-hot {
  border-color: var(--kk-acc);
  color: var(--kk-acc);
}
.kk-m4b-chip.is-hidden { display: none; }
.kk-m4b-chip svg { width: 12px; height: 12px; }
.kk-m4b { position: relative; }
.kk-m4b-bot {
  padding: 12px 20px calc(20px + var(--safe-bottom)) 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-areas:
    "prog prog"
    "tcurr ttotal"
    "controls controls";
  column-gap: 8px;
  row-gap: 6px;
  border-top: 1px solid var(--kk-line);
  background: var(--kk-surface);
  border-radius: 0;
  border-left: 0; border-right: 0;
  transition: opacity .25s, transform .25s;
}
.kk-m4b-bot .kk-m4b-prog { grid-area: prog; }
.kk-m4b-bot .kk-m4b-controls { grid-area: controls; }
.kk-m4b-time { font-size: 11px; color: var(--kk-text-2); font-variant-numeric: tabular-nums; align-self: center; }
.kk-m4b-time-l { grid-area: tcurr; text-align: left; }
.kk-m4b-time-r { grid-area: ttotal; text-align: right; }
.kk-m4b-prog {
  position: relative;
  height: 16px;
  display: flex;
  align-items: center;
  cursor: pointer;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
.kk-m4b-prog::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 2px;
  background: var(--kk-line);
}
.kk-m4b-prog > i {
  position: relative;
  display: block;
  height: 3px;
  width: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: var(--kk-acc);
  border-radius: 2px;
  transition: transform 200ms linear;
  z-index: 1;
}
/* Scrubbing state: fatter track + fatter fill, no width transition so the
   handle tracks the finger 1:1 instead of easing 200ms behind. Mode-specific
   rules below adjust the resting height; this one only governs drag. */
.kk-m4b-prog.is-scrubbing {
  height: 28px;
}
.kk-m4b-prog.is-scrubbing::before {
  height: 6px;
  border-radius: 3px;
}
.kk-m4b-prog.is-scrubbing > i {
  height: 6px;
  border-radius: 3px;
  transition: none;
}
/* Slider thumb during drag — matches .slider-thumb (settings sliders) so
   the visual is consistent with every other draggable handle in the app. */
.kk-m4b-prog::after {
  content: "";
  position: absolute;
  top: 50%;
  left: calc(var(--frac, 0) * 100%);
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
  transform: translate(-50%, -50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
  z-index: 2;
}
.kk-m4b-prog.is-scrubbing::after {
  opacity: 1;
}
.kk-m4b-times {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--kk-text-2);
  font-variant-numeric: tabular-nums;
}
.kk-m4b-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.kk-m4b-controls button {
  background: transparent;
  border: 0;
  color: var(--kk-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.kk-m4b-skip { font-size: 12px; font-weight: 700; min-width: 44px; }
.kk-m4b-prev, .kk-m4b-next { width: 44px; height: 44px; }
.kk-m4b-prev svg, .kk-m4b-next svg { width: 22px; height: 22px; }
.kk-m4b-rewind { width: 44px; height: 44px; }
.kk-m4b-rewind svg { width: 20px; height: 20px; }
/* Rewind is a reader-mode-only control; fully removed from flex flow in m4b
   cover mode so the hidden slot+gap doesn't shift the other controls off-center. */
#view-m4b[data-mode="m4b"] .kk-m4b-rewind {
  display: none;
}
.kk-m4b-controls .kk-m4b-play {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--kk-text);
  color: var(--kk-bg) !important;
}
.kk-m4b-play svg { width: 28px; height: 28px; }
#app[data-view="m4b"] #kk-tab-bar { display: none; }

/* === COMPONENT: M4B <-> Reader Morph (Spec 3) === */
.kk-morph-stage { flex: 1; position: relative; overflow: hidden; }
.kk-morph-hero,
.kk-morph-reader { position: absolute; inset: 0; }
.kk-morph-hero { display: flex; flex-direction: column; }
.kk-morph-hero > .kk-m4b-stage { flex: 1; }

/* Portrait m4b mode (phone AND tablet): lay the player out as a grid that fills
   exactly one screen — top bar, cover/title/chips (flexible), transport pinned
   at the very bottom. The series queue is the next grid row, sitting BELOW the
   fold so it only appears when you scroll down (no peeking under the controls).
   .kk-m4b is already overflow-y:auto in m4b mode (see rule below). Landscape
   tablet keeps its own 2-column grid. */
@media (orientation: portrait) {
  #view-m4b[data-mode="m4b"] .kk-m4b {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;   /* top | hero (fills) | transport */
    grid-auto-rows: 0;                   /* implicit queue row = 0 height so it
                                            does NOT steal space from the 1fr
                                            hero; its content overflows below
                                            the fold and is reached by scrolling */
  }
  #view-m4b[data-mode="m4b"] .kk-morph-stage {
    min-height: 0;                       /* the 1fr track sizes it */
    overflow: visible;
  }
  #view-m4b[data-mode="m4b"] .kk-morph-hero {
    position: relative; inset: auto; height: 100%;
  }
  #view-m4b[data-mode="m4b"] .kk-m4b-stage { overflow: visible; padding-top: 32px; }
}

/* M4B mode (default) */
#view-m4b[data-mode="m4b"] .kk-morph-hero {
  opacity: 1; transform: none; pointer-events: auto;
  transition: opacity 220ms ease, transform 280ms cubic-bezier(0.25,0.46,0.45,0.94);
}
#view-m4b[data-mode="m4b"] .kk-morph-reader {
  opacity: 0; pointer-events: none;
  transform: translateY(12px);
  transition: opacity 200ms ease, transform 240ms cubic-bezier(0.25,0.46,0.45,0.94);
}
#view-m4b[data-mode="m4b"] .kk-m4b-title-lockup {
  opacity: 0; pointer-events: none; transform: translateY(-4px);
  transition: opacity 180ms ease, transform 240ms ease;
}

/* Reader mode */
#view-m4b[data-mode="reader"] .kk-morph-hero {
  opacity: 0; pointer-events: none;
  transform: scale(0.92) translateY(-8px);
  transition: opacity 200ms ease, transform 260ms cubic-bezier(0.25,0.46,0.45,0.94);
}
#view-m4b[data-mode="reader"] .kk-morph-reader {
  opacity: 1; pointer-events: auto;
  transform: translateY(0);
  transition: opacity 240ms ease 60ms, transform 280ms cubic-bezier(0.25,0.46,0.45,0.94);
}
#view-m4b[data-mode="reader"] .kk-m4b-title-lockup {
  opacity: 1; pointer-events: auto; transform: translateY(0);
  transition: opacity 220ms ease 80ms, transform 240ms ease 60ms;
}
#view-m4b[data-mode="reader"] .kk-m4b-reader-btn { display: none; }

/* Top-bar lockup look (override .kk-m4b-top > button) */
.kk-m4b-top > button.kk-m4b-title-lockup {
  width: auto; height: auto;
  display: flex; align-items: center; justify-content: center;
  gap: 8px;
  background: transparent; border: 0; color: var(--kk-text);
  padding: 4px 8px; border-radius: 12px; cursor: pointer;
  min-width: 0; max-width: 0; overflow: hidden;
  transition: max-width 240ms ease, padding 240ms ease, opacity 220ms ease 80ms;
}
#view-m4b[data-mode="reader"] .kk-m4b-title-lockup {
  max-width: calc(100% - 96px);
  flex: 0 1 auto;
}
#view-m4b[data-mode="reader"] .kk-m4b-lockup-info {
  align-items: flex-start; text-align: left;
  flex: 0 1 auto;
  min-width: 0;
}
.kk-m4b-lockup-cover {
  width: 28px; height: 28px; border-radius: 6px; flex-shrink: 0;
  background: var(--kk-surface-2); overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--kk-text-2);
}
.kk-m4b-lockup-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kk-m4b-lockup-info { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-width: 0; flex: 1; }
.kk-m4b-lockup-title { font-size: 12px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.kk-m4b-lockup-sub   { font-size: 10px; color: var(--kk-text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* Reader layer hosts #sub-list directly while in M4B view.
   The default .kk-read-text padding (80px top / 130px bottom) was sized for
   the original view-player where kk-top and kk-bot are ABSOLUTE z=10 children
   of #kk-read that overlap the scroll area. In m4b view the top bar is a
   real flex sibling so morph-reader already starts BELOW it, and the bottom
   pill sits at bottom:16+safe-bottom (height ~64). Override paddings to
   match this layout — too-large top wastes header space, too-large bottom
   creates the "huge gap" the user reported. */
.kk-morph-reader > #sub-list {
  /* Inset the SCROLL CONTAINER itself so it lives between the top bar and
     the bottom transport pill (+ chap line). With the container physically
     shorter, scrollIntoView({block:'center'}) naturally centers the active
     line in the visible reader band. No scroll-padding hacks needed — those
     stack badly with the inherited .kk-read-text content padding. */
  position: absolute;
  top: 64px;
  left: 0;
  right: 0;
  bottom: calc(120px + var(--safe-bottom));
  padding: 20px 26px;
}

/* Util strip + tap-zone, when parked inside M4B reader layer.
   Container is position:absolute inset:0, so absolute children resolve to it. */
.kk-morph-reader > .kk-tap-zone { z-index: 5; }
/* Util strip sits at the same bottom anchor as the m4b pill (kk-m4b-bot)
   so the two swap cleanly — matches the original view-player kk-bot ↔ strip
   behavior. The default .kk-util-strip transform translateY(100% + 30px)
   pushes the closed state offscreen below. */
.kk-morph-reader > .kk-util-strip {
  bottom: calc(var(--safe-bottom) + 16px);
}
/* In m4b cover mode, fully hide the util strip + tap-zone parked in morph-reader. */
#view-m4b[data-mode="m4b"] .kk-morph-reader > .kk-util-strip,
#view-m4b[data-mode="m4b"] .kk-morph-reader > .kk-tap-zone {
  display: none;
}

/* Transport morphs in reader mode into the original reader pill:
   floating, surface bg, pill border, surface-2 circles + accent disc.
   Spring-ish easing + a touch of overshoot makes the morph feel less
   stiff than the previous linear ease. */
.kk-m4b-bot,
.kk-m4b-bot .kk-m4b-prog,
.kk-m4b-bot .kk-m4b-controls,
.kk-m4b-bot .kk-m4b-play,
.kk-m4b-bot .kk-m4b-prev,
.kk-m4b-bot .kk-m4b-next,
.kk-m4b-bot .kk-m4b-skip,
.kk-m4b-bot .kk-m4b-time {
  transition:
    width 300ms cubic-bezier(0.34, 1.2, 0.5, 1),
    height 300ms cubic-bezier(0.34, 1.2, 0.5, 1),
    max-width 300ms cubic-bezier(0.34, 1.2, 0.5, 1),
    padding 300ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 300ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity 240ms ease,
    background 280ms ease,
    border-color 280ms ease,
    border-radius 300ms cubic-bezier(0.22, 1, 0.36, 1),
    left 300ms cubic-bezier(0.22, 1, 0.36, 1),
    right 300ms cubic-bezier(0.22, 1, 0.36, 1),
    bottom 300ms cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 300ms ease;
}
.kk-m4b-bot {
  will-change: transform, left, right, bottom, border-radius, padding;
}
.kk-m4b-bot .kk-m4b-play {
  will-change: width, height, border-radius;
}
/* Brief glow during morph so the user sees the pill "become" a pill. */
#view-m4b[data-mode="reader"] .kk-m4b-bot {
  box-shadow: 0 6px 24px -10px rgba(0,0,0,0.45);
}

#view-m4b[data-mode="reader"] .kk-m4b-bot {
  position: absolute;
  left: 12px; right: 12px;
  bottom: calc(var(--safe-bottom) + 16px);
  padding: 6px 14px 8px;
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-lg);
  z-index: 10;
  grid-template-columns: 50px 1fr 50px;
  grid-template-areas:
    "prog prog prog"
    "tcurr controls ttotal";
  column-gap: 6px;
  row-gap: 4px;
  box-shadow: 0 4px 14px -8px rgba(0,0,0,0.25);
}
#view-m4b[data-mode="reader"] .kk-m4b-prog {
  display: flex;
  height: 12px;
  margin: 0 -4px 2px;
}
#view-m4b[data-mode="reader"] .kk-m4b-prog::before { height: 2px; }
#view-m4b[data-mode="reader"] .kk-m4b-prog > i { height: 2px; }
#view-m4b[data-mode="reader"] .kk-m4b-prog.is-scrubbing { height: 22px; }
#view-m4b[data-mode="reader"] .kk-m4b-prog.is-scrubbing::before { height: 5px; }
#view-m4b[data-mode="reader"] .kk-m4b-prog.is-scrubbing > i { height: 5px; transition: none; }
#view-m4b[data-mode="reader"] .kk-m4b-time { font-size: 11px; font-family: var(--kk-font-mono); }
#view-m4b[data-mode="reader"] .kk-m4b-time-r { text-align: right; }
/* Chapter + author line below the reader transport. Hidden in M4B-only mode. */
.kk-m4b-reader-chap {
  display: none;
  font-size: 11px;
  color: var(--kk-text-2);
  text-align: center;
  padding: 8px 14px 0;
  font-family: var(--kk-font-ui);
  letter-spacing: 0.02em;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  grid-column: 1 / -1;
}
#view-m4b[data-mode="reader"] .kk-m4b-reader-chap { display: block; }
/* Quieter player buttons in reader mode so they don't fight the text.
   Brighten on press/focus/hover. */
#view-m4b[data-mode="reader"] .kk-m4b-controls > button {
  opacity: 0.7;
  transition: opacity 180ms ease;
}
#view-m4b[data-mode="reader"] .kk-m4b-controls > button:hover,
#view-m4b[data-mode="reader"] .kk-m4b-controls > button:active,
#view-m4b[data-mode="reader"] .kk-m4b-controls > button:focus-visible {
  opacity: 1;
}
@media (min-width: 768px) {
  #view-m4b[data-mode="reader"] .kk-m4b-time { font-size: 14px; }
  #view-m4b[data-mode="reader"] .kk-m4b-bot {
    grid-template-columns: 70px 1fr 90px;
  }
  .kk-bot-time { font-size: 13px; }
}
@media (min-width: 1024px) {
  #view-m4b[data-mode="reader"] .kk-m4b-time { font-size: 16px; }
  #view-m4b[data-mode="reader"] .kk-m4b-bot {
    grid-template-columns: 80px 1fr 100px;
  }
  .kk-bot-time { font-size: 15px; }
}

#view-m4b[data-mode="reader"] .kk-m4b-controls {
  justify-content: center;
  gap: 12px;
}
#view-m4b[data-mode="reader"] .kk-m4b-skip {
  max-width: 0; min-width: 0; padding: 0; opacity: 0; overflow: hidden; pointer-events: none;
}
#view-m4b[data-mode="reader"] .kk-m4b-prev,
#view-m4b[data-mode="reader"] .kk-m4b-next,
#view-m4b[data-mode="reader"] .kk-m4b-rewind {
  width: 40px; height: 40px;
  background: var(--kk-surface-2);
  border-radius: 50%;
  color: var(--kk-text);
}
#view-m4b[data-mode="reader"] .kk-m4b-prev svg,
#view-m4b[data-mode="reader"] .kk-m4b-next svg { width: 20px; height: 20px; }
#view-m4b[data-mode="reader"] .kk-m4b-rewind svg { width: 18px; height: 18px; }
#view-m4b[data-mode="reader"] .kk-m4b-controls .kk-m4b-play {
  width: 48px; height: 48px;
}
#view-m4b[data-mode="reader"] .kk-m4b-play svg { width: 18px; height: 18px; }

/* === Larger viewports: scale M4B time labels proportionally === */
@media (min-width: 768px) {
  .kk-m4b-time { font-size: 14px; }
}
@media (min-width: 1024px) {
  .kk-m4b-time { font-size: 16px; }
}

/* === Narrow viewport (Chrome Android 360x800 baseline) === */
@media (max-width: 400px) {
  /* M4B view: tighten side padding so 5-button pill fits cleanly. */
  .kk-m4b-bot {
    padding: 10px 12px calc(16px + var(--safe-bottom)) 12px;
    column-gap: 6px;
  }
  .kk-m4b-controls { gap: 4px; }
  .kk-m4b-skip { min-width: 38px; font-size: 11px; }
  .kk-m4b-prev, .kk-m4b-next { width: 40px; height: 40px; }
  .kk-m4b-prev svg, .kk-m4b-next svg { width: 20px; height: 20px; }
  .kk-m4b-controls .kk-m4b-play { width: 56px; height: 56px; }
  .kk-m4b-play svg { width: 24px; height: 24px; }
  /* Top bar: reduce gap + padding so back/lockup/reader-btn/menu all fit. */
  .kk-m4b-top { padding: 10px 10px; min-height: 52px; gap: 6px; }
  .kk-m4b-top > button { width: 36px; height: 36px; }
  .kk-m4b-top > button svg { width: 18px; height: 18px; }
  .kk-m4b-reader-btn { padding: 0 10px; font-size: 12px; }
  /* Hero stage: cover sized for narrow screens, less vertical padding. */
  .kk-m4b-stage { padding: 16px 16px 8px 16px; gap: 10px; }
  .kk-m4b-cover { width: min(220px, 56vw); height: min(220px, 56vw); }
  .kk-m4b-title { font-size: 18px; }
  .kk-m4b-chip { padding: 4px 8px; font-size: 10px; }
  /* Reader-mode pill: snug horizontals so prev/rewind/play/next fit. */
  #view-m4b[data-mode="reader"] .kk-m4b-bot {
    left: 8px; right: 8px; padding: 6px 10px;
    grid-template-columns: 44px 1fr 44px;
    column-gap: 4px;
  }
  #view-m4b[data-mode="reader"] .kk-m4b-controls { gap: 8px; }
  #view-m4b[data-mode="reader"] .kk-m4b-prev,
  #view-m4b[data-mode="reader"] .kk-m4b-next,
  #view-m4b[data-mode="reader"] .kk-m4b-rewind {
    width: 36px; height: 36px;
  }
  #view-m4b[data-mode="reader"] .kk-m4b-controls .kk-m4b-play {
    width: 44px; height: 44px;
  }
  /* Library bar stats: shrink gap so 3 stats fit at 360px. */
  .kk-lib-bar-r { gap: 8px; }
  .kk-lib-bar-stat { padding: 0 4px; font-size: 12px; }
}

/* ====================================================================
   SPEC 4 v3 — M4B QUEUE + TABLET LANDSCAPE + DESKTOP (Phase 8, 2.8.05)
   Mobile (default): single-column scrollable, queue inline below transport.
   Tablet landscape (1024-1279 landscape): 2-col grid, queue right column.
                                            Adds NOW LISTENING label + mode pill.
   Desktop (>=1280 landscape): 3-col grid, prototype left nav rail + center + queue.
                               NO bottom transport bar — transport stays in center.
   ==================================================================== */

/* Shared queue panel styling */
.kk-m4b-queue-hd {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--kk-line);
}
.kk-m4b-queue-lbl {
  font-family: var(--kk-font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--kk-text-3);
  font-weight: 700;
  text-transform: uppercase;
}
.kk-m4b-queue-title {
  font-family: var(--kk-font-jp);
  font-size: 15px;
  font-weight: 600;
  margin-top: 4px;
  color: var(--kk-text);
}
.kk-m4b-queue-list {
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kk-m4b-q-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.kk-m4b-q-row:active,
.kk-m4b-q-row:hover { background: var(--kk-surface-2); }
.kk-m4b-q-row.is-active {
  background: var(--kk-acc-soft);
  border-left: 2px solid var(--kk-acc);
  padding-left: 8px;
}
.kk-m4b-q-row.is-active .kk-m4b-q-title { color: var(--kk-acc); }
.kk-m4b-q-cover {
  width: 40px; height: 40px;
  border-radius: 6px;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--kk-surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700;
  color: var(--kk-text-2);
}
.kk-m4b-q-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kk-m4b-q-info { flex: 1; min-width: 0; }
.kk-m4b-q-title {
  font-family: var(--kk-font-jp);
  font-size: 13px; font-weight: 500;
  color: var(--kk-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kk-m4b-q-sub {
  font-family: var(--kk-font-mono);
  font-size: 10px;
  color: var(--kk-text-3);
  letter-spacing: 0.2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kk-m4b-q-time {
  font-family: var(--kk-font-mono);
  font-size: 10px;
  color: var(--kk-text-3);
  font-variant-numeric: tabular-nums;
}

/* Hero label in top bar (NOW LISTENING · series). Hidden on mobile. */
.kk-m4b-top-hero { display: none; }
.kk-m4b-top-lbl {
  font-family: var(--kk-font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--kk-text-3);
  font-weight: 700;
}
.kk-m4b-top-series {
  font-family: var(--kk-font-jp);
  font-size: 15px;
  font-weight: 600;
  color: var(--kk-text);
  margin-left: 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 240px;
}

/* Mode pill (audio | reader). Hidden on mobile — existing Reader button does this. */
.kk-m4b-mode-pill { display: none; }
.kk-m4b-mode-pill {
  align-items: center;
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--kk-line);
  border-radius: var(--kk-r-pill);
  padding: 3px;
  gap: 2px;
}
.kk-m4b-mode-pill button {
  width: 36px; height: 26px;
  border-radius: var(--kk-r-pill);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--kk-text-3);
  transition: background 180ms, color 180ms;
}
.kk-m4b-mode-pill button.is-on {
  background: var(--kk-text);
  color: var(--kk-bg);
}

/* Desktop left nav rail — hidden on mobile and tablet landscape. */
.kk-m4b-dsk-nav { display: none; }

/* === Mobile (default): queue inline below transport === */
.kk-m4b-queue {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--kk-line);
  background: var(--kk-bg);
  flex-shrink: 0;
}
#view-m4b[data-mode="m4b"] .kk-m4b {
  overflow-y: auto;
  overflow-x: hidden;
}
#view-m4b[data-mode="reader"] .kk-m4b-queue { display: none; }

/* === Tablet landscape (1024-1279 AND landscape): 2-col grid === */
@media (min-width: 1024px) and (orientation: landscape) {
  #view-m4b[data-mode="m4b"] .kk-m4b,
  #view-m4b[data-mode="reader"] .kk-m4b {
    display: grid;
    grid-template-columns: 1fr 380px;
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "top    queue"
      "stage  queue"
      "bot    queue";
    overflow: hidden;
  }
  #view-m4b .kk-m4b-top    { grid-area: top; }
  #view-m4b .kk-morph-stage { grid-area: stage; }
  #view-m4b .kk-m4b-bot    { grid-area: bot; }
  #view-m4b .kk-m4b-queue {
    grid-area: queue;
    display: flex !important;
    border-top: 0;
    border-left: 1px solid var(--kk-line);
    background: rgba(0,0,0,0.18);
    overflow: hidden;
  }
  #view-m4b .kk-m4b-queue-list {
    flex: 1;
    overflow-y: auto;
  }

  /* Show hero label + mode pill, hide the small title lockup + Reader button. */
  #view-m4b .kk-m4b-top-hero { display: inline-flex; align-items: baseline; flex: 1; min-width: 0; }
  #view-m4b .kk-m4b-mode-pill { display: inline-flex; }
  #view-m4b .kk-m4b-title-lockup { display: none; }
  #view-m4b .kk-m4b-reader-btn { display: none; }
  /* Center cover + meta side-by-side per prototype TabletLandscape */
  #view-m4b[data-mode="m4b"] .kk-m4b-stage {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 28px;
    padding: 16px 28px;
    text-align: left;
  }
  #view-m4b[data-mode="m4b"] .kk-m4b-stage > .kk-m4b-cover {
    width: 240px; height: 240px;
    margin: 0;
    flex-shrink: 0;
  }
  #view-m4b[data-mode="m4b"] .kk-m4b-meta-wrap {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    min-width: 0;
  }
  #view-m4b[data-mode="m4b"] .kk-m4b-stage > .kk-m4b-meta-wrap > .kk-m4b-title {
    font-size: 28px;
    text-align: left;
    margin: 0;
  }
  #view-m4b[data-mode="m4b"] .kk-m4b-stage > .kk-m4b-meta-wrap > .kk-m4b-sub {
    text-align: left;
    margin: 0;
  }
  #view-m4b[data-mode="m4b"] .kk-m4b-stage > .kk-m4b-meta-wrap > .kk-m4b-chips {
    justify-content: flex-start;
    margin: 0;
  }
}

/* === Desktop (>=1280 AND landscape): 3-col grid with nav rail === */
@media (min-width: 1280px) and (orientation: landscape) {
  #view-m4b[data-mode="m4b"] .kk-m4b,
  #view-m4b[data-mode="reader"] .kk-m4b {
    grid-template-columns: 240px 1fr 400px;
    grid-template-areas:
      "nav top    queue"
      "nav stage  queue"
      "nav bot    queue";
  }
  #view-m4b .kk-m4b-dsk-nav {
    grid-area: nav;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 16px 12px;
    background: rgba(0,0,0,0.18);
    border-right: 1px solid var(--kk-line);
    overflow-y: auto;
  }
  .kk-dsk-brand {
    font-family: var(--kk-font-jp);
    font-size: 20px;
    font-weight: 700;
    color: var(--kk-acc);
    padding: 4px 10px 14px;
  }
  .kk-dsk-nav-row {
    display: flex; align-items: center; gap: 12px;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 13px;
    color: var(--kk-text-2);
    text-align: left;
    width: 100%;
    background: transparent;
    border: 0;
    cursor: pointer;
  }
  .kk-dsk-nav-row:hover,
  .kk-dsk-nav-row:active { background: var(--kk-surface-2); }
  .kk-dsk-nav-row.on {
    background: var(--kk-acc-soft);
    color: var(--kk-acc);
    font-weight: 600;
  }
  .kk-dsk-nav-sect {
    font-family: var(--kk-font-mono);
    font-size: 9px;
    color: var(--kk-text-3);
    letter-spacing: 0.12em;
    padding: 14px 12px 4px;
    text-transform: uppercase;
  }
  .kk-dsk-nav-series-list {
    display: flex; flex-direction: column; gap: 2px;
  }
  .kk-dsk-nav-series {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 10px;
    border-radius: 8px;
    background: transparent; border: 0;
    text-align: left;
    width: 100%;
    cursor: pointer;
  }
  .kk-dsk-nav-series:hover,
  .kk-dsk-nav-series:active { background: var(--kk-surface-2); }
  .kk-dsk-nav-series.is-active { background: var(--kk-acc-soft); }
  .kk-dsk-nav-series .cv {
    width: 30px; height: 42px;
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid var(--kk-line);
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: var(--kk-surface-2);
    color: var(--kk-text-2);
    font-weight: 700;
  }
  .kk-dsk-nav-series .cv img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .kk-dsk-nav-series .n {
    font-family: var(--kk-font-jp);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    color: var(--kk-text);
    flex: 1;
    min-width: 0;
  }
  .kk-dsk-import {
    margin-top: auto;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px dashed var(--kk-line-2);
    display: flex; align-items: center; gap: 8px;
    font-family: var(--kk-font-mono);
    font-size: 11px;
    color: var(--kk-text-2);
    letter-spacing: 0.3px;
    background: transparent;
    cursor: pointer;
  }
  .kk-dsk-import:hover { background: var(--kk-surface-2); }
  /* Bigger cover on desktop — prototype shows 320px */
  #view-m4b[data-mode="m4b"] .kk-m4b-stage {
    gap: 36px;
    padding: 28px 36px;
  }
  #view-m4b[data-mode="m4b"] .kk-m4b-stage > .kk-m4b-cover {
    width: 320px; height: 320px;
  }
  #view-m4b[data-mode="m4b"] .kk-m4b-stage > .kk-m4b-meta-wrap > .kk-m4b-title {
    font-size: 38px;
    line-height: 1.05;
  }
  #view-m4b .kk-m4b-queue-hd { padding: 16px 14px 12px; }
}

/* ====================================================================
   SPEC 4 v4 — Unified M4B top bar across viewports (2.8.06)
   Mobile / tablet portrait / tablet landscape / desktop all show the
   same top-bar layout:
     [back]   [cover-thumb + title + sub]   [audio | reader pill]   [menu]
   The "NOW LISTENING · series" hero label and the standalone "Reader"
   button from earlier iterations are retired — pill replaces them.
   Pill is absolutely centered so the menu/chapter button can't overlap.
   ==================================================================== */

/* Top bar lays out left-to-right so the lockup hugs the back button
   instead of centering on top of the absolute-centered pill. */
#view-m4b .kk-m4b-top {
  justify-content: flex-start;
}

/* Always-on title lockup. Overrides the m4b/reader morph that previously
   hid it in cover mode and the tablet/desktop hide rules from v3. */
#view-m4b .kk-m4b-top > button.kk-m4b-title-lockup,
#view-m4b[data-mode="m4b"] .kk-m4b-title-lockup,
#view-m4b[data-mode="reader"] .kk-m4b-title-lockup {
  display: flex !important;
  align-items: center;
  gap: 8px;
  opacity: 1;
  pointer-events: auto;
  transform: none;
  width: auto;
  height: auto;
  min-width: 0;
  max-width: calc(50% - 70px);
  margin: 0 0 0 38px;        /* clear the back button */
  padding: 4px 8px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  flex: 0 1 auto;
  overflow: hidden;
  transition: none;
  z-index: 1;
}

/* Hide the old hero label + Reader button at every viewport. */
#view-m4b .kk-m4b-top-hero,
#view-m4b .kk-m4b-reader-btn {
  display: none !important;
}

/* Mode pill: visible everywhere, absolutely centered. */
#view-m4b .kk-m4b-mode-pill {
  display: inline-flex !important;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 2;
}

/* Phones: shrink pill a touch so it fits next to a long title. */
@media (max-width: 400px) {
  #view-m4b .kk-m4b-top {
    min-height: 52px;
  }
  #view-m4b .kk-m4b-mode-pill button {
    width: 32px;
    height: 24px;
  }
  #view-m4b .kk-m4b-top > button.kk-m4b-title-lockup {
    margin-left: 34px;
    max-width: calc(50% - 60px);
  }
}

/* ====================================================================
   FAB inside bottom nav (2.8.08)
   FAB used to float in the library view's lower-right corner and overlap
   the mini-player. It's now the centered 3rd item of the tab bar:
     [Home] [Library] [FAB +] [Search] [Study]
   The arc menu (folder / file buttons + dim) lives at app level so the
   buttons fly up around the now-centered FAB.
   ==================================================================== */
.kk-tab-fab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  padding: 0;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
.kk-tab-fab::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: var(--kk-acc);
  box-shadow: 0 0 18px color-mix(in srgb, var(--kk-acc) 45%, transparent);
  z-index: 0;
}
.kk-tab-fab .kk-fab-plus {
  width: 22px;
  height: 22px;
  color: var(--kk-bg);
  position: relative;
  z-index: 1;
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.kk-tab-fab.is-open .kk-fab-plus {
  transform: rotate(45deg);
}
.kk-tab-fab:active::before {
  transform: scale(0.94);
  transition: transform 0.1s ease;
}

/* Keep the dim + arc buttons hidden when arc is closed. FAB itself is
   persistent across all views with the tab bar (home/library/search/study). */
.kk-fab-dim:not(.is-open),
.kk-fab-arc-btn:not(.is-open),
.kk-fab-arc-label:not(.is-open) {
  pointer-events: none;
}

/* Reanchor the arc menu + dim to viewport (they're now siblings of the
   tab bar, not children of view-library). */
.kk-fab-dim {
  position: fixed;
  inset: 0;
  z-index: 18;
}
.kk-fab-arc-btn {
  position: fixed;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--kk-acc);
  color: var(--kk-bg);
  border: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transform: scale(0);
  pointer-events: none;
  transition: opacity 220ms ease, transform 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 21;
  box-shadow: 0 0 18px color-mix(in srgb, var(--kk-acc) 45%, transparent);
}
.kk-fab-arc-btn.is-open {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}
/* Anchor arc buttons in a triangle around the centered FAB: folder above-left,
   file above-right, FAB at the apex (in the tab bar below). Both buttons
   share the same vertical offset so they form the triangle's base above. */
#kk-fab-folder {
  bottom: calc(100px + var(--safe-bottom));
  left: 50%;
  margin-left: -64px;
}
#kk-fab-file {
  bottom: calc(100px + var(--safe-bottom));
  left: 50%;
  margin-left: 20px;
}
.kk-fab-arc-label {
  position: fixed;
  font-family: var(--kk-font-mono);
  font-size: 11px;
  color: var(--kk-text-2);
  background: var(--kk-surface);
  border: 1px solid var(--kk-line);
  padding: 5px 10px;
  border-radius: var(--kk-r-pill);
  opacity: 0;
  transform: translateX(-8px);
  pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
  z-index: 21;
  white-space: nowrap;
}
.kk-fab-arc-label.is-open {
  opacity: 1;
  transform: translateX(0);
}
#kk-fab-folder-lbl {
  bottom: calc(152px + var(--safe-bottom));
  left: calc(50% + 30px);
}
#kk-fab-file-lbl {
  bottom: calc(98px + var(--safe-bottom));
  left: calc(50% + 30px);
}

/* ====================================================================
   Centering offsets for toast + pomodoro badge (2.8.09)
   On tablet/desktop the left nav rail shifts the content's true center
   off the viewport's 50%. Same on M4B where the queue sits on the right
   (and on desktop, a separate left nav lives inside view-m4b). Both
   toast (position:fixed) and the pomodoro cap (position:absolute inside
   view-m4b) read this variable to land on the actual stage center.
   ==================================================================== */
:root { --kk-stage-offset: 0px; }

@media (min-width: 1024px) and (orientation: landscape) {
  /* Non-m4b views ride the tab-bar rail (var(--kk-side, 84px) wide) */
  #app:not([data-view="m4b"]) { --kk-stage-offset: calc(var(--kk-side) / 2); }
  /* M4B tablet landscape: queue takes 380px on the right, no left rail */
  #app[data-view="m4b"] { --kk-stage-offset: -190px; }
}
@media (min-width: 1280px) and (orientation: landscape) {
  /* M4B desktop: 240px nav left + 400px queue right -> net shift left 80 */
  #app[data-view="m4b"] { --kk-stage-offset: -80px; }
}

.toast { left: calc(50% + var(--kk-stage-offset, 0px)); }
.kk-pomo-cap { left: calc(50% + var(--kk-stage-offset, 0px)); }

/* Override the base .kk-tab-fab { flex: 1 } from the mobile block when
   the tab bar flips to its vertical rail at >=1024 landscape. Must live
   AFTER the base rule (cascade), otherwise the mobile flex:1 wins. */
@media (min-width: 1024px) and (orientation: landscape) {
  #kk-tab-bar .kk-tab-fab {
    flex: 0 0 auto;
    min-height: 60px;
    padding: 16px 4px;
    margin: 4px 8px;
  }
}

/* ====================================================================
   Round 6 polish (2.8.10)
   ==================================================================== */

/* Immersion mirror for m4b reader — parallel to .kk-read[data-immersion=on]
   rules at line ~1391. Hide top bar, transport, util strip, tap-zone, fn-bar
   so only the text remains. The kk-immersion-exit chevron stays on screen. */
#view-m4b[data-immersion="on"] .kk-m4b-top {
  background: transparent;
  border-color: transparent;
}
#view-m4b[data-immersion="on"] .kk-m4b-top > *:not(.kk-immersion-exit) {
  opacity: 0;
  pointer-events: none;
}
#view-m4b[data-immersion="on"] .kk-m4b-top > .kk-immersion-exit {
  opacity: 0.32;
  pointer-events: auto;
}
#view-m4b[data-immersion="on"] .kk-m4b-bot,
#view-m4b[data-immersion="on"] .kk-fn-bar {
  opacity: 0;
  pointer-events: none;
}
#view-m4b[data-immersion="on"] .kk-m4b-bot,
#view-m4b[data-immersion="on"] .kk-fn-bar { transform: translateY(8px); }
#view-m4b[data-immersion="on"] .kk-util-strip,
#view-m4b[data-immersion="on"] #kk-tap-zone { display: none; }

/* Pomodoro badge sat at 90px from screen bottom — that landed on top of
   the m4b transport. Lift it clear. */
.kk-pomo-cap { bottom: calc(var(--safe-bottom) + 140px); }

/* Arc menu labels redundant — folder/file glyphs are obvious. */
.kk-fab-arc-label { display: none !important; }

/* Tab bar sits at z:20 so the FAB dim at z:18 was leaving the bar
   clickable through it. Raise dim above the bar — and raise the arc
   buttons themselves above the dim so they remain hittable. The FAB tab
   cell stays at its normal z; taps that land on the dim close the arc,
   which is correct behaviour. */
.kk-fab-dim { z-index: 25; }
.kk-fab-arc-btn { z-index: 27; }
.kk-fab-arc-label { z-index: 26; }

/* EPUB inside the m4b reader: hide the audio transport, dim the audio
   half of the mode pill, and position the existing TTS function bar where
   the transport used to be. */
#view-m4b[data-kind="epub"] .kk-m4b-bot { display: none; }
#view-m4b[data-kind="epub"] #kk-m4b-mode-audio {
  opacity: 0.35;
  pointer-events: none;
  cursor: not-allowed;
}
#view-m4b[data-kind="epub"] .kk-fn-bar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(var(--safe-bottom) + 16px);
  transform: none;
  opacity: 1;
  pointer-events: auto;
  z-index: 10;
}

/* === COMPONENT: Smart-Skip precise/basic badge + scan progress bar === */
.kk-skip-badge[hidden] { display: none !important; }
.kk-skip-badge {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 8px 0 2px; padding: 4px 10px;
  font-size: 12px; font-weight: 700; letter-spacing: .02em;
  border-radius: 999px; border: 1px solid var(--kk-line-2);
  background: var(--kk-surface-2); color: var(--kk-text-2);
}
.kk-skip-badge.is-precise {
  color: var(--kk-acc); border-color: var(--kk-acc);
  background: var(--kk-acc-soft);
}
.kk-skip-progress { margin: 10px 2px 2px; }
.kk-skip-progress-track {
  height: 6px; border-radius: 999px; overflow: hidden;
  background: var(--kk-surface-2); border: 1px solid var(--kk-line);
}
.kk-skip-progress-fill {
  height: 100%; width: 0%; border-radius: 999px;
  background: var(--kk-acc); transition: width .2s ease;
}
.kk-skip-progress-label {
  display: block; margin-top: 6px;
  font-size: 11px; color: var(--kk-text-2);
}

/* === First-launch V3 Immersive === */

.v3-root {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--kk-bg);
}

/* ============ BACKDROP : drifting book spines ============ */
.v3-backdrop {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  mask-image: linear-gradient(to bottom, transparent 0%, #000 18%, #000 82%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 18%, #000 82%, transparent 100%);
}

.v3-shelf {
  position: absolute;
  left: 0;
  display: flex;
  gap: 12px;
  align-items: flex-end;
  white-space: nowrap;
  animation: v3-drift 90s linear infinite;
  will-change: transform;
}
.v3-shelf.row-a { top: 8%; animation-duration: 110s; opacity: 0.85; }
.v3-shelf.row-b { top: 36%; animation-duration: 90s; animation-direction: reverse; opacity: 0.65; }
.v3-shelf.row-c { top: 64%; animation-duration: 130s; opacity: 0.78; }

@keyframes v3-drift {
  from { transform: translateX(0); }
  to   { transform: translateX(-50%); }
}
@media (prefers-reduced-motion: reduce) {
  .v3-shelf { animation: none; }
}

.v3-spine {
  width: 36px;
  height: 220px;
  border-radius: 2px;
  background: linear-gradient(180deg, #38402f, #1f2519);
  border: 1px solid var(--kk-line-2);
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 20px 40px -20px rgba(0,0,0,0.6);
}
.v3-spine::before {
  content: '';
  position: absolute;
  left: 6px; top: 14px; bottom: 14px;
  width: 1px;
  background: rgba(255,255,255,0.04);
}
.v3-spine::after {
  content: attr(data-jp);
  position: absolute;
  left: 0; right: 0; top: 24px;
  text-align: center;
  font-family: var(--kk-font-jp);
  font-size: 13px;
  letter-spacing: 0.5em;
  color: rgba(232, 235, 230, 0.65);
  writing-mode: vertical-rl;
  margin: 0 auto;
  width: 14px;
  line-height: 1.4;
  font-weight: 600;
}

.v3-spine.w-48 { width: 48px; }
.v3-spine.w-30 { width: 30px; }
.v3-spine.h-180 { height: 180px; }
.v3-spine.h-200 { height: 200px; }
.v3-spine.h-240 { height: 240px; }
.v3-spine.h-260 { height: 260px; }
.v3-spine.tone-warm { background: linear-gradient(180deg, #3d362c, #221f1a); }
.v3-spine.tone-cool { background: linear-gradient(180deg, #2a313a, #181c22); }
.v3-spine.tone-green { background: linear-gradient(180deg, #2f3d2d, #1a241d); }
.v3-spine.tone-deep { background: linear-gradient(180deg, #252b34, #14181f); }

.v3-spine.accent {
  background: linear-gradient(180deg, #2b3a22, #1a2414);
  border-color: var(--kk-acc-line);
  box-shadow: 0 20px 50px -16px rgba(155,191,122,0.25), 0 0 0 1px var(--kk-acc-line);
}
.v3-spine.accent::after { color: var(--kk-acc); }

.v3-vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(70% 60% at 50% 50%, rgba(20,23,26,0.78) 0%, rgba(20,23,26,0.35) 45%, rgba(20,23,26,0.1) 75%, transparent 100%);
  pointer-events: none;
}

.v3-glow {
  position: absolute;
  left: 50%; top: 50%;
  width: 600px; height: 600px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 50% 50%, rgba(155,191,122,0.10), transparent 60%);
  filter: blur(40px);
  pointer-events: none;
}

/* ============ FOREGROUND CARD ============ */
.v3-stage {
  position: relative;
  height: 100%;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
}

.v3-card {
  position: relative;
  width: 100%;
  max-width: 640px;
  padding: 26px 22px;
  border-radius: 20px;
  background: color-mix(in srgb, var(--kk-surface) 70%, transparent);
  border: 1px solid var(--kk-line-2);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  box-shadow:
    0 60px 120px -40px rgba(0, 0, 0, 0.8),
    0 0 0 1px rgba(255,255,255,0.02) inset;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
@media (min-width: 760px) {
  .v3-card { padding: 50px 56px; max-width: 720px; gap: 26px; }
}

.v3-card-top {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
@media (min-width: 760px) {
  .v3-card-top { display: flex; }
}
.v3-card-top-jp {
  font-family: var(--kk-font-jp);
  font-size: 11px;
  letter-spacing: 0.4em;
  color: var(--kk-text-3);
}

.v3-card-meta-mobile {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--kk-font-mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--kk-text-3);
  text-transform: uppercase;
}
.v3-card-meta-mobile .acc { color: var(--kk-acc); }
.v3-card-meta-mobile .rule { flex: 1; height: 1px; background: linear-gradient(to right, var(--kk-line), transparent); }
@media (min-width: 760px) {
  .v3-card-meta-mobile { display: none; }
}

.v3-headline {
  font-family: 'Shippori Mincho', var(--kk-font-jp);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--kk-text);
  margin: 0;
  line-height: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.v3-h-kanji {
  font-family: var(--kk-font-jp);
  font-weight: 600;
  color: var(--kk-acc);
  font-size: clamp(56px, 18vw, 96px);
  line-height: 0.92;
  letter-spacing: -0.02em;
}
.v3-h-jp {
  display: none;
  font-family: var(--kk-font-jp);
  font-weight: 600;
  font-size: clamp(40px, 6vw, 72px);
  line-height: 1;
  color: var(--kk-text);
}
.v3-h-en {
  font-family: 'Shippori Mincho', var(--kk-font-jp);
  font-weight: 600;
  font-size: clamp(22px, 3vw, 30px);
  line-height: 1.15;
  color: var(--kk-text);
  letter-spacing: -0.01em;
  margin-top: 4px;
}
.v3-h-en .en-long { display: none; }
.v3-h-en .en-short { display: inline; }

@media (min-width: 760px) {
  .v3-headline {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 14px;
  }
  .v3-h-jp { display: inline; }
  .v3-h-en {
    flex-basis: 100%;
    margin-top: 8px;
    font-size: clamp(22px, 2.4vw, 30px);
  }
  .v3-h-en .en-long { display: inline; }
  .v3-h-en .en-short { display: none; }
}

.v3-desc {
  font-size: clamp(13px, 1vw, 15px);
  line-height: 1.65;
  color: var(--kk-text-2);
  margin: 0;
  max-width: 52ch;
}
.v3-desc .long { display: none; }
@media (min-width: 760px) {
  .v3-desc .long { display: inline; }
  .v3-desc .short { display: none; }
}

.v3-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.v3-cta-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 18px 24px;
  border-radius: 18px;
  background: var(--kk-acc);
  color: #0c100a;
  font-weight: 600;
  font-size: 15px;
  border: 1px solid var(--kk-acc);
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
  box-shadow: 0 12px 32px -12px rgba(155,191,122,0.55);
}
.v3-cta-primary:hover { box-shadow: 0 16px 40px -10px rgba(155,191,122,0.6); }
.v3-cta-primary:active { transform: translateY(1px); }
.v3-cta-primary .arrow {
  margin-left: 2px;
  transition: transform 0.2s ease;
}
.v3-cta-primary:hover .arrow { transform: translateX(3px); }

.v3-more-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--kk-text-3);
  font-family: var(--kk-font-mono);
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 8px;
  margin-top: 2px;
  transition: color 0.15s;
}
.v3-more-toggle:hover { color: var(--kk-text-2); }
.v3-more-toggle .chev {
  transition: transform 0.25s ease;
}
.v3-more-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
@media (min-width: 760px) { .v3-more-toggle { display: none; } }

.v3-cta-row {
  display: grid;
  grid-template-rows: 0fr;
  grid-template-columns: 1fr;
  overflow: hidden;
  opacity: 0;
  margin-top: 0;
  transition: opacity 0.25s ease, margin-top 0.32s ease;
}
.v3-cta-row > * { min-height: 0; }
.v3-cta-row-inner {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  overflow: hidden;
}
.v3-cta-row.is-open {
  grid-template-rows: 1fr;
  opacity: 1;
  margin-top: 2px;
}
@media (min-width: 760px) {
  .v3-cta-row {
    grid-template-rows: 1fr;
    grid-template-columns: 1fr;
    opacity: 1;
    overflow: visible;
  }
  .v3-cta-row-inner {
    grid-template-columns: 1fr 1fr;
    overflow: visible;
  }
}
.v3-cta-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 18px;
  border-radius: 16px;
  background: transparent;
  border: 1px solid var(--kk-line);
  color: var(--kk-text-2);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.v3-cta-secondary:hover { background: var(--kk-surface-2); color: var(--kk-text); border-color: var(--kk-line-2); }

.v3-hint {
  display: none;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-radius: 14px;
  border: 1.5px dashed var(--kk-line-2);
  font-family: var(--kk-font-mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--kk-text-3);
  text-transform: uppercase;
}
@media (min-width: 760px) { .v3-hint { display: flex; } }
.v3-hint .arrow-dn {
  color: var(--kk-acc);
  animation: v3-bob 1.6s ease-in-out infinite;
}
@keyframes v3-bob {
  0%, 100% { transform: translateY(0); opacity: 0.7; }
  50%      { transform: translateY(3px); opacity: 1; }
}
.v3-hint .grow { flex: 1; }
.v3-hint .formats { color: var(--kk-text-2); }

.v3-side {
  display: none;
  position: absolute;
  top: 50%; transform: translateY(-50%);
  font-family: var(--kk-font-jp);
  font-size: 13px;
  letter-spacing: 0.5em;
  color: var(--kk-text-3);
  writing-mode: vertical-rl;
  pointer-events: none;
}
@media (min-width: 1100px) {
  .v3-side { display: block; }
  .v3-side.left  { left: 36px; }
  .v3-side.right { right: 36px; }
}
.v3-side .accent { color: var(--kk-acc); }

.v3-corner {
  display: none;
  position: absolute;
  font-family: var(--kk-font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--kk-text-3);
  text-transform: uppercase;
}
@media (min-width: 900px) {
  .v3-corner { display: block; }
  .v3-corner.tl { top: 28px; left: 28px; }
  .v3-corner.tr { top: 28px; right: 28px; }
  .v3-corner.bl { bottom: 28px; left: 28px; }
  .v3-corner.br { bottom: 28px; right: 28px; }
}

/* Drop overlay (first-launch) */
.drop-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--kk-bg) 70%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
.drop-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}
.drop-overlay-inner {
  border: 2px dashed var(--kk-acc);
  border-radius: 24px;
  padding: 60px 80px;
  text-align: center;
  background: color-mix(in srgb, var(--kk-acc-soft) 80%, transparent);
  box-shadow: 0 0 80px rgba(155, 191, 122, 0.18);
  transform: scale(0.96);
  transition: transform 0.2s ease;
}
.drop-overlay.is-active .drop-overlay-inner { transform: scale(1); }
.drop-overlay-kanji {
  font-family: var(--kk-font-jp);
  font-size: 96px;
  color: var(--kk-acc);
  line-height: 1;
  margin-bottom: 8px;
}
.drop-overlay-title {
  font-family: var(--kk-font-jp);
  font-size: 28px;
  color: var(--kk-text);
  margin-bottom: 6px;
}
.drop-overlay-sub {
  font-family: var(--kk-font-mono);
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--kk-acc);
  text-transform: uppercase;
}

/* === / First-launch V3 Immersive === */

/* === COMPONENT: Word Karaoke (2nd highlight) === */
/* Each unit of the active line is a .kk-w span; karaoke toggles .kk-on (spoken
   now) and .kk-sung (already spoken). Snappy pop hides stable-ts's ~100ms drift.
   transform=GPU, no reflow, no neighbor shove. */
.kk-w{
  display:inline-block;
  transform-origin:center 88%;
  opacity:.5;                /* un-spoken trail = grey, both paused and playing */
  transition:opacity .14s, color .12s, transform .15s cubic-bezier(.34,1.56,.64,1);
}
.kk-w.kk-sung{ opacity:1; }
.kk-w.kk-on{
  opacity:1;
  color:var(--kk-acc);
  transform:scale(1.38);
  text-shadow:0 0 16px var(--kk-acc-glow, rgba(124,198,255,.6));
}
body.kk-nopop .kk-w.kk-on{ transform:none; }
body.kk-nocolor .kk-w.kk-on{ color:inherit; text-shadow:none; }
/* === / Word Karaoke === */
