/* ============================================================
 * Text2Bitig — стили
 * ============================================================ */

@font-face {
  font-family: 'Bitig';
  src: url('bitig.ttf') format('truetype');
  font-display: swap;
}

/* Палитра в оттенках флага Казахстана: небесно-голубой + золото */
:root {
  --bg: #eef6f9;
  --panel: #ffffff;
  --border: #cde2ea;
  --text: #16323f;
  --muted: #6e8a96;
  --accent: #009cc4;       /* голубой флага */
  --accent-hover: #007fa3;
  --accent-soft: #dcf2f8;
  --gold: #d9a509;         /* золото флага (затемнено для контраста на белом) */
  --input-bg: #fbfeff;
  --shadow: 0 2px 8px rgba(22, 50, 63, .08);
  --radius: 10px;
  --bitig-size: 16px;
}

[data-theme='dark'] {
  --bg: #0d1f2a;
  --panel: #142c3a;
  --border: #23485a;
  --text: #dcedf4;
  --muted: #7fa2b1;
  --accent: #2cc5e8;
  --accent-hover: #5bd5f2;
  --accent-soft: #14404f;
  --gold: #fec50c;         /* золото флага */
  --input-bg: #102532;
  --shadow: 0 2px 8px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background .25s, color .25s;
}

/* ---------- шапка ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-glyph {
  font-family: 'Bitig', serif;
  font-size: 48px;
  color: var(--gold);
  line-height: 1;
}

.brand h1 { margin: 0; font-size: 20px; letter-spacing: .3px; }

.subtitle { margin: 2px 0 0; font-size: 13px; color: var(--muted); }

.topbar-controls { display: flex; align-items: center; gap: 8px; }

#theme {
  width: 38px; height: 38px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
  transition: background .15s;
}
#theme:hover { background: var(--accent-soft); }

/* ---------- контейнер ---------- */

.container {
  width: min(860px, 100% - 32px);
  margin: 24px auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  flex: 1;
}

/* ---------- меню разделов ---------- */

.tabs {
  display: flex;
  gap: 26px;
  border-bottom: 1px solid var(--border);
  padding: 0 6px;
}

.tab {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .3px;
  padding: 10px 2px;
  margin-bottom: -1px;          /* подчёркивание ложится на линию меню */
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.view { display: none; flex-direction: column; gap: 18px; }
.view.active { display: flex; }

/* ---------- рекламный блок ---------- */

.ad-slot { text-align: center; }
/* скрыт, пока внутри нет рекламного блока */
.ad-slot:empty,
.ad-slot:not(:has(.adsbygoogle)) { display: none; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

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

.options summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  user-select: none;
}
.options summary:hover { color: var(--accent); }

.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px 18px;
  margin: 12px 0 14px;
}

.opt {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 2px;
  font-size: 14px;
}

.opt span {
  border-bottom: 1px dotted var(--muted); /* намёк на подсказку при наведении */
  cursor: help;
}

.opt input {
  accent-color: var(--accent);
  width: 16px; height: 16px;
  cursor: pointer;
}

.method-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
}

.method-row label { font-size: 14px; color: var(--muted); white-space: nowrap; }

select {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  cursor: pointer;
  max-width: 100%;
}

.method-row select { flex: 1; min-width: 240px; }

/* ---------- редактор ---------- */

.editor { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.field-head label {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.count { font-size: 12px; color: var(--muted); }

textarea {
  font: inherit;
  width: 100%;
  resize: vertical;
  padding: 12px 14px;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  line-height: 1.55;
  transition: border-color .15s, box-shadow .15s;
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea.bitig {
  font-family: 'Bitig', serif;
  font-size: var(--bitig-size);
  line-height: 1.7;
  direction: rtl; /* битиг исторически пишется справа налево */
}

.mini-btn {
  font: inherit;
  font-size: 12px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--muted);
  cursor: pointer;
  transition: background .12s;
}
.mini-btn:hover { background: var(--accent-soft); color: var(--text); }

/* ---------- переключатель направления ---------- */

.swap-row {
  display: flex;
  justify-content: center;
  margin: -6px 0;
}

.swap {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--accent);
  font-size: 19px;
  cursor: pointer;
  transition: background .15s, transform .25s;
  line-height: 1;
}
.swap:hover { background: var(--accent-soft); }
.swap.reversed { transform: rotate(180deg); }

/* режим битиг → латиница: прямые опции гаснут, обратные появляются */
.options .opt.rev { display: none; }
.options.reverse .opt.rev { display: flex; }
.options.reverse .opt.fwd,
.options.reverse .method-row { opacity: .45; pointer-events: none; }

/* ---------- кнопки ---------- */

.actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.btn {
  font: inherit;
  font-size: 14px;
  padding: 9px 22px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--accent-soft); }
.btn:active { transform: translateY(1px); }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover { background: var(--accent-hover); }
.btn.primary.ok { background: #3d8b40; border-color: #3d8b40; }

/* ---------- RTL-переключатель ---------- */

.field-tools {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* селект выходного алфавита — виден только в режиме битиг → латиница */
.out-script {
  display: none;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--muted);
}
.reverse-mode .out-script { display: block; }

/* ---------- клавиатура битиг ---------- */

.kbd { display: none; } /* видна только в режиме битиг → латиница */
.reverse-mode .kbd { display: block; }

.kbd summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  user-select: none;
}
.kbd summary:hover { color: var(--accent); }

/* ---------- обучение ---------- */

.sub-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 14px 0 4px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border);
}
.mini-btn.sub.active, .mini-btn.lesson.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.sub-view { display: none; }
.sub-view.active { display: block; }

/* карточки алфавита */
.flash-card {
  text-align: center;
  padding: 22px 10px 10px;
}
.flash-glyph {
  font-family: 'Bitig', serif;
  font-size: 96px;
  line-height: 1.2;
  color: var(--gold);
  min-height: 120px;
}
.flash-reading { font-size: 26px; font-weight: 600; }
.flash-reading-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 4px;
}

/* прописи */
.trace-wrap { text-align: center; margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--border); }
#trace-canvas {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  touch-action: none;
  cursor: crosshair;
  margin-bottom: 8px;
}
.flash-type { color: var(--muted); font-size: 13px; margin-top: 4px; }

.flash-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 12px;
}
.flash-nav .btn { min-width: 56px; font-size: 18px; padding: 6px 0; }
.flash-progress { color: var(--muted); font-size: 13px; min-width: 56px; text-align: center; }

/* грамматика */
.grammar-list {
  margin: 14px 0 4px;
  padding-left: 22px;
  font-size: 15px;
  line-height: 1.7;
}
.grammar-list li { margin-bottom: 10px; }
.grammar-list .g { font-family: 'Bitig', serif; font-size: 20px; color: var(--gold); }

/* исторические тексты */
.hist-text { margin: 16px 0; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--input-bg); }
.hist-name { font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--accent); margin-bottom: 8px; }
.hist-bitig { font-family: 'Bitig', serif; font-size: 24px; line-height: 1.8; direction: rtl; color: var(--gold); }
.hist-translit { color: var(--muted); font-style: italic; margin: 8px 0 4px; font-size: 14px; }
.hist-trans { font-size: 15px; }

.learn-lessons { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 4px; }

.learn-card { text-align: center; padding: 6px 0 2px; }

.learn-prompt { margin: 8px 0 4px; color: var(--muted); font-size: 13px; }

.learn-q {
  font-family: 'Bitig', serif;
  font-size: 72px;
  color: var(--gold);
  min-height: 92px;
  line-height: 1.25;
}
.learn-q.as-reading {
  font-family: inherit;
  font-size: 32px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}

.learn-answers {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 220px));
  gap: 10px;
  justify-content: center;
  margin: 14px 0;
}

.learn-ans {
  font: inherit;
  font-size: 16px;
  padding: 13px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--input-bg);
  color: var(--text);
  cursor: pointer;
  transition: background .12s;
}
.learn-ans:hover { background: var(--accent-soft); }
.learn-ans.as-glyph { font-family: 'Bitig', serif; font-size: 30px; }
.learn-ans.right { background: #3d8b40; border-color: #3d8b40; color: #fff; }
.learn-ans.wrong { background: #b3402e; border-color: #b3402e; color: #fff; }

.learn-status {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  min-height: 20px;
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
}
#learn-feedback { font-weight: 600; }

.abc h2, .help h2, .learn h2 {
  margin: 0 0 4px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}

.kbd-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 6px;
  margin-top: 12px;
}

.kbd-key {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  cursor: pointer;
  transition: background .12s, transform .05s;
}
.kbd-key:hover { background: var(--accent-soft); }
.kbd-key:active { transform: translateY(1px); }
.kbd-key span { font-family: 'Bitig', serif; font-size: 22px; color: var(--text); line-height: 1.1; }
.kbd-key small { font-size: 10px; color: var(--muted); }

/* ---------- справочник алфавита ---------- */

.abc-wrap { max-height: 62vh; overflow-y: auto; margin-top: 12px; }

#abc-table, #dict-table { width: 100%; border-collapse: collapse; font-size: 14px; }
#abc-table th, #dict-table th {
  text-align: left;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  position: sticky; top: 0;
  background: var(--panel);
}
#abc-table td, #dict-table td { padding: 5px 10px; border-top: 1px solid var(--border); }
#abc-table td.g, #dict-table td.g { font-family: 'Bitig', serif; font-size: 24px; color: var(--gold); }

/* ---------- справка ---------- */

.help summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  user-select: none;
}
.help summary:hover { color: var(--accent); }

.help ul {
  margin: 12px 0 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.65;
}
.help li { margin-bottom: 4px; }

/* ---------- подвал ---------- */

.footer {
  text-align: center;
  padding: 14px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
.footer a { color: var(--muted); }
.footer a:hover { color: var(--accent); }

/* ---------- планшеты ---------- */

@media (max-width: 760px) {
  .container { width: calc(100% - 24px); margin: 16px auto; gap: 14px; }
  .options-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  :root { --bitig-size: 21px; }
}

/* ---------- телефоны ---------- */

@media (max-width: 560px) {
  body { font-size: 14px; }
  .topbar { padding: 10px 14px; gap: 10px; }
  .brand { gap: 10px; }
  .brand-glyph { font-size: 48px; }
  .brand h1 { font-size: 17px; }
  .subtitle { font-size: 11px; }
  .topbar-controls { margin-left: auto; }
  #theme { width: 34px; height: 34px; }
  .container { width: calc(100% - 16px); margin: 12px auto; gap: 12px; }
  .panel { padding: 12px; }
  .options-grid { grid-template-columns: 1fr; gap: 2px; }
  .opt { padding: 8px 2px; }              /* крупнее зона нажатия */
  .opt input { width: 18px; height: 18px; }
  .method-row select { min-width: 100%; }
  .tabs { gap: 16px; overflow-x: auto; }
  .tab { font-size: 13px; white-space: nowrap; }
  textarea { padding: 10px 12px; }
  :root { --bitig-size: 19px; }
  .swap { width: 44px; height: 44px; font-size: 21px; } /* удобнее пальцем */
  .actions { flex-wrap: wrap; }
  .actions .btn { flex: 1; padding: 11px 10px; }
}

/* ---------- узкие экраны ---------- */

@media (max-width: 360px) {
  .subtitle { display: none; }
  :root { --bitig-size: 17px; }
}

/* ---------- печать ---------- */

.print-block { display: none; }

@media print {
  .topbar, .options, .actions, .swap-row, .kbd, .abc, .help, .learn, .footer,
  .tabs, .ad-slot, .field-head, textarea { display: none !important; }
  body { background: #fff; color: #000; }
  .panel { border: none; box-shadow: none; padding: 0; }
  .print-block {
    display: block;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 13pt;
    line-height: 1.6;
    margin-bottom: 18pt;
  }
  .print-block.bitig-print {
    font-family: 'Bitig', serif;
    font-size: 20pt;
    line-height: 1.8;
    direction: rtl;
  }
}
