/* =====================================================
   積読フレンド — styles.css
   Rules:
   · No box-shadow or drop-shadow anywhere
   · No background fills except: topbar, nav,
     flashcard back face, rating buttons, theme dots
   · Everything else: border/stroke only, transparent bg
   · Rounded corners everywhere (--radius-box / --radius-pill)
   · Fonts: Funnel Display (UI) + Kosugi Maru (Japanese)
===================================================== */

/* ── Google Fonts ─────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Funnel+Display:wght@300;400;500;600&family=Kosugi+Maru&display=swap');

/* ── Theme tokens ─────────────────────────────────── */

/* Theme 1 — Flowers (default) */
:root {
  --bg:             #F0F2E6;
  --accent:         #CAC4F6;
  --accent-2:       #667F60;
  --ink:            #4B4A3E;
  --muted:          color-mix(in srgb, var(--ink) 55%, transparent);

  --border:         color-mix(in srgb, var(--ink) 22%, transparent);
  --border-strong:  color-mix(in srgb, var(--ink) 42%, transparent);
  --accent-stroke:  color-mix(in srgb, var(--accent) 80%, var(--ink) 20%);
  --accent2-stroke: color-mix(in srgb, var(--accent-2) 70%, var(--ink) 30%);

  --radius-box:  18px;
  --radius-pill: 999px;
  --stroke:      1.5px;
  --stroke-strong: 2px;

  --ring: 0 0 0 3px color-mix(in srgb, var(--accent) 50%, transparent);

  /* flashcard back — intentional fill */
  --fc-back-bg:  color-mix(in srgb, var(--ink) 90%, var(--bg));
  --fc-back-ink: var(--bg);
}

/* Theme 2 — Strawberry Matcha (commented out — too close to Flowers)
:root[data-theme="joyful"] {
  --bg:             #F5F2EC;
  --accent:         #C8B8C8;
  --accent-2:       #8AAF6A;
  --ink:            #2C2820;
  --muted:          color-mix(in srgb, var(--ink) 50%, transparent);
  --border:         rgba(44,40,32,0.15);
  --border-strong:  rgba(44,40,32,0.28);
  --accent-stroke:  #C07090;
  --accent2-stroke: #6A9448;
  --ring: 0 0 0 3px rgba(192,112,144,0.25);
  --fc-back-bg:  #2C2820;
  --fc-back-ink: #F5F2EC;
} */

/* Theme 3 — Plum */
:root[data-theme="plum"] {
  --bg:             #2A1620;
  --accent:         #AF6384;
  --accent-2:       #7C6E8A;
  --ink:            #F0E8EE;
  --muted:          color-mix(in srgb, var(--ink) 55%, transparent);

  --border:         rgba(240,232,238,0.20);
  --border-strong:  rgba(240,232,238,0.38);
  --accent-stroke:  rgba(175,99,132,0.95);
  --accent2-stroke: rgba(124,110,138,0.90);

  --ring: 0 0 0 3px rgba(175,99,132,0.40);

  --fc-back-bg:  color-mix(in srgb, var(--accent) 30%, var(--ink) 70%);
  --fc-back-ink: var(--ink);
}

/* Theme 4 — Coffee */
:root[data-theme="coffee"] {
  --bg:             #EDE6CE;       /* warmer parchment, less green */
  --accent:         #6B3C2E;       /* espresso — topbar & nav */
  --accent-2:       #86ABCB;       /* dusty blue */
  --ink:            #2E1F18;       /* very dark espresso */
  --muted:          color-mix(in srgb, var(--ink) 50%, transparent);

  --border:         rgba(46,31,24,0.16);
  --border-strong:  rgba(46,31,24,0.30);
  --accent-stroke:  #E5A2A0;       /* blush rose — badges, links, highlights */
  --accent2-stroke: #86ABCB;       /* dusty blue — secondary badges */

  --topbar-ink:     #EDE6CE;       /* cream text on espresso topbar */

  --ring: 0 0 0 3px rgba(229,162,160,0.30);

  --fc-back-bg:  #2E1F18;
  --fc-back-ink: #EDE6CE;
}
/* Coffee theme — light text on dark espresso topbar */
:root[data-theme="coffee"] .topbar h1,
:root[data-theme="coffee"] .topbar-right,
:root[data-theme="coffee"] .tagline {
  color: #EDE6CE;
}
:root[data-theme="coffee"] .topbar-right .btn {
  color: #EDE6CE !important;
  border-color: rgba(237,230,206,0.50) !important;
  background: transparent !important;
}
:root[data-theme="coffee"] .topbar-right .btn:hover {
  background: rgba(237,230,206,0.12) !important;
}
:root[data-theme="coffee"] .theme-dot {
  border-color: rgba(237,230,206,0.5);
}



/* ── Reset ────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  box-shadow: none !important;
  text-shadow: none !important;
}

/* Prevent any element from overflowing the viewport width */
img, canvas, video, iframe, table {
  max-width: 100%;
}

/* ── Base ─────────────────────────────────────────── */
body {
  font-family: 'Funnel Display', sans-serif;
  font-weight: 300;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
}

/* Japanese text */
.kanji-large, .kanji-cell,
.reading, .reading-cell,
.fc-word, .fc-word-back, .fc-reading-front, .fc-reading-back,
.mini-k, .mini-r,
.selected-radicals, .radical-btn,
.book-item, .fc-results-title,
.fc-stat .val, .fc-again-item .k, .fc-again-item .r,
.candidate-row button,
.search-bar input {
  font-family: 'Kosugi Maru', sans-serif;
}

/* ── Typography ──────────────────────────────────── */
h1, h2, h3 {
  font-family: 'Funnel Display', sans-serif;
  font-weight: 400;
  letter-spacing: 0.03em;
}
h2 {
  font-size: 0.82rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--muted);
}

/* ── TOPBAR (filled — intentional) ──────────────── */
.topbar {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: var(--accent);
  border-bottom: var(--stroke-strong) solid var(--border-strong);
}
.topbar h1 {
  font-family: 'Kosugi Maru', sans-serif;
  font-weight: 400;
  font-size: 1.2rem;
  letter-spacing: 0.06em;
  color: var(--ink);
}
.topbar-right { display: flex; align-items: center; gap: 14px; }
.tagline {
  font-family: 'Funnel Display', sans-serif;
  font-weight: 300;
  font-size: 0.88rem;
  font-style: italic;
  color: var(--ink);
  opacity: 0.78;
  white-space: nowrap;
}

/* Theme dots — hardcoded per-theme swatches, always circular */
.theme-dots { display: flex; gap: 8px; align-items: center; }
.theme-dot {
  width: 16px;
  height: 16px;
  min-width: 16px;
  padding: 0;          /* override global button padding that was making them oval */
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}
.theme-dot:hover  { transform: scale(1.25); }
.theme-dot.active { border-color: var(--ink); }

/* Each dot always shows its own theme's main colour, regardless of active theme */
.theme-dot[data-theme="flowers"] { background: #CAC4F6; }
.theme-dot[data-theme="joyful"]  { background: #C8B8C8; }
.theme-dot[data-theme="plum"]    { background: #AF6384; }
.theme-dot[data-theme="coffee"]  { background: #6B3C2E; }

/* ── NAV (filled — intentional) ─────────────────── */
.nav-wrap {
  position: relative;
  overflow: hidden;
  background: color-mix(in srgb, var(--accent) 55%, var(--bg) 45%);
  border-bottom: var(--stroke) solid var(--border-strong);
}
nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 18px;
  align-items: center;
  background: transparent;
  border-bottom: none;
}
nav button {
  background: transparent;
  border: var(--stroke) solid transparent;
  border-radius: var(--radius-pill);
  font-family: 'Funnel Display', sans-serif;
  font-weight: 400;
  font-size: 0.95rem;
  padding: 6px 16px;
  cursor: pointer;
  color: var(--ink);
  opacity: 0.62;
  transition: opacity 140ms ease, border-color 140ms ease, transform 140ms ease;
  letter-spacing: 0.04em;
}
nav button:hover         { opacity: 1; transform: translateY(-1px); }
nav button.active        { opacity: 1; border-color: var(--ink); font-weight: 500; }
nav button:focus-visible { outline: none; box-shadow: var(--ring) !important; }

/* ── Main layout ─────────────────────────────────── */
main { max-width: 1100px; margin: 0 auto; padding: 28px 20px; overflow-x: hidden; }

/* ── Panel visibility ────────────────────────────── */
.panel { display: none; overflow: hidden; max-width: 100%; }
.panel.active {
  display: block;
  max-width: 100%;
  overflow-x: hidden;
  animation: panelIn 180ms ease both;
}
@keyframes panelIn {
  from { opacity: 0; transform: translateY(5px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Cards — stroke only ─────────────────────────── */
.card {
  background: transparent;
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-box);
  padding: 22px;
}
.card h2 {
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: var(--stroke) solid var(--border);
}

/* ── Inputs, textareas, selects — stroke only ────── */
input, textarea, select {
  font-family: 'Funnel Display', sans-serif;
  font-weight: 300;
  background: transparent;
  color: var(--ink);
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-pill);
  padding: 8px 14px;
  outline: none;
  transition: border-color 140ms ease;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent-stroke);
  box-shadow: var(--ring) !important;
}
textarea {
  border-radius: var(--radius-box);
  resize: vertical;
  line-height: 1.8;
}
select { padding-right: 28px; cursor: pointer; }

input[type=range] {
  border: none;
  border-radius: 0;
  padding: 0;
  accent-color: var(--ink);
  width: 80px;
}
#panel-writing input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: var(--radius-pill);
  background: linear-gradient(
    to right,
    var(--accent-stroke) 0%,
    var(--accent-stroke) var(--val, 50%),
    var(--border-strong) var(--val, 50%),
    var(--border-strong) 100%
  );
  outline: none;
  cursor: pointer;
}
#panel-writing input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-stroke);
  cursor: pointer;
  border: none;
}
#panel-writing input[type=range]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-stroke);
  cursor: pointer;
  border: none;
}
#panel-writing input[type=range]::-moz-range-track {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
}
#panel-writing input[type=range]::-moz-range-progress {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--accent-stroke);
}
input[type=color] {
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  overflow: hidden;
  background: none;
  -webkit-appearance: none;
  appearance: none;
}
input[type=color]::-webkit-color-swatch-wrapper {
  padding: 0;
  border-radius: 50%;
}
input[type=color]::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}
input[type=color]::-moz-color-swatch {
  border: none;
  border-radius: 50%;
}

/* ── Canvas — stroke only ────────────────────────── */
canvas {
  display: block;
  background: transparent;
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-box);
  cursor: crosshair;
  touch-action: none;
  pointer-events: auto;
  max-width: 100%;
  width: 100%;
  height: auto;
}
/* Writing canvases get fixed height, width capped by container */
#writing-canvas-1,
#writing-canvas-2 {
  display: block;
  width: 100% !important;
  max-width: 100% !important;
  height: 300px !important;
  box-sizing: border-box;
}
#writing-canvas-1, #writing-canvas-2 {
  pointer-events: auto !important;
  touch-action: none !important;
  cursor: crosshair;
}

/* ── Buttons — stroke only ───────────────────────── */
button, .btn {
  font-family: 'Funnel Display', sans-serif;
  font-weight: 400;
  background: transparent;
  border: var(--stroke) solid var(--accent2-stroke);
  border-radius: var(--radius-pill);
  color: var(--ink);
  padding: 7px 16px;
  cursor: pointer;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
  transition: border-color 130ms ease, transform 120ms ease, opacity 130ms ease;
}
button:hover, .btn:hover  { border-color: var(--accent-stroke); transform: translateY(-1px); }
button:active, .btn:active { transform: translateY(0); }
button:focus-visible, .btn:focus-visible { outline: none; box-shadow: var(--ring) !important; }

.btn-outline { border-color: var(--border); }
.btn-outline:hover { border-color: var(--border-strong); }
.btn-sm { padding: 4px 12px; font-size: 0.82rem; }

.del-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  border-radius: var(--radius-pill);
  transition: color 140ms ease;
}
.del-btn:hover { color: var(--accent-stroke); }

/* ── Utility ─────────────────────────────────────── */
.status-msg {
  font-size: 0.88rem;
  color: var(--muted);
  font-style: italic;
  padding: 10px 0;
}
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
  font-style: italic;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

/* ── Search bar ──────────────────────────────────── */
.search-bar { display: flex; gap: 8px; margin-bottom: 18px; min-width: 0; }
.search-bar input { flex: 1; min-width: 0; font-family: 'Kosugi Maru', sans-serif; font-size: 1.05rem; }
.search-bar .btn { flex-shrink: 0; white-space: nowrap; }

/* ── Lookup results ──────────────────────────────── */
#results { min-height: 80px; }
.result-entry {
  border-bottom: var(--stroke) solid var(--border);
  padding: 14px 0;
  animation: fadeIn 0.25s ease;
}
.result-entry:last-child { border-bottom: none; }

.word-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.kanji-large { font-size: 2rem; line-height: 1; }
.reading     { font-size: 1rem; color: var(--muted); }

.jlpt-badge {
  font-size: 0.68rem;
  font-family: 'Funnel Display', sans-serif;
  border: var(--stroke) solid var(--accent-stroke);
  border-radius: var(--radius-pill);
  padding: 2px 8px;
  letter-spacing: 0.06em;
  background: transparent;
  color: var(--ink);
}
.meanings { font-size: 1rem; margin-bottom: 6px; line-height: 1.6; }
.tags      { font-size: 0.8rem; color: var(--muted); font-style: italic; }

.add-btn {
  margin-top: 8px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.add-btn select { max-width: 180px; font-size: 0.85rem; }

/* ── Grid layouts ────────────────────────────────── */
.lookup-grid { display: block; }

/* ── Word Lists ──────────────────────────────────── */
.lists-layout { display: grid; grid-template-columns: 220px 1fr; gap: 24px; min-height: 60vh; align-items: start; }
@media (max-width: 700px) { .lists-layout { grid-template-columns: 1fr; } }

.new-book-form { display: flex; gap: 6px; margin-bottom: 14px; align-items: center; }
.new-book-form input { flex: 1; font-size: 0.9rem; min-width: 0; }
.new-book-form .btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 1;
}

.book-list { display: flex; flex-direction: column; gap: 6px; }
.book-item {
  padding: 10px 14px;
  background: transparent;
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-box);
  cursor: pointer;
  font-family: 'Kosugi Maru', sans-serif;
  font-size: 0.88rem;
  transition: border-color 140ms ease;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.book-item:hover  { border-color: var(--border-strong); }
.book-item.active { border-color: var(--accent-stroke); }
.book-item .book-count { font-size: 0.72rem; color: var(--muted); }

.words-table { width: 100%; border-collapse: collapse; }
.words-table th {
  text-align: left;
  padding: 8px 12px;
  background: transparent;
  border: var(--stroke) solid var(--border);
  font-family: 'Funnel Display', sans-serif;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.words-table td {
  padding: 10px 12px;
  border: var(--stroke) solid var(--border);
  vertical-align: top;
  background: transparent;
}
.words-table tr:nth-child(even) td {
  background: color-mix(in srgb, var(--ink) 3%, transparent);
}
.words-table .kanji-cell   { font-family: 'Kosugi Maru', sans-serif; font-size: 1.2rem; width: 90px; }
.words-table .reading-cell { font-family: 'Kosugi Maru', sans-serif; font-size: 0.88rem; color: var(--muted); width: 120px; }
.words-table .meaning-cell { font-size: 0.92rem; }
.words-table .action-cell  { width: 50px; text-align: center; }

/* Share toolbar */
.share-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  align-items: center;
}
.sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.76rem;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-style: italic;
  color: var(--muted);
  border: var(--stroke) solid var(--border);
  background: transparent;
}
.sync-badge.live    { color: #3a9e5c; border-color: #3a9e5c; }
.sync-badge.live::before { content: '●'; font-style: normal; font-size: 0.55rem; }
.sync-badge.syncing { color: #c8920a; border-color: #c8920a; }
.sync-badge.syncing::before { content: '↻'; font-style: normal; }
.sync-badge.error   { color: var(--accent-stroke); border-color: var(--accent-stroke); }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--ink) 38%, transparent);
  z-index: 200;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);

  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg);
  border: var(--stroke-strong) solid var(--border-strong);
  border-radius: var(--radius-box);
  padding: 28px 28px 24px;
  max-width: 460px;
  width: 90%;
  animation: fadeIn 0.18s ease;
}
.modal h2 { margin-bottom: 18px; padding-bottom: 10px; border-bottom: var(--stroke) solid var(--border); }
.modal-section { margin-bottom: 18px; }
.modal-section label {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.modal-row   { display: flex; gap: 8px; align-items: stretch; }
.modal-input { flex: 1; font-size: 0.9rem; min-width: 0; border-radius: var(--radius-pill); }
.modal-input.mono { font-family: monospace; font-size: 0.82rem; letter-spacing: 0.05em; }
.modal-desc  { font-size: 0.82rem; color: var(--muted); font-style: italic; margin-top: 6px; line-height: 1.5; }
.modal-footer   { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.modal-divider  { border: none; border-top: var(--stroke) solid var(--border); margin: 18px 0; }

/* Import banner */
#import-banner {
  background: var(--accent);
  color: var(--ink);
  padding: 12px 20px;
  text-align: center;
  font-size: 0.95rem;
  border-bottom: var(--stroke) solid var(--border-strong);
}

/* ── Handwriting panel ───────────────────────────── */
.writing-layout           { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.writing-layout > * { min-width: 0; overflow: hidden; }
.writing-layout.writing-one { grid-template-columns: 1fr; max-width: 600px; margin: 0 auto; }
.writing-layout.writing-two { grid-template-columns: 1fr 1fr; }
@media (max-width: 980px) { .writing-layout.writing-two { grid-template-columns: 1fr; } }
@media (max-width: 700px) { .writing-layout { grid-template-columns: 1fr; } }

.canvas-wrap     { display: flex; flex-direction: column; gap: 12px; overflow: hidden; min-width: 0; }
.canvas-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.brush-row       { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; color: var(--muted); }
.hw-build        { grid-column: 1 / -1; }

.candidate-row { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.candidate-row button { font-family: 'Kosugi Maru', sans-serif; font-size: 1.1rem; padding: 5px 12px; }

.mini-row {
  display: grid;
  grid-template-columns: 110px 110px 1fr;
  gap: 10px;
  padding: 10px 0;
  border-top: var(--stroke) solid var(--border);
  cursor: pointer;
  transition: opacity 130ms ease;
}
.mini-row:hover        { opacity: 0.72; }
.mini-row:first-child  { border-top: none; }
.mini-k { font-family: 'Kosugi Maru', sans-serif; font-size: 1.4rem; }
.mini-r { font-family: 'Kosugi Maru', sans-serif; color: var(--muted); font-size: 0.9rem; }
.mini-m { color: var(--ink); font-size: 0.88rem; }
@media (max-width: 700px) {
  .mini-row { grid-template-columns: 90px 1fr; }
  .mini-m   { grid-column: 1 / -1; }
}

/* ── Radicals panel ──────────────────────────────── */
#panel-radicals { overflow: visible; }
.radical-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  align-items: start;
  max-width: 720px;
  margin: 0 auto;
}
.radical-layout > * { min-width: 0; overflow: hidden; }
.radical-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
  gap: 4px;
  width: 100%;
  max-height: 280px;
  overflow-y: auto;
  overflow-x: hidden;
}
.stroke-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
  width: 100%;
}
@media (max-width: 900px) {
  /* Tablet and below: picker on top, build word below */
  .radical-grid {
    max-height: none;
    grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  }
}

.radical-info { font-size: 0.84rem; color: var(--muted); margin-bottom: 12px; line-height: 1.55; }

.selected-radicals {
  font-family: 'Kosugi Maru', sans-serif;
  font-size: 1.6rem;
  letter-spacing: 0.2em;
  min-height: 2.2rem;
  margin-bottom: 10px;
  color: var(--accent-stroke);
}

.stroke-filter { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.stroke-btn {
  background: transparent;
  border: var(--stroke) solid var(--border);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.82rem;
  cursor: pointer;
  transition: border-color 130ms ease;
}
.stroke-btn:hover  { border-color: var(--border-strong); }
.stroke-btn.active { border-color: var(--accent-stroke); color: var(--accent-stroke); }

.radical-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 300px;
  overflow-y: auto;
  background: transparent;
  border: var(--stroke) solid var(--border);
  padding: 10px;
  border-radius: var(--radius-box);
}
.radical-btn {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Kosugi Maru', sans-serif;
  font-size: 1.15rem;
  border: var(--stroke) solid var(--border);
  background: transparent;
  cursor: pointer;
  border-radius: 10px;
  transition: border-color 130ms ease;
  position: relative;
}
.radical-btn:hover    { border-color: var(--border-strong); }
.radical-btn.selected { border-color: var(--accent-stroke); color: var(--accent-stroke); }
.radical-btn .strokes {
  position: absolute;
  top: 1px; right: 2px;
  font-size: 0.42rem;
  font-family: monospace;
  color: var(--muted);
  opacity: 0.7;
}
.radical-btn.selected .strokes { color: var(--accent-stroke); opacity: 1; }

/* Kanji result buttons in radical panel */
.radical-kanji-btn {
  font-family: 'Kosugi Maru', sans-serif;
  font-size: 1.15rem;
  width: 38px;
  height: 38px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ── Flashcards ──────────────────────────────────── */
.fc-setup { max-width: 560px; margin: 0 auto; }
.fc-setup .card { margin-bottom: 20px; }
.fc-book-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.fc-book-opt {
  padding: 8px 18px;
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-pill);
  background: transparent;
  cursor: pointer;
  font-family: 'Kosugi Maru', sans-serif;
  font-size: 0.88rem;
  transition: border-color 130ms ease;
}
.fc-book-opt:hover    { border-color: var(--border-strong); }
.fc-book-opt.selected { border-color: var(--accent-stroke); color: var(--accent-stroke); }

.fc-options { display: flex; flex-direction: column; gap: 12px; }
.fc-option-row { display: flex; align-items: center; gap: 14px; font-size: 0.92rem; margin-bottom: 12px; }
.fc-option-row label { min-width: 80px; color: var(--muted); flex-shrink: 0; }
.fc-option-row select, .fc-option-row .fc-book-grid { flex: 1; }
.fc-option-row label  { min-width: 130px; color: var(--muted); }
.fc-option-row select { font-size: 0.88rem; }

.fc-study { display: none; }
.fc-study.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 16px 0;
}

.fc-progress-bar-wrap {
  width: 100%; max-width: 600px;
  display: flex; align-items: center; gap: 14px;
  font-size: 0.84rem; color: var(--muted);
}
.fc-progress-bar {
  flex: 1; height: 5px;
  background: color-mix(in srgb, var(--ink) 12%, transparent);
  border-radius: var(--radius-pill);
  overflow: hidden;
  border: none;
}
.fc-progress-fill {
  height: 100%;
  background: var(--accent-stroke);
  border-radius: var(--radius-pill);
  transition: width 0.4s ease;
}

.fc-card-scene {
  width: 100%; max-width: 520px; height: 300px;
  perspective: 1000px;
  cursor: pointer;
}
.fc-card-inner {
  width: 100%; height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.5s cubic-bezier(0.4,0,0.2,1);
}
.fc-card-scene.flipped .fc-card-inner { transform: rotateY(180deg); }

.fc-card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius-box);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  border: var(--stroke-strong) solid var(--border);
  background: transparent;
}
.fc-front { background: transparent; }
.fc-back {
  background: var(--fc-back-bg);   /* intentional fill */
  border-color: transparent;
  transform: rotateY(180deg);
  color: var(--fc-back-ink);
}

.fc-hint {
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}
.fc-back .fc-hint { color: color-mix(in srgb, var(--fc-back-ink) 50%, transparent); }

.fc-word {
  font-family: 'Kosugi Maru', sans-serif;
  font-size: 4.5rem;
  line-height: 1;
  text-align: center;
  color: var(--ink);
}
.fc-word-back {
  font-family: 'Kosugi Maru', sans-serif;
  font-size: 2.5rem;
  margin-bottom: 8px;
}
.fc-meaning-back {
  font-family: 'Funnel Display', sans-serif;
  font-size: 1.35rem;
  text-align: center;
  line-height: 1.5;
  margin-bottom: 6px;
}
.fc-reading-front { font-family: 'Kosugi Maru', sans-serif; font-size: 1rem; color: var(--muted); margin-top: 10px; }
.fc-reading-back  {
  font-family: 'Kosugi Maru', sans-serif;
  font-size: 0.95rem; margin-top: 8px;
  color: color-mix(in srgb, var(--fc-back-ink) 55%, transparent);
}
.fc-tap-hint {
  font-family: 'Funnel Display', sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 12px;
}

/* ── Flashcard source toggle ─────────────────────── */
.fc-source-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
}
.fc-source-btn {
  padding: 6px 14px;
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.84rem;
  cursor: pointer;
  transition: border-color 120ms, color 120ms;
}
.fc-source-btn:hover {
  border-color: var(--accent-stroke);
}
.fc-source-btn.selected {
  border-color: var(--accent-stroke);
  color: var(--accent-stroke);
}

/* Rating buttons — intentional fills (semantic colour coding) */
.fc-ratings {
  display: none;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 520px; width: 100%;
}
.fc-ratings.visible { display: flex; animation: fadeIn 0.22s ease; }

.fc-rating-btn {
  flex: 1;
  min-width: 88px; max-width: 136px;
  padding: 11px 8px;
  border-radius: var(--radius-box);
  font-family: 'Funnel Display', sans-serif;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform 0.1s, opacity 0.1s;
  border: none;
}
.fc-rating-btn:hover  { opacity: 0.86; transform: translateY(-2px); }
.fc-rating-btn:active { transform: scale(0.96); }
.fc-rating-btn .label { font-weight: 500; font-size: 0.9rem; }
.fc-rating-btn .sub   { font-family: 'Kosugi Maru', sans-serif; font-size: 0.72rem; opacity: 0.78; }

/* These fills are intentional semantic colour coding */
.fc-btn-again { background: #E8A5A5; color: #5a2525; }
.fc-btn-hard  { background: #E8C99A; color: #5a3a10; }
.fc-btn-good  { background: #A8D4B0; color: #1e4a28; }
.fc-btn-easy  { background: #B0C4E8; color: #1a2e52; }

.fc-session-stats {
  display: flex; gap: 22px; justify-content: center;
  max-width: 520px; width: 100%;
  font-size: 0.84rem; color: var(--muted);
}
.fc-stat { text-align: center; }
.fc-stat .val {
  font-family: 'Funnel Display', sans-serif;
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--ink);
  display: block;
}
.fc-shortcuts {
  font-size: 0.73rem; color: var(--muted);
  font-style: italic; text-align: center; opacity: 0.8;
}

.fc-results {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 40px 20px;
  text-align: center;
  max-width: 560px;
  margin: 0 auto;
}
.fc-results.active { display: flex; animation: fadeIn 0.35s ease; }
.fc-results-title  { font-family: 'Funnel Display', sans-serif; font-size: 1.9rem; font-weight: 300; letter-spacing: 0.12em; }

.fc-results-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; width: 100%; }
.fc-results-stat {
  background: transparent;
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-box);
  padding: 16px 8px;
  text-align: center;
}
.fc-results-stat .big { font-family: 'Funnel Display', sans-serif; font-size: 2rem; font-weight: 400; }
.fc-results-stat .lbl { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; margin-top: 4px; }

.fc-again-list {
  width: 100%;
  background: transparent;
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-box);
  padding: 16px 18px;
  text-align: left;
}
.fc-again-list h3 { font-size: 0.78rem; letter-spacing: 0.15em; color: var(--muted); text-transform: uppercase; margin-bottom: 10px; }
.fc-again-item {
  display: flex; gap: 12px; padding: 6px 0;
  border-bottom: var(--stroke) solid var(--border);
  font-size: 0.9rem; align-items: baseline;
}
.fc-again-item:last-child { border-bottom: none; }
.fc-again-item .k { font-family: 'Kosugi Maru', sans-serif; font-size: 1.2rem; min-width: 32px; }
.fc-again-item .r { font-family: 'Kosugi Maru', sans-serif; color: var(--muted); font-size: 0.84rem; }
.fc-again-item .m { color: var(--ink); }

/* ── Flashcard setup book/option selectors ───────── */
.fc-option-row select { border-radius: var(--radius-pill); }

/* ── Scrollbar ───────────────────────────────────── */
::-webkit-scrollbar       { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: var(--radius-pill); }

/* =====================================================
   BOOKSHELF TAB
===================================================== */

/* Add bar */
.shelf-add-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.shelf-add-bar input {
  flex: 1;
  min-width: 180px;
  font-size: 0.95rem;
}

/* Two-column layout */
.shelf-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
@media (max-width: 760px) {

}

/* ── Left sidebar ─────────────────────────────────── */
.shelf-sidebar {
  width: 100%;
}
#shelf-list {
  width: 100%;
}
.shelf-select {
  width: 100%;
  font-family: 'Kosugi Maru', sans-serif;
  font-size: 0.95rem;
  padding: 10px 40px 10px 16px;
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 14px center;
  color: var(--ink);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  transition: border-color 130ms ease;
}
.shelf-select:focus {
  border-color: var(--accent-stroke);
  box-shadow: var(--ring);
}

.shelf-group-label {
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  width: 100%;
  text-align: center;
  padding: 4px 0 2px;
}

/* shelf-item kept for potential future use */
.shelf-item { display: none; }
.shelf-item:last-child { border-bottom: none; }
.shelf-item:hover { background: color-mix(in srgb, var(--ink) 5%, transparent); }
.shelf-item.active { background: color-mix(in srgb, var(--accent) 22%, transparent); }

.shelf-item-title {
  font-family: 'Kosugi Maru', sans-serif;
  font-size: 0.88rem;
  line-height: 1.3;
}
.shelf-item-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 0.72rem;
  color: var(--muted);
}
.shelf-item-stars {
  color: var(--accent-stroke);
  letter-spacing: -1px;
  font-size: 0.75rem;
}
.shelf-vocab-count {
  font-size: 0.68rem;
  opacity: 0.75;
}

/* ── Detail pane ──────────────────────────────────── */
.shelf-detail {
  min-height: 300px;
}
.shelf-empty-detail {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.shelf-detail-inner {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.shelf-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}
.shelf-detail-titles { flex: 1; min-width: 0; }
.shelf-detail-title {
  font-family: 'Kosugi Maru', sans-serif;
  font-size: 1.4rem;
  line-height: 1.2;
  margin-bottom: 4px;
}
.shelf-detail-author {
  font-family: 'Kosugi Maru', sans-serif;
  font-size: 0.9rem;
  color: var(--muted);
}
.shelf-detail-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* Status + rating row */
.shelf-meta-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.shelf-status-badge {
  font-size: 0.8rem;
  padding: 3px 12px;
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--muted);
}
.shelf-date {
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
}

/* Stars (interactive) */
.shelf-stars, .shelf-modal-stars {
  display: flex;
  gap: 2px;
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
}
.shelf-stars .star, .shelf-modal-stars .star {
  color: var(--border-strong);
  transition: color 100ms ease, transform 100ms ease;
  user-select: none;
}
.shelf-stars .star:hover,
.shelf-stars .star.filled,
.shelf-modal-stars .star:hover,
.shelf-modal-stars .star.filled {
  color: var(--accent-stroke);
}
.shelf-stars .star:hover { transform: scale(1.2); }

/* Section blocks */
.shelf-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.shelf-section-label {
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.shelf-notes-text {
  font-size: 0.95rem;
  line-height: 1.75;
  color: var(--ink);
  white-space: pre-wrap;
}

/* Vocab header row */
.shelf-vocab-header {
  align-items: center;
}
.shelf-vocab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 5px;
  font-size: 0.65rem;
  border: var(--stroke) solid var(--border);
  border-radius: var(--radius-pill);
  margin-left: 5px;
  vertical-align: middle;
}
.shelf-vocab-search {
  width: 160px;
  font-size: 0.82rem;
  padding: 5px 12px;
}

/* Modal rows */
.shelf-modal-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.shelf-modal-row .modal-section { min-width: 0; }



/* ── JLPT badge (small, in vocab tables) ─────────────── */
.jlpt-sm {
  font-size: 0.65rem;
  padding: 1px 5px;
  opacity: 0.85;
}
td.jlpt-cell { white-space: nowrap; }

/* ════════════════════════════════════════════════════════════
   MOBILE  (≤ 640 px  — iPhone SE through iPhone Pro Max)
   ════════════════════════════════════════════════════════════ */

/* ── Tablet topbar & nav fixes (641px–900px) ──────────────── */
@media (max-width: 900px) {
  /* Hide tagline to give Sync/WK buttons room */
  .tagline { display: none; }

  /* Nav scrolls horizontally, no wrap */
  nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 6px 12px;
    gap: 4px;
  }
  nav::-webkit-scrollbar { display: none; }
  nav button {
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* Topbar: tighten spacing */
  .topbar { gap: 10px; padding: 10px 16px; }
  .topbar-right { gap: 8px; }
  .sync-btn { font-size: 0.75rem !important; padding: 4px 10px !important; }
}

@media (max-width: 640px) {

  /* ── Topbar ─────────────────────────────────────────── */
  .topbar          { padding: 9px 14px; gap: 8px; }
  .topbar h1       { font-size: 1.05rem; letter-spacing: 0.03em; }
  .tagline         { display: none; }            /* too cramped on small screens */
  .topbar-right    { gap: 8px; }
  .sync-btn        { font-size: 0.7rem !important;
                     padding: 3px 8px !important; }
  .theme-dot       { width: 14px !important; height: 14px !important;
                     min-width: 14px !important; }

  /* ── Nav — single scrollable row, no wrapping ───────── */
  nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;       /* Firefox */
    padding: 6px 10px;
    gap: 4px;
  }
  nav::-webkit-scrollbar { display: none; }
  nav button {
    font-size: 0.75rem;
    padding: 5px 10px;
    white-space: nowrap;
    flex-shrink: 0;
  }

  /* ── Main container ─────────────────────────────────── */
  main { padding: 12px 10px; }

  /* ── Cards ──────────────────────────────────────────── */
  .card         { padding: 14px 13px; }
  .card h2      { font-size: 0.7rem; margin-bottom: 10px; padding-bottom: 6px; }

  /* ── Buttons ─────────────────────────────────────────── */
  .btn    { padding: 8px 14px;  font-size: 0.85rem; }
  .btn-sm { padding: 5px 10px;  font-size: 0.78rem; }

  /* ── Search bar ─────────────────────────────────────── */
  .search-bar       { gap: 6px; margin-bottom: 12px; }
  .search-bar input { font-size: 0.95rem; padding: 8px 12px; }
  .search-bar .btn  { padding: 8px 12px; }

  /* ── Lookup results ─────────────────────────────────── */
  .lookup-grid      { grid-template-columns: 1fr; gap: 12px; }
  .kanji-large      { font-size: 2.2rem !important; }
  .result-entry     { padding: 10px 0; }
  .add-btn          { flex-wrap: wrap; gap: 6px; }
  .add-btn select   { max-width: 100% !important; width: 100%; }

  /* Quick notes */
  #quick-notes { min-height: 100px !important; font-size: 0.9rem !important; }

  /* ── Books / Shelf ──────────────────────────────────── */
  .shelf-layout    { gap: 10px; }
  .shelf-add-bar   { flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
  .shelf-add-bar input { width: 100%; min-width: 0 !important; }
  .shelf-sidebar   { justify-content: center; }
  .shelf-detail    { min-height: 0; }

  /* ── Handwriting canvases ───────────────────────────── */
  .writing-layout,
  .writing-layout.writing-two { grid-template-columns: 1fr; gap: 12px; }
  /* canvas sizing handled by #writing-canvas-1/2 rule */
  .brush-row { gap: 6px; }
  .brush-row input[type="range"] { width: 90px; }
  .candidate-row  { gap: 5px; flex-wrap: wrap; }
  .hw-build       { padding: 12px; }

  /* ── Radicals ───────────────────────────────────────── */
  .radical-layout { grid-template-columns: 1fr; gap: 12px; }
  .radical-grid { max-height: 60vh; }

  /* ── Flashcards ─────────────────────────────────────── */
  .fc-setup .card { padding: 14px 12px; }
  .fc-book-grid   { gap: 6px; }
  .fc-book-opt    { font-size: 0.82rem; padding: 6px 10px; }

  .fc-study.active  { gap: 14px; padding: 10px 0; }
  .fc-card-scene    { height: 240px !important; max-width: 100%; }
  .fc-word          { font-size: 3.6rem !important; line-height: 1.1; }
  .fc-word-back     { font-size: 2rem   !important; }
  .fc-meaning-back  { font-size: 0.95rem !important; }
  .fc-reading-back  { font-size: 0.85rem !important; }
  .fc-hint          { font-size: 0.62rem; }
  .fc-tap-hint      { font-size: 0.72rem; }

  .fc-ratings       { gap: 6px; }
  .fc-rating-btn    { padding: 10px 6px !important; min-width: 70px !important; }
  .fc-rating-btn .sub { display: none; }   /* hide Japanese sub-labels */
  .fc-rating-btn .label { font-size: 0.82rem; }

  .fc-progress-bar-wrap { gap: 8px; font-size: 0.78rem; }
  .fc-session-stats     { gap: 10px; }
  .fc-stat .val         { font-size: 1.1rem; }
  .fc-shortcuts         { display: none; }  /* keyboard shortcuts irrelevant on touch */

  /* ── Modals ─────────────────────────────────────────── */
  .modal {
    margin: 10px;
    padding: 18px 15px;
    max-height: 88vh;
    overflow-y: auto;
    border-radius: var(--radius-box);
  }
  .modal h2       { font-size: 0.88rem; }
  .modal-section  { margin-bottom: 12px; }
  .modal-input    { font-size: 0.88rem; padding: 7px 10px; }
  .modal-footer   { gap: 8px; }
  .shelf-modal-row { flex-direction: column; gap: 0; }

  /* ── Misc ───────────────────────────────────────────── */
  .status-msg  { font-size: 0.82rem; }
  .empty-state { font-size: 0.84rem; }
  .words-table { font-size: 0.82rem; }
  .mini-row    { gap: 4px; font-size: 0.85rem; }

}

/* ── Landscape phone (wide but short) ────────────────── */
@media (max-height: 500px) and (max-width: 900px) {
  .fc-card-scene { height: 180px !important; }
  .topbar        { padding: 5px 14px; }
  nav            { padding: 3px 10px; }
}

/* ============================================================
   NEW STYLES: Example sentences, WK badge, Reader, WK modal
   ============================================================ */


/* ── WaniKani level badge ───────────────────────────────────── */
.wk-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-family: 'Funnel Display', sans-serif;
  border: var(--stroke) solid var(--accent-stroke);
  border-radius: var(--radius-pill);
  padding: 2px 8px;
  letter-spacing: 0.06em;
  background: transparent;
  color: var(--ink);
  vertical-align: middle;
  margin-left: 4px;
}
.wk-badge-pending {
  opacity: 0.45;
}

/* WK level in vocab table */
.wk-cell { text-align: center; }
.wk-badge-sm {
  font-size: 0.65rem;
  font-family: 'Funnel Display', sans-serif;
  border: var(--stroke) solid var(--accent-stroke);
  border-radius: var(--radius-pill);
  padding: 2px 7px;
  letter-spacing: 0.06em;
  background: transparent;
  color: var(--ink);
}

/* ── Reader panel ───────────────────────────────────────────── */
.reader-controls { margin-bottom: 16px; }

.reader-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.reader-toolbar select {
  padding: 7px 12px;
  border: 1.5px solid var(--card-stroke);
  border-radius: 6px;
  background: var(--card-bg);
  color: inherit;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.reader-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  cursor: pointer;
  user-select: none;
}
.reader-article-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.reader-article-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  width: 100%;
  padding: 10px 14px;
  background: color-mix(in srgb, var(--bg) 60%, var(--border) 40%);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.reader-article-btn:hover {
  background: color-mix(in srgb, var(--accent) 15%, var(--bg) 85%);
  border-color: var(--accent-stroke);
}
.reader-article-thumb {
  width: 64px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--border);
}
.reader-article-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.reader-article-title {
  font-size: 0.92rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.reader-article-date {
  font-size: 0.75rem;
  opacity: 0.55;
}
.reader-article-btn:hover {
  background: var(--card-bg);
  border-color: var(--accent-stroke);
}
.reader-article-title { font-family: 'Kosugi Maru', sans-serif; flex: 1; }
.reader-article-date  { font-size: 0.75rem; opacity: 0.55; white-space: nowrap; }

.reader-back-bar {
  display: flex;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--card-stroke);
}
.reader-body {
  font-family: 'Kosugi Maru', sans-serif;
  font-size: 1.1rem;
  line-height: 2.4;
  max-width: 680px;
}
.reader-body ruby rt { font-size: 0.6em; }
.reader-body p { margin: 0 0 1em; }

.reader-article-desc {
  font-size: 0.78rem;
  opacity: 0.5;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── WaniKani settings modal ────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--bg);
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-box, 18px);
  box-shadow: 0 8px 40px rgba(0,0,0,0.32), 0 0 0 1px var(--border-strong);
  width: 100%;
  max-width: 440px;
  margin: 16px;
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--card-stroke);
}
.modal-header h3 {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.modal-close {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  opacity: 0.5;
  padding: 2px 6px;
}
.modal-close:hover { opacity: 1; }
/* ── Themed checkbox (furigana toggle & others) ─────────────────────────────── */
input[type="checkbox"] {
  appearance: none !important;
  -webkit-appearance: none !important;
  display: inline-block !important;
  width: 18px !important;
  height: 18px !important;
  min-width: 18px !important;
  max-width: 18px !important;
  flex: none !important;
  padding: 0 !important;
  border: var(--stroke-strong) solid var(--border-strong) !important;
  border-radius: 5px !important;
  background: transparent !important;
  cursor: pointer;
  position: relative;
  vertical-align: middle;
  transition: background 120ms ease, border-color 120ms ease;
}
input[type="checkbox"]:checked {
  background: var(--accent-stroke) !important;
  border-color: var(--accent-stroke) !important;
}
input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 10px;
  border: 2px solid var(--bg);
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}
input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: var(--ring);
}

/* ── Vocab table WK column ──────────────────────────────────── */
/* ── Reader article links & body ────────────────────────────── */
#reader-body a,
#reader-body a:visited {
  color: var(--accent-stroke);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid var(--accent-stroke);
}
#reader-body a:hover {
  opacity: 0.75;
}
#reader-body img {
  max-width: 100%;
  border-radius: 8px;
  margin: 8px 0;
  display: block;
}
#reader-body h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 6px;
}
#reader-body h4 {
  font-size: 0.8rem;
  opacity: 0.6;
  margin: 0 0 12px;
}
#reader-body h4 a {
  font-weight: 500;
}
#reader-body audio {
  display: none;
}
@media (max-width: 640px) {
  .reader-toolbar { gap: 10px; }
  .reader-article-btn { padding: 9px 11px; font-size: 0.84rem; }
  .reader-body { font-size: 1rem; line-height: 2.2; }
  .example-sentence { padding: 7px 10px; }
}


/* ── Mobile optimisation pass ───────────────────────────────── */
@media (max-width: 640px) {

  /* Sources modal */
  #sources-modal .modal-box { margin: 12px; }
  #sources-modal .modal-box a { color: var(--accent-stroke); }

  /* Vocab table — horizontal scroll so it doesn't squeeze */
  /* vocab table adapts to screen width on mobile */
  .words-table { table-layout: fixed; width: 100%; }
  .words-table th, .words-table td { word-break: break-word; }
  .words-table td:nth-child(1) { width: 18%; }
  .words-table td:nth-child(2) { width: 20%; }
  .words-table td:nth-child(3) { width: 38%; max-width: none; white-space: normal; }
  .words-table td:nth-child(4) { width: 14%; }
  .words-table td:nth-child(5) { width: 10%; }

  /* Reader article list thumbnails — smaller on mobile */
  .reader-article-thumb { width: 48px; height: 36px; }

  /* Reader article title — allow wrapping on small screens */
  .reader-article-title { white-space: normal; }

  /* Reader body — tighter line height for small screens */
  .reader-body p    { margin-bottom: 0.9em; }

  /* Handwriting hw-word-suggestions wraps cleanly */
  .hw-word-suggestions { gap: 6px; flex-wrap: wrap; }
  .hw-suggestion-btn   { font-size: 1rem; padding: 6px 10px; }

  /* Radicals grid — more columns so grid isn't too sparse */
  .radical-grid { grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)); }

  /* Flashcard rating buttons full-width row on very small screens */
  .fc-ratings { flex-wrap: wrap; }
  .fc-rating-btn { flex: 1; min-width: 60px !important; }

  /* Footer wraps gracefully */
  footer { line-height: 2.2; padding: 16px 12px 24px; }

  /* Modal box full-width on small screens */
  .modal-box { margin: 8px !important; max-width: calc(100vw - 16px) !important; }

  /* Topbar WK button text hidden, show icon only */
  .wk-connect-btn span.wk-label { display: none; }
}

@media (max-width: 400px) {
  /* Very small phones — nav text even smaller */
  nav button { font-size: 0.68rem; padding: 4px 8px; }
  .fc-word   { font-size: 3rem !important; }
}

/* ── Vocab table meaning column ───────────────────── */
.words-table td:nth-child(3) {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 640px) {
  .words-table td:nth-child(3) { max-width: 140px; }
}
/* ── Nav scroll fade (mobile) ──────────────────────── */
@media (max-width: 640px) {
  .nav-wrap {
    position: relative;
  }
  .nav-wrap::after {
    content: '';
    position: absolute;
    right: 0; top: 0; bottom: 0;
    width: 32px;
    background: linear-gradient(to right, transparent, var(--bg));
    pointer-events: none;
  }
}
@media (max-width: 380px) {
  .topbar-right { gap: 5px; }
  .wk-btn-text { display: none; }
  .sync-btn .sync-label { display: none; }
}
