/* Layout: one calm column like a lesson page (title, task, example + console,
   hint, editor, tests); a fixed action button at the bottom. Dark only:
   the app always looks the same, whatever theme Telegram uses. */
:root {
  color-scheme: dark;

  /* palette: violet-tinted night, cream text, lavender accent */
  --bg: #17141d;
  --surface: #201c28;
  --raised: #2a2535;
  --code: #110f16;
  --line: #322c40;
  --line-strong: #4a4060;
  --cream: #f2e9d8;
  --muted: #a69db6;
  --accent: #ad94fb;
  --accent-ink: #1a1424;
  --selection: #ad94fb59;
  --ok: #93d3a2;
  --bad: #f2899b;
  --warn: #e8c17d;

  /* syntax */
  --syn-kw: #c6a8ff;
  --syn-ident: #8cb4ff;
  --syn-prop: #f5a3c7;
  --syn-str: #b8e38f;
  --syn-num: #f7a46f;
  --syn-fn: #7fdcc9;
  --syn-punct: #b8afc6;
  --syn-cmt: #6f6782;

  /* type */
  --font-ui: "Golos Text", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-code: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --code-size: 15px;

  --r-lg: 18px;
  --r-md: 12px;
  --r-sm: 7px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--bg); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--cream);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 24px calc(120px + env(safe-area-inset-bottom, 0px));
}
.is-tg .app { padding-block: 16px 32px; }

.screen { display: flex; flex-direction: column; gap: 22px; }

/* ---------- type ---------- */
.eyebrow,
.label {
  margin: 0;
  font-family: var(--font-code);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.wordmark {
  margin: 6px 0 0;
  font-size: 36px;
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: -0.025em;
  text-wrap: balance;
}
h2 {
  margin: 6px 0 0;
  font-size: 27px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
.lede { margin: 10px 0 0; color: var(--muted); max-width: 46ch; }
.prose { margin: 0; font-size: 17px; line-height: 1.6; max-width: 62ch; }
.prose code {
  font-family: var(--font-code);
  font-size: 0.86em;
  padding: 0.1em 0.42em;
  border-radius: var(--r-sm);
  background: var(--raised);
  color: var(--cream);
  white-space: nowrap;
}
.mono { font-family: var(--font-code); font-variant-numeric: tabular-nums; }
.status { margin: 0; padding: 14px 16px; border-radius: var(--r-md); background: var(--surface); color: var(--bad); }

/* ---------- list screen ---------- */
.masthead { display: flex; flex-direction: column; }
.progress { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; }
.progress-row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; color: var(--muted); }
.progress-track { height: 6px; border-radius: 999px; background: var(--raised); overflow: hidden; }
.progress-fill { height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width 0.45s ease; }

.kata-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.kata {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--cream);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.kata:hover { border-color: var(--line-strong); }
.kata-num { font-family: var(--font-code); font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.kata-title { font-weight: 600; }
.rank {
  font-family: var(--font-code);
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--raised);
  color: var(--muted);
  white-space: nowrap;
}
.rank[data-kyu="8"] { color: var(--ok); }
.rank[data-kyu="7"] { color: var(--accent); }
.rank[data-kyu="6"] { color: var(--warn); }
.check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--line-strong);
  display: grid;
  place-items: center;
  color: var(--accent-ink);
}
.check.done { background: var(--accent); border-color: var(--accent); }
.check svg { width: 12px; height: 12px; }

/* ---------- task screen ---------- */
.back {
  align-self: flex-start;
  padding: 4px 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.task-head { display: flex; flex-direction: column; }
.solved-tag { color: var(--ok); }

/* example: code + console, like a lesson card */
.code-card { margin: 0; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--code); overflow: hidden; }
.code {
  margin: 0;
  padding: 18px 20px;
  overflow-x: auto;
  font-family: var(--font-code);
  font-size: var(--code-size);
  line-height: 1.65;
  color: var(--cream);
  font-variant-ligatures: none;
}
.console {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 20px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.console-out {
  margin: 0;
  font-family: var(--font-code);
  font-size: var(--code-size);
  line-height: 1.6;
  color: var(--cream);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* hint callout */
.note {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 16px 18px;
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  background: var(--raised);
}
.note .label { color: var(--accent); }
.link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 500;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link.small { font-size: 14px; }

/* editor: highlighted <pre> under a transparent <textarea>, both with identical metrics */
.field { display: flex; flex-direction: column; gap: 10px; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.editor {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--code);
  transition: border-color 0.15s ease;
}
.editor:focus-within { border-color: var(--accent); }
.editor-hl,
.editor textarea {
  margin: 0;
  border: 0;
  padding: 18px 20px;
  font-family: var(--font-code);
  font-size: var(--code-size);
  line-height: 1.65;
  letter-spacing: 0;
  tab-size: 2;
  font-variant-ligatures: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
}
.editor-hl {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  color: var(--cream);
}
.editor textarea {
  position: relative;
  display: block;
  width: 100%;
  min-height: 210px;
  resize: none;
  overflow: hidden;
  outline: none;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: var(--accent);
}
.editor textarea::selection { background: var(--selection); }

/* test results */
.results {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--code);
}
.results-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
#results-summary { font-weight: 600; }
.results.pass #results-summary { color: var(--ok); }
.results.fail #results-summary { color: var(--bad); }
.results-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.result {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  font-family: var(--font-code);
  font-size: 14px;
  line-height: 1.55;
}
.result .icon { width: 18px; height: 18px; margin-top: 2px; }
.result.pass .icon { color: var(--ok); }
.result.fail .icon { color: var(--bad); }
.result .body { min-width: 0; display: flex; flex-direction: column; gap: 2px; overflow-wrap: anywhere; }
.result .meta { color: var(--muted); }
.result .meta b { font-weight: 500; color: var(--cream); }
.logs { display: flex; flex-direction: column; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.logs .console-out { font-size: 14px; }

/* bottom action */
.action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  padding-top: 14px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, var(--bg) 72%, transparent);
}
.action-btn {
  display: block;
  width: 100%;
  max-width: 608px;
  min-height: 56px;
  margin: 0 auto;
  border: 0;
  border-radius: var(--r-lg);
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
}
.action-btn:hover { filter: brightness(1.06); }
.action-btn:active { transform: scale(0.985); }
.action-btn:disabled { cursor: progress; filter: saturate(0.6); }

/* focus */
.kata:focus-visible,
.back:focus-visible,
.link:focus-visible,
.action-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* syntax colors (no bold/italic: both editor layers must keep identical glyph widths) */
.tok-kw { color: var(--syn-kw); }
.tok-ident { color: var(--syn-ident); }
.tok-prop { color: var(--syn-prop); }
.tok-str { color: var(--syn-str); }
.tok-num { color: var(--syn-num); }
.tok-fn { color: var(--syn-fn); }
.tok-punct { color: var(--syn-punct); }
.tok-cmt { color: var(--syn-cmt); }

@media (max-width: 380px) {
  :root { --code-size: 14px; }
  .wordmark { font-size: 31px; }
  h2 { font-size: 24px; }
  .prose { font-size: 16px; }
  .kata { gap: 10px; padding: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
