/* =========================================================================
   汉语笔记 — «Тушь и бумага»
   ========================================================================= */

/* ---------- Дизайн-токены ---------- */

:root {
  --bg:            #FAF6EF;
  --bg-tint:       #F3EDE2;
  --surface:       #FFFDF8;
  --surface-2:     #F7F2E9;
  --text:          #1F1D1A;
  --text-dim:      #6B655C;
  --text-faint:    #948D82;
  --line:          #E3DCD0;
  --line-strong:   #D2C8B7;
  --accent:        #C8322B;
  --accent-soft:   rgba(200, 50, 43, 0.10);
  --accent-line:   rgba(200, 50, 43, 0.28);
  --ok:            #3F7D4E;
  --ok-soft:       rgba(63, 125, 78, 0.12);
  --bad:           #B33A2B;
  --bad-soft:      rgba(179, 58, 43, 0.12);

  --tone-1: #2F6FA8;
  --tone-2: #2E8B57;
  --tone-3: #9A5BA8;
  --tone-4: #C0561F;
  --tone-0: #8B857A;

  --shadow-sm: 0 1px 2px rgba(60, 45, 25, 0.05);
  --shadow-md: 0 2px 10px rgba(60, 45, 25, 0.07), 0 1px 2px rgba(60, 45, 25, 0.04);
  --shadow-lg: 0 12px 40px rgba(60, 45, 25, 0.12);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;

  --font-serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, 'Times New Roman', serif;
  --font-sans:  -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, 'Helvetica Neue', Arial, sans-serif;
  --font-cn:    'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', 'Source Han Sans SC', var(--font-sans);
  /* Для строк, где кириллица соседствует с иероглифами: латиница и кириллица
     берутся из системного шрифта, иероглифы подхватываются фолбэком. */
  --font-mixed: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, 'Helvetica Neue', Arial,
                'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
  --font-mono:  ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

  --header-h: 116px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

:root[data-theme="dark"] {
  --bg:            #17181C;
  --bg-tint:       #131418;
  --surface:       #1E2025;
  --surface-2:     #24272D;
  --text:          #EDE9E1;
  --text-dim:      #9A968C;
  --text-faint:    #75716A;
  --line:          #2C2F36;
  --line-strong:   #3A3E47;
  --accent:        #E8564C;
  --accent-soft:   rgba(232, 86, 76, 0.13);
  --accent-line:   rgba(232, 86, 76, 0.32);
  --ok:            #64B87A;
  --ok-soft:       rgba(100, 184, 122, 0.14);
  --bad:           #E8564C;
  --bad-soft:      rgba(232, 86, 76, 0.14);

  --tone-1: #6AA9DC;
  --tone-2: #5FBE86;
  --tone-3: #C08FD0;
  --tone-4: #E58B4E;
  --tone-0: #918C83;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 14px 44px rgba(0, 0, 0, 0.5);
}

/* ---------- Сброс и база ---------- */

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* мягкое «свечение бумаги» в углу — очень деликатное */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 70% 50% at 15% -5%, var(--accent-soft), transparent 60%),
    radial-gradient(ellipse 60% 45% at 92% 8%, rgba(140, 120, 90, 0.07), transparent 65%);
}

:root[data-theme="dark"] body::before {
  background:
    radial-gradient(ellipse 70% 50% at 15% -5%, rgba(232, 86, 76, 0.07), transparent 60%),
    radial-gradient(ellipse 60% 45% at 92% 8%, rgba(120, 140, 190, 0.05), transparent 65%);
}

h1, h2, h3, h4 {
  font-family: var(--font-serif);
  font-weight: 600;
  line-height: 1.25;
  margin: 0;
  letter-spacing: -0.01em;
}

p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }

button, input, select { font: inherit; color: inherit; }

.wrap {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
  position: relative;
  z-index: 1;
}

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

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #fff;
  padding: 10px 18px; border-radius: 0 0 var(--radius) 0;
  text-decoration: none;
}
.skip-link:focus { left: 0; }

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

/* ---------- Шапка ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 95%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--line);
}

@supports not (backdrop-filter: blur(1px)) {
  .site-header { background: var(--bg); }
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 14px;
  padding-bottom: 12px;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand-seal {
  flex: none;
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #FFF6F2;
  font-family: var(--font-cn);
  font-size: 22px;
  line-height: 1;
  border-radius: 5px;
  box-shadow: var(--shadow-sm);
  user-select: none;
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }

.brand-title {
  font-family: var(--font-cn);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-tools { display: flex; align-items: center; gap: 8px; flex: none; }

.icon-btn {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-dim);
  transition: color .18s var(--ease), border-color .18s var(--ease), background .18s var(--ease);
}
.icon-btn:hover {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }

.icon-sun { display: none; }
.icon-moon { display: block; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }

.tone-swatch { display: flex; gap: 2px; }
.tone-swatch i { width: 5px; height: 14px; border-radius: 1px; display: block; }
#tone-toggle[aria-pressed="false"] .tone-swatch i { background: var(--line-strong) !important; }

/* ---------- Навигация ---------- */

.site-nav { border-top: 1px solid transparent; }

.nav-scroll {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  scroll-snap-type: x proximity;
}
.nav-scroll::-webkit-scrollbar { display: none; }

.nav-tab {
  flex: none;
  position: relative;
  background: none;
  border: 0;
  padding: 10px 14px 13px;
  cursor: pointer;
  color: var(--text-dim);
  font-size: 14.5px;
  white-space: nowrap;
  scroll-snap-align: start;
  transition: color .18s var(--ease);
}
.nav-tab::after {
  content: '';
  position: absolute;
  left: 14px; right: 14px; bottom: 0;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  transform: scaleX(0);
  transform-origin: center;
  transition: transform .22s var(--ease);
}
.nav-tab:hover { color: var(--text); }
.nav-tab.is-active { color: var(--accent); font-weight: 500; }
.nav-tab.is-active::after { transform: scaleX(1); }

/* ---------- Секции ---------- */

main { padding: 40px 24px 80px; }

.section { display: none; animation: fade-in .28s var(--ease); }
.section.is-active { display: block; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.section-title {
  font-size: 26px;
  margin-bottom: 6px;
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 25px;
  margin-bottom: 15px;
}
.section-title .cn {
  font-family: var(--font-cn);
  font-size: 15px;
  font-weight: 400;
  color: var(--text-faint);
  letter-spacing: 0.14em;
}

.section-lead {
  color: var(--text-dim);
  max-width: 62ch;
  margin-bottom: 26px;
  font-size: 15px;
}

.group-title {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 38px 0 16px;
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.group-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}
.group-title .count {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0;
  color: var(--text-faint);
  text-transform: none;
}
.group-title .glyph {
  font-family: var(--font-cn);
  color: var(--accent);
  font-size: 15px;
  letter-spacing: 0;
}

/* ---------- Обзор ---------- */

.hero { padding: 18px 0 34px; }

.hero-kicker {
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 14px;
  font-weight: 500;
}

.hero-title {
  font-family: var(--font-cn);
  font-size: clamp(44px, 9vw, 76px);
  letter-spacing: 0.08em;
  line-height: 1;
  margin-bottom: 18px;
}

.hero-lead {
  color: var(--text-dim);
  max-width: 58ch;
  font-size: 16.5px;
  line-height: 1.7;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1px;
  margin-top: 32px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.stat {
  background: var(--surface);
  padding: 18px 16px;
  text-align: center;
}
.stat-value {
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 600;
  line-height: 1;
  color: var(--accent);
}
.stat-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
  letter-spacing: 0.03em;
}

.word-of-day {
  margin: 12px 0 8px;
  padding: 24px 26px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
.wod-label {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
  width: 100%;
}
.wod-hanzi {
  font-family: var(--font-cn);
  font-size: 46px;
  line-height: 1.1;
}
.wod-body { display: flex; flex-direction: column; gap: 2px; }
.wod-pinyin { font-size: 18px; }
.wod-ru { color: var(--text-dim); }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin: 18px 0 34px;
}

.tile {
  position: relative;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: transform .18s var(--ease), border-color .18s var(--ease), box-shadow .18s var(--ease);
  overflow: hidden;
}
.tile:hover {
  transform: translateY(-2px);
  border-color: var(--accent-line);
  box-shadow: var(--shadow-md);
}
.tile-glyph {
  position: absolute;
  right: 10px; bottom: -12px;
  font-family: var(--font-cn);
  font-size: 62px;
  line-height: 1;
  color: var(--text);
  opacity: 0.055;
  pointer-events: none;
}
.tile-name { font-family: var(--font-serif); font-size: 17px; font-weight: 600; margin-bottom: 4px; }
.tile-desc { font-size: 13.5px; color: var(--text-dim); }

.note-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
}
.note-card h3 { font-size: 15px; margin-bottom: 12px; }
.note-list { display: flex; flex-direction: column; gap: 9px; font-size: 14px; color: var(--text-dim); }
.note-list li { display: flex; align-items: center; gap: 10px; }

/* ---------- Панель инструментов ---------- */

.toolbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 26px;
  box-shadow: var(--shadow-sm);
}

.search-box { position: relative; margin-bottom: 16px; }

.search-icon {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  width: 17px; height: 17px;
  fill: none; stroke: var(--text-faint); stroke-width: 1.7; stroke-linecap: round;
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 12px 40px 12px 42px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 15px;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
  -webkit-appearance: none;
  appearance: none;
}
.search-input::placeholder { color: var(--text-faint); }
.search-input:focus {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-input::-webkit-search-decoration,
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; }

.search-clear {
  position: absolute;
  right: 8px; top: 50%;
  transform: translateY(-50%);
  width: 26px; height: 26px;
  display: grid; place-items: center;
  background: none; border: 0;
  border-radius: 50%;
  color: var(--text-faint);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
}
.search-clear:hover { background: var(--surface-2); color: var(--text); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 18px;
  align-items: flex-end;
}

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.field select {
  padding: 8px 30px 8px 11px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5L6 8l3-3.5' fill='none' stroke='%23948D82' stroke-width='1.4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 12px;
}
.field select:focus { outline: none; border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--text-dim);
  cursor: pointer;
  padding-bottom: 8px;
}
.check input { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

.toolbar-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }

.result-count {
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-faint);
  font-family: var(--font-mono);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14.5px;
  cursor: pointer;
  transition: background .18s var(--ease), border-color .18s var(--ease), color .18s var(--ease), transform .1s var(--ease);
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--accent); color: #FFF6F2; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }

.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--text-dim); }
.btn-ghost:hover { border-color: var(--accent-line); color: var(--accent); background: var(--accent-soft); }

.btn-ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 40%, transparent); color: var(--ok); }
.btn-ok:hover { background: color-mix(in srgb, var(--ok) 22%, transparent); }

.btn-again { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.btn-again:hover { background: color-mix(in srgb, var(--accent) 20%, transparent); }

/* ---------- Бейджи и метки ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 3px;
  line-height: 1.5;
  white-space: nowrap;
}

.badge-pos {
  background: var(--surface-2);
  color: var(--text-faint);
  border: 1px solid var(--line);
  text-transform: lowercase;
  font-weight: 500;
}

.badge-src { border: 1px solid var(--line-strong); color: var(--text-faint); background: transparent; }
.badge-src[data-src="roman"] { color: #4B7BA8; border-color: rgba(75, 123, 168, 0.4); }
.badge-src[data-src="dasha"] { color: #A8548C; border-color: rgba(168, 84, 140, 0.4); }
.badge-src[data-src="both"]  { color: var(--accent); border-color: var(--accent-line); }

:root[data-theme="dark"] .badge-src[data-src="roman"] { color: #7FB2DC; border-color: rgba(127, 178, 220, 0.35); }
:root[data-theme="dark"] .badge-src[data-src="dasha"] { color: #D48CBE; border-color: rgba(212, 140, 190, 0.35); }

.dot-restored {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: transparent;
  border: 1.5px solid var(--line-strong);
  flex: none;
  vertical-align: middle;
}
.word-hanzi .dot-restored { margin-left: 7px; }

/* ---------- Карточка слова ---------- */

.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(238px, 1fr));
  gap: 12px;
}

.word-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease), transform .18s var(--ease);
}
.word-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.word-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.word-hanzi {
  font-family: var(--font-cn);
  font-size: 40px;
  line-height: 1.15;
  letter-spacing: 0.02em;
  word-break: break-all;
}

.word-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex: none; }

.word-pinyin { font-size: 16px; letter-spacing: 0.01em; margin-bottom: 3px; }
.word-ru { color: var(--text-dim); font-size: 14.5px; line-height: 1.45; }

.word-note {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--line);
  font-size: 12.5px;
  color: var(--text-faint);
  line-height: 1.5;
}

.speak-btn {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--text-faint);
  cursor: pointer;
  flex: none;
  transition: color .16s var(--ease), border-color .16s var(--ease), background .16s var(--ease);
}
.speak-btn:hover { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }
.speak-btn.is-playing { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.speak-btn svg { width: 12px; height: 12px; fill: currentColor; }

.speak-inline {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  display: inline-grid;
  place-items: center;
  opacity: 0;
  transition: opacity .16s var(--ease), color .16s var(--ease);
  vertical-align: middle;
  flex: none;
}
.speak-inline svg { width: 11px; height: 11px; fill: currentColor; }
.example:hover .speak-inline,
.dlg-line:hover .speak-inline,
.speak-inline:focus-visible { opacity: 1; }
.speak-inline:hover { color: var(--accent); }

/* В системе нет китайского голоса — прячем всё, что связано с озвучкой. */
:root.no-speech .speak-btn,
:root.no-speech .speak-inline { display: none !important; }

/* ---------- Тоновые цвета ---------- */

.tones-on .t1 { color: var(--tone-1); }
.tones-on .t2 { color: var(--tone-2); }
.tones-on .t3 { color: var(--tone-3); }
.tones-on .t4 { color: var(--tone-4); }
.tones-on .t0 { color: var(--tone-0); }

/* ---------- Грамматика ---------- */

.rules-card {
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 30px;
}
.rules-title {
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 12px;
}
.rules-list { display: flex; flex-direction: column; gap: 8px; }
.rules-list li {
  position: relative;
  padding-left: 20px;
  font-size: 14.5px;
  line-height: 1.55;
}
.rules-list li::before {
  content: '！';
  position: absolute;
  left: 0; top: 0;
  color: var(--accent);
  font-size: 12px;
  font-family: var(--font-cn);
}

.gram-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 26px 28px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}

.gram-head {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 18px;
}

.gram-num {
  flex: none;
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border: 1px solid var(--accent-line);
  color: var(--accent);
  border-radius: 5px;
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 600;
}

.gram-title { font-size: 18.5px; line-height: 1.35; }

.gram-formula {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin-bottom: 16px;
}
.gram-formula-cn {
  font-family: var(--font-mixed);
  font-size: 17px;
  line-height: 1.5;
}
.gram-formula-py {
  font-size: 13px;
  color: var(--text-faint);
  font-family: var(--font-mono);
  margin-top: 5px;
}

.gram-explain {
  color: var(--text-dim);
  font-size: 14.5px;
  line-height: 1.65;
  margin-bottom: 18px;
  max-width: 66ch;
}

.gram-rules {
  margin: 0 0 18px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.gram-rules li {
  padding: 9px 14px;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--accent);
}

.examples-label {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 10px;
}

.examples { display: flex; flex-direction: column; gap: 2px; }

.example {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  transition: background .16s var(--ease);
}
.example:hover { background: var(--surface-2); }
.example:nth-child(odd) { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.example:nth-child(odd):hover { background: var(--surface-2); }

.ex-hanzi {
  font-family: var(--font-cn);
  font-size: 19px;
  line-height: 1.5;
  letter-spacing: 0.02em;
}
.ex-pinyin { font-size: 13.5px; color: var(--text-dim); grid-column: 1; }
.ex-ru { font-size: 14px; color: var(--text-dim); grid-column: 1; }
.ex-ru::before { content: '— '; color: var(--text-faint); }
.example .speak-inline { grid-row: 1; grid-column: 2; align-self: center; }

/* ---------- Фонетика ---------- */

.phon-block { margin-bottom: 34px; }

.phon-row { margin-bottom: 20px; }
.phon-row-title {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 10px;
}

.phon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
}

.phon-cell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 8px;
  text-align: center;
  transition: border-color .16s var(--ease), transform .16s var(--ease);
}
.phon-cell:hover { border-color: var(--accent-line); transform: translateY(-1px); }
.phon-letter {
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.phon-ru { font-size: 12px; color: var(--text-dim); margin-top: 3px; min-height: 1.2em; }

.tones-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.tone-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-align: center;
}
.tone-mark {
  font-family: var(--font-cn);
  font-size: 40px;
  line-height: 1;
  margin-bottom: 10px;
}
.tone-card[data-tone="1"] .tone-mark { color: var(--tone-1); }
.tone-card[data-tone="2"] .tone-mark { color: var(--tone-2); }
.tone-card[data-tone="3"] .tone-mark { color: var(--tone-3); }
.tone-card[data-tone="4"] .tone-mark { color: var(--tone-4); }
.tone-card[data-tone="0"] .tone-mark { color: var(--tone-0); }

.tone-shape { width: 40px; height: 28px; margin: 0 auto 10px; display: block; fill: none; stroke-width: 2; stroke-linecap: round; }
.tone-card[data-tone="1"] .tone-shape { stroke: var(--tone-1); }
.tone-card[data-tone="2"] .tone-shape { stroke: var(--tone-2); }
.tone-card[data-tone="3"] .tone-shape { stroke: var(--tone-3); }
.tone-card[data-tone="4"] .tone-shape { stroke: var(--tone-4); }
.tone-card[data-tone="0"] .tone-shape { stroke: var(--tone-0); stroke-dasharray: 3 4; }

.tone-name { font-family: var(--font-serif); font-size: 15px; font-weight: 600; }
.tone-desc { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }

/* ---------- Числа и даты ---------- */

.num-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(114px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.num-cell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 10px 14px;
  text-align: center;
  transition: border-color .16s var(--ease), transform .16s var(--ease);
}
.num-cell:hover { border-color: var(--accent-line); transform: translateY(-2px); }
.num-hanzi { font-family: var(--font-cn); font-size: 34px; line-height: 1.1; white-space: nowrap; }
.num-pinyin { font-size: 13.5px; margin-top: 6px; }
.num-value {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 2px;
}
.num-math {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
  margin-top: 3px;
}

.info-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 18px;
}
.info-card h3 {
  font-size: 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.info-card h3 .cn {
  font-family: var(--font-cn);
  font-size: 13px;
  font-weight: 400;
  color: var(--text-faint);
  letter-spacing: 0.1em;
}
.info-text { color: var(--text-dim); font-size: 14.5px; line-height: 1.6; max-width: 66ch; }

.date-list { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.date-item {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 16px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}
.date-hanzi { font-family: var(--font-cn); font-size: 23px; letter-spacing: 0.03em; }
.date-body { display: flex; flex-direction: column; }
.date-pinyin { font-size: 13px; color: var(--text-dim); }
.date-ru { font-size: 14.5px; }
.date-who { margin-left: auto; font-size: 12px; color: var(--text-faint); }

.chips { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.chip {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  text-align: center;
}
.chip-hanzi { font-family: var(--font-cn); font-size: 20px; }
.chip-py { font-size: 12px; color: var(--text-dim); }
.chip-ru { font-size: 13px; margin-top: 2px; }

/* ---------- Диалоги ---------- */

.dlg-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 26px 28px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}

.dlg-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.dlg-title { font-size: 18px; }
.dlg-cn {
  font-family: var(--font-cn);
  font-size: 13px;
  color: var(--text-faint);
  letter-spacing: 0.1em;
}
.dlg-note {
  font-size: 13px;
  color: var(--text-faint);
  margin-bottom: 18px;
  font-style: italic;
}

.dlg-lines { display: flex; flex-direction: column; gap: 3px; }

.dlg-line {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 3px 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  transition: background .16s var(--ease);
}
.dlg-line:hover { background: var(--surface-2); }

.dlg-who {
  grid-row: 1 / span 3;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  padding-top: 5px;
}
.dlg-line[data-who="B"] .dlg-who { color: var(--text-faint); }
.dlg-line[data-who=""] .dlg-who { visibility: hidden; }

.dlg-hanzi { font-family: var(--font-cn); font-size: 20px; line-height: 1.5; grid-column: 2; }
.dlg-pinyin { font-size: 13.5px; color: var(--text-dim); grid-column: 2; }
.dlg-ru { font-size: 14px; color: var(--text-dim); grid-column: 2; }
.dlg-ru::before { content: '— '; color: var(--text-faint); }
.dlg-line .speak-inline { grid-row: 1; grid-column: 3; align-self: center; }

.text-author {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}

.ex-sentences { display: flex; flex-direction: column; gap: 2px; }
.ex-sentence {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 4px 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
}
.ex-sentence:nth-child(odd) { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.ex-sentence:hover { background: var(--surface-2); }
.ex-n { font-family: var(--font-mono); font-size: 12px; color: var(--text-faint); grid-row: 1 / span 3; padding-top: 4px; }
.ex-src { font-size: 14px; color: var(--text-dim); grid-column: 2; }
.ex-alt {
  grid-column: 2;
  font-size: 12.5px;
  color: var(--text-faint);
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px dashed var(--line);
}
.ex-alt .cn { font-family: var(--font-cn); font-size: 15px; }

/* ---------- Флеш-карточки ---------- */

.fc-stage { display: flex; flex-direction: column; align-items: center; gap: 22px; }

.fc-progress {
  width: 100%;
  max-width: 520px;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.fc-bar {
  flex: 1;
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}
.fc-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width .3s var(--ease);
}

.fc-card {
  width: 100%;
  max-width: 520px;
  min-height: 290px;
  perspective: 1400px;
  cursor: pointer;
  background: none;
  border: 0;
  padding: 0;
  display: block;
}

.fc-inner {
  position: relative;
  width: 100%;
  min-height: 290px;
  transform-style: preserve-3d;
  transition: transform .55s var(--ease);
}
.fc-card.is-flipped .fc-inner { transform: rotateY(180deg); }

.fc-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.fc-back { transform: rotateY(180deg); background: var(--surface-2); }

.fc-hanzi { font-family: var(--font-cn); font-size: 74px; line-height: 1.1; letter-spacing: 0.04em; text-align: center; }
.fc-pinyin { font-size: 24px; }
.fc-ru { font-size: 21px; text-align: center; line-height: 1.35; }
.fc-hint {
  position: absolute;
  bottom: 16px;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.fc-topic {
  position: absolute;
  top: 16px; left: 20px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.fc-seal {
  position: absolute;
  top: 14px; right: 16px;
  width: 22px; height: 22px;
  border: 1.5px solid var(--accent-line);
  border-radius: 3px;
  display: grid; place-items: center;
  font-family: var(--font-cn);
  font-size: 11px;
  color: var(--accent);
  opacity: 0.75;
}
.fc-note {
  font-size: 12.5px;
  color: var(--text-faint);
  text-align: center;
  max-width: 40ch;
  line-height: 1.5;
  margin-top: 4px;
}

.fc-pinyin-big { font-size: 34px; letter-spacing: 0.01em; text-align: center; }
.fc-hanzi-small {
  font-family: var(--font-cn);
  font-size: 30px;
  line-height: 1.2;
  color: var(--text-dim);
  text-align: center;
}

/* Карточка с выбором варианта */
.fc-choice-card {
  position: relative;
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 44px 28px 30px;
  text-align: center;
}

.fc-choice-prompt {
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 16px;
}

.fc-choice-subject {
  font-family: var(--font-cn);
  font-size: 68px;
  line-height: 1.1;
  letter-spacing: 0.04em;
}
.fc-choice-subject.is-text {
  font-family: var(--font-sans);
  font-size: 26px;
  line-height: 1.35;
  padding: 12px 0;
}
.fc-choice-subject.is-pinyin {
  font-family: var(--font-sans);
  font-size: 38px;
  line-height: 1.25;
  padding: 8px 0;
}

.fc-ru-small { font-size: 15px; color: var(--text-dim); text-align: center; }

/* Полный ответ под вопросом квиза */
.quiz-reveal {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed var(--line);
  animation: fade-in .24s var(--ease);
}
.quiz-reveal-hanzi { font-family: var(--font-cn); font-size: 28px; }
.quiz-reveal-pinyin { font-size: 17px; }
.quiz-reveal-ru { color: var(--text-dim); font-size: 15px; }

.quiz-deck-label {
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40%;
}

.fc-choice-answer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px dashed var(--line);
  animation: fade-in .24s var(--ease);
}
.fc-choice-hanzi { font-family: var(--font-cn); font-size: 30px; }
.fc-choice-pinyin { font-size: 18px; }
.fc-choice-ru { color: var(--text-dim); font-size: 15px; }

.fc-stage .quiz-options { width: 100%; max-width: 520px; }

.fc-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.fc-keys { font-size: 12px; color: var(--text-faint); text-align: center; }
.fc-keys kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 3px;
  padding: 1px 5px;
  margin: 0 2px;
}

/* ---------- Квиз ---------- */

.quiz-stage { max-width: 620px; margin: 0 auto; }

.quiz-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-dim);
}
.quiz-score { color: var(--ok); }

.quiz-question {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 30px 28px;
  text-align: center;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.quiz-prompt {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 16px;
}
.quiz-subject { font-family: var(--font-cn); font-size: 54px; line-height: 1.15; }
.quiz-subject.is-text { font-family: var(--font-sans); font-size: 26px; line-height: 1.35; }
.quiz-subject.is-pinyin { font-family: var(--font-sans); font-size: 34px; }

.quiz-options { display: flex; flex-direction: column; gap: 9px; }

.quiz-option {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 15px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color .16s var(--ease), background .16s var(--ease), transform .12s var(--ease);
}
.quiz-option:hover:not(:disabled) { border-color: var(--accent-line); background: var(--accent-soft); }
.quiz-option:disabled { cursor: default; }
.quiz-option.is-correct { border-color: var(--ok); background: var(--ok-soft); }
.quiz-option.is-wrong { border-color: var(--bad); background: var(--bad-soft); }

.quiz-key {
  flex: none;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-faint);
}
.quiz-option.is-correct .quiz-key { border-color: var(--ok); color: var(--ok); }
.quiz-option.is-wrong .quiz-key { border-color: var(--bad); color: var(--bad); }

.quiz-label { font-size: 16px; line-height: 1.4; }
.quiz-label.cn { font-family: var(--font-cn); font-size: 24px; }

.quiz-next { margin-top: 18px; display: flex; justify-content: center; }

.quiz-result { text-align: center; padding: 20px 0; }
.quiz-result-score {
  font-family: var(--font-serif);
  font-size: 56px;
  line-height: 1;
  color: var(--accent);
  margin-bottom: 8px;
}
.quiz-result-label { color: var(--text-dim); margin-bottom: 26px; }

.quiz-review { text-align: left; margin-top: 26px; }
.quiz-review-title {
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 12px;
}
.quiz-mistake {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--bad);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}
.qm-hanzi { font-family: var(--font-cn); font-size: 26px; }
.qm-body { display: flex; flex-direction: column; gap: 2px; }
.qm-pinyin { font-size: 13px; color: var(--text-dim); }
.qm-right { font-size: 14.5px; }
.qm-wrong { font-size: 12.5px; color: var(--text-faint); }
.qm-wrong s { text-decoration-color: var(--bad); }

/* ---------- Пустое состояние ---------- */

.empty {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-dim);
}
.empty-glyph {
  font-family: var(--font-cn);
  font-size: 52px;
  color: var(--line-strong);
  margin-bottom: 14px;
  display: block;
}
.empty p { font-size: 15px; }
.empty .hint { font-size: 13px; color: var(--text-faint); margin-top: 6px; }

/* ---------- Тост ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: var(--bg);
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 60;
  opacity: 0;
  transition: opacity .22s var(--ease), transform .22s var(--ease);
  max-width: calc(100vw - 40px);
  text-align: center;
}
.toast.is-visible { opacity: 1; transform: translateX(-50%) translateY(0); }

.toast-action {
  margin-left: 4px;
  padding: 4px 12px;
  border: 1px solid var(--bg);
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background .16s var(--ease);
}
.toast-action:hover { background: color-mix(in srgb, var(--bg) 22%, transparent); }

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

.site-footer {
  border-top: 1px solid var(--line);
  padding: 26px 0 34px;
  color: var(--text-faint);
  font-size: 13px;
  text-align: center;
  margin-top: 25px;
}

/* ---------- Адаптив ---------- */

@media (max-width: 720px) {
  .wrap { padding: 0 16px; }
  main { padding: 28px 16px 64px; }

  .brand-sub { display: none; }
  .header-inner { padding-top: 12px; padding-bottom: 10px; }

  .hero { padding: 6px 0 26px; }
  .hero-lead { font-size: 15.5px; }

  .word-grid { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: 1fr; }

  .gram-card, .dlg-card { padding: 20px 18px; border-radius: var(--radius); }
  .toolbar { padding: 16px; }

  .filters { gap: 12px; }
  .field { flex: 1 1 140px; }
  .field select { width: 100%; }

  .word-of-day { padding: 20px; gap: 16px; }
  .wod-hanzi { font-size: 38px; }

  .fc-card, .fc-inner { min-height: 240px; }
  .fc-hanzi { font-size: 58px; }
  .fc-actions .btn { flex: 1 1 130px; }
  .fc-choice-card { padding: 38px 18px 24px; }
  .fc-choice-subject { font-size: 54px; }
  .fc-choice-subject.is-text { font-size: 22px; }
  .fc-pinyin-big { font-size: 28px; }

  .quiz-subject { font-size: 44px; }
  .quiz-subject.is-text { font-size: 22px; }

  .dlg-line { grid-template-columns: 22px 1fr auto; gap: 3px 8px; }
  .example .speak-inline, .dlg-line .speak-inline { opacity: 1; }

  .date-who { margin-left: 0; width: 100%; }
}

@media (max-width: 420px) {
  .hero-title { font-size: 42px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Уважение к настройкам ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .fc-card.is-flipped .fc-inner { transition: none; }
}

@media print {
  .site-header, .site-footer, .toolbar, .speak-btn, .speak-inline, .toast { display: none !important; }
  .section { display: block !important; }
  body { background: #fff; color: #000; }
}
