* { box-sizing: border-box; }

:root {
  --bg: #faf8f4;
  --panel: #f1ede6;
  --card: #ffffff;
  --border: #e4dfd5;
  --text: #29261f;
  --muted: #857e70;
  --accent: #1d63a8;
  --accent-soft: #e8f0f8;
  --masc: #2563eb;
  --fem: #d43d3d;
  --neut: #c07a10;
  --verb: #0d8a66;
  --other: #78716c;
  --studied: rgba(250, 204, 21, 0.28);
  --shadow: 0 1px 3px rgba(40, 30, 10, 0.06), 0 8px 24px rgba(40, 30, 10, 0.05);
  --shadow-pop: 0 4px 12px rgba(20, 15, 5, 0.1), 0 16px 40px rgba(20, 15, 5, 0.14);
  --serif: "Iowan Old Style", "Palatino", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #191714;
    --panel: #211e1a;
    --card: #262320;
    --border: #38332c;
    --text: #ece7dd;
    --muted: #9a927f;
    --accent: #6aa5db;
    --accent-soft: #253242;
    --masc: #7aa5f5;
    --fem: #ef8383;
    --neut: #e0a952;
    --verb: #4cc39a;
    --other: #a29d94;
    --studied: rgba(250, 204, 21, 0.16);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-pop: 0 8px 30px rgba(0, 0, 0, 0.55);
  }
}
:root[data-theme="dark"] {
  --bg: #191714;
  --panel: #211e1a;
  --card: #262320;
  --border: #38332c;
  --text: #ece7dd;
  --muted: #9a927f;
  --accent: #6aa5db;
  --accent-soft: #253242;
  --masc: #7aa5f5;
  --fem: #ef8383;
  --neut: #e0a952;
  --verb: #4cc39a;
  --other: #a29d94;
  --studied: rgba(250, 204, 21, 0.16);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-pop: 0 8px 30px rgba(0, 0, 0, 0.55);
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
[hidden] { display: none !important; }
.hidden { display: none !important; }
button { font-family: inherit; }

.layout { display: flex; min-height: 100vh; }

/* ---------- rail (language + navigation + settings) ---------- */
.rail {
  width: 236px; flex-shrink: 0;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 18px;
  background: var(--panel); border-right: 1px solid var(--border);
  padding: 16px 12px 14px;
}
.brand { display: block; text-decoration: none; color: inherit; margin-bottom: 2px; }
.brand-name {
  display: block; font-size: 19px; font-weight: 700; letter-spacing: -0.01em; color: var(--text);
}
.brand-tag { display: block; font-size: 11px; color: var(--muted); line-height: 1.3; }
.brand:hover .brand-name { color: var(--accent); }

.rail-top { position: relative; display: flex; align-items: center; gap: 8px; }
.lang-btn {
  flex: 1; display: flex; align-items: center; gap: 10px; text-align: left;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 8px 10px; cursor: pointer; box-shadow: var(--shadow);
  transition: border-color 0.15s;
}
.lang-btn:hover { border-color: var(--accent); }
.lang-flag {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; flex-shrink: 0;
  border: 1.5px solid currentColor; border-radius: 50%; font-size: 11px; font-weight: 700; letter-spacing: 0.04em;
}
.lang-option .lang-flag { width: 26px; height: 26px; font-size: 10px; }
.lang-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.lang-text > span:first-child { font-size: 15px; font-weight: 600; }
.lang-native { font-size: 11px; color: var(--muted); }
.caret { margin-left: auto; color: var(--muted); }
.lang-menu {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-pop); padding: 6px;
}
.lang-option {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: none; background: none; color: var(--text); border-radius: 8px;
  padding: 7px 8px; cursor: pointer; font-size: 14px;
}
.lang-option:hover { background: var(--accent-soft); }
.lang-option.active { color: var(--accent); font-weight: 600; }
.lang-menu-hint { margin: 6px 8px 4px; font-size: 11px; color: var(--muted); line-height: 1.4; }
.rail-toggle {
  display: none; border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 9px; padding: 5px 9px; cursor: pointer; align-items: center;
}

.rail-nav { flex: 1; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.rail-group h3 {
  margin: 0 0 4px 10px; font-size: 10px; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--muted);
}
.rail-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  border: none; background: none; color: var(--text);
  font-size: 14px; font-weight: 500; padding: 8px 10px; border-radius: 10px; cursor: pointer;
  transition: background 0.12s;
}
.rail-item:hover { background: var(--card); }
.rail-item.active { background: var(--card); color: var(--accent); box-shadow: var(--shadow); }
.rail-item .icon { flex-shrink: 0; }
.rail-row { display: flex; align-items: center; }
.rail-row .rail-item { flex: 1; }
.rail-chevron {
  border: none; background: none; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px;
  display: inline-flex; transition: transform 0.15s;
}
.rail-chevron:hover { color: var(--text); background: var(--card); }
.rail-entry:not(.open) .rail-chevron { transform: rotate(-90deg); }
.rail-subs { display: flex; flex-direction: column; margin: 2px 0 4px 18px; padding-left: 10px; border-left: 1px solid var(--border); }
.rail-entry:not(.open) .rail-subs { display: none; }
.rail-sub {
  display: flex; align-items: center; gap: 8px; text-align: left; border: none; background: none;
  color: var(--muted); font-size: 13px; padding: 5px 8px; border-radius: 8px; cursor: pointer;
}
.rail-sub:hover { color: var(--text); background: var(--card); }
.rail-sub.active { color: var(--accent); font-weight: 500; }
.icon { vertical-align: -3px; }
button .icon, a .icon { pointer-events: none; }

.rail-bottom { display: flex; flex-direction: column; gap: 12px; }
.rail-hours { font-size: 12px; color: var(--muted); }
.rail-settings { display: flex; flex-direction: column; gap: 7px; }
.rail-settings select {
  font: inherit; font-size: 12px; color: var(--text); background: var(--card);
  border: 1px solid var(--border); border-radius: 7px; padding: 2px 6px; margin-left: 4px;
}
.rail-credit { margin: 0; font-size: 10px; color: var(--muted); line-height: 1.4; }
.rail-credit a { color: var(--muted); }
.toggle { font-size: 12px; color: var(--muted); user-select: none; cursor: pointer; }
.learner-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* ---------- admin ---------- */
.admin-panels { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }
.adm-card { padding: 18px 22px 20px; }
.adm-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.adm-head h2 { margin: 0 0 2px; font-size: 17px; }
.adm-head .muted { margin: 0; font-size: 12.5px; }
.adm-head .ghost-btn { padding: 6px 9px; }
.adm-total { margin: 0 0 12px; font-size: 14px; color: var(--muted); }
.adm-section { margin-bottom: 14px; }
.adm-row {
  display: grid; grid-template-columns: minmax(160px, 1.2fr) 2fr 130px; align-items: center; gap: 10px;
  padding: 3px 0 3px calc(var(--depth, 0) * 18px); font-size: 13px;
}
.adm-section > .adm-row, .adm-section > .adm-details > summary > .adm-row { font-weight: 600; }
.adm-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adm-bar { display: block; height: 8px; border-radius: 4px; background: var(--panel); overflow: hidden; }
.adm-fill { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.adm-num { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.adm-details > summary { list-style: none; cursor: pointer; }
.adm-details > summary::-webkit-details-marker { display: none; }
.adm-details > summary .adm-label::before { content: "▸ "; color: var(--muted); }
.adm-details[open] > summary .adm-label::before { content: "▾ "; }
.adm-sub { margin: 14px 0 6px; font-size: 14px; }
.adm-kv { border-collapse: collapse; font-size: 13px; width: 100%; }
.adm-kv th { text-align: left; font-weight: 500; color: var(--muted); padding: 3px 12px 3px 0; vertical-align: top; white-space: nowrap; }
.adm-kv td { padding: 3px 0; }
.adm-actions { display: flex; flex-direction: column; gap: 10px; }
.adm-simple { display: flex; gap: 8px; flex-wrap: wrap; }
.adm-result { margin: 12px 0 0; font-size: 12px; white-space: pre-wrap; background: var(--panel); padding: 10px 12px; border-radius: 9px; max-height: 260px; overflow: auto; }
.adm-sub.small { font-size: 13px; margin-top: 12px; }
.adm-note { margin: 4px 0 10px; font-size: 12.5px; }
.adm-sum { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.adm-sum h3 { margin-right: 6px; }
.adm-filter { margin-left: auto; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.adm-chip { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11.5px; font-weight: 600; background: var(--panel); color: var(--muted); white-space: nowrap; }
.adm-chip.ok { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.adm-chip.warn, .adm-chip.stale { background: rgba(214, 150, 20, 0.16); color: #a86f00; }
.adm-chip.unbaked { background: rgba(120, 120, 140, 0.16); color: var(--muted); }
.adm-chip.error { background: rgba(200, 50, 50, 0.14); color: #b02a2a; }
.adm-scroll { overflow-x: auto; margin: 6px 0 10px; }
.adm-table { border-collapse: collapse; font-size: 12.5px; width: 100%; }
.adm-table th { text-align: left; font-weight: 500; color: var(--muted); padding: 4px 10px 4px 0; white-space: nowrap; border-bottom: 1px solid var(--border); }
.adm-table td { padding: 5px 10px 5px 0; vertical-align: top; border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent); }
.adm-table td:last-child, .adm-table th:last-child { padding-right: 0; }
.adm-problems { display: block; font-size: 11.5px; max-width: 260px; }
.adm-rowacts { display: flex; gap: 6px; flex-wrap: wrap; }
.ghost-btn.tiny { padding: 3px 8px; font-size: 12px; }
.adm-input { font: inherit; font-size: 12.5px; padding: 4px 7px; border: 1px solid var(--border); border-radius: 7px; background: var(--bg); color: inherit; min-width: 120px; }
.adm-budget { height: 6px; border-radius: 3px; background: var(--panel); overflow: hidden; margin: -6px 0 12px; }
.adm-budget .adm-fill { display: block; height: 100%; background: var(--accent); }
.adm-budget.warn .adm-fill { background: #c9401f; }
.adm-words { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.adm-word { font-size: 12.5px; padding: 2px 8px; background: var(--panel); border-radius: 9px; }
.adm-form { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.adm-form-head { font-size: 13px; margin-bottom: 8px; }
.adm-fields { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: flex-end; }
.adm-field { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.adm-jobs { display: flex; flex-direction: column; gap: 6px; }
.adm-job { border: 1px solid var(--border); border-radius: 9px; padding: 6px 10px; font-size: 13px; }
.adm-job > summary { cursor: pointer; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.adm-job .ghost-btn.tiny { margin-left: auto; }
.adm-pre { margin: 8px 0 2px; font-size: 11.5px; white-space: pre-wrap; max-height: 220px; overflow: auto; background: var(--panel); padding: 8px 10px; border-radius: 7px; }
.adm-details.plain > summary { font-size: 12.5px; color: var(--muted); }
.learner-row select { margin-left: 0; }

/* ---------- sign in (rail) ---------- */
.rail-auth { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.rail-auth form { display: flex; flex-direction: column; gap: 6px; }
.rail-auth input { font: inherit; font-size: 12px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--card); color: var(--text); }
.rail-auth .ghost-btn { padding: 5px 9px; font-size: 12px; align-self: flex-start; }
.rail-auth .who { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-auth a { color: var(--accent); }

/* ---------- check yourself (comprehension questions) ---------- */
.check { margin: 22px 0 8px; padding: 14px 18px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--card); }
.check-title { margin: 0 0 8px; font-size: 15px; }
.check-q { padding: 8px 0; border-top: 1px solid var(--border); }
.check-question { margin: 0 0 6px; font-size: 15px; }
.check-answer { margin: 6px 0 0; font-size: 14px; color: var(--accent); }

/* ---------- today (random mode) ---------- */
.lib-today { margin: 0 0 18px; padding: 14px 16px 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--card); box-shadow: var(--shadow); }
.today-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; font-size: 14px; }
.today-head strong { font-size: 15px; }
.today-head .ctl { margin-left: auto; font-size: 12.5px; color: var(--muted); }
.today-head .ctl select { font: inherit; font-size: 12.5px; margin-left: 4px; color: var(--text); background: var(--card); border: 1px solid var(--border); border-radius: 7px; padding: 2px 6px; }
.today-head .ghost-btn { padding: 5px 10px; font-size: 12.5px; }
.today-grid { margin: 0; }
.today-why { margin: 8px 0 0; font-size: 12px; color: var(--accent); }
.dialect { border-bottom: 1px dotted var(--accent); cursor: help; }
.toggle input { accent-color: var(--accent); }

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; padding: 26px 32px 48px; max-width: 980px; }
.view { animation: rise 0.2s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.view-intro { color: var(--muted); font-size: 13px; max-width: 640px; line-height: 1.5; margin: 0 0 14px; }
.empty-note { font-size: 13px; color: var(--muted); }

.errors {
  margin-bottom: 14px; padding: 10px 14px; border-radius: 10px;
  background: rgba(220, 60, 60, 0.08); border: 1px solid rgba(220, 60, 60, 0.3);
  color: var(--fem); font-size: 14px;
}
.errors div + div { margin-top: 4px; }
.voice-warning, .notice {
  margin-bottom: 14px; padding: 10px 14px; border-radius: 10px;
  background: rgba(220, 160, 20, 0.09); border: 1px solid rgba(220, 160, 20, 0.35);
  color: var(--neut); font-size: 13px; line-height: 1.5;
}
.notice code { background: var(--panel); border-radius: 5px; padding: 1px 5px; font-size: 12px; }
.notice.info { background: var(--accent-soft); border-color: transparent; color: var(--text); }

/* ---------- shared components ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 20px 24px 22px; box-shadow: var(--shadow);
}
.primary-btn {
  background: var(--accent); color: #fff; border: none; border-radius: 9px;
  padding: 9px 20px; font-size: 14px; font-weight: 500; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 8px;
  transition: filter 0.15s, transform 0.1s;
}
.primary-btn:hover { filter: brightness(1.08); }
.primary-btn .icon, .ghost-btn .icon, .back-btn .icon, .side-head a .icon { vertical-align: -2px; }
.ghost-btn { display: inline-flex; align-items: center; gap: 6px; }
.back-btn { display: inline-flex; align-items: center; gap: 4px; }
.primary-btn:active { transform: scale(0.97); }
.primary-btn:disabled { opacity: 0.6; cursor: wait; }
.btn-spinner {
  display: none; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.35); border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
.primary-btn.loading .btn-spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.ghost-btn {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 9px; padding: 8px 16px; font-size: 14px; cursor: pointer;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }
.back-btn {
  border: none; background: none; color: var(--accent); font-size: 13px;
  cursor: pointer; padding: 0; margin-bottom: 12px; font-weight: 500;
}
.round-btn {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 50%; width: 40px; height: 40px; font-size: 15px; cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.round-btn:hover { border-color: var(--accent); color: var(--accent); }
.round-btn { display: inline-flex; align-items: center; justify-content: center; }
.round-btn.speaking { border-color: var(--verb); color: var(--verb); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(13, 138, 102, 0.15); } }
.rate-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.rate-label input { width: 90px; accent-color: var(--accent); }
.kbd-hint { color: var(--muted); font-size: 12px; }
.kbd-hint kbd {
  font-family: inherit; font-size: 11px; background: var(--panel);
  border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 5px; margin-right: 2px;
}
.input-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }

/* split layout: main column + side list (Translate history, Notes notebook) */
.split-layout { display: flex; gap: 24px; align-items: flex-start; }
.split-main { flex: 1; min-width: 0; }
.side-panel { width: 250px; flex-shrink: 0; }
.side-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; }
.side-title { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.side-head a { font-size: 12px; color: var(--accent); text-decoration: none; font-weight: 500; }
.side-head a:hover { text-decoration: underline; }
.side-list { list-style: none; margin: 0; padding: 0; }
.side-list li {
  padding: 9px 12px; margin-bottom: 7px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--border);
  cursor: pointer; position: relative;
  transition: border-color 0.15s, transform 0.1s;
}
.side-list li:hover { border-color: var(--accent); }
.side-list li:active { transform: scale(0.985); }
.side-list .h-main { font-size: 13px; display: block; padding-right: 18px; font-weight: 500; }
.side-list .h-sub {
  font-size: 11px; color: var(--muted); display: block; padding-right: 18px;
  margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.side-list .h-del {
  position: absolute; top: 7px; right: 8px; border: none; background: none;
  color: var(--muted); cursor: pointer; padding: 2px; display: inline-flex;
  opacity: 0; transition: opacity 0.15s;
}
.side-list li:hover .h-del { opacity: 1; }
.side-list .h-del:hover { color: var(--fem); }
.history-empty { font-size: 13px; color: var(--muted); }

/* ---------- translate ---------- */
.input-area textarea {
  width: 100%; font-size: 17px; padding: 14px 16px;
  border: 1px solid var(--border); border-radius: 12px;
  resize: vertical; font-family: inherit;
  background: var(--card); color: var(--text);
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}
.input-area textarea:focus { outline: none; border-color: var(--accent); }
.empty-hint { margin-top: 36px; color: var(--muted); font-size: 14px; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.example {
  border: 1px dashed var(--border); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 6px 14px; font-size: 13px; cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.example:hover { border-color: var(--accent); color: var(--accent); border-style: solid; }

.result { margin-top: 26px; animation: rise 0.25s ease-out; }
.result-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.english-line { color: var(--muted); font-size: 15px; margin: 0; flex: 1; min-width: 200px; }
.audio-controls { display: flex; align-items: center; gap: 10px; }
.target-output { font-family: var(--serif); font-size: 30px; line-height: 1.55; margin-top: 14px; }
.target-output .sent { display: block; margin-bottom: 6px; }
.shimmer {
  display: inline-block; height: 30px; width: 70%; border-radius: 8px;
  background: linear-gradient(90deg, var(--panel) 25%, var(--border) 50%, var(--panel) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.word {
  cursor: pointer; border-radius: 5px; padding: 0 2px;
  border-bottom: 2px solid transparent;
  transition: border-color 0.12s, background 0.2s;
}
.word:hover { border-bottom-color: currentColor; }
.word.studied { background: var(--studied); }
body.colored .word.masc { color: var(--masc); }
body.colored .word.fem { color: var(--fem); }
body.colored .word.neut { color: var(--neut); }
body.colored .word.verb { color: var(--verb); }
body.colored .word.other { color: var(--other); }

.sentence-note {
  margin-top: 14px; font-size: 14px; line-height: 1.5;
  background: var(--accent-soft); border-radius: 10px; padding: 11px 14px;
  animation: rise 0.25s ease-out;
}
.sentence-note { border-left: 3px solid var(--accent); }
.engine-note { font-size: 12px; color: var(--muted); margin-top: 10px; margin-bottom: 0; }
.legend { margin-top: 16px; display: none; gap: 14px; font-size: 12px; padding-left: 4px; }
body.colored .legend { display: flex; flex-wrap: wrap; }
.lg { color: var(--muted); }
.lg::before { content: "●"; margin-right: 4px; }
.lg.masc::before { color: var(--masc); }
.lg.fem::before { color: var(--fem); }
.lg.neut::before { color: var(--neut); }
.lg.verb::before { color: var(--verb); }
.lg.other::before { color: var(--other); }

/* ---------- library head + cards ---------- */
.lib-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.lib-head-text { flex: 1; min-width: 260px; }
.lib-head .view-intro { margin-bottom: 0; }
.lib-title { margin: 0 0 6px; font-size: 22px; }
.lib-filters { display: flex; gap: 14px; flex-wrap: wrap; }
.lib-filters .ctl { min-width: 130px; }
.lib-cats {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin: 18px 0 22px;
}
.lib-cat {
  display: flex; flex-direction: column; align-items: flex-start; gap: 10px; text-align: left;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 14px; padding: 14px 14px 12px; cursor: pointer; box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.15s;
}
.lib-cat:hover { border-color: var(--accent); transform: translateY(-1px); }
.lib-cat.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.lib-cat.empty { color: var(--muted); }
.lib-cat .icon { width: 22px; height: 22px; }
.lib-cat-label { font-size: 14px; font-weight: 600; }
.lib-cat-count { font-size: 11px; color: var(--muted); margin-top: -6px; }
.lib-cat.active .lib-cat-count { color: inherit; opacity: 0.75; }
.chip {
  border: 1px solid var(--border); background: var(--card); color: var(--muted);
  border-radius: 999px; padding: 4px 11px; font-size: 12px; cursor: pointer;
}
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; margin-top: 16px; }
.pkg-card {
  text-align: left; background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px; cursor: pointer; color: var(--text);
  display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.1s; font-size: 14px;
}
.pkg-card:hover { border-color: var(--accent); }
.pkg-card:active { transform: scale(0.985); }
.pkg-card strong { font-size: 15px; }
.cc-desc { color: var(--muted); font-size: 13px; }
.cc-meta { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 4px; }
.badge {
  font-size: 10px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  border-radius: 999px; padding: 2px 8px; background: var(--panel); color: var(--muted);
}
.badge.level-a { background: rgba(13, 138, 102, 0.13); color: var(--verb); }
.badge.level-b { background: rgba(192, 122, 16, 0.14); color: var(--neut); }
.badge.level-c { background: rgba(212, 61, 61, 0.12); color: var(--fem); }
.badge.culture { background: var(--accent-soft); color: var(--accent); }

/* ---------- player heads (Read + Listen) ---------- */
.player-title-row { display: flex; align-items: flex-start; gap: 16px; justify-content: space-between; }
.player-head h2 { margin: 0 0 4px; font-size: 19px; }
.player-desc { margin: 0; color: var(--muted); font-size: 13px; }
.convo-controls { display: flex; align-items: center; gap: 20px; margin-top: 14px; flex-wrap: wrap; }

/* ---------- reader ---------- */
.read-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#read-play { min-width: 124px; justify-content: center; }
.read-progress { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.player-top { display: flex; align-items: center; min-height: 40px; margin-bottom: 10px; padding-right: 52px; }
.player-top .back-btn { margin-bottom: 0; }

/* floating settings: a sticky dock at the top of the player holds the button and its panel */
.float-dock { position: sticky; top: 10px; height: 0; z-index: 25; }
.fab {
  position: absolute; right: 0; top: 0; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--card); color: var(--text); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; box-shadow: var(--shadow-pop);
  transition: border-color 0.15s, color 0.15s;
}
.fab:hover, .fab.on { border-color: var(--accent); color: var(--accent); }
.settings-panel {
  position: absolute; right: 0; top: 48px; width: min(400px, calc(100vw - 32px));
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 16px 12px; box-shadow: var(--shadow-pop); animation: rise 0.15s ease-out;
}
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; font-size: 13px; }
.settings-head .sheet-close { padding: 2px; }
.srow {
  display: grid; grid-template-columns: 92px 1fr 48px; align-items: center; gap: 8px;
  font-size: 12px; color: var(--muted); margin-bottom: 8px;
}
.srow.dim { opacity: 0.45; }
.srow select {
  grid-column: 2 / 4; font: inherit; font-size: 12.5px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 7px; padding: 4px 6px; min-width: 0;
}
.srow input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; min-width: 0; }
.srow output { text-align: right; color: var(--text); font-variant-numeric: tabular-nums; font-weight: 500; }
.srow-toggles { display: flex; gap: 16px; margin: 6px 0 8px; }
.srow-toggles .toggle { font-size: 12.5px; display: inline-flex; align-items: center; gap: 5px; }
.settings-panel .kbd-help { margin: 0; line-height: 1.5; border-top: 1px solid var(--border); padding-top: 8px; }

.ctl { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.ctl select {
  font: inherit; font-size: 13px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 5px 8px;
}
.ctl input[type="range"] { width: 100%; accent-color: var(--accent); margin: 0; }
.ctl small { font-size: 11px; opacity: 0.8; }
.ctl.toggle { flex-direction: row; align-items: center; gap: 6px; align-self: end; font-size: 13px; }
.kbd-help { margin: 12px 0 0; font-size: 11px; color: var(--muted); }

.read-lines { list-style: none; margin: 18px 0 0; padding: 0; max-width: 720px; }
.rl {
  padding: 12px 16px 13px; border-radius: 14px; border: 1px solid transparent;
  margin-bottom: 4px; cursor: pointer; opacity: 0.55;
  transition: opacity 0.3s, border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.rl:hover { opacity: 0.85; }
.rl.reached { opacity: 1; }
.rl.current { background: var(--card); border-color: var(--accent); box-shadow: var(--shadow), 0 0 0 3px var(--accent-soft); }
.rl-head { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.rl-num { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rl-speaker { font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--accent); }
.rl-text { font-family: var(--serif); font-size: 24px; line-height: 1.5; transition: filter 0.2s; }
.read-lines.text-spoken .rl:not(.reached) .rl-text,
.read-lines.text-hidden .rl-text { filter: blur(7px); user-select: none; }
.read-lines .rl .rl-text.peek { filter: none; }
.rl-sub { position: relative; min-height: 20px; margin-top: 5px; font-size: 14px; line-height: 1.4; color: var(--muted); }
.rl-sub span { display: block; opacity: 0; transform: translateY(2px); transition: opacity 0.4s ease, transform 0.4s ease; }
.rl-sub.shown span, .read-lines.subs-always .rl-sub span { opacity: 1; transform: none; }
.rl-sub:not(.shown)::after { content: "· · ·"; position: absolute; left: 0; top: 0; opacity: 0.5; letter-spacing: 1px; }
.read-lines.subs-always .rl-sub::after { content: none; }
.rl-time { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rl-head .t-btn { opacity: 0; transition: opacity 0.15s; }
.rl:hover .t-btn, .rl.current .t-btn, .rl-head .t-btn.recording, .rl-head .t-mine { opacity: 1; }
.rl-note {
  display: none; margin-top: 7px; padding: 7px 11px 7px 10px; border-radius: 9px;
  background: var(--accent-soft); font-size: 12.5px; line-height: 1.45; white-space: pre-line;
  animation: rise 0.25s ease-out; align-items: flex-start; gap: 7px; border-left: 3px solid var(--accent);
}
.rl-note .icon { flex-shrink: 0; margin-top: 2px; color: var(--accent); }
.rl.reached .rl-note { display: flex; }
.read-lines.notes-off .rl-note { display: none; }

/* ---------- book reading view: paragraphs, tap a sentence for its translation ---------- */
.book { max-width: 680px; margin: 22px 0 0; font-family: var(--serif); font-size: 21px; line-height: 1.75; }
.bk-hint { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 12px; color: var(--muted); margin: 0 0 14px; }
.bk-para { margin: 0 0 1.1em; }
.bk-h { font-size: 24px; font-weight: 600; margin: 1.4em 0 0.5em; line-height: 1.3; display: block; }
.bk-hint + .bk-h { margin-top: 0.2em; }
.bk-sent {
  border-radius: 6px; padding: 1px 3px; cursor: pointer; transition: background 0.15s;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.bk-sent:hover { background: var(--accent-soft); }
.bk-sent.open, .bk-sent.current { background: var(--accent-soft); }
.bk-sent.current { box-shadow: 0 0 0 1px var(--accent); }
.sent-pop {
  position: absolute; z-index: 40; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-pop); padding: 10px 12px; font-size: 14px; line-height: 1.45;
  display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: flex-start; animation: rise 0.15s ease-out;
}
.sent-pop[hidden] { display: none; }
.sent-pop .sp-text { flex: 1; min-width: 0; }
.sent-pop .sp-play { border: none; background: none; color: var(--muted); cursor: pointer; padding: 2px; display: inline-flex; }
.sent-pop .sp-play:hover { color: var(--accent); }
.sent-pop .sp-note {
  flex-basis: 100%; display: flex; gap: 7px; font-size: 12.5px; color: var(--muted);
  border-top: 1px solid var(--border); padding-top: 7px; white-space: pre-line;
}
.sent-pop .sp-note .icon { flex-shrink: 0; margin-top: 2px; color: var(--accent); }
.book { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.bk-sent { touch-action: pan-y; }
.bk-sent.resume { box-shadow: 0 0 0 2px var(--accent); }
.bk-speaker { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent); margin-right: 8px; }
.sent-pop .eword { cursor: pointer; border-bottom: 1px dotted transparent; border-radius: 3px; }
.sent-pop .eword:hover { border-bottom-color: var(--accent); color: var(--accent); }
.chap-nav { display: flex; align-items: center; gap: 8px; margin: 14px 0 0; flex-wrap: wrap; }
.chap-nav .ghost-btn { padding: 6px 9px; }
.chap-nav .ghost-btn:disabled { opacity: 0.4; cursor: default; }
.chap-nav select {
  font: inherit; font-size: 13px; color: var(--text); background: var(--card); max-width: min(420px, 60vw);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 8px;
}
.badge.free { background: rgba(13, 138, 102, 0.12); color: var(--verb); }
.badge.paid { background: rgba(192, 122, 16, 0.14); color: var(--neut); }
.badge.reviewed { background: rgba(13, 138, 102, 0.14); color: var(--verb); }
.cc-author { font-size: 12px; color: var(--muted); margin-top: -2px; }
/* the other direction: English word → words of the language */
.p-dir { font-size: 12px; color: var(--muted); margin-left: 8px; }
.p-cands { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.p-cand { border-top: 1px solid var(--border); padding-top: 7px; }
.p-cand-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.p-cand-lemma { border: none; background: none; cursor: pointer; font-family: var(--serif); font-size: 18px; color: var(--text); padding: 0; }
.p-cand-lemma:hover { color: var(--accent); }
.p-cand .p-def-text { font-size: 13px; color: var(--muted); margin-top: 2px; }
.p-cand .p-forms { margin-left: auto; }
.p-cand .p-forms.open { background: var(--accent-soft); }
.p-inline-forms { margin-top: 8px; }
.p-inline-forms .paradigm h3 { font-size: 12px; margin: 6px 0 4px; color: var(--muted); }
.p-inline-forms .ptable { font-size: 12.5px; }
.p-matched { margin: 4px 0 0; font-size: 12px; color: var(--muted); font-style: italic; }
.pnote { margin: 8px 0 2px; padding: 8px 10px; border-radius: 9px; background: var(--accent-soft); font-size: 12.5px; line-height: 1.45; }
.pnote p { margin: 3px 0 0; }
.muted { color: var(--muted); }
#player.book-mode .srow.subs, #player.book-mode .srow.text, #player.book-mode .srow.delay { display: none; }
#player.book-mode .kbd-help.lines-only, #player:not(.book-mode) .kbd-help.book-only { display: none; }

/* ---------- listen (dialogue turns) + notes segments ---------- */
.convo-turns { list-style: none; margin: 18px 0 0; padding: 0; }
.turn {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 16px 13px; margin-bottom: 10px; max-width: 640px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.turn.sp-b { margin-left: auto; }
.turn.playing { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.t-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.t-speaker { font-size: 11px; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.turn.sp-a .t-speaker { color: var(--accent); }
.turn.sp-b .t-speaker { color: var(--verb); }
.t-time { font-variant-numeric: tabular-nums; text-transform: none !important; letter-spacing: 0 !important; }
.t-btn {
  border: 1px solid var(--border); background: var(--card); color: var(--muted);
  border-radius: 999px; font-size: 11px; padding: 3px 8px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px; line-height: 1;
  transition: color 0.15s, border-color 0.15s;
}
.t-btn:hover { color: var(--accent); border-color: var(--accent); }
.t-rec.recording { color: #fff; background: var(--fem); border-color: var(--fem); animation: pulse 1.2s infinite; }
.t-mine { color: var(--verb); border-color: var(--verb); }
.t-cz { font-family: var(--serif); font-size: 22px; line-height: 1.5; }
.t-en { color: var(--muted); font-size: 13px; margin-top: 4px; transition: filter 0.15s; }
.convo-turns.hide-en .t-en { filter: blur(6px); cursor: pointer; user-select: none; }
.convo-turns.hide-en .t-en.revealed { filter: none; }

/* ---------- immersion hours ---------- */
.hours-card { margin-bottom: 18px; padding: 16px 20px; }
.hours-row { display: flex; justify-content: space-between; align-items: baseline; }
.hours-row strong { font-size: 14px; }
.hours-label { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.hours-bar { height: 8px; border-radius: 999px; background: var(--panel); margin-top: 8px; overflow: hidden; }
.rail .hours-bar { background: var(--border); height: 6px; }
.hours-fill { height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width 0.4s ease; }
.hours-fill.done { background: var(--verb); }
.hours-hint { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.hours-hint code { background: var(--panel); border-radius: 5px; padding: 1px 5px; font-size: 11px; }

/* ---------- notes ---------- */
.note-editor { padding: 18px 20px; }
.note-prompt { margin: 0 0 12px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.note-editor textarea {
  width: 100%; font-size: 16px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 10px;
  resize: vertical; font-family: inherit; background: var(--bg); color: var(--text);
}
.note-editor textarea:focus { outline: none; border-color: var(--accent); }
.note-segments { margin-top: 18px; }
.note-seg { max-width: 720px; }

/* ---------- popover ---------- */
.popover {
  position: absolute; z-index: 50; max-width: 370px; min-width: 250px; max-height: 72vh; overflow-y: auto;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-pop); padding: 15px 17px; font-size: 14px;
  animation: pop 0.16s ease-out; color: var(--text);
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(0.98); } to { opacity: 1; transform: none; } }
.popover::before {
  content: ""; position: absolute; top: -6px; left: var(--arrow-x, 50%);
  width: 10px; height: 10px; transform: translateX(-50%) rotate(45deg);
  background: var(--card); border-left: 1px solid var(--border); border-top: 1px solid var(--border);
}
.popover.above::before {
  top: auto; bottom: -6px; border-left: none; border-top: none;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.popover .p-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.popover .p-form { font-size: 21px; font-weight: 600; font-family: var(--serif); }
.popover .p-speak { border: none; background: none; cursor: pointer; padding: 2px; color: var(--muted); display: inline-flex; }
.popover .p-speak:hover { color: var(--accent); }
.p-meaning { margin-bottom: 9px; padding-bottom: 9px; border-bottom: 1px dashed var(--border); }
.p-lemma-line { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; font-size: 13px; }
.p-lemma { font-family: var(--serif); font-size: 17px; font-weight: 600; }
.p-arrow { color: var(--muted); }
.p-gloss { font-style: italic; font-size: 14px; }
.p-gloss.muted { color: var(--muted); font-style: normal; font-size: 12px; }
.p-defs { margin-top: 5px; display: flex; flex-direction: column; gap: 3px; }
.p-def { font-size: 12.5px; line-height: 1.45; }
.p-def > .term { margin-right: 5px; }
.p-tags .term { margin-right: 5px; color: var(--verb); }
.p-def-text { color: var(--muted); }
.p-via { color: var(--muted); font-style: italic; }
.popover .p-row { margin: 3px 0; }
.p-row .term:first-child, .p-lemma-line .term:first-child { color: var(--muted); }
.p-sep { color: var(--muted); }
.term {
  background: none; border: none; padding: 0; margin: 0; font: inherit; color: inherit;
  cursor: help; border-bottom: 1px dotted var(--muted); border-radius: 0; line-height: inherit;
}
.term:hover, .term.open { color: var(--accent) !important; border-bottom-color: var(--accent); }
.popover .p-why { margin-top: 10px; padding-top: 9px; border-top: 1px dashed var(--border); font-size: 13px; line-height: 1.45; }
.p-term {
  margin-top: 10px; padding: 9px 11px; border-radius: 10px; background: var(--accent-soft);
  font-size: 12.5px; line-height: 1.45; animation: rise 0.2s ease-out;
}
.p-term strong { display: block; margin-bottom: 3px; font-size: 13px; }
.p-term p { margin: 0; }
.p-term .p-example { margin-top: 5px; font-family: var(--serif); font-size: 13.5px; }

/* ---------- sheet (inflection tables) ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.35);
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
}
.sheet-card {
  background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-pop); width: min(760px, 100%); padding: 18px 22px 22px; animation: sheet-in 0.2s ease-out;
}
@keyframes sheet-in { from { transform: translateY(10px); } to { transform: none; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.sheet-head h2 { margin: 0; font-size: 18px; }
.sheet-close { border: none; background: none; color: var(--muted); cursor: pointer; padding: 4px 8px; display: inline-flex; }
.sheet-close:hover { color: var(--text); }
.paradigm h3 { margin: 12px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.ptable { border-collapse: collapse; font-size: 14px; margin: 6px 0 12px; width: 100%; }
.ptable th, .ptable td { text-align: left; padding: 5px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.ptable thead th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.ptable tbody th { font-weight: 500; color: var(--muted); white-space: nowrap; font-size: 13px; }
.ptable.wide { font-size: 13px; }
.pform {
  border: none; background: none; padding: 0; margin: 0; font: inherit; color: var(--text);
  font-family: var(--serif); font-size: 16px; cursor: pointer; border-bottom: 1px dotted transparent;
}
.pform:hover { color: var(--accent); border-bottom-color: var(--accent); }
.pextras, .phelp { font-size: 13px; color: var(--muted); margin: 8px 0 0; line-height: 1.5; }
.plist { list-style: none; margin: 4px 0 8px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; }
.ptags { margin-left: 6px; font-size: 11px; color: var(--muted); }
.p-forms {
  margin-left: auto; border: 1px solid var(--border); background: var(--card); color: var(--accent);
  border-radius: 999px; font-size: 11px; padding: 2px 9px; cursor: pointer; display: inline-flex; align-items: center; gap: 4px;
}
.p-forms:hover { border-color: var(--accent); }

/* ---------- grammar ---------- */
.gr-section { margin-bottom: 18px; }
.gr-section h2 { margin: 0 0 10px; font-size: 16px; }
.gr-text { font-size: 14px; line-height: 1.55; color: var(--text); margin: 0 0 10px; }
.gr-input {
  flex: 1; font: inherit; font-size: 15px; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--bg); color: var(--text);
}
.gr-input:focus { outline: none; border-color: var(--accent); }
.gr-result { margin-top: 10px; }
.gr-entry { margin: 4px 0; font-size: 14px; }
.table-wrap { overflow-x: auto; }
.gtable { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.gtable th, .gtable td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.gtable thead th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.gtable tbody th { font-weight: 500; white-space: nowrap; }
.gr-q { font-family: var(--serif); white-space: nowrap; }
.gr-prep { font-family: var(--serif); }
.gr-ex { font-family: var(--serif); color: var(--muted); }
.gtable .p-speak { border: none; background: none; cursor: pointer; padding: 0 4px; color: var(--muted); vertical-align: middle; }
.gtable .p-speak:hover { color: var(--accent); }
.gr-terms { display: flex; flex-direction: column; gap: 10px; }
.gr-term-list { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; }
.gr-term-card { padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); font-size: 13.5px; line-height: 1.5; }
.gr-term-card strong { display: block; margin-bottom: 3px; }
.gr-term-card p { margin: 0; }
.gr-term-card .p-example { margin-top: 5px; font-family: var(--serif); }

/* ---------- mobile ---------- */
@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .rail {
    width: 100%; height: auto; position: sticky; top: 0; z-index: 20;
    flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px;
    padding: 8px 10px; border-right: none; border-bottom: 1px solid var(--border);
  }
  .rail-top { flex: 1; }
  .lang-btn { padding: 5px 8px; }
  .lang-flag { font-size: 18px; }
  .rail-toggle { display: inline-block; }
  .rail-nav { flex: 0 0 100%; flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .rail-group { display: flex; gap: 4px; }
  .rail-group h3 { display: none; }
  .rail-item { width: auto; padding: 6px 10px; font-size: 13px; }
  .rail-bottom { display: none; width: 100%; }
  .rail.open .rail-bottom { display: flex; }
  .rail-subs, .rail-chevron { display: none; }
  .lib-filters { width: 100%; }
  .main { padding: 16px; }
  .split-layout { flex-direction: column; }
  .side-panel { width: 100%; }
  .target-output { font-size: 25px; }
  .turn { max-width: 100%; }
  .rl-text { font-size: 21px; }
  .book { font-size: 19px; }
  .read-actions { align-items: flex-start; }
}

/* the server is not reachable and no offline copy exists (shell.js unreachable()) */
.unreachable { max-width: 560px; padding: 48px 32px; }
.unreachable h1 { margin-bottom: 12px; }
.unreachable p { margin: 0 0 12px; line-height: 1.5; }

/* a piece whose line translations came from software, not a person (library.js machineTranslated) */
.badge.machine { background: rgba(190, 120, 0, 0.16); color: #9a5b00; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .badge.machine { color: #e2a44a; } }
:root[data-theme="dark"] .badge.machine { color: #e2a44a; }

/* ---------- Overheard (the feed) ---------- */
/* A phone-shaped column on a desktop, most of the screen on a phone. The
   scene behind a card is always dark so the text over it reads the same in
   either theme, which is why the word colours are pinned here rather than
   inherited from the page. */
.fd { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.fd-top { display: flex; align-items: center; gap: 10px; width: 100%; max-width: 460px; }
.fd-top h2 { margin: 0; font-size: 19px; }
.fd-badge {
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px;
}
.fd-top .fd-mute { margin-left: auto; }

.fd-stream {
  width: 100%; max-width: 460px; height: min(74vh, 740px);
  overflow-y: auto; overscroll-behavior-y: contain;
  scroll-snap-type: y mandatory; scrollbar-width: none;
  border: 1px solid var(--border); border-radius: 22px; box-shadow: var(--shadow);
  background: #14120f;
}
.fd-stream::-webkit-scrollbar { display: none; }
.fd-stream:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.fd-card {
  position: relative; height: 100%; scroll-snap-align: start; scroll-snap-stop: always;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 24px 22px 18px; overflow: hidden; color: #f6f2ea;
  --masc: #8fb6f7; --fem: #f39a9a; --neut: #e6b566; --verb: #5ed0a8; --other: #d6d0c4;
}
/* Each piece gets its own light, so you recognise where you are before you
   have read a word. Bright enough to be a place, dark enough to read on. */
.fd-bg {
  position: absolute; inset: 0; z-index: 0;
  background:
    radial-gradient(90% 55% at 22% 10%, hsl(var(--h1) 62% 52%) 0%, transparent 68%),
    radial-gradient(85% 60% at 88% 32%, hsl(var(--h2) 58% 40%) 0%, transparent 66%),
    linear-gradient(165deg, hsl(var(--h1) 42% 26%), hsl(var(--h2) 38% 13%) 78%);
}
.fd-bg::after {   /* the words sit on this, never straight on the scene */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(9, 7, 5, 0) 0%, rgba(9, 7, 5, 0.28) 34%,
                              rgba(9, 7, 5, 0.8) 66%, rgba(9, 7, 5, 0.93) 100%);
}

.fd-head { position: relative; z-index: 1; display: flex; flex-wrap: wrap; gap: 7px; }
.fd-tag {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: rgba(246, 242, 234, 0.9); background: rgba(20, 16, 12, 0.4);
  border: 1px solid rgba(246, 242, 234, 0.28); border-radius: 999px; padding: 4px 10px;
  backdrop-filter: blur(6px);
}
.fd-place { text-transform: none; letter-spacing: 0.02em; font-weight: 600; }
.fd-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

.fd-body { position: relative; z-index: 1; margin-top: auto; display: flex; flex-direction: column; gap: 14px; }
.fd-turn { display: flex; flex-direction: column; gap: 3px; }
.fd-who {
  font-size: 11px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  color: rgba(246, 242, 234, 0.62);
}
.fd-line { font-family: var(--serif); font-size: 23px; line-height: 1.45; text-shadow: 0 1px 10px rgba(0, 0, 0, 0.55); }
.fd-line .word { border-bottom-color: rgba(246, 242, 234, 0.28); }
.fd-line .word.studied { background: rgba(250, 204, 21, 0.3); border-radius: 3px; }
.fd-en {
  font-size: 14.5px; line-height: 1.45; color: rgba(246, 242, 234, 0.76);
  border-left: 2px solid rgba(246, 242, 234, 0.25); padding-left: 9px;
}

.fd-foot {
  position: relative; z-index: 1; display: flex; align-items: flex-end; gap: 10px;
  margin-top: 18px; padding-top: 12px; border-top: 1px solid rgba(246, 242, 234, 0.14);
}
.fd-source { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.fd-title {
  font-size: 12.5px; color: rgba(246, 242, 234, 0.72);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 210px;
}
.fd-source .fd-level { font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em; color: rgba(246, 242, 234, 0.5); }
.fd-actions { margin-left: auto; display: flex; gap: 8px; }

.fd-btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  font-size: 13px; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
}
.fd-card .fd-btn {
  border-color: rgba(246, 242, 234, 0.3); background: rgba(20, 16, 12, 0.45); color: #f6f2ea;
  backdrop-filter: blur(6px);
}
.fd-card .fd-btn:hover { border-color: rgba(246, 242, 234, 0.62); }
.fd-card.showing-en .fd-reveal { background: rgba(246, 242, 234, 0.9); color: #14120f; }

.fd-empty { justify-content: center; align-items: center; text-align: center; }
.fd-empty p { position: relative; z-index: 1; max-width: 280px; line-height: 1.5; }
.fd-hint { font-size: 12px; color: var(--muted); margin: 0; text-align: center; }

@media (max-width: 720px) {
  .fd-stream { max-width: none; height: calc(100vh - 190px); border-radius: 16px; }
  .fd-top { max-width: none; }
  .fd-line { font-size: 21px; }
}

/* ---------- Today (the front door) ---------- */
.td { max-width: 900px; }
.td-head h2 { margin: 0 0 6px; font-size: 26px; }
.td-why { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.5; max-width: 60ch; }
.td-grid { margin-bottom: 16px; }
.td-reason { margin: 8px 0 0; font-size: 12.5px; color: var(--accent); }
.td-reason.revisit { color: var(--neut); font-weight: 600; }
.td-reason.companion { color: var(--verb); font-weight: 600; }
.td-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.td-level { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.td-level select { font-family: inherit; font-size: 13px; padding: 3px 6px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--card); color: var(--text); }
.td-more { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 26px; padding-top: 18px; border-top: 1px solid var(--border); }
.td-link {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 14px;
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--card); color: var(--text); box-shadow: var(--shadow);
}
.td-link:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- the account menu (was a permanently open drawer) ---------- */
.rail-more {
  display: flex; align-items: center; gap: 9px; width: 100%; cursor: pointer;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 8px 10px; font-size: 13.5px; text-align: left;
}
.rail-more:hover { border-color: var(--accent); }
.rail-more.open { border-color: var(--accent); }
.rail-more-icon { display: inline-flex; color: var(--muted); }
#rail-more-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail-more .caret { margin-left: 0; color: var(--muted); transition: transform 0.15s; }
.rail-more.open .caret { transform: rotate(180deg); }
.rail-panel {
  margin-top: 10px; display: flex; flex-direction: column; gap: 14px;
  max-height: 60vh; overflow-y: auto;
}
.rail-extra { display: flex; flex-direction: column; gap: 2px; }
.rail-quiet {
  display: flex; align-items: center; gap: 8px; cursor: pointer; text-align: left;
  border: 0; background: none; color: var(--muted); font-size: 13px; padding: 5px 2px; border-radius: 8px;
}
.rail-quiet:hover { color: var(--accent); }

/* ---------- reading modes ---------- */
.rs-modes { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.rs-mode {
  display: flex; flex-direction: column; gap: 1px; cursor: pointer; text-align: left;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  border-radius: 10px; padding: 8px 11px; font-size: 13.5px;
}
.rs-mode strong { font-weight: 600; }
.rs-mode span { font-size: 12px; color: var(--muted); }
.rs-mode:hover { border-color: var(--accent); }
.rs-mode.on { border-color: var(--accent); background: var(--accent-soft); }
.rs-mode.on span { color: var(--text); }
.rs-custom-btn {
  border: 0; background: none; color: var(--muted); cursor: pointer;
  font-size: 12.5px; padding: 4px 2px; text-decoration: underline; text-underline-offset: 3px;
}
.rs-custom-btn:hover, .rs-custom-btn.open { color: var(--accent); }

/* ---------- how hard a piece is for its own level ---------- */
/* A vertical gauge beside the level badge: low and green at the gentle end of
   the level, filling up through amber to red at the hard end. */
.diffbar {
  display: inline-flex; align-items: flex-end; vertical-align: middle;
  width: 9px; height: 19px; margin-left: 3px; padding: 1px;
  border-radius: 4px; background: color-mix(in srgb, var(--text) 9%, transparent);
  border: 1px solid var(--border); overflow: hidden; flex-shrink: 0;
}
.diffbar-fill { display: block; width: 100%; border-radius: 2px; background: currentColor; }
.diffbar.green { color: #3f9d5a; }
.diffbar.amber { color: #d99a1c; }
.diffbar.red { color: #cf5340; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .diffbar.green { color: #59bd76; }
  :root:not([data-theme="light"]) .diffbar.amber { color: #e6b64a; }
  :root:not([data-theme="light"]) .diffbar.red { color: #e4705c; }
}
:root[data-theme="dark"] .diffbar.green { color: #59bd76; }
:root[data-theme="dark"] .diffbar.amber { color: #e6b64a; }
:root[data-theme="dark"] .diffbar.red { color: #e4705c; }

/* the line of encouragement under Today's picks */
.td-note {
  margin: 0 0 18px; padding: 11px 15px; border-radius: 10px; max-width: 62ch;
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text); font-size: 13.5px; line-height: 1.55;
}
.td-toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }

/* the one-time explanation of delayed subtitles, shown where it is true */
.pl-tip {
  margin: 0 0 14px; padding: 10px 14px; border-radius: 10px;
  background: var(--accent-soft); color: var(--text); font-size: 13.5px; line-height: 1.5;
  border: 1px solid var(--border); max-width: 62ch;
}
