@font-face {
  font-family: "Literata";
  src: url("fonts/literata-cyrillic.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Literata";
  src: url("fonts/literata-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- Темы. «Бумага» — по умолчанию, как экран Kindle ---------- */

:root,
:root[data-theme="paper"] {
  --bg: #f3f0e8;
  --fg: #24211d;
  --fg-soft: #3b3731;
  --dim: #716c62;
  --faint: #aaa59a;
  --line: #ddd8cc;
  --panel: #ebe7dd;
  --btn: #e3ded2;
  --btn-hover: #d9d3c5;
  --focus: #a33a28;
  --accent: #2a2723;
  --on-accent: #f3f0e8;
  --mark: rgba(163, 58, 40, 0.14);
  --cover-shadow: 0 1px 2px rgba(60, 50, 30, 0.18), 0 8px 18px rgba(60, 50, 30, 0.14);
  --grain: 0.55;
  color-scheme: light;
}

:root[data-theme="sepia"] {
  --bg: #f1e5ce;
  --fg: #3b2e20;
  --fg-soft: #4a3b2b;
  --dim: #7b6852;
  --faint: #ae9b80;
  --line: #dccbae;
  --panel: #e8dac0;
  --btn: #e2d2b5;
  --btn-hover: #d8c6a6;
  --focus: #a5432b;
  --accent: #3b2e20;
  --on-accent: #f1e5ce;
  --mark: rgba(165, 67, 43, 0.15);
  --cover-shadow: 0 1px 2px rgba(70, 45, 20, 0.2), 0 8px 18px rgba(70, 45, 20, 0.16);
  --grain: 0.55;
  color-scheme: light;
}

:root[data-theme="graphite"] {
  --bg: #1e1f22;
  --fg: #dedad2;
  --fg-soft: #c9c4ba;
  --dim: #8f8b84;
  --faint: #5e5c58;
  --line: #313236;
  --panel: #26272a;
  --btn: #2e2f33;
  --btn-hover: #383a3e;
  --focus: #e2826a;
  --accent: #e2826a;
  --on-accent: #1e1f22;
  --mark: rgba(226, 130, 106, 0.22);
  --cover-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 18px rgba(0, 0, 0, 0.35);
  --grain: 0;
  color-scheme: dark;
}

:root[data-theme="night"] {
  --bg: #000000;
  --fg: #d3ccbe;
  --fg-soft: #b9b2a5;
  --dim: #807a70;
  --faint: #4b4740;
  --line: #1d1c1a;
  --panel: #121110;
  --btn: #1b1a18;
  --btn-hover: #25231f;
  --focus: #da8a6e;
  --accent: #da8a6e;
  --on-accent: #000000;
  --mark: rgba(218, 138, 110, 0.22);
  --cover-shadow: 0 1px 2px rgba(0, 0, 0, 0.6), 0 8px 18px rgba(0, 0, 0, 0.5);
  --grain: 0;
  color-scheme: dark;
}

:root[data-theme="amber"] {
  --bg: #000000;
  --fg: #d29a55;
  --fg-soft: #b98648;
  --dim: #8a663b;
  --faint: #554027;
  --line: #231a0f;
  --panel: #110c06;
  --btn: #1b140b;
  --btn-hover: #261c10;
  --focus: #ffc27d;
  --accent: #c98a45;
  --on-accent: #000000;
  --mark: rgba(255, 194, 125, 0.18);
  --cover-shadow: 0 1px 2px rgba(0, 0, 0, 0.6), 0 8px 18px rgba(0, 0, 0, 0.5);
  --grain: 0;
  color-scheme: dark;
}

:root {
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Literata", "PT Serif", Georgia, "Times New Roman", serif;
  --book: var(--serif);
  --word-weight: 500;
  --word-scale: 1;
  --warm: 0;
}

:root.sans { --book: var(--sans); }

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.3s, color 0.3s;
}

body.boot { visibility: hidden; }

/* Лёгкое зерно бумаги на светлых темах — как матовый экран электронной книги. */
body::before {
  position: fixed;
  inset: 0;
  z-index: 0;
  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.9' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.3  0 0 0 0 0.25  0 0 0 0 0.15  0 0 0 0.09 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  opacity: var(--grain);
  pointer-events: none;
  content: "";
}

/* В приложении с экрана «Домой» часы и батарея белые и лежат поверх страницы.
   На светлых темах подкладываем под них мягкую тень, чтобы их было видно. */
@media (display-mode: standalone) {
  :root[data-theme="paper"] body::after,
  :root[data-theme="sepia"] body::after {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 60;
    height: env(safe-area-inset-top);
    background: linear-gradient(rgba(30, 24, 16, 0.42), rgba(30, 24, 16, 0.3) 55%, rgba(30, 24, 16, 0));
    pointer-events: none;
    content: "";
  }
}

/* Тёплый свет: оранжевый слой «умножения» поверх всего, как подсветка Kindle Paperwhite. */
#warm {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #ff9a3c;
  mix-blend-mode: multiply;
  opacity: calc(var(--warm) * 0.42);
  pointer-events: none;
}

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.screen { position: relative; z-index: 1; height: 100vh; height: 100dvh; }

.icon-btn {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--dim);
}
.icon-btn:hover { background: var(--btn); color: var(--fg); }
.icon-btn svg { width: 22px; height: 22px; }

.text-btn { padding: 8px 10px; border: 0; border-radius: 10px; background: none; color: var(--focus); font-size: 16px; font-weight: 500; }
.text-btn:hover { background: var(--btn); }

.hint { margin: 14px 2px 0; color: var(--dim); font-size: 14px; }
.hint.warn { color: var(--focus); }

/* ---------- Библиотека ---------- */

#home {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: max(20px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) calc(36px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
}

.home-inner { max-width: 760px; margin: 0 auto; }

.lib-head { display: flex; align-items: center; gap: 4px; margin: 6px 0 2px; }
.lib-head h1 { flex: 1; margin: 0; font-family: var(--serif); font-size: 32px; font-weight: 600; letter-spacing: -0.01em; }
#home-settings { margin-right: -10px; }

.sync-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 18px -6px;
  padding: 4px 6px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--dim);
  font-size: 14px;
  text-align: left;
}
.sync-line:hover { background: var(--btn); }
.sync-line i { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.sync-line.ok i { background: #6f9a6a; }
.sync-line.busy i { background: var(--dim); animation: pulse 1s ease-in-out infinite; }
.sync-line.offline i, .sync-line.error i { background: #c9953f; }
.sync-line.auth i { background: var(--focus); }
@keyframes pulse { 50% { opacity: 0.3; } }

.continue {
  display: flex;
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
  padding: 16px;
  border-radius: 18px;
  background: var(--panel);
}
.continue .cover { width: 92px; flex: none; }
.continue-info { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.continue-info small { color: var(--dim); font-size: 13px; letter-spacing: 0.02em; }
.continue-info .t { margin-top: 2px; font-family: var(--serif); font-size: 20px; font-weight: 600; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.continue-info .a { margin-top: 2px; color: var(--dim); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.continue-info .p { margin-top: auto; padding-top: 10px; color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; }
.continue-info .bar-mini { margin: 6px 0 12px; }
.go-btn {
  align-self: flex-start;
  padding: 10px 20px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}

.bar-mini { height: 4px; overflow: hidden; border-radius: 2px; background: var(--line); }
.bar-mini i { display: block; height: 100%; background: var(--focus); }

.add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px;
  border: 1.5px dashed var(--faint);
  border-radius: 14px;
  color: var(--fg);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.add-btn:hover { border-color: var(--focus); background: var(--panel); }
.add-btn svg { width: 20px; height: 20px; color: var(--focus); }

#shelf { margin-top: 28px; }
#shelf h2 { margin: 0 0 14px; color: var(--dim); font-size: 14px; font-weight: 600; letter-spacing: 0.02em; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 24px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tile { position: relative; }
.tile-open {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
}
.tile .t { font-size: 14px; font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tile .a { margin-top: -6px; color: var(--dim); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cover {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  border-radius: 4px 6px 6px 4px;
  background: var(--btn);
  box-shadow: var(--cover-shadow);
}
.cover img { display: block; width: 100%; height: 100%; object-fit: cover; }
.cover .cover-bar { position: absolute; right: 0; bottom: 0; left: 0; height: 4px; background: rgba(0, 0, 0, 0.28); }
.cover .cover-bar i { display: block; height: 100%; background: #f0e6d2; }
.cover .badge {
  position: absolute;
  top: 6px;
  right: 6px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(20, 18, 15, 0.62);
  color: #f3efe6;
}
.cover .badge svg { width: 15px; height: 15px; }
.cover .badge.spin svg { animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Обложка, если в книге своей нет: как у Kindle — однотонная с названием. */
.cover.gen {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14% 11% 16%;
  color: #f4efe4;
  font-family: var(--serif);
  text-align: center;
}
.cover.gen::before { position: absolute; inset: 5%; border: 1px solid rgba(244, 239, 228, 0.35); border-radius: 2px; content: ""; }
.cover.gen .gt { font-size: 13px; font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.cover.gen .ga { font-size: 10px; opacity: 0.8; }

.tile-del {
  position: absolute;
  top: -8px;
  left: -8px;
  z-index: 2;
  display: none;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 2px solid var(--bg);
  border-radius: 50%;
  background: #c4473a;
  color: #fff;
}
.tile-del svg { width: 14px; height: 14px; stroke-width: 2.6; }
.editing .tile-del { display: grid; }
.editing .tile-open { animation: wobble 0.3s ease-in-out infinite alternate; }
@keyframes wobble { from { transform: rotate(-0.6deg); } to { transform: rotate(0.6deg); } }

/* ---------- Читалка ---------- */

#reader { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); }

.bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: max(6px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  transition: opacity 0.35s;
}

.bar-mid { flex: 1; min-width: 0; text-align: center; }

#book-title { overflow: hidden; color: var(--dim); font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }

.chapter {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  max-width: 100%;
  padding: 1px 4px 1px 8px;
  border-radius: 8px;
  font-family: var(--book);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.chapter:hover { background: var(--btn); }
.chapter:has(select:focus-visible) { outline: 2px solid var(--focus); }
#chapter-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chapter svg { flex: none; width: 16px; height: 16px; color: var(--dim); }
/* Сам список невидим и лежит поверх названия: нажатие открывает обычный выбор главы. */
.chapter select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  font-size: 16px;
  opacity: 0;
  cursor: pointer;
}
.chapter select option { background: var(--panel); color: var(--fg); }

#stage {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto minmax(0, 1.3fr);
  grid-template-columns: minmax(0, 1fr);
  min-height: 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.stage-top { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 12px; min-height: 0; padding: 0 16px 16px; transition: opacity 0.3s; }

.size-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  width: min(100%, 360px);
  cursor: auto;
}
.size-row span { color: var(--dim); font-family: var(--book); line-height: 1; user-select: none; }
.size-row .a-small { font-size: 14px; }
.size-row .a-big { font-size: 24px; }

.hint-line { color: var(--faint); font-size: 13px; text-align: center; }

.word-box {
  position: relative;
  width: min(100% - 32px, 760px);
  margin: 0 auto;
  padding: 26px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.word-box::before, .word-box::after {
  position: absolute;
  left: 50%;
  width: 2px;
  height: 12px;
  margin-left: -1px;
  background: var(--faint);
  content: "";
}
.word-box::before { top: 0; }
.word-box::after { bottom: 0; }

/* Средняя колонка — опорная буква; крайние равны, поэтому буква всегда ровно по центру. */
.word {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  min-height: 1.25em;
  color: var(--fg);
  font-family: var(--book);
  font-size: calc(clamp(34px, 9.5vw, 72px) * var(--word-scale));
  font-weight: var(--word-weight);
  line-height: 1.25;
  white-space: nowrap;
}
.word .l { display: flex; justify-content: flex-end; }
.word .r { display: flex; justify-content: flex-start; }
.word .f { color: var(--focus); }
.word.head { font-weight: 700; }
.no-focus .word .f { color: inherit; }

/* Страница на паузе — набрана как в электронной книге. */
.page {
  position: relative;
  width: min(100% - 36px, 34em);
  margin: 0 auto;
  padding: 18px 0 30px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  color: var(--fg-soft);
  font-family: var(--book);
  font-size: 19px;
  line-height: 1.6;
  text-align: justify;
  hyphens: auto;
  -webkit-hyphens: auto;
  cursor: auto;
  -webkit-mask-image: linear-gradient(transparent, #000 22px, #000 calc(100% - 36px), transparent);
  mask-image: linear-gradient(transparent, #000 22px, #000 calc(100% - 36px), transparent);
  transition: opacity 0.25s;
}
.page::-webkit-scrollbar { display: none; }
.page p { margin: 0; text-indent: 1.4em; }
.page p.h { margin: 0.9em 0 0.5em; color: var(--fg); font-weight: 600; text-align: center; text-indent: 0; }
.page p.h:first-child { margin-top: 0; }
.page span { border-radius: 3px; cursor: pointer; }
.page .cur { background: var(--mark); box-shadow: 0 0 0 2px var(--mark); color: var(--fg); }
@media (hover: hover) {
  .page span:hover { color: var(--fg); }
}

.controls {
  display: grid;
  gap: 4px;
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 2px max(18px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  transition: opacity 0.35s;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: -4px;
  color: var(--dim);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
#left { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.buttons { display: flex; align-items: center; justify-content: center; gap: 26px; margin: 4px 0 2px; }

.ctl {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--btn);
  color: var(--fg);
}
.ctl:hover { background: var(--btn-hover); }
.ctl svg { width: 22px; height: 22px; }

.play {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  transition: transform 0.15s;
}
.play:active { transform: scale(0.95); }
.play svg { width: 30px; height: 30px; fill: currentColor; stroke: none; }
.play .i-pause, .playing .play .i-play { display: none; }
.playing .play .i-pause { display: block; }

.speed { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px; }
.speed .small { width: 42px; height: 42px; font-size: 22px; line-height: 1; }
.speed-mid { display: grid; }
.speed-val { color: var(--dim); font-size: 13px; text-align: center; font-variant-numeric: tabular-nums; }
.speed-val b { color: var(--fg); font-size: 17px; }

/* Тонкая полоска прогресса внизу, пока идут слова. */
#line {
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 2;
  width: var(--fill, 0%);
  height: 2px;
  background: var(--faint);
  opacity: 0;
  transition: opacity 0.35s;
  pointer-events: none;
}

/* Во время чтения остаётся только слово. Нажатие в любом месте — пауза. */
.playing .bar, .playing .controls { opacity: 0; pointer-events: none; }
.playing .stage-top, .playing .page { visibility: hidden; opacity: 0; }
.playing #line { opacity: 1; }
.playing.reveal .bar, .playing.reveal .controls { opacity: 1; pointer-events: auto; }
.playing.idle, .playing.idle * { cursor: none !important; }

/* ---------- Ползунки ---------- */

input[type="range"] {
  width: 100%;
  height: 30px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--focus) var(--fill, 0%), var(--line) var(--fill, 0%));
}
input[type="range"]::-webkit-slider-thumb {
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border: 0;
  border-radius: 50%;
  background: var(--fg);
  -webkit-appearance: none;
}
input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 2px; background: var(--focus); }
input[type="range"]::-moz-range-thumb { width: 18px; height: 18px; border: 0; border-radius: 50%; background: var(--fg); }
@media (pointer: coarse) {
  input[type="range"] { height: 36px; }
  input[type="range"]::-webkit-slider-thumb { width: 24px; height: 24px; margin-top: -10px; }
  input[type="range"]::-moz-range-thumb { width: 24px; height: 24px; }
}

/* ---------- Настройки ---------- */

dialog {
  width: min(100% - 24px, 460px);
  max-height: calc(100% - 24px);
  padding: 0;
  border: 0;
  border-radius: 22px;
  background: var(--panel);
  color: var(--fg);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.4);
  overscroll-behavior: contain;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog form { display: grid; gap: 20px; padding: 22px 20px calc(20px + env(safe-area-inset-bottom)); }
dialog h2 { margin: 0; font-family: var(--serif); font-size: 24px; font-weight: 600; }

.opt { display: grid; gap: 10px; }
.opt > span { color: var(--dim); font-size: 14px; font-weight: 500; }
.note { margin: 0; color: var(--dim); font-size: 13px; line-height: 1.5; }

.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.sw {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 12px 6px 9px;
  border: 2px solid transparent;
  border-radius: 14px;
  background: var(--s-bg);
  color: var(--s-fg);
  box-shadow: inset 0 0 0 1px rgba(128, 128, 128, 0.25);
}
.sw b { font-family: var(--serif); font-size: 22px; font-weight: 600; line-height: 1.1; }
.sw small { font-size: 12px; opacity: 0.85; }
.sw[aria-pressed="true"] { border-color: var(--focus); }
.sw-paper { --s-bg: #f3f0e8; --s-fg: #24211d; }
.sw-sepia { --s-bg: #f1e5ce; --s-fg: #3b2e20; }
.sw-graphite { --s-bg: #1e1f22; --s-fg: #dedad2; }
.sw-night { --s-bg: #000; --s-fg: #d3ccbe; }
.sw-amber { --s-bg: #000; --s-fg: #d29a55; }
.sw-auto { --s-bg: linear-gradient(135deg, #f3f0e8 50%, #000 50%); }
.sw-auto b { color: #8f8a80; }
.sw-auto small { color: #8f8a80; }

.seg { display: flex; align-items: center; gap: 3px; padding: 3px; border-radius: 12px; background: var(--btn); }
.seg button { flex: 1; padding: 9px 4px; border: 0; border-radius: 9px; background: none; font-size: 15px; white-space: nowrap; }
.seg button:hover { background: var(--btn-hover); }
.seg button[aria-pressed="true"] { background: var(--bg); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18); }
.seg .f-serif { font-family: var(--serif); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.switch input { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--focus); cursor: pointer; }

.sync-box { padding: 14px; border-radius: 14px; background: var(--btn); }
.sync-box .note { color: var(--fg-soft); }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.soft-btn { padding: 10px 14px; border: 0; border-radius: 11px; background: var(--bg); font-size: 15px; font-weight: 500; }
.soft-btn:hover { background: var(--panel); }
.link-btn { margin-top: 10px; padding: 4px 0; border: 0; background: none; color: var(--dim); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; }
.pair-code { margin-top: 12px; text-align: center; }
.pair-code b { display: block; font-family: var(--serif); font-size: 38px; font-weight: 600; letter-spacing: 0.18em; font-variant-numeric: tabular-nums; }
.pair-code small { color: var(--dim); font-size: 13px; }
.code-row { display: flex; gap: 8px; margin-top: 10px; }
.code-row input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg);
  font-size: 18px;
  letter-spacing: 0.12em;
}

.keys { margin: 0; color: var(--dim); font-size: 13px; line-height: 1.7; }
.keys kbd { padding: 1px 6px; border-radius: 5px; background: var(--btn); font: inherit; }
@media (hover: none) { .kbd-only { display: none; } }

.done { padding: 13px; border: 0; border-radius: 14px; background: var(--accent); color: var(--on-accent); font-size: 16px; font-weight: 600; }

/* ---------- Сообщения и перетаскивание ---------- */

#toast {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 10px 12px 10px 16px;
  border-radius: 14px;
  background: var(--fg);
  color: var(--bg);
  font-size: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px);
  transition: opacity 0.25s, transform 0.25s;
}
#toast.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
#toast-btn { flex: none; padding: 6px 10px; border: 0; border-radius: 9px; background: var(--bg); color: var(--fg); font-size: 14px; font-weight: 600; }

#drop {
  position: fixed;
  inset: 12px;
  z-index: 45;
  display: grid;
  place-items: center;
  border: 2px dashed var(--focus);
  border-radius: 20px;
  background: var(--bg);
  font-size: 20px;
  font-weight: 600;
  opacity: 0.95;
  pointer-events: none;
}

/* Низкий экран (телефон боком) — всё компактнее. */
@media (max-height: 560px) {
  .word-box { padding: 14px 0; }
  .stage-top { gap: 6px; padding-bottom: 8px; }
  .hint-line { display: none; }
  .buttons { gap: 18px; margin: 0; }
  .play { width: 52px; height: 52px; }
  .ctl { width: 40px; height: 40px; }
  .page { font-size: 16px; }
}
