/*
 * «Балл» design system, v0 (docs/design/README.md).
 * T12 copies this file to app/web/static/css/app.css. No external fonts or assets:
 * the UI face is the system stack, numbers and math use KaTeX_Main, which
 * katex.min.css (vendored) already declares.
 */

:root {
  /* palette: a squared school notebook and a ballpoint pen; no teacher's red */
  --paper: #fafbfc;
  --grid: #dfe6ee;
  --graphite: #2b2f36;
  --graphite-soft: #5e6673;
  --ink: #2340a8;
  --ink-hover: #1a3189;
  --highlighter: #ffe45c;
  --caution: #8a5a00; /* input format problems only, never near the forecast */

  /* type */
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --font-math: "KaTeX_Main", "Times New Roman", serif;
  --text-sm: 0.875rem;  /* 14 / 20 */
  --text-base: 1rem;    /* 16 / 24 */
  --text-lg: 1.25rem;   /* 20 / 28 */
  --text-xl: 1.75rem;   /* 28 / 36 */
  --text-forecast: 5.5rem;

  /* spacing: only these steps */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 24px;
  --s-6: 32px;
  --s-7: 48px;
  --s-8: 64px;

  --radius: 8px;
  --measure: 34rem;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--graphite);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: 1.5;
}

h1,
h2,
h3,
p {
  margin: 0;
  text-wrap: pretty;
}

h1,
h2 {
  text-wrap: balance;
}

h2 {
  font-size: var(--text-lg);
  line-height: 1.4;
  font-weight: 600;
}

a {
  color: var(--ink);
  text-underline-offset: 3px;
}

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

.skip-link {
  position: absolute;
  left: var(--s-4);
  top: -100px;
  background: var(--paper);
  padding: var(--s-2) var(--s-3);
}

.skip-link:focus {
  top: var(--s-2);
}

/* ---------- page frame: one left-aligned column ---------- */

.page {
  max-width: var(--measure);
  margin: 0 auto;
  padding: var(--s-4) var(--s-4) var(--s-8);
}

/* the demo (T19): a quiet line above the page, not a banner */
.demo-note {
  padding: var(--s-2) var(--s-4);
  background: var(--grid);
  color: var(--graphite);
  font-size: var(--text-sm);
  text-align: center;
}

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s-4);
  padding-bottom: var(--s-5);
}

.masthead__name {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--graphite);
  text-decoration: none;
}

.masthead__aside {
  font-size: var(--text-sm);
  color: var(--graphite-soft);
}

.stack > * + * {
  margin-top: var(--s-6);
}

.muted {
  color: var(--graphite-soft);
}

.small {
  font-size: var(--text-sm);
  line-height: 1.45;
}

/* ---------- forecast: the number, its range and the scale version ---------- */

.forecast__subject {
  font-size: var(--text-sm);
  color: var(--graphite-soft);
}

.forecast__lead {
  margin-top: var(--s-4);
  font-size: var(--text-base);
}

.forecast__num {
  display: block;
  font-family: var(--font-math);
  font-size: var(--text-forecast);
  line-height: 1;
  font-weight: 400;
  font-variant-numeric: lining-nums tabular-nums;
  margin: var(--s-1) 0 var(--s-2) -0.04em; /* optical alignment of the numeral with the text edge */
}

.forecast__range {
  font-size: var(--text-lg);
  line-height: 1.4;
}

.forecast__range .num,
.num {
  font-family: var(--font-math);
  font-variant-numeric: lining-nums tabular-nums;
}

.forecast__scale {
  margin-top: var(--s-1);
}

/* ---------- number line on squared paper ---------- */

.numline {
  margin: var(--s-5) 0 0;
}

.numline__paper {
  margin: 0 calc(-1 * var(--s-4));
  padding: var(--s-3) var(--s-4) var(--s-1);
  background-color: #fff;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 16px 16px;
  background-position: -1px -1px;
}

@media (min-width: 36rem) {
  .numline__paper {
    margin-left: 0;
    margin-right: 0;
    border-radius: var(--radius);
  }
}

.numline svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.numline figcaption {
  margin-top: var(--s-2);
  font-size: var(--text-sm);
  line-height: 1.45;
  color: var(--graphite-soft);
}

.nl-axis {
  stroke: var(--graphite);
  stroke-width: 1.5;
}

.nl-arrow {
  fill: var(--graphite);
}

.nl-tick {
  stroke: var(--graphite);
  stroke-width: 1;
}

.nl-label {
  font-family: var(--font-math);
  font-size: 13px;
  fill: var(--graphite-soft);
  text-anchor: middle;
}

.nl-label--end {
  fill: var(--graphite);
}

.nl-label--point {
  fill: var(--graphite);
  font-weight: 700;
}

.nl-hatch {
  fill: url(#hatch);
}

.nl-hatch-line {
  stroke: var(--ink);
  stroke-width: 1.4;
}

.nl-endpoint {
  fill: var(--ink);
}

.nl-point {
  stroke: var(--graphite);
  stroke-width: 2;
}

.nl-exam {
  fill: var(--ink);
}

.nl-exam--out {
  fill: #fff;
  stroke: var(--ink);
  stroke-width: 1.5;
}

.nl-target {
  stroke: var(--graphite);
  stroke-width: 1.5;
  stroke-dasharray: 3 3;
}

/* the one orchestrated moment: the range is drawn, then the imagined exams land */
@media (prefers-reduced-motion: no-preference) {
  .numline--enter .nl-hatch {
    transform-box: fill-box;
    transform-origin: center;
    animation: nl-draw 700ms var(--ease) both;
  }

  .numline--enter .nl-exam,
  .numline--enter .nl-exam--out {
    animation: nl-land 500ms var(--ease) both;
    animation-delay: calc(500ms + var(--i, 0) * 60ms);
  }
}

@keyframes nl-draw {
  from {
    transform: scaleX(0);
  }
}

@keyframes nl-land {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
}

/* ---------- explanation of a wide range ---------- */

.note p + p,
.note details {
  margin-top: var(--s-2);
}

.note summary {
  cursor: pointer;
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 3px;
  list-style: none;
  width: fit-content;
}

.note summary::-webkit-details-marker {
  display: none;
}

.note details[open] summary {
  margin-bottom: var(--s-2);
}

/* ---------- target ---------- */

.target {
  font-size: var(--text-base);
}

/* ---------- three topics ---------- */

.topics {
  border: 0;
  margin: 0;
  padding: 0;
}

.topics legend {
  padding: 0;
  font-size: var(--text-lg);
  line-height: 1.4;
  font-weight: 600;
}

.topics__hint {
  margin-top: var(--s-1);
}

.topics__list {
  list-style: none;
  margin: var(--s-4) 0 0;
  padding: 0;
}

.topic {
  position: relative;
  display: grid;
  grid-template-columns: 20px 1fr;
  column-gap: var(--s-3);
  padding: var(--s-3) 0;
  cursor: pointer;
}

.topic + .topic {
  border-top: 1px solid var(--grid);
}

.topic input {
  margin: 3px 0 0;
  width: 18px;
  height: 18px;
  accent-color: var(--ink);
}

.topic__name {
  position: relative;
  width: fit-content;
  font-weight: 600;
}

/* the chosen topic is marked the way a student marks a line: with a highlighter */
.topic__name::before {
  content: "";
  position: absolute;
  inset: 0.3em -0.2em -0.05em;
  z-index: -1;
  background: var(--highlighter);
  border-radius: 2px;
  transform: scaleX(0) rotate(-0.6deg);
  transform-origin: left center;
  transition: transform 300ms var(--ease);
}

.topic__name {
  z-index: 0;
}

.topic:has(input:checked) .topic__name::before {
  transform: scaleX(1) rotate(-0.6deg);
}

@media (prefers-reduced-motion: reduce) {
  .topic__name::before {
    transition: none;
  }
}

.topic__price {
  grid-column: 2;
  font-size: var(--text-sm);
  color: var(--graphite-soft);
}

.topic__price .num {
  color: var(--graphite);
}

/* ---------- actions ---------- */

.actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--s-3);
  margin-top: var(--s-5);
}

@media (min-width: 36rem) {
  .actions {
    align-items: flex-start;
  }
}

.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 48px;
  padding: var(--s-3) var(--s-5);
  border: 0;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 200ms var(--ease), transform 200ms var(--ease);
}

.btn:hover {
  background: var(--ink-hover);
}

.btn:active {
  transform: translateY(1px);
}

.btn[disabled],
.btn[aria-disabled="true"] {
  background: var(--grid);
  color: var(--graphite-soft);
  cursor: not-allowed;
}

.btn--quiet {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1.5px var(--ink);
}

.btn--quiet:hover {
  background: #eef1fa;
}

.btn--loading {
  color: transparent;
  position: relative;
  pointer-events: none;
}

.btn--loading::after {
  content: "Считаем…";
  position: absolute;
  color: #fff;
}

/* ---------- task screen ---------- */

.progress {
  font-size: var(--text-sm);
  color: var(--graphite-soft);
}

.task__statement {
  font-size: var(--text-lg);
  line-height: 1.6;
}

.task__statement .katex {
  font-size: 1.1em;
}

.answer {
  display: grid;
  gap: var(--s-2);
}

.answer label {
  font-weight: 600;
}

.answer input {
  width: 100%;
  min-height: 48px;
  padding: var(--s-2) var(--s-3);
  border: 1.5px solid var(--graphite-soft);
  border-radius: var(--radius);
  background: #fff;
  color: var(--graphite);
  font-family: var(--font-math);
  font-size: var(--text-lg);
}

.answer input:focus-visible {
  outline-offset: 0;
  border-color: var(--ink);
}

.answer input[readonly] {
  background: var(--paper);
  border-style: dashed;
}

.answer__hint {
  font-size: var(--text-sm);
  color: var(--graphite-soft);
}

.answer__problem {
  font-size: var(--text-sm);
  color: var(--caution);
}

.recorded {
  padding: var(--s-3) 0;
  border-top: 1px solid var(--grid);
}

.report {
  font-size: var(--text-sm);
}

/* ---------- history of the range (dashboard) ---------- */

.ladder svg {
  display: block;
  width: 100%;
  height: auto;
}

.ladder__date {
  font-family: var(--font-ui);
  font-size: 13px;
  fill: var(--graphite-soft);
}

.ladder__date--now {
  fill: var(--graphite);
  font-weight: 600;
}

.ladder__guide {
  stroke: var(--grid);
  stroke-width: 1;
}

/* ---------- T12 additions: pieces the prototypes do not draw ---------- */

/* a label moved aside so that the labels of the number line do not run into each other */
.nl-label--left {
  text-anchor: end;
}

.nl-label--right {
  text-anchor: start;
}

.nl-target-label {
  font-family: var(--font-math);
  font-size: 13px;
  fill: var(--graphite);
  text-anchor: middle;
}

/* start screen and the goals form */
.start__title {
  font-size: var(--text-xl);
  line-height: 1.3;
  font-weight: 600;
}

.start__lead {
  margin-top: var(--s-3);
}

.form > * + * {
  margin-top: var(--s-5);
}

.answer select,
.answer input[type="date"] {
  width: 100%;
  min-height: 48px;
  padding: var(--s-2) var(--s-3);
  border: 1.5px solid var(--graphite-soft);
  border-radius: var(--radius);
  background: #fff;
  color: var(--graphite);
  font-family: var(--font-ui);
  font-size: var(--text-base);
}

.answer select:focus-visible,
.answer input[type="date"]:focus-visible {
  outline-offset: 0;
  border-color: var(--ink);
}

.answer input[type="number"] {
  font-family: var(--font-ui);
}

/* the drawing of a task (SVG from the generator) never pushes the page wider than the screen */
.task__figure svg {
  max-width: 100%;
  height: auto;
}

/* long words and formulas wrap or scroll inside their own box, not the page */
.task__statement {
  overflow-wrap: anywhere;
}

.task__statement .katex-display {
  overflow-x: auto;
  overflow-y: hidden;
}

.message p + p {
  margin-top: var(--s-3);
}

/* registration, consents and the account (T13) */
.form .answer input,
.form .answer select {
  font-family: var(--font-ui);
  font-size: var(--text-base);
}

.check {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
}

.check input {
  flex: none;
  width: 24px;
  height: 24px;
  margin-top: 2px;
  accent-color: var(--ink);
}

.account__sub {
  font-size: var(--text-lg);
  line-height: 1.4;
  font-weight: 600;
}

.legal p + p,
.note .form {
  margin-top: var(--s-3);
}

.notice {
  margin-top: var(--s-3);
  color: var(--graphite-soft);
}

.result__stored {
  margin-top: var(--s-3);
}

.account__sub + p {
  margin-top: var(--s-2);
}

/* ---------- lessons: solution, explanation, report (T14) ---------- */

.solution,
.explanation {
  display: grid;
  gap: var(--s-2);
  margin-top: var(--s-5);
  padding-top: var(--s-3);
  border-top: 1px solid var(--grid);
}

.solution__text {
  white-space: pre-line;
}

.report summary {
  cursor: pointer;
  color: var(--graphite-soft);
}

.answer textarea {
  width: 100%;
  padding: var(--s-2) var(--s-3);
  border: 1.5px solid var(--graphite-soft);
  border-radius: var(--radius);
  background: #fff;
  color: var(--graphite);
  font: inherit;
}

.answer textarea:focus-visible {
  outline-offset: 0;
  border-color: var(--ink);
}

/* a button inside a form inside `.actions` takes the width like a button that is a direct child */
.actions > form {
  display: grid;
}
