:root {
  --bg: #f4f5fb; --card: #ffffff; --fg: #1b1f2a; --muted: #6b7385; --line: #e5e8f0;
  --accent: #5b5bf0; --accent-2: #8b5cf6; --accent-soft: #eeeefe; --danger: #e5484d; --ok: #1f9d55;
  --shadow: 0 1px 2px rgba(20, 24, 40, .05), 0 4px 14px rgba(20, 24, 40, .06);
  --shadow-hover: 0 2px 4px rgba(20, 24, 40, .06), 0 10px 24px rgba(20, 24, 40, .10);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1117; --card: #181b24; --fg: #e8eaf0; --muted: #8e97aa; --line: #262a37;
    --accent: #7c7cff; --accent-2: #a78bfa; --accent-soft: #23253d; --danger: #ff6b70; --ok: #5ed38a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
    --shadow-hover: 0 2px 4px rgba(0, 0, 0, .35), 0 10px 24px rgba(0, 0, 0, .35);
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 15.5px/1.55 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* header */
header {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 10px 24px; align-items: center;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--card) 80%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
h1 {
  margin: 0; font-size: 1.35rem; font-weight: 800; letter-spacing: -.02em;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
nav { display: flex; gap: 4px; padding: 4px; background: var(--bg); border-radius: 999px; border: 1px solid var(--line); }
.author { margin-left: auto; font-size: .78rem; color: var(--muted); display: flex; gap: 10px; align-items: center; }
.author input { width: 170px; border-radius: 999px; }

/* form controls */
input, textarea, select, button { font: inherit; color: inherit; }
input, textarea, select {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent); background: var(--card);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
textarea { width: 100%; min-height: 9em; resize: vertical; line-height: 1.5; }

button {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 7px 14px;
  cursor: pointer; font-weight: 500; transition: transform .1s, border-color .15s, background .15s, box-shadow .15s;
}
button:hover { border-color: var(--accent); }
button:active { transform: scale(.97); }
button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 40%, transparent);
}
button.primary:hover { box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 50%, transparent); }
button.link {
  border: 0; background: none; padding: 3px 8px; color: var(--muted); font-size: .82rem; border-radius: 6px;
}
button.link:hover { color: var(--accent); background: var(--accent-soft); }
button.link.danger:hover { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.tab { border: 0; background: none; border-radius: 999px; padding: 5px 16px; color: var(--muted); }
.tab:hover { color: var(--fg); }
.tab.active { background: var(--card); color: var(--accent); box-shadow: var(--shadow); font-weight: 600; }

#error { background: var(--danger); color: #fff; padding: 10px 24px; font-weight: 500; }

/* layout */
main {
  display: grid; grid-template-columns: 250px 1fr; gap: 28px;
  max-width: 1120px; margin: 28px auto; padding: 0 24px; align-items: start;
}
main.single { grid-template-columns: 1fr; max-width: 820px; }
@media (max-width: 760px) {
  main { grid-template-columns: 1fr; gap: 16px; margin-top: 16px; }
  header { padding: 10px 16px; }
  .author { margin-left: 0; }
}

/* sidebar */
aside {
  position: sticky; top: 76px; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow);
}
@media (max-width: 760px) { aside { position: static; } }
aside ul { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 2px; }
aside li { display: flex; align-items: center; border-radius: 10px; transition: background .15s; }
aside li:hover { background: var(--bg); }
aside li.sel { background: var(--accent-soft); }
aside li.sel button.cat { color: var(--accent); font-weight: 600; }
aside li button.cat {
  flex: 1; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 10px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
aside li button.link { opacity: 0; }
aside li:hover button.link, aside li.sel button.link { opacity: 1; }
aside form { display: flex; gap: 6px; padding-top: 10px; border-top: 1px solid var(--line); }
aside form input { flex: 1; min-width: 0; padding: 6px 10px; }
aside form button { padding: 6px 12px; }

/* toolbar */
.toolbar { display: flex; gap: 10px; margin-bottom: 18px; }
.toolbar input { flex: 1; padding: 10px 16px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); }
.toolbar a { text-decoration: none; display: contents; }
.toolbar button { border-radius: 999px; padding: 9px 18px; white-space: nowrap; }

/* questions */
.q {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 4px 18px; margin-bottom: 12px; box-shadow: var(--shadow);
  transition: box-shadow .2s, border-color .2s;
}
.q:hover { box-shadow: var(--shadow-hover); }
.q .q { margin: 10px 0 0; background: var(--bg); box-shadow: none; border-radius: 12px; }
.q .q:hover { box-shadow: none; border-color: var(--accent); }
.followups { margin: 10px 0 12px 8px; padding-left: 16px; border-left: 2px solid var(--accent-soft); }

details > summary {
  cursor: pointer; font-weight: 600; padding: 12px 0; list-style: none;
  display: flex; align-items: baseline; gap: 10px;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: ""; flex: none; width: 7px; height: 7px; margin-top: 2px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform .18s;
}
details[open] > summary::before { transform: rotate(45deg); border-color: var(--accent); }
details[open] > summary { color: var(--accent); }
details > :not(summary) { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(-3px); } }

.badge {
  display: inline-block; background: var(--accent-soft); color: var(--accent); border-radius: 999px;
  padding: 1px 10px; font-size: .72rem; font-weight: 600; white-space: nowrap;
}
.answer { margin: 0 0 8px; padding: 2px 0 2px 16px; border-left: 3px solid var(--accent-soft); overflow-wrap: anywhere; }
.empty { color: var(--muted); font-style: italic; }
.actions { margin: 4px 0 12px; display: flex; flex-wrap: wrap; gap: 2px; }
.meta { color: var(--muted); font-size: .8rem; }

form.edit { display: grid; gap: 10px; margin: 12px 0; }
form.edit .row { display: flex; gap: 8px; flex-wrap: wrap; }

/* history */
.hist {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 18px; margin-bottom: 10px; box-shadow: var(--shadow);
}
.hist .old, .hist .new { padding: 4px 10px; border-radius: 8px; white-space: pre-wrap; margin-top: 2px; }
.hist .old { background: color-mix(in srgb, var(--danger) 10%, transparent); color: var(--danger); text-decoration: line-through; }
.hist .new { background: color-mix(in srgb, var(--ok) 11%, transparent); color: var(--ok); }
.hist .field { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 10px; }

/* follow-up rows in the new-question form */
.fu-box { display: grid; gap: 10px; }
.fu-row {
  display: grid; gap: 6px; padding: 10px 12px 6px 14px; background: var(--bg);
  border-left: 3px solid var(--accent); border-radius: 10px;
}
.fu-row button.link { justify-self: end; }

/* account */
.account { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.account .author { margin-left: 0; }
.account .who { font-weight: 600; }
form.login { display: flex; gap: 6px; flex-wrap: wrap; }
form.login input { width: 120px; padding: 6px 12px; border-radius: 999px; }
form.login button { padding: 5px 12px; border-radius: 999px; }

/* filters & chips */
.filters { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
.filters .chips { margin: 0; }
.chip { border-radius: 999px; padding: 3px 12px; font-size: .82rem; color: var(--muted); }
.chip.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.badge.solved { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.badge.todo { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge { margin-left: 6px; }

/* training */
.stats { padding: 14px 18px; }
.bar-track { height: 8px; background: var(--bg); border-radius: 999px; margin-top: 8px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; transition: width .3s; }
.q .row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 12px; }
.modes { margin-top: 4px; }
.train-card { padding: 14px 22px 6px; }
.train-q { font-size: 1.25rem; margin: 8px 0 14px; letter-spacing: -.01em; }
details.fu { border-top: 1px solid var(--line); }
details.fu:first-child { border-top: 0; }

/* welcome popup */
.overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px;
  background: rgba(10, 12, 24, .55); backdrop-filter: blur(4px); animation: fade .2s ease;
}
.modal {
  width: min(420px, 100%); display: grid; gap: 12px; padding: 26px;
  background: var(--card); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.modal h2 { margin: 0; font-size: 1.4rem; letter-spacing: -.02em; }
.modal p { margin: 0; color: var(--muted); }
.modal .row { display: flex; gap: 8px; }
.modal .row button { flex: 1; }
.modal-err { color: var(--danger); font-size: .88rem; }
.modal > button.link { justify-self: center; }

/* training center v2 */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat-tiles div { background: var(--bg); border-radius: 12px; padding: 10px 14px; display: grid; }
.stat-tiles b { font-size: 1.5rem; letter-spacing: -.02em; }
.stat-tiles span { color: var(--muted); font-size: .78rem; }
.cat-progress { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px 20px; margin-top: 14px; font-size: .85rem; }
.cat-progress small { color: var(--muted); }
.cat-progress .bar-track { margin-top: 3px; height: 6px; }
.setup { display: grid; gap: 4px; padding: 16px 18px; }
.setup .meta { margin-top: 10px; text-transform: uppercase; letter-spacing: .06em; font-size: .72rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin: 6px 0; }
.tile { text-align: left; display: grid; gap: 2px; padding: 12px 14px; border-radius: 12px; align-content: start; }
.tile .tile-icon { font-size: 1.4rem; }
.tile small { color: var(--muted); font-weight: 400; line-height: 1.3; }
.tile em { font-style: normal; font-size: .78rem; color: var(--accent); margin-top: 4px; }
.tile.on { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
button.big { padding: 11px 28px; font-size: 1.05rem; border-radius: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.train-card { padding: 18px 24px 12px; }
.train-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.train-q { font-size: 1.35rem; margin: 18px 0 14px; letter-spacing: -.01em; line-height: 1.35; }
.fu-step { margin: 14px 0 0 6px; padding-left: 14px; border-left: 3px solid var(--accent); animation: fade .25s ease; }
.fu-q { font-weight: 600; }
.hoca { display: inline-block; background: var(--accent-soft); color: var(--accent); font-size: .7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; border-radius: 999px; padding: 1px 9px; margin-right: 8px; }
.hint { color: var(--muted); font-size: .74rem; padding-bottom: 8px; }
.summary .score { font-size: 2.6rem; font-weight: 800; letter-spacing: -.03em; }
.summary .score small { font-size: 1.1rem; color: var(--muted); font-weight: 500; }
.missed { margin: 4px 0 8px; padding-left: 20px; }
.modal button.big { width: 100%; }
.modal p.small { font-size: .85rem; }
.modal .or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .8rem; margin-top: 4px; }
.modal .or::before, .modal .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* feedback button */
.fab {
  position: fixed; right: 18px; bottom: 18px; z-index: 50; border-radius: 999px; padding: 9px 16px;
  box-shadow: var(--shadow-hover); background: var(--card);
}
.modal textarea { min-height: 9em; }

button.link.solve:hover { color: var(--ok); background: color-mix(in srgb, var(--ok) 12%, transparent); }
.solve-btn {
  margin-left: auto; flex: none; padding: 3px 12px; font-size: .82rem; border-radius: 999px;
  color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, var(--line));
  background: color-mix(in srgb, var(--ok) 8%, transparent);
}
.solve-btn:hover { background: var(--ok); border-color: var(--ok); color: #fff; }

/* import */
.scheme-btn { border-radius: 999px; font-size: .85rem; }
.modal.wide { width: min(640px, 100%); }
.modal.wide textarea { font-family: ui-monospace, monospace; font-size: .85rem; }
.hint-banner {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 12px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 14%, transparent), color-mix(in srgb, var(--accent-2) 14%, transparent));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--line)); line-height: 1.4;
}
.hint-banner > span { font-size: 1.4rem; }
.hint-banner small { color: var(--muted); display: block; margin-top: 4px; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 560px) { .steps { grid-template-columns: 1fr; } }
.steps li { display: flex; gap: 10px; align-items: flex-start; background: var(--bg); border-radius: 12px; padding: 10px 12px; }
.steps li > div { display: grid; gap: 4px; justify-items: start; }
.steps small { color: var(--muted); line-height: 1.3; }
.step-n {
  flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-size: .8rem; font-weight: 700;
}
button.mini { padding: 3px 10px; font-size: .78rem; border-radius: 999px; }

/* formatted answers (Markdown subset) */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md li { margin: 2px 0; }
.md li > ul, .md li > ol { margin: 2px 0; }
.md h3, .md h4, .md h5, .md h6 { margin: 12px 0 4px; line-height: 1.3; }
.md h3 { font-size: 1.1rem; } .md h4 { font-size: 1rem; } .md h5, .md h6 { font-size: .92rem; color: var(--muted); }
.md code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .88em; background: var(--bg);
  border: 1px solid var(--line); border-radius: 5px; padding: 0 5px; }
.md a { color: var(--accent); }
.md-table { overflow-x: auto; margin: 8px 0; -webkit-overflow-scrolling: touch; }
.md table { border-collapse: collapse; font-size: .92em; min-width: 100%; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--bg); font-weight: 600; white-space: nowrap; }

/* follow-up rows in forms: reorder controls */
.fu-row .fu-ctl { display: flex; gap: 2px; justify-content: flex-end; }
.fu-row .fu-ctl .link { font-size: .9rem; }

/* account dialog */
.modal .edit { display: grid; gap: 8px; padding-top: 6px; }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
button.danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
button.link.who { color: var(--fg); font-weight: 600; font-size: .9rem; }

/* offline banner */
#offline { background: #b45309; color: #fff; padding: 8px 24px; font-size: .88rem; text-align: center; }

/* mobile */
body { padding-bottom: calc(60px + env(safe-area-inset-bottom)); }
@media (max-width: 760px) {
  body { font-size: 16px; }
  header { gap: 8px 12px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); }
  h1 { font-size: 1.2rem; }
  nav { order: 3; width: 100%; justify-content: space-between; }
  nav .tab { flex: 1; text-align: center; padding: 8px 6px; }
  .scheme-btn { order: 2; margin-left: auto; padding: 6px 12px; }
  .account { order: 4; width: 100%; margin-left: 0; flex-wrap: wrap; }
  .account .author { width: 100%; justify-content: space-between; }
  .account .author input { flex: 1; width: auto; }
  form.login { width: 100%; }
  form.login input { flex: 1 1 110px; width: auto; }
  input, textarea, select { font-size: 16px; } /* prevents iOS zoom on focus */
  button { min-height: 40px; }
  button.link { min-height: 36px; padding: 6px 10px; }
  main { padding: 0 12px; margin: 12px auto; gap: 12px; }
  aside { padding: 8px; }
  aside ul { display: flex; flex-wrap: wrap; gap: 6px; }
  aside li { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; }
  aside li.sel { background: var(--accent-soft); border-color: var(--accent); }
  aside li button.cat { padding: 6px 10px; min-height: 0; }
  aside li button.link { min-height: 0; padding: 4px 6px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar input { flex: 1 1 100%; }
  .toolbar button { flex: 1; }
  .toolbar a { display: contents; }
  .filters { flex-direction: column; }
  .q { padding: 2px 12px; }
  details > summary { flex-wrap: wrap; row-gap: 6px; }
  .solve-btn { margin-left: 0; min-height: 34px; }
  .followups { margin-left: 2px; padding-left: 10px; }
  .actions button.link { padding: 8px 10px; }
  .train-card { padding: 12px 14px 8px; }
  .train-q { font-size: 1.2rem; }
  .q .row { flex-direction: column; }
  .q .row button { width: 100%; }
  .hint { display: none; } /* keyboard shortcuts are useless on touch */
  .stat-tiles { grid-template-columns: repeat(2, 1fr); }
  .tiles { grid-template-columns: 1fr; }
  .overlay { align-items: end; padding: 0; }
  .modal, .modal.wide { width: 100%; max-height: 92vh; overflow-y: auto; border-radius: 20px 20px 0 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .fab { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); padding: 10px 14px; }
  #offline { padding: 8px 12px; }
}
@media (hover: none) {
  aside li button.link { opacity: 1; }
}

/* subcategories */
aside li.sub { margin-left: 16px; }
aside li.sub button.cat { font-size: .92em; color: var(--muted); }
aside li.sub.sel button.cat { color: var(--accent); }
aside form { flex-wrap: wrap; }
aside form select { max-width: 100%; }
@media (max-width: 760px) { aside li.sub { margin-left: 0; } }

/* collapsible categories in the sidebar */
aside li button.twisty, aside li .twisty-gap { flex: none; width: 24px; min-height: 0; padding: 0; border: 0; background: none; }
aside li button.twisty { height: 28px; display: grid; place-items: center; color: var(--muted); border-radius: 8px; }
aside li button.twisty::before {
  content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(-45deg); transition: transform .15s;
}
aside li button.twisty.open::before { transform: rotate(45deg); }
aside li button.twisty:hover { background: var(--accent-soft); color: var(--accent); }
aside li button.cat .sub-count {
  margin-left: 6px; padding: 0 7px; font-size: .72rem; font-weight: 600; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
@media (max-width: 760px) {
  aside li button.twisty { height: 32px; width: 28px; }
  aside li .twisty-gap { display: none; }
}

/* changelog */
#changelog-btn { position: relative; }
#changelog-btn.has-new {
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; font-weight: 600;
  box-shadow: 0 2px 10px color-mix(in srgb, var(--accent) 45%, transparent);
}
.new-dot {
  position: absolute; top: -3px; right: -3px; width: 10px; height: 10px; border-radius: 50%;
  background: #ff5d73; border: 2px solid var(--card); animation: pulse 1.8s ease-out infinite;
}
.new-dot[hidden] { display: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255, 93, 115, .6); } 70%, 100% { box-shadow: 0 0 0 8px rgba(255, 93, 115, 0); } }
.modal.changelog { max-height: 85vh; overflow-y: auto; }
.cl-list { display: grid; gap: 14px; }
.cl-entry { border-top: 1px solid var(--line); padding-top: 10px; }
.cl-entry:first-child { border-top: 0; padding-top: 0; }
.cl-entry h3 { margin: 0; font-size: 1.02rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cl-entry ul { margin: 6px 0 0; padding-left: 20px; }
.cl-entry li { margin: 3px 0; }
.badge.new { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
@media (prefers-reduced-motion: reduce) { .new-dot { animation: none; } }
