/* =========================================================
   Говорящий Брайль — editorial / tactile paper design
   ========================================================= */

:root,
[data-theme="light"] {
  --paper: #f3eee4;
  --paper-2: #ebe4d6;
  --sheet: #fbf8f2;
  --ink: #1f1c18;
  --ink-2: #4a443b;
  --ink-3: #847b6d;
  --rule: #d9d0bf;
  --rule-strong: #b9ad97;
  --accent: #a8442a;
  --accent-ink: #fff8f1;
  --accent-soft: #f1ddd2;
  --olive: #56603b;
  --focus: #c47a1e;
  --viewfinder: #1b1916;
  --dot-off: #d8cfbd;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset, 0 1px 2px rgba(60, 45, 20, 0.06), 0 12px 32px -18px rgba(60, 45, 20, 0.28);
  --emboss: 0 1px 0 rgba(255, 255, 255, 0.9), 0 -1px 0 rgba(90, 70, 40, 0.18);
  --box-stroke: #e0a24a;
  --grain-opacity: 0.35;
  color-scheme: light;
}

[data-theme="dark"] {
  --paper: #191714;
  --paper-2: #211e1a;
  --sheet: #24211c;
  --ink: #efe8dc;
  --ink-2: #c9c0b1;
  --ink-3: #8f8676;
  --rule: #3a352d;
  --rule-strong: #554d41;
  --accent: #e07a55;
  --accent-ink: #1d120c;
  --accent-soft: #3a2519;
  --olive: #a9b57f;
  --focus: #f0b04a;
  --viewfinder: #0f0e0c;
  --dot-off: #3d372e;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 16px 36px -20px rgba(0, 0, 0, 0.7);
  --emboss: 0 1px 0 rgba(255, 255, 255, 0.06), 0 -1px 0 rgba(0, 0, 0, 0.5);
  --box-stroke: #f0b04a;
  --grain-opacity: 0.18;
  color-scheme: dark;
}

[data-theme="hc"] {
  --paper: #000;
  --paper-2: #000;
  --sheet: #000;
  --ink: #ffe600;
  --ink-2: #ffe600;
  --ink-3: #fff38a;
  --rule: #ffe600;
  --rule-strong: #ffe600;
  --accent: #ffe600;
  --accent-ink: #000;
  --accent-soft: #000;
  --olive: #ffe600;
  --focus: #fff;
  --viewfinder: #000;
  --dot-off: #5c5300;
  --shadow: none;
  --emboss: none;
  --box-stroke: #00ff88;
  --grain-opacity: 0;
  color-scheme: dark;
}

[data-fontsize="normal"] { font-size: 16px; }
[data-fontsize="large"] { font-size: 18.5px; }
[data-fontsize="xlarge"] { font-size: 21px; }

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: "Onest", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  position: relative;
}

/* paper grain */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.35  0 0 0 0 0.28  0 0 0 0 0.18  0 0 0 0.22 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  mix-blend-mode: multiply;
}

body > * { position: relative; z-index: 1; }

h1, h2, h3 { margin: 0; font-weight: 600; }

:focus-visible {
  outline: 2.5px solid var(--focus);
  outline-offset: 3px;
  border-radius: 6px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink);
  color: var(--paper);
  padding: 0.7rem 1.1rem;
  font-weight: 600;
  z-index: 100;
}
.skip-link:focus { left: 1rem; top: 1rem; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden { display: none !important; }

.ico {
  width: 1.2em;
  height: 1.2em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

kbd {
  font-family: "Onest", system-ui, sans-serif;
  font-size: 0.78em;
  font-weight: 600;
  padding: 0.12em 0.5em;
  border-radius: 5px;
  border: 1px solid var(--rule-strong);
  border-bottom-width: 2px;
  background: var(--sheet);
  color: var(--ink-2);
}

.eyebrow {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---------------- Masthead ---------------- */
.masthead {
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(var(--paper), var(--paper));
}

.masthead-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.25rem 1.75rem 0.9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 2rem;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: 0.9rem;
  color: inherit;
  text-decoration: none;
}

.mark {
  display: grid;
  grid-template-columns: repeat(2, 9px);
  grid-template-rows: repeat(3, 9px);
  grid-auto-flow: column;
  gap: 4px 5px;
  padding: 7px 8px;
  border-radius: 9px;
  background: var(--sheet);
  border: 1px solid var(--rule);
  box-shadow: var(--shadow);
}
.mark i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--dot-off);
}
.mark i.on {
  background: var(--accent);
  box-shadow: inset 0 -1.5px 0 rgba(0, 0, 0, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.wordmark-text { display: flex; flex-direction: column; line-height: 1.15; }

.wordmark-title {
  font-family: "Literata", "PT Serif", Georgia, serif;
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.wordmark-sub {
  font-family: "Literata", "PT Serif", Georgia, serif;
  font-style: italic;
  font-size: 0.92rem;
  color: var(--ink-3);
}

.masthead-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--ink-2);
  padding: 0.35rem 0.2rem;
  margin-right: 0.5rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent);
}
.status-dot.ready {
  background: var(--olive);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--olive) 22%, transparent);
}

.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 999px;
  background: var(--paper-2);
  border: 1px solid var(--rule);
}

.chip-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.38rem 0.85rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
}
.chip-btn:hover { color: var(--ink); }
.chip-btn.active {
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(40, 30, 10, 0.12), 0 0 0 1px var(--rule);
}

.segmented-font .chip-btn:nth-child(1) { font-size: 0.78rem; }
.segmented-font .chip-btn:nth-child(2) { font-size: 0.92rem; }
.segmented-font .chip-btn:nth-child(3) { font-size: 1.06rem; }

[data-theme="hc"] .chip-btn.active { background: var(--ink); color: #000; }

/* Tabs */
.tabs {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 1.75rem;
  display: flex;
  gap: 2rem;
  overflow-x: auto;
}

.tab-btn {
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 0.75rem 0 0.85rem;
  font: inherit;
  font-size: 1rem;
  font-weight: 500;
  color: var(--ink-3);
  cursor: pointer;
  display: inline-flex;
  align-items: baseline;
  gap: 0.55rem;
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s;
}
.tab-btn:hover { color: var(--ink); }
.tab-btn.active { color: var(--ink); border-bottom-color: var(--accent); }

.tab-num {
  font-family: "Literata", Georgia, serif;
  font-style: italic;
  font-size: 0.82rem;
  color: var(--accent);
  font-variant-numeric: oldstyle-nums;
}

/* ---------------- Page ---------------- */
.page {
  max-width: 1320px;
  margin: 0 auto;
  padding: 2.25rem 1.75rem 3rem;
}

.tab-panel { animation: fade 0.35s ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.intro {
  max-width: 46rem;
  margin-bottom: 2rem;
}

.intro-title {
  font-family: "Literata", "PT Serif", Georgia, serif;
  font-size: clamp(1.7rem, 3.2vw, 2.45rem);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.015em;
}
.intro-title em {
  font-style: italic;
  font-weight: 400;
  color: var(--accent);
}

.intro-lead {
  margin: 0.8rem 0 0;
  font-size: 1.05rem;
  color: var(--ink-2);
  max-width: 40rem;
}

.reader-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 1.75rem;
  align-items: start;
}

.cards-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 1.75rem;
  align-items: stretch;
}

.side { display: flex; flex-direction: column; gap: 1.25rem; }

@media (max-width: 1040px) {
  .reader-grid, .cards-grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--sheet);
  border: 1px solid var(--rule);
  border-radius: 16px;
  padding: 1.35rem 1.4rem;
  box-shadow: var(--shadow);
}

[data-theme="hc"] .panel { border-width: 2px; }

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem 1rem;
  margin-bottom: 1rem;
}

.panel-title {
  font-family: "Literata", "PT Serif", Georgia, serif;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.005em;
}

/* ---------------- Viewfinder ---------------- */
.cam-tools { display: flex; align-items: center; gap: 0.5rem; }

.viewfinder {
  position: relative;
  min-height: 360px;
  max-height: 560px;
  border-radius: 12px;
  background:
    radial-gradient(120% 90% at 50% 40%, color-mix(in srgb, var(--viewfinder) 80%, #3a3128) 0%, var(--viewfinder) 70%);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  isolation: isolate;
}

.viewfinder.dragover { box-shadow: inset 0 0 0 2px var(--box-stroke); }

#camera-video,
#preview-image {
  display: block;
  max-width: 100%;
  max-height: 540px;
  width: auto;
  height: auto;
  object-fit: contain;
}

#overlay-canvas { position: absolute; pointer-events: none; }

.crop {
  position: absolute;
  width: 22px;
  height: 22px;
  border-color: rgba(255, 244, 225, 0.55);
  border-style: solid;
  border-width: 0;
  z-index: 3;
  pointer-events: none;
}
.crop-tl { top: 14px; left: 14px; border-top-width: 1.5px; border-left-width: 1.5px; border-top-left-radius: 4px; }
.crop-tr { top: 14px; right: 14px; border-top-width: 1.5px; border-right-width: 1.5px; border-top-right-radius: 4px; }
.crop-bl { bottom: 14px; left: 14px; border-bottom-width: 1.5px; border-left-width: 1.5px; border-bottom-left-radius: 4px; }
.crop-br { bottom: 14px; right: 14px; border-bottom-width: 1.5px; border-right-width: 1.5px; border-bottom-right-radius: 4px; }

.placeholder {
  text-align: center;
  padding: 2rem 1.5rem;
  color: #efe6d6;
}

.placeholder-cells {
  display: inline-flex;
  gap: 14px;
  margin-bottom: 1.4rem;
}
.placeholder-cells .cell {
  display: grid;
  grid-template-columns: repeat(2, 12px);
  grid-template-rows: repeat(3, 12px);
  grid-auto-flow: column;
  gap: 6px 7px;
}
.placeholder-cells i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(255, 240, 215, 0.1);
}
.placeholder-cells i.on {
  background: radial-gradient(circle at 38% 32%, #fff6e6 0%, #d9c7a8 55%, #9c8a6c 100%);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.45);
}

.placeholder-title {
  font-family: "Literata", Georgia, serif;
  font-size: 1.25rem;
  margin: 0 0 0.25rem;
  color: #fbf3e6;
}
.placeholder-hint { margin: 0 0 1.1rem; color: #b8ab96; font-size: 0.95rem; }
.placeholder-keys { margin: 0; font-size: 0.85rem; color: #a99c87; }
.placeholder-keys kbd { background: rgba(255, 255, 255, 0.06); color: #efe6d6; border-color: rgba(255, 255, 255, 0.22); }
.sep { opacity: 0.5; margin: 0 0.25rem; }

.scanning {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: rgba(20, 17, 13, 0.42);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 1.4rem;
}
.scan-line {
  position: absolute;
  left: 8%;
  right: 8%;
  height: 1.5px;
  background: var(--box-stroke);
  box-shadow: 0 0 14px 2px color-mix(in srgb, var(--box-stroke) 55%, transparent);
  animation: sweep 1.3s ease-in-out infinite alternate;
}
@keyframes sweep { from { top: 14%; } to { top: 86%; } }
.scanning-label {
  font-size: 0.9rem;
  color: #fbf3e6;
  background: rgba(20, 17, 13, 0.7);
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
}

/* ---------------- Buttons ---------------- */
.actions { margin-top: 1.1rem; display: flex; flex-direction: column; gap: 0.7rem; }
.actions-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.6rem; }
.actions-row .btn { white-space: nowrap; font-size: 0.9rem; padding-left: 0.75rem; padding-right: 0.75rem; }
@media (max-width: 640px) { .actions-row { grid-template-columns: 1fr; } }

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.2;
  padding: 0.8rem 1.1rem;
  min-height: 3rem;
  border-radius: 11px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.08s ease, background 0.18s, border-color 0.18s, color 0.18s, box-shadow 0.18s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; }
.btn-accent:disabled {
  opacity: 1;
  background: var(--paper-2);
  color: var(--ink-3);
  border-color: var(--rule);
  box-shadow: none;
}

.btn-ink {
  background: var(--ink);
  color: var(--paper);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.12) inset, 0 6px 16px -8px rgba(30, 20, 5, 0.55);
}
.btn-ink:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 88%, var(--accent)); }

.btn-hero {
  min-height: 3.75rem;
  font-size: 1.1rem;
  border-radius: 13px;
  position: relative;
}
.btn-kbd {
  position: absolute;
  right: 1rem;
  background: transparent;
  color: color-mix(in srgb, var(--paper) 70%, transparent);
  border-color: color-mix(in srgb, var(--paper) 30%, transparent);
}
@media (max-width: 520px) { .btn-kbd { display: none; } }

.btn-accent {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.18) inset, 0 6px 16px -8px color-mix(in srgb, var(--accent) 70%, transparent);
}
.btn-accent:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 88%, #000); }

.btn-line {
  background: transparent;
  color: var(--ink);
  border-color: var(--rule-strong);
}
.btn-line:hover:not(:disabled) { border-color: var(--ink); background: var(--paper); }
.btn-line[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-wide { flex: 1 1 14rem; }
.btn-small { min-height: 2.4rem; padding: 0.5rem 0.85rem; font-size: 0.88rem; }

.icon-btn {
  appearance: none;
  width: 2.6rem;
  height: 2.6rem;
  display: inline-grid;
  place-items: center;
  border-radius: 10px;
  border: 1px solid var(--rule-strong);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.link-btn {
  appearance: none;
  background: none;
  border: 0;
  padding: 0.2rem 0;
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink-3);
  text-decoration: underline;
  text-decoration-color: var(--rule-strong);
  text-underline-offset: 3px;
  cursor: pointer;
}
.link-btn:hover { color: var(--accent); text-decoration-color: currentColor; }

[data-theme="hc"] .btn { border: 2px solid var(--ink); }
[data-theme="hc"] .btn-ink,
[data-theme="hc"] .btn-accent { background: var(--ink); color: #000; }

/* ---------------- Samples ---------------- */
.samples {
  margin-top: 1.4rem;
  padding-top: 1.1rem;
  border-top: 1px dashed var(--rule-strong);
}
.samples-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.samples-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.6rem;
}

.sample-btn {
  appearance: none;
  text-align: left;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 11px;
  padding: 0.75rem 0.9rem 0.8rem;
  cursor: pointer;
  transition: border-color 0.18s, background 0.18s, transform 0.12s;
  position: relative;
}
.sample-btn::after {
  content: "→";
  position: absolute;
  right: 0.85rem;
  top: 0.7rem;
  color: var(--ink-3);
  transition: transform 0.18s, color 0.18s;
}
.sample-btn:hover { border-color: var(--rule-strong); background: var(--sheet); }
.sample-btn:hover::after { transform: translateX(3px); color: var(--accent); }
.sample-btn strong {
  display: block;
  font-family: "Literata", Georgia, serif;
  font-weight: 600;
  font-size: 0.98rem;
  padding-right: 1.4rem;
  margin-bottom: 0.15rem;
}
.sample-btn span { display: block; font-size: 0.82rem; color: var(--ink-3); line-height: 1.4; }

/* ---------------- Checkboxes ---------------- */
.check {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.92rem;
  color: var(--ink-2);
  cursor: pointer;
  position: relative;
}
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.check-box {
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 5px;
  border: 1.5px solid var(--rule-strong);
  background: var(--sheet);
  display: inline-grid;
  place-items: center;
  flex: none;
  transition: background 0.15s, border-color 0.15s;
}
.check input:checked + .check-box {
  background: var(--ink);
  border-color: var(--ink);
}
.check input:checked + .check-box::after {
  content: "";
  width: 0.32rem;
  height: 0.6rem;
  border: solid var(--paper);
  border-width: 0 2px 2px 0;
  transform: translateY(-1px) rotate(45deg);
}
.check input:focus-visible + .check-box { outline: 2.5px solid var(--focus); outline-offset: 2px; }

/* ---------------- Reading sheet ---------------- */
.meta { display: flex; flex-wrap: wrap; gap: 0 0.9rem; }
.meta-item {
  font-size: 0.8rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}
.meta-item + .meta-item::before {
  content: "·";
  margin-right: 0.9rem;
  margin-left: -0.45rem;
  color: var(--rule-strong);
}

.reading {
  min-height: 8.5rem;
  padding: 1.1rem 1.2rem;
  border-radius: 12px;
  background:
    repeating-linear-gradient(to bottom, transparent 0, transparent calc(2.35rem - 1px), color-mix(in srgb, var(--rule) 70%, transparent) calc(2.35rem - 1px), color-mix(in srgb, var(--rule) 70%, transparent) 2.35rem),
    var(--paper);
  background-position: 0 1.05rem;
  border: 1px solid var(--rule);
  font-family: "Literata", "PT Serif", Georgia, serif;
  font-size: 1.7rem;
  font-weight: 500;
  line-height: 2.35rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.reading.empty {
  font-style: italic;
  font-weight: 400;
  font-size: 1.15rem;
  color: var(--ink-3);
}
[data-theme="hc"] .reading { background: #000; }

.braille-strip { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.4rem; }

.braille-line {
  font-size: 1.55rem;
  letter-spacing: 0.14em;
  line-height: 1.5;
  color: var(--ink-2);
  padding: 0.55rem 0.9rem;
  border-radius: 10px;
  background: var(--paper-2);
  text-shadow: var(--emboss);
  white-space: pre-wrap;
  word-break: break-all;
  min-height: 2.9rem;
}

.sheet-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-top: 1.15rem; }

/* ---------------- Settings ---------------- */
.settings { padding-bottom: 1.2rem; }
.summary {
  list-style: none;
  cursor: pointer;
  margin-bottom: 0;
}
.summary::-webkit-details-marker { display: none; }
.summary::after {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  border: solid var(--ink-3);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
  margin-left: auto;
  transition: transform 0.2s;
}
.settings[open] .summary { margin-bottom: 1.1rem; }
.settings[open] .summary::after { transform: rotate(-135deg); }
.summary-hint { font-size: 0.85rem; color: var(--ink-3); font-style: italic; font-family: "Literata", Georgia, serif; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem 1.1rem;
  margin-top: 1rem;
}
.settings .settings-grid { margin-top: 0; }
@media (max-width: 560px) { .settings-grid { grid-template-columns: 1fr; } }

.field-group { display: flex; flex-direction: column; gap: 0.38rem; }
.field-group label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-2);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.field-group output { font-weight: 500; color: var(--accent); font-variant-numeric: tabular-nums; }

.field {
  width: 100%;
  font: inherit;
  font-size: 0.95rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
  padding: 0.62rem 0.8rem;
  transition: border-color 0.18s, box-shadow 0.18s;
}
select.field {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  padding-right: 2.3rem;
  background-image: 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.5 1.5L6 6l4.5-4.5' fill='none' stroke='%23847b6d' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-position: right 0.85rem center;
  background-size: 12px 8px;
  background-repeat: no-repeat;
}
.field:hover { border-color: var(--ink-3); }
.field:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
.field-compact { width: auto; min-width: 12rem; padding-top: 0.45rem; padding-bottom: 0.45rem; font-size: 0.88rem; }
.field-area {
  font-family: "Literata", Georgia, serif;
  font-size: 1.15rem;
  line-height: 1.5;
  resize: vertical;
}

.stepper { display: flex; align-items: center; gap: 0.55rem; }
.step-btn {
  appearance: none;
  width: 2.3rem;
  height: 2.3rem;
  flex: none;
  border-radius: 50%;
  border: 1px solid var(--rule-strong);
  background: var(--paper);
  color: var(--ink);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}
.step-btn:hover { border-color: var(--ink); }

input[type="range"] {
  flex: 1;
  appearance: none;
  height: 2px;
  background: var(--rule-strong);
  border-radius: 2px;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--sheet);
  border: 2px solid var(--accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--sheet);
  border: 2px solid var(--accent);
  cursor: pointer;
}

.toggles {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1.1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--rule-strong);
}

/* ---------------- Journal ---------------- */
.journal-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
}
.history-empty {
  color: var(--ink-3);
  font-style: italic;
  font-family: "Literata", Georgia, serif;
  font-size: 0.95rem;
}
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--rule);
}
.history-item:last-child { border-bottom: 0; }
.history-item-text {
  flex: 1;
  font-family: "Literata", Georgia, serif;
  font-size: 1rem;
}
.history-item .chip-btn {
  border: 1px solid var(--rule-strong);
  font-size: 0.8rem;
  padding: 0.3rem 0.75rem;
}
.history-item .chip-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ---------------- Cards tab ---------------- */
.card-preview {
  margin-top: 0.9rem;
  min-height: 168px;
  border-radius: 12px;
  border: 1px dashed var(--rule-strong);
  background: var(--paper);
  display: grid;
  place-items: center;
  padding: 1rem;
  overflow: auto;
}
#gen-card-img {
  max-width: 100%;
  border-radius: 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08), 0 18px 34px -20px rgba(50, 35, 10, 0.5);
  transform: rotate(-0.6deg);
}

/* ---------------- Alphabet ---------------- */
.section-label {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin: 1.8rem 0 0.9rem;
  font-family: "Literata", Georgia, serif;
  font-size: 1.15rem;
  font-weight: 600;
}
.section-label:first-child { margin-top: 0.2rem; }
.section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
  transform: translateY(-0.3em);
}
.section-label small {
  font-family: "Onest", sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-2);
}

.alpha-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 0.6rem;
}
.alpha-grid-wide { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

.alpha-card {
  appearance: none;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 0.85rem 0.5rem 0.7rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: border-color 0.18s, transform 0.12s, background 0.18s;
}
.alpha-card:hover {
  border-color: var(--rule-strong);
  background: var(--sheet);
  transform: translateY(-1px);
}
.alpha-card:hover .dot-pip.on { background: var(--accent); }

.alpha-char {
  font-family: "Literata", Georgia, serif;
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1;
}
.alpha-grid-wide .alpha-char { font-size: 0.98rem; font-family: "Onest", sans-serif; font-weight: 600; text-align: center; }

.dots-matrix {
  display: grid;
  grid-template-columns: repeat(2, 11px);
  grid-template-rows: repeat(3, 11px);
  grid-auto-flow: column;
  gap: 5px 7px;
}
.dot-pip {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--dot-off);
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.08);
  transition: background 0.18s;
}
.dot-pip.on {
  background: var(--ink);
  box-shadow: inset 0 -1.5px 0 rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.alpha-dots-num {
  font-size: 0.72rem;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------------- Footer ---------------- */
.colophon {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.5rem 1.75rem 2.5rem;
  border-top: 1px solid var(--rule);
  font-size: 0.82rem;
  color: var(--ink-3);
  font-family: "Literata", Georgia, serif;
  font-style: italic;
}

@media (max-width: 640px) {
  .masthead-inner, .tabs, .page, .colophon { padding-left: 1.1rem; padding-right: 1.1rem; }
  .panel { padding: 1.1rem; border-radius: 14px; }
  .reading { font-size: 1.4rem; }
  .status { width: 100%; margin: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
