:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f6);
  --text: var(--tg-theme-text-color, #111114);
  --hint: var(--tg-theme-hint-color, #8a8a93);
  --link: var(--tg-theme-link-color, #2f7cf6);
  --accent: var(--tg-theme-button-color, #2f7cf6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: color-mix(in srgb, var(--text) 10%, transparent);
  --ok: #1f9d55;
  --page-bg: #fbfaf7;
  --radius: 12px;
  --bar-h: 52px;
  --dock-h: 64px;
  font-synthesis: none;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg2); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* вход */
.gate { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; background: var(--bg); z-index: 50; }
.gate-box { max-width: 340px; text-align: center; }
.gate h1 { font-size: 20px; margin: 16px 0 8px; }
.gate p { color: var(--hint); margin: 0 0 20px; }
.spinner { width: 28px; height: 28px; margin: 0 auto; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn { height: 44px; padding: 0 18px; border-radius: 10px; background: var(--bg2); font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn:active { opacity: .7; }

/* верхняя панель */
.bar { position: fixed; top: 0; left: 0; right: 0; height: var(--bar-h); display: flex; align-items: center; justify-content: space-between;
  padding: 0 6px; background: var(--bg); border-bottom: 1px solid var(--line); z-index: 10; }
.icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; }
.icon:active { background: var(--bg2); }
.title { display: flex; flex-direction: column; align-items: center; min-width: 0; padding: 4px 12px; border-radius: 10px; }
.title:active { background: var(--bg2); }
.title span { font-weight: 650; font-size: 16px; }
.title small { color: var(--hint); font-size: 12px; max-width: 62vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* страница */
.viewer { position: fixed; top: var(--bar-h); bottom: var(--dock-h); left: 0; right: 0; overflow: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg2); touch-action: pan-x pan-y; }
.page-wrap { position: relative; margin: 0 auto; width: 100%; max-width: 900px; background: var(--page-bg); }
.page-wrap img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-select: none; min-height: 60vh; }
.viewer.zoom .page-wrap { width: 200%; max-width: none; }
.hot { position: absolute; inset: 0; }
.hot button { position: absolute; left: 0; width: 100%; border-radius: 6px; }
.hot button.ready:active, .hot button.flash { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.hot .tag { position: absolute; left: 2%; top: 0; width: 10%; height: 28px; border-radius: 6px; }
.hot button.ready .tag { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent); }

/* нижняя панель */
.dock { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--dock-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: flex; align-items: center; gap: 4px; padding-left: 4px; padding-right: 4px; background: var(--bg); border-top: 1px solid var(--line); z-index: 10; }
.nav { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 10px; }
.nav:active { background: var(--bg2); }
.nav:disabled { opacity: .3; }
.chips { flex: 1; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 0 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 36px; min-width: 44px; padding: 0 12px; border-radius: 18px; background: var(--bg2); font-weight: 650; font-variant-numeric: tabular-nums; }
.chip.ready { background: color-mix(in srgb, var(--accent) 14%, var(--bg)); color: var(--link); }
.chip:active { opacity: .7; }
.chips .empty { color: var(--hint); font-size: 13px; margin: auto; }

/* листы */
.sheet { position: fixed; inset: 0; z-index: 30; background: var(--bg); display: flex; flex-direction: column; animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(12px); opacity: 0; } }
.sheet-head { flex: none; height: var(--bar-h); display: flex; align-items: center; gap: 4px; padding: 0 6px; border-bottom: 1px solid var(--line); }
.sheet-title { flex: 1; display: flex; flex-direction: column; align-items: center; min-width: 0; }
.sheet-title b { font-size: 16px; }
.sheet-title small { color: var(--hint); font-size: 12px; max-width: 70vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-head input { flex: 1; height: 40px; border-radius: 10px; border: 0; background: var(--bg2); color: var(--text); padding: 0 12px; font: inherit; outline: none; }

.tabs { flex: none; display: flex; gap: 6px; overflow-x: auto; padding: 10px 12px; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; height: 34px; min-width: 44px; padding: 0 12px; border-radius: 17px; background: var(--bg2); font-weight: 600; }
.tabs button.on { background: var(--accent); color: var(--accent-text); }

.sol-body { flex: 1; overflow-y: auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }
.sol-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 20px 0 8px; }
.sol-body h3:first-child { margin-top: 0; }
.cond { background: var(--bg2); border-radius: var(--radius); padding: 12px 14px; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; }
.steps li { position: relative; padding: 0 0 12px 34px; counter-increment: s; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 1px; width: 24px; height: 24px; border-radius: 50%; background: var(--bg2);
  font-size: 13px; font-weight: 700; display: grid; place-items: center; color: var(--hint); }
.answer { border-radius: var(--radius); padding: 12px 14px; background: color-mix(in srgb, var(--ok) 12%, var(--bg)); border: 1px solid color-mix(in srgb, var(--ok) 35%, transparent); font-weight: 600; }
.check { color: var(--hint); font-size: 14px; }
.note { font-size: 14px; border-left: 3px solid var(--accent); padding: 4px 0 4px 10px; color: var(--text); }
.missing { text-align: center; color: var(--hint); padding: 48px 16px; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.katex { font-size: 1.06em; }
.sol-body img { max-width: 100%; border-radius: 8px; background: #fff; }

/* списки */
.list { list-style: none; margin: 0; padding: 0 0 calc(24px + env(safe-area-inset-bottom)); overflow-y: auto; flex: 1; }
.list li button { width: 100%; text-align: left; display: flex; gap: 12px; align-items: baseline; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.list li button:active { background: var(--bg2); }
.list .k { flex: none; min-width: 48px; font-weight: 700; color: var(--link); font-variant-numeric: tabular-nums; }
.list .t { flex: 1; min-width: 0; }
.list .t small { display: block; color: var(--hint); font-size: 13px; }
.list .p { flex: none; color: var(--hint); font-size: 13px; font-variant-numeric: tabular-nums; }
.list .grp { padding: 16px 16px 6px; font-size: 13px; color: var(--hint); text-transform: uppercase; letter-spacing: .04em; }
.hint { padding: 14px 16px; color: var(--hint); font-size: 14px; }

/* переход к странице */
.modal { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.35); display: grid; place-items: center; padding: 24px; }
.modal-box { width: 100%; max-width: 320px; background: var(--bg); border-radius: 16px; padding: 18px; }
.modal-box label { font-weight: 650; display: block; margin-bottom: 10px; }
.modal-box input { width: 100%; height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); color: var(--text); padding: 0 12px; font-size: 18px; outline: none; }
.modal-box .err { color: #d33; font-size: 14px; min-height: 20px; margin: 8px 0; }
.modal-box .row { display: flex; gap: 8px; justify-content: flex-end; }

.toast { position: fixed; left: 50%; bottom: calc(var(--dock-h) + 16px); transform: translateX(-50%); background: rgba(20,20,24,.9); color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 14px; z-index: 60; }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
#sol { z-index: 35; }
