/* DevOps Quest — оболочка и страницы. Мобильный экран — основной. */
:root {
  color-scheme: light;
  --bg: #eef1f4;
  --surface: #ffffff;
  --surface-2: #f5f7f9;
  --ink: #17222e;
  --ink-2: #4a5868;
  --line: #d3dae1;
  --line-strong: #9aa7b4;
  --accent: #0b6477;
  --accent-ink: #ffffff;
  --accent-soft: #dff0f4;
  --ok: #1a7044;
  --ok-soft: #e0f1e7;
  --warn: #855600;
  --warn-soft: #fbefd3;
  --err: #ad2f27;
  --err-soft: #fbe6e3;
  --focus: #0b6477;
  --term-bg: #0d1319;
  --term-ink: #dbe4ec;
  --r-card: 10px;
  --r-ctl: 8px;
  --top-h: 52px;
  --nav-h: 60px;
  --sans: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  --vvh: 100dvh;
  --vvo: 0px;
  /* безопасные отступы: вырез экрана и (внутри Telegram) шапка Mini App */
  --sat: max(env(safe-area-inset-top, 0px), var(--tg-top, 0px));
  --sab: max(env(safe-area-inset-bottom, 0px), var(--tg-bottom, 0px));
  --sal: max(env(safe-area-inset-left, 0px), var(--tg-left, 0px));
  --sar: max(env(safe-area-inset-right, 0px), var(--tg-right, 0px));
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f151b; --surface: #17202a; --surface-2: #1d2833;
    --ink: #e4eaf0; --ink-2: #a3b3c2; --line: #2c3947; --line-strong: #5d6f81;
    --accent: #67c5de; --accent-ink: #05212a; --accent-soft: #17323c;
    --ok: #68c794; --ok-soft: #173326; --warn: #e5b452; --warn-soft: #3a2e12;
    --err: #f3847c; --err-soft: #40201d; --focus: #8ad6ea;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f151b; --surface: #17202a; --surface-2: #1d2833;
  --ink: #e4eaf0; --ink-2: #a3b3c2; --line: #2c3947; --line-strong: #5d6f81;
  --accent: #67c5de; --accent-ink: #05212a; --accent-soft: #17323c;
  --ok: #68c794; --ok-soft: #173326; --warn: #e5b452; --warn-soft: #3a2e12;
  --err: #f3847c; --err-soft: #40201d; --focus: #8ad6ea;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
body {
  font: 400 1rem/1.5 var(--sans);
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }
h1 { font-size: 1.375rem; line-height: 1.25; font-weight: 600; letter-spacing: -0.005em; }
h2 { font-size: 1.125rem; line-height: 1.3; font-weight: 600; }
h3 { font-size: 1rem; line-height: 1.35; font-weight: 600; }
a { color: var(--accent); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code, kbd, pre, .mono { font-family: var(--mono); font-size: 0.9375em; }
code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 5px; padding: 0.05em 0.35em; overflow-wrap: anywhere; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.ic { width: 20px; height: 20px; flex: none; }
pre { overflow-x: auto; }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: fixed; left: 8px; top: -60px; z-index: 100; background: var(--surface); padding: 12px 16px; border-radius: var(--r-ctl); border: 1px solid var(--line-strong); }
.skip:focus { top: 8px; }
.muted { color: var(--ink-2); }
.small { font-size: 0.875rem; line-height: 1.45; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- оболочка ---------- */
.app {
  position: fixed; left: 0; right: 0; top: var(--vvo); height: var(--vvh);
  display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr);
  background: var(--surface);
  padding: var(--sat) var(--sar) 0 var(--sal);
}
.topbar {
  grid-row: 2; display: flex; align-items: center; gap: 4px; min-height: var(--top-h);
  padding: 0 8px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.0625rem; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 8px; }
.topbar .brand { font-weight: 600; }
.iconbtn {
  display: inline-grid; place-items: center; min-width: 44px; min-height: 44px; padding: 0 8px;
  background: none; border: 0; border-radius: var(--r-ctl); color: var(--ink); text-decoration: none;
}
.iconbtn:hover { background: var(--surface-2); }
.iconbtn svg { width: 22px; height: 22px; }
#main { grid-row: 3; min-height: 0; background: var(--bg); overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
#main.ws-host { overflow: hidden; }
#main:focus, #main:focus-visible, .ws-panel:focus-visible { outline: none; }

.nav {
  grid-row: 4; display: flex; background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--sab);
}
.nav a {
  flex: 1; min-width: 0; min-height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 0.6875rem; line-height: 1.1; color: var(--ink-2); text-decoration: none; position: relative;
}
.nav a svg { width: 22px; height: 22px; }
.nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }
.nav a[aria-current="page"]::before { content: ''; position: absolute; top: -1px; left: 22%; right: 22%; height: 3px; background: var(--accent); border-radius: 0 0 3px 3px; }
.nav .nav-brand, .nav .nav-foot { display: none; }
.app[data-mode="workspace"] .nav, .app[data-mode="bare"] .nav, .app[data-mode="bare"] .topbar { display: none; }

@media (min-width: 1024px) {
  .app { grid-template-columns: 212px minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); }
  .app[data-mode="bare"] { grid-template-columns: minmax(0, 1fr); }
  .nav { grid-row: 2 / span 2; grid-column: 1; flex-direction: column; border-top: 0; border-right: 1px solid var(--line); padding: 12px 10px; gap: 2px; background: var(--surface); }
  .app[data-mode="workspace"] .nav { display: flex; }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 44px; padding: 0 12px; font-size: 0.9375rem; border-radius: var(--r-ctl); }
  .nav a[aria-current="page"] { background: var(--accent-soft); }
  .nav a[aria-current="page"]::before { display: none; }
  .nav .nav-brand { display: block; font-weight: 600; font-size: 1.0625rem; padding: 8px 12px 16px; color: var(--ink); }
  .nav .nav-foot { display: block; margin-top: auto; padding: 8px 12px; font-size: 0.8125rem; color: var(--ink-2); overflow-wrap: anywhere; }
  .topbar { grid-column: 2; }
  #main { grid-column: 2; }
  .app[data-mode="bare"] #main { grid-column: 1; }
  .topbar .brand-only { display: none; }
}

/* ---------- страница ---------- */
.page { max-width: 760px; margin: 0 auto; padding: 16px 16px 32px; display: flex; flex-direction: column; gap: 16px; }
.page.wide { max-width: 1040px; }
.page > header p { color: var(--ink-2); margin-top: 4px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.cluster { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.split { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.split > :first-child { min-width: 0; }
@media (min-width: 1024px) {
  .page { padding: 24px 32px 48px; gap: 20px; }
  .cols-2 { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 20px; align-items: start; }
}

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card > h2 + *, .card > h3 + * { margin-top: 8px; }

/* ---------- кнопки, поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 18px;
  border-radius: var(--r-ctl); border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  font-weight: 600; text-decoration: none; text-align: center; line-height: 1.2;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: translateY(1px); }
.btn.quiet { background: var(--surface); color: var(--ink); border-color: var(--line-strong); font-weight: 500; }
.btn.quiet:hover { background: var(--surface-2); filter: none; }
.btn.danger { background: var(--surface); color: var(--err); border-color: var(--err); }
.btn.compact { min-height: 44px; padding: 0 14px; font-size: 0.9375rem; }
.btn.block { display: flex; width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; filter: none; transform: none; }
.btn .spin, .spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; min-height: 44px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 500; font-size: 0.9375rem; }
.field .hint { font-size: 0.8125rem; color: var(--ink-2); }
.input {
  min-height: 48px; padding: 0 14px; width: 100%; border-radius: var(--r-ctl); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font-size: 1rem;
}
.input::placeholder { color: var(--ink-2); opacity: 0.8; }
.input:focus-visible { outline-offset: 0; border-color: var(--focus); }

.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--r-ctl); overflow: hidden; background: var(--surface); }
.seg button { min-height: 44px; padding: 0 14px; border: 0; background: none; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- сообщения ---------- */
.note { border-radius: var(--r-ctl); padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--line); border-left: 4px solid var(--line-strong); }
.note.ok { background: var(--ok-soft); border-color: transparent; border-left-color: var(--ok); }
.note.warn { background: var(--warn-soft); border-color: transparent; border-left-color: var(--warn); }
.note.err { background: var(--err-soft); border-color: transparent; border-left-color: var(--err); }
.note.info { background: var(--accent-soft); border-color: transparent; border-left-color: var(--accent); }
.note strong:first-child { display: block; }
.note .cluster { margin-top: 10px; }

.tag { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 0.8125rem; line-height: 1.5; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.banner { display: flex; gap: 12px; align-items: center; justify-content: space-between; padding: 8px 12px 8px 16px; background: var(--warn-soft); color: var(--ink); border-bottom: 1px solid var(--line); font-size: 0.9375rem; }
.banner.info { background: var(--accent-soft); }
.banners { grid-row: 1; grid-column: 1 / -1; }
.toasts { position: fixed; left: 12px; right: 12px; top: calc(var(--vvo) + var(--sat) + 6px); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; max-width: 520px; background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: var(--r-ctl); font-size: 0.9375rem; }

/* ---------- путь шагов (общий мотив: рельс со станциями) ---------- */
.track { display: flex; align-items: center; gap: 0; }
.track i { display: block; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-strong); background: var(--surface); flex: none; }
.track i + i { margin-left: 14px; position: relative; }
.track i + i::before { content: ''; position: absolute; right: 100%; top: 50%; width: 14px; height: 2px; margin-right: 2px; background: var(--line-strong); transform: translateY(-50%); }
.track i.done { background: var(--ok); border-color: var(--ok); }
.track i.done + i::before { background: var(--ok); }
.track i.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.track.tight i { width: 10px; height: 10px; }
.track.tight i + i { margin-left: 8px; }
.track.tight i + i::before { width: 8px; }

.meter { display: inline-flex; gap: 3px; vertical-align: middle; }
.meter i { width: 14px; height: 8px; border-radius: 2px; background: var(--line); }
.meter i.on { background: var(--accent); }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 3px; }

/* ---------- строки-ссылки ---------- */
.rows > li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 16px; color: inherit; text-decoration: none; width: 100%; background: none; border: 0; text-align: left; }
a.row:hover, button.row:hover { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 500; overflow-wrap: anywhere; }
.row .sub { font-size: 0.8125rem; color: var(--ink-2); }
.row.off { color: var(--ink-2); }
.row .chev { color: var(--ink-2); flex: none; }
.dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line-strong); flex: none; }
.dot.done { background: var(--ok); border-color: var(--ok); }
.dot.started { border-color: var(--accent); background: linear-gradient(90deg, var(--accent) 50%, transparent 50%); }
.dot.planned { border-style: dashed; }

/* ---------- вход ---------- */
.auth { min-height: 100%; display: grid; place-items: start center; padding: 24px 16px 32px; }
.auth-box { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 20px; margin-top: 4vh; }
.auth-box .lede { color: var(--ink-2); margin-top: 6px; }
.prompt-mark { font-family: var(--mono); font-weight: 600; color: var(--accent); }
.auth form { display: flex; flex-direction: column; gap: 14px; }

/* ---------- главная ---------- */
.resume { border-left: 4px solid var(--accent); }
.resume .where { color: var(--ink-2); font-size: 0.9375rem; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: 12px; }
.stat b { display: block; font-size: 1.375rem; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.8125rem; color: var(--ink-2); }

/* ---------- дорожная карта ---------- */
.stage { display: flex; flex-direction: column; gap: 8px; }
.stage > h3 { color: var(--ink-2); font-weight: 500; font-size: 0.9375rem; padding: 4px 2px 0; }
.mod { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); overflow: hidden; }
.mod > summary { list-style: none; display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 64px; cursor: pointer; }
.mod > summary::-webkit-details-marker { display: none; }
.mod .mod-id { font-family: var(--mono); font-size: 0.8125rem; color: var(--ink-2); width: 34px; flex: none; }
.mod .mod-title { font-weight: 500; }
.mod .mod-meta { font-size: 0.8125rem; color: var(--ink-2); margin-top: 2px; }
.mod.locked > summary .mod-title { color: var(--ink-2); }
.mod[open] > summary { border-bottom: 1px solid var(--line); }
.mod .bar { margin-top: 6px; max-width: 220px; }
.mod summary svg { flex: none; color: var(--ink-2); width: 20px; height: 20px; }
.mod[open] summary .caret { transform: rotate(90deg); }
.mod .why { padding: 10px 14px; font-size: 0.875rem; color: var(--ink-2); background: var(--surface-2); border-bottom: 1px solid var(--line); }

/* ---------- справочник ---------- */
.ref { display: flex; flex-direction: column; gap: 12px; }
.ref-search { position: sticky; top: 0; z-index: 2; background: var(--bg); padding: 0 0 8px; }
.ws .ref-search { background: var(--surface); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 44px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); font-family: var(--mono); font-size: 0.9375rem; }
.chip:hover { background: var(--surface-2); }
.cmd-card > summary { list-style: none; cursor: pointer; display: flex; gap: 12px; align-items: baseline; padding: 14px 16px; min-height: 56px; }
.cmd-card > summary::-webkit-details-marker { display: none; }
.cmd-card > summary b { font-family: var(--mono); font-weight: 600; flex: none; }
.cmd-card > summary span { color: var(--ink-2); font-size: 0.9375rem; min-width: 0; }
.cmd-card[open] > summary { border-bottom: 1px solid var(--line); }
.cmd-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 14px; }
.cmd-body h4 { margin: 0 0 6px; font-size: 0.875rem; font-weight: 600; color: var(--ink-2); }
.cmd-body pre { margin: 0; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-ctl); white-space: pre-wrap; overflow-wrap: anywhere; }
.keys { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 12px; }
.keys dt { font-family: var(--mono); font-weight: 600; white-space: nowrap; }
.ex { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; border-top: 1px solid var(--line); }
.ex:first-of-type { border-top: 0; padding-top: 0; }
.ex code { align-self: flex-start; }
.ex .cluster { margin-top: 2px; }
.cmd-body ul.plain { list-style: disc; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }

/* ---------- прогресс ---------- */
.scale { display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 8px 12px; align-items: center; font-size: 0.9375rem; }
.scale b { font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 16px; }
.kv dd { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- повторение ---------- */
.flash { min-height: 220px; display: flex; flex-direction: column; gap: 14px; }
.flash .q { font-size: 1.125rem; font-weight: 500; line-height: 1.4; }
.flash .a { border-top: 1px solid var(--line); padding-top: 14px; }
.rate { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }

/* ---------- текст урока ---------- */
.prose { display: flex; flex-direction: column; gap: 10px; max-width: 68ch; }
.prose h3 { margin-top: 6px; }
.prose p { overflow-wrap: break-word; }
.prose ul { list-style: disc; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }

.empty { text-align: left; color: var(--ink-2); padding: 8px 0; }
.loading { display: flex; align-items: center; gap: 10px; color: var(--ink-2); padding: 24px 16px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  .spin { animation: none; border-right-color: currentColor; border-style: dotted; }
}
