:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --text: #e8ecf1;
  --muted: #8b99a8;
  --accent: #3d9a7a;
  --danger: #c75c5c;
  --ok: #45a868;
  --warn: #c9a24a;
  --border: #2a3545;
  --font: "Georgia", "Times New Roman", serif;
  --sans: system-ui, "Segoe UI", Roboto, Ubuntu, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); }
h1 { font-size: 1.25rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }
.tagline { margin: 0.15rem 0 0; font-size: 0.85rem; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #151c28, var(--bg));
}
.brand { display: flex; gap: 0.65rem; align-items: center; }
.brand-mark { font-size: 1.5rem; }
.header-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.main { padding: 1rem; max-width: 960px; margin: 0 auto; }
.view { margin-bottom: 1.5rem; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
}
.btn {
  font: inherit;
  cursor: pointer;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #243044;
  color: var(--text);
}
.btn:hover { filter: brightness(1.08); }
.btn-primary { background: var(--accent); border-color: #2d7a62; color: #0b120e; font-weight: 600; }
.btn-ghost { background: transparent; }
.btn-success { background: #2d5a3f; border-color: var(--ok); }
.btn-danger { background: #5a2d2d; border-color: var(--danger); }
.tabs { display: flex; gap: 0.25rem; margin-bottom: 0.75rem; }
.tab {
  flex: 1;
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #1e2736;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
}
.tab.active { color: var(--text); border-color: var(--accent); background: #243044; }
.auth-lang-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.5rem; font-size: 0.88rem; flex-wrap: wrap; }
.auth-ui-lang { font: inherit; padding: 0.35rem 0.5rem; border-radius: 8px; border: 1px solid var(--border); background: #121820; color: var(--text); max-width: 100%; }
.auth-pwa-hint { font-size: 0.88rem; line-height: 1.45; margin: 0 0 0.65rem; }
.form-auth label { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.65rem; font-size: 0.9rem; }
.form-auth input, .form-auth select, .form-auth textarea {
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #121820;
  color: var(--text);
  font: inherit;
}
.form-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.5rem; align-items: center; }
.forgot-box { margin-top: 1rem; font-size: 0.9rem; color: var(--muted); }
.banner {
  margin: 0.5rem 1rem 0;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 0.88rem;
  max-width: 960px;
  margin-left: auto;
  margin-right: auto;
}
.banner-info { background: #243044; border: 1px solid var(--border); }
.banner-success { background: #1e332a; border: 1px solid #2d6a4f; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.book-list { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.book-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border);
}
.book-list button.link { background: none; border: none; color: var(--accent); text-align: left; cursor: pointer; padding: 0; font: inherit; flex: 1; }
.book-groups { display: flex; flex-direction: column; gap: 1rem; margin-top: 0.5rem; }
.book-group { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.5rem 0.85rem; }
.book-group h3 { margin: 0.25rem 0 0.35rem; font-size: 0.95rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.book-tag { font-size: 0.7rem; padding: 0.1rem 0.4rem; border-radius: 999px; background: #243044; color: var(--muted); border: 1px solid var(--border); margin-left: 0.4rem; }
.book-tag.shared { background: #2a4a3a; color: #b5e0c8; border-color: #2d6a4f; }
.book-meta { display: flex; align-items: center; gap: 0.35rem; }
.drafts-box { margin-top: 1rem; font-size: 0.9rem; }
.draft-list { list-style: none; padding: 0; margin: 0.25rem 0 0; }
.draft-list li { display: flex; justify-content: space-between; align-items: center; padding: 0.25rem 0; }
.reader-toolbar h2 { flex: 1; font-size: 1rem; }
.reader-chrome { display: flex; justify-content: center; margin-top: 0.35rem; }
.reader-pager { display: flex; align-items: center; gap: 0.5rem; }
.reader-page-label { font-size: 0.9rem; min-width: 7rem; text-align: center; }
.reader-shell {
  margin-top: 0.5rem;
  padding: 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #121820;
  min-height: 180px;
}
.reader-inner { font-family: var(--font); font-size: 1.15rem; line-height: 1.75; white-space: normal; word-wrap: break-word; text-align: justify; text-justify: inter-word; hyphens: auto; }
.reader-text .word-tok {
  display: inline;
  padding: 0.05rem 0.1rem;
  margin: 0 0.02rem;
  border-radius: 4px;
  border: none;
  background: transparent;
  font: inherit;
  cursor: pointer;
  vertical-align: baseline;
}
.reader-text .word-tok.state-none { color: #c9cdd3; }
.reader-text .word-tok.state-ok { color: var(--ok); font-weight: 600; }
.reader-text .word-tok.state-learned { color: #e6c84a; font-weight: 600; }
.reader-text .word-tok.state-fail { color: #e07070; font-weight: 600; }
.reader-text .word-tok.state-translated { position: relative; }
.reader-text .word-tok.state-translated::after {
  content: "";
  display: inline-block;
  width: 0.42rem;
  height: 0.42rem;
  margin-left: 0.15rem;
  border-radius: 999px;
  background: rgba(201, 162, 74, 0.95);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.35);
  vertical-align: middle;
}
.filter-dim { opacity: 0.28; }
.reader-text .word-tok.state-ok.filter-dim,
.reader-text .word-tok.state-fail.filter-dim,
.reader-text .word-tok.state-learned.filter-dim { opacity: 1; }
.filter-hit { outline: 1px dashed rgba(255,255,255,0.25); }
.word-flash { outline: 2px solid var(--warn); background: rgba(201, 162, 74, 0.18); border-radius: 4px; animation: wm-flash 2.2s ease-out 1; }
.word-same { border-radius: 4px; }
.word-same.state-ok { background: rgba(69, 168, 104, 0.14); }
.word-same.state-fail { background: rgba(224, 112, 112, 0.12); }
.word-same.state-learned { background: rgba(230, 200, 74, 0.14); }
.word-same.state-none { background: rgba(201, 162, 74, 0.09); }
@keyframes wm-flash { from { background: rgba(201, 162, 74, 0.45); } to { background: rgba(201, 162, 74, 0.12); } }
.wm-occ-row { display: flex; flex-direction: column; align-items: center; gap: 0.35rem; margin: 0.35rem 0; font-size: 0.88rem; }
.wm-occ-row.hidden { display: none !important; }
.wm-occ-nav { display: flex; align-items: center; gap: 0.35rem; }
.wm-occ-pos { min-width: 4rem; text-align: center; font-variant-numeric: tabular-nums; }
.wm-trans-panel { margin: 0.45rem 0; padding: 0.55rem 0.65rem; border-radius: 10px; border: 1px solid var(--border); background: #121820; }
.wm-trans-panel.hidden { display: none !important; }
.wm-trans-caption { font-size: 0.82rem; margin-bottom: 0.35rem; }
.wm-trans-result { font-size: 0.95rem; line-height: 1.5; white-space: pre-wrap; max-height: 14rem; overflow: auto; color: var(--text); }
.gram-filters { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.35rem; }
.gram-filters button { font-size: 0.8rem; }
.gram-filters button.active { outline: 2px solid var(--accent); }
.stats-summary { font-size: 0.95rem; line-height: 1.5; }
.stats-book { margin-top: 1rem; font-size: 0.9rem; overflow-x: auto; }
table.simple { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.simple th, table.simple td { border: 1px solid var(--border); padding: 0.35rem 0.45rem; text-align: left; }
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}
.modal[hidden] { display: none !important; }
.modal-card {
  position: relative;
  width: min(100%, 420px);
  max-height: 90vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1rem 0.75rem;
}
.modal-x {
  position: absolute;
  top: 0.35rem;
  right: 0.45rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.35rem;
  cursor: pointer;
  line-height: 1;
}
.wm-word { font-size: 1.75rem; font-weight: 700; text-align: center; margin: 0.25rem 0 0.5rem; }
.wm-translit { text-align: center; font-size: 0.95rem; margin: -0.35rem 0 0.5rem; }
.wm-context { font-size: 0.95rem; line-height: 1.45; }
.wm-grid { display: grid; gap: 0.5rem; margin: 0.5rem 0; }
.wm-grid label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; }
.wm-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.5rem 0; }
.wm-history { margin-top: 0.5rem; border-top: 1px solid var(--border); padding-top: 0.5rem; }
.wm-history-body { max-height: 160px; overflow: auto; font-size: 0.82rem; }
.history-row { border-bottom: 1px solid var(--border); padding: 0.35rem 0; }
.history-row time { font-size: 0.75rem; color: var(--muted); }
.history-row .ok { color: var(--ok); margin-left: 0.35rem; }
.history-row .fail { color: var(--danger); margin-left: 0.35rem; }
.wm-pos { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; margin: 0.25rem 0; }
.toast-root { position: fixed; bottom: 1rem; right: 1rem; left: 1rem; display: flex; flex-direction: column; gap: 0.35rem; align-items: flex-end; pointer-events: none; z-index: 100; }
.toast {
  pointer-events: auto;
  max-width: 420px;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  background: #243044;
  border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(0,0,0,0.35);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.25s, transform 0.25s;
}
.toast-in { opacity: 1; transform: translateY(0); }
.toast-out { opacity: 0; }
.toast-info { border-color: var(--border); }
.toast-error { border-color: var(--danger); background: #3a2424; }
