/* Страница телефона. Ограничения «простого HTML» — только у книги; здесь обычный современный CSS.
   Карточка сверху — содержимое нажатой закладки; её рамка и заголовок — цвета этой закладки,
   закладки внизу — ярлыки того же цвета. Общий файл для server.js и PHP-версии. */
:root {
  color-scheme: light dark;
  --bg: #eef1f5; --surface: #ffffff; --surface2: #f5f7fa;
  --text: #1a1d23; --muted: #5b6370; --line: #d5dae1;
  --blue: #2563eb; --green: #15803d; --orange: #c2410c;
  --ok: #15803d; --err: #c81e1e;
  --acc: var(--blue);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --surface: #1a1d23; --surface2: #22262e;
    --text: #e8eaed; --muted: #9aa3ad; --line: #353b45;
    --blue: #3b82f6; --green: #22a356; --orange: #ea6c1a;
    --ok: #4ade80; --err: #f87171;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115; --surface: #1a1d23; --surface2: #22262e;
  --text: #e8eaed; --muted: #9aa3ad; --line: #353b45;
  --blue: #3b82f6; --green: #22a356; --orange: #ea6c1a;
  --ok: #4ade80; --err: #f87171;
}

/* Цвет нажатой закладки — на всю форму. */
form[data-tab="text"] { --acc: var(--blue); }
form[data-tab="url"]  { --acc: var(--green); }
form[data-tab="set"]  { --acc: var(--orange); }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text);
       -webkit-tap-highlight-color: transparent; }

/* dvh — видимая высота экрана телефона: без адресной строки и, с interactive-widget, над клавиатурой. */
form { height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 10px; padding: 10px; }

/* ---------- карточка закладки ---------- */
.card { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--surface);
        border: 2px solid var(--acc); border-radius: 16px; overflow: hidden;
        box-shadow: 0 2px 10px rgb(0 0 0 / .08); }
.panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.head { margin: 0; padding: 10px 16px; background: var(--acc); color: #fff; font-size: 17px; font-weight: 600;
        letter-spacing: .01em; }
.body { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding: 16px; }

#editor { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px; outline: none;
          white-space: pre-wrap; overflow-wrap: anywhere; font-size: 17px; line-height: 1.5; }
#editor:empty::before { content: attr(data-placeholder); color: var(--muted); }
/* Поле для чтения, пока его не тронули; правка — фон чуть темнее, видно, что сейчас пишут. */
#editor[contenteditable="false"] { cursor: text; }
#editor[contenteditable="true"] { background: var(--surface2); }

.field { width: 100%; height: 48px; padding: 0 14px; font: inherit; font-size: 17px; color: var(--text);
         background: var(--surface2); border: 1px solid var(--line); border-radius: 12px; outline: none; }
.field:focus { border-color: var(--acc); box-shadow: 0 0 0 3px color-mix(in srgb, var(--acc) 25%, transparent); }

/* Выбор «Только текст / С оформлением» — два больших переключателя. */
.seg { display: flex; gap: 8px; }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: flex; align-items: center; justify-content: center; height: 44px; padding: 0 8px; text-align: center;
            border: 1px solid var(--line); border-radius: 12px; background: var(--surface2); color: var(--muted); font-size: 15px; }
.seg input:checked + span { border: 2px solid var(--acc); color: var(--acc); font-weight: 600;
                            background: color-mix(in srgb, var(--acc) 10%, var(--surface)); }

.hint { margin: 0; font-size: 14px; color: var(--muted); }
ol.hint { padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }

/* Закладка браузера «В книгу» — отдельный блок под основным. */
.bm { display: flex; flex-direction: column; gap: 10px; padding-top: 14px; border-top: 1px dashed var(--line); }
.bm .btn { align-self: flex-start; font-size: 16px; }
.field.code { height: auto; padding: 8px 10px; font: 12px/1.3 ui-monospace, Consolas, monospace; resize: none; }

.set { display: flex; flex-direction: column; gap: 8px; font-weight: 600; }
.num { display: flex; gap: 8px; align-items: center; }
.num .field { width: 7em; text-align: center; font-size: 20px; font-weight: 600; }
.num .btn { font-size: 24px; }
/* Код с книги и «Подключить» (v1.15.0). */
/* Не влезают в ряд — кнопка сама уходит вниз и тянется на всю ширину (владелец 04.11.2026: обрезалась). */
/* Всегда столбиком: поле, под ним кнопка на всю ширину — при крупном шрифте телефона ряд не влезал. */
.num.pair { flex-direction: column; align-items: stretch; }
.num.pair .field { width: 100%; letter-spacing: 2px; }
.num.pair .btn { width: 100%; height: 52px; font-size: 18px; white-space: nowrap; }
.connect .body { display: flex; flex-direction: column; gap: 12px; }
/* «☰» — меню телефона, слева в заголовке карточки (v1.16.0); «←» — назад из меню. */
.menu-btn, .back-btn { display: inline-flex; align-items: center; justify-content: center; height: 32px; min-width: 40px;
            padding: 0 10px; font-size: 18px; font-weight: 700; color: #fff; text-decoration: none;
            background: rgb(255 255 255 / .2); border: 1px solid rgb(255 255 255 / .6); border-radius: 16px; }
.menu-btn { position: absolute; top: 6px; left: 8px; z-index: 1; }
.menu-btn ~ .panel .head { padding-left: 60px; }
.back-btn { margin: -6px 8px -6px -8px; }
.danger-zone { padding-top: 14px; border-top: 1px dashed var(--line); }
/* «Разорвать» — ссылка в виде кнопки; «Назад к выбору» (v1.15.3). */
a.btn { display: inline-flex; align-items: center; justify-content: center; align-self: flex-start; text-decoration: none; }
.hint.back { padding: 0 16px; }
.hint.back a { color: inherit; }

/* ---------- строка состояния и кнопки — внизу карточки ---------- */
.line { display: flex; gap: 8px; padding: 6px 16px; font-size: 13px; color: var(--muted);
        border-top: 1px solid var(--line); min-height: 1.6em; }
#status { flex: 1; }
.ver { white-space: nowrap; opacity: .8; }
.bar { display: flex; gap: 8px; align-items: center; padding: 8px 10px 10px; background: var(--surface2); }
.gap { flex: 1; }

.btn { min-width: 44px; height: 44px; padding: 0 10px; font: inherit; font-size: 19px; color: var(--text);
       background: var(--surface); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--acc); border-color: var(--acc); color: #fff; font-weight: 600; }
.btn.wide { padding: 0 20px; font-size: 17px; }
.btn:disabled { opacity: .5; }

.ok { color: var(--ok); }
.err { color: var(--err); }

/* ---------- сохранённые тексты ---------- */
/* Кнопка «☰ N» — справа в заголовке карточки, на любой закладке. */
.card { position: relative; }
.head { padding-right: 76px; }
.hist-btn { position: absolute; top: 6px; right: 8px; height: 32px; padding: 0 12px; font: inherit; font-size: 15px;
            font-weight: 700; color: #fff; background: rgb(255 255 255 / .2); border: 1px solid rgb(255 255 255 / .6);
            border-radius: 16px; cursor: pointer; }
/* Всплывающая форма: затемнение и окно, прижатое к правому верхнему углу. */
/* У .hist свои размеры и направление: общее правило form (колонка на весь экран) сюда не подходит. */
.hist { position: fixed; inset: 0; z-index: 10; height: auto; gap: 0; flex-direction: row; background: rgb(0 0 0 / .4); display: flex;
        justify-content: flex-end; align-items: flex-start; padding: 10px; }
.hist-box { width: min(420px, 100%); max-height: calc(100dvh - 20px); display: flex; flex-direction: column;
            background: var(--surface); border-radius: 16px; overflow: hidden; box-shadow: 0 8px 30px rgb(0 0 0 / .3); }
.hist-head { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px; background: var(--text);
             color: var(--surface); font-weight: 600; }
.hist-head span { flex: 1; }
.hist-head .x { width: 40px; height: 40px; font-size: 20px; color: inherit; background: transparent; border: 0; cursor: pointer; }
.hist-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
.hist-list li { display: flex; align-items: stretch; border-bottom: 1px solid var(--line); }
.hist-list button.del { flex: none; width: 52px; padding: 0; align-items: center; justify-content: center;
                        font-size: 18px; border-left: 1px solid var(--line); opacity: .75; }
.hist-list button, .hist-list .cur { display: flex; flex-direction: column; gap: 2px; width: 100%; padding: 10px 16px;
                                     font: inherit; text-align: left; color: var(--text); background: none; border: 0; cursor: pointer; }
.hist-list .cur { background: color-mix(in srgb, var(--acc) 12%, var(--surface)); border-left: 4px solid var(--acc); }
.hist-list .when { font-size: 13px; color: var(--muted); }
.hist-list .what { font-size: 16px; overflow-wrap: anywhere; }
.hist-list .badge { align-self: flex-start; padding: 1px 8px; font-size: 12px; font-weight: 700; color: #fff;
                    background: var(--acc); border-radius: 8px; }
.hist-list .empty { padding: 16px; color: var(--muted); }
.hist .hint { padding: 10px 16px; }
/* «Удалить все» и вопрос перед ним. */
.del-all { padding: 10px 16px 0; }
.del-all .ask { display: flex; flex-direction: column; gap: 10px; padding: 12px; border: 1px solid var(--line);
                border-radius: 12px; background: var(--surface2); }
.del-all .ask[hidden] { display: none; }
.del-all .ask p { margin: 0; }
.del-all .ask label { display: flex; align-items: center; gap: 8px; }
.del-all .ask input { width: 20px; height: 20px; }
.ask-btns { display: flex; gap: 8px; }
.ask-btns .btn { flex: 1; }
.btn.danger { color: #fff; background: #c62828; border-color: #c62828; }

/* ---------- закладки ---------- */
.tabs { display: flex; gap: 8px; }
.tabs button { flex: 1; height: 58px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
               font: inherit; font-size: 14px; color: var(--muted); background: var(--surface);
               border: 1px solid var(--line); border-radius: 14px; cursor: pointer; }
.tabs .ic { font-size: 20px; line-height: 1; }
.tabs button[data-tab="text"] { --tab: var(--blue); }
.tabs button[data-tab="url"]  { --tab: var(--green); }
.tabs button[data-tab="set"]  { --tab: var(--orange); }
/* Ненажатая — с полоской своего цвета сверху, нажатая — залита им целиком. */
.tabs button { border-top: 4px solid var(--tab); }
.tabs button.on { background: var(--tab); border-color: var(--tab); color: #fff; font-weight: 700;
                  box-shadow: 0 2px 8px color-mix(in srgb, var(--tab) 40%, transparent); }
