/* ==========================================================================
   Qutir — visual system
   The app is dressed as the object it replaces: a squared maths exercise book,
   written in ink, corrected in the teacher's red pen.
   ========================================================================== */

:root {
  /* paper and ink */
  --paper: #fbf9f3;
  --paper-raised: #ffffff;
  --grid: rgba(120, 158, 194, 0.22);
  --margin-rule: rgba(200, 16, 46, 0.28);
  --ink: #16233a;
  --ink-soft: #5b697f;
  --ink-faint: #7f8b9d;
  --hairline: #e2ddd2;

  /* marks */
  --pen-red: #c8102e;
  --pen-red-wash: rgba(200, 16, 46, 0.07);
  --green: #1b7a5a;
  --green-wash: rgba(27, 122, 90, 0.09);
  --amber: #f2b705;
  --amber-wash: rgba(242, 183, 5, 0.14);

  /* type */
  --font-ui: system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans Ethiopic', 'Abyssinica SIL', sans-serif;
  --font-math: ui-monospace, 'DejaVu Sans Mono', 'Roboto Mono', 'Noto Sans Mono', 'Courier New', monospace;

  --square: 24px; /* the ruled grid pitch, and the app's spacing unit */
  --radius: 3px; /* paper does not have rounded corners; keep it nearly square */
  --keypad-h: 232px;
}

html[data-lang='am'] {
  --font-ui: 'Noto Sans Ethiopic', 'Abyssinica SIL', system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background-color: var(--paper);
  /* squared paper */
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--square) var(--square);
  background-position: -1px -1px;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ------------------------------------------------------------------- shell */

.shell {
  position: relative;
  display: flex;
  flex-direction: column;
  max-width: 460px;
  margin: 0 auto;
  min-height: 100vh;
  padding: 0 var(--square) calc(var(--square) * 1.5);
}

/* the exercise-book margin line */
.shell::before {
  content: '';
  position: fixed;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-230px);
  width: 1px;
  background: var(--margin-rule);
  pointer-events: none;
}
@media (max-width: 480px) {
  .shell::before {
    left: 14px;
    transform: none;
  }
}

/* ------------------------------------------------------------------ header */

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: calc(var(--square) * 1.25) 0 var(--square);
}

.wordmark {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 0;
}
.wordmark span {
  color: var(--ink-faint);
  font-weight: 500;
  margin-inline-start: 8px;
  font-size: 0.95rem;
  letter-spacing: 0;
}

.tagline {
  color: var(--ink-soft);
  font-size: 0.92rem;
  margin: 0 0 calc(var(--square) * 1.5);
  max-width: 32ch;
}

/* topbar used inside a practice session */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  min-height: 56px;
}
.topbar-title {
  font-weight: 650;
  font-size: 1rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------------- type scale */

h2.section {
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.005em;
  margin: 0 0 4px;
}
p.note {
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin: 0 0 var(--square);
}
.eyebrow {
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ---------------------------------------------------------------- controls */

.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  padding: 14px 18px;
  min-height: 50px;
  width: 100%;
  cursor: pointer;
  transition: transform 90ms ease, opacity 90ms ease;
}
.btn:active {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.4;
  cursor: default;
}
.btn-quiet {
  background: transparent;
  color: var(--ink);
  border-color: var(--hairline);
}
.btn-link {
  background: none;
  border: none;
  color: var(--ink-soft);
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 10px 2px;
  min-height: 44px;
  font: inherit;
  cursor: pointer;
  width: auto;
}
.btn-danger {
  background: none;
  border-color: rgba(200, 16, 46, 0.4);
  color: var(--pen-red);
}

.btn-back {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  flex: 0 0 44px;
  background: none;
  border: 1px solid var(--hairline);
  color: var(--ink);
  font-size: 1.1rem;
  border-radius: var(--radius);
  cursor: pointer;
}

.field {
  display: block;
  width: 100%;
  font: inherit;
  padding: 13px 14px;
  min-height: 50px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--paper-raised);
  color: var(--ink);
  margin-bottom: 12px;
}
.field:focus {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
  border-color: var(--ink);
}

:where(button, input, select, [tabindex]):focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.row {
  display: flex;
  gap: 10px;
}
.row > * {
  flex: 1;
}

/* ------------------------------------------------------------------- cards */

.card {
  display: block;
  width: 100%;
  text-align: start;
  background: var(--paper-raised);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  font: inherit;
  color: inherit;
  cursor: pointer;
  position: relative;
  transition: border-color 120ms ease, transform 90ms ease;
}
.card:active {
  transform: translateY(1px);
}
.card:hover {
  border-color: var(--ink-faint);
}

.card-title {
  font-weight: 650;
  margin: 0 0 3px;
  padding-inline-end: 52px;
}
.card-sub {
  color: var(--ink-soft);
  font-size: 0.86rem;
  margin: 0;
  padding-inline-end: 52px;
}

/* the small progress dial on each topic card */
.dial {
  position: absolute;
  top: 14px;
  inset-inline-end: 14px;
  width: 38px;
  height: 38px;
}
.dial-track {
  fill: none;
  stroke: var(--hairline);
  stroke-width: 3;
}
.dial-value {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: center;
}
.dial-label {
  font-family: var(--font-math);
  font-size: 11px;
  fill: var(--ink-soft);
  text-anchor: middle;
  dominant-baseline: central;
}
.band-strong .dial-value {
  stroke: var(--green);
}
.band-mid .dial-value,
.band-thin .dial-value {
  stroke: var(--amber);
}
.band-low .dial-value {
  stroke: var(--pen-red);
}

/* -------------------------------------------------------------- the problem */

.session-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.pips {
  display: flex;
  gap: 4px;
}
.pip {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1px solid var(--ink-faint);
}
.pip-right {
  background: var(--green);
  border-color: var(--green);
}
.pip-wrong {
  background: var(--pen-red);
  border-color: var(--pen-red);
}

.problem {
  padding: calc(var(--square) * 1.5) 0 var(--square);
  min-height: 168px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.problem-prompt {
  font-size: 0.95rem;
  color: var(--ink-soft);
  margin: 0 0 18px;
}

.expr {
  font-family: var(--font-math);
  font-size: clamp(1.9rem, 9vw, 2.9rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink);
  line-height: 1.15;
  white-space: pre-line;
  font-variant-numeric: tabular-nums;
}
.expr-small {
  font-size: clamp(1.1rem, 5vw, 1.5rem);
  letter-spacing: 0;
}

/* fractions get set as real stacked fractions, not 3/4 */
.fracline {
  display: flex;
  align-items: center;
  gap: 14px;
  font-family: var(--font-math);
  font-size: clamp(1.8rem, 8vw, 2.6rem);
}
.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.05;
}
.frac-den {
  border-top: 2px solid var(--ink);
  padding-top: 2px;
  margin-top: 2px;
  min-width: 1.4em;
  text-align: center;
}
.frac-num {
  min-width: 1.4em;
  text-align: center;
}

/* -------------------------------------------------------- answer + marking */

.answer-wrap {
  position: relative;
  margin-bottom: 14px;
}
.answer-box {
  font-family: var(--font-math);
  font-size: 1.6rem;
  font-variant-numeric: tabular-nums;
  min-height: 62px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--paper-raised);
  border: 1px solid var(--hairline);
  border-bottom-width: 2px;
  border-radius: var(--radius);
  color: var(--ink);
}
.answer-box.is-empty {
  color: var(--ink-faint);
}
.answer-box.is-right {
  border-color: var(--green);
  background: var(--green-wash);
}
.answer-box.is-wrong {
  border-color: var(--pen-red);
  background: var(--pen-red-wash);
}
.caret {
  display: inline-block;
  width: 2px;
  height: 1.5rem;
  background: var(--ink);
  margin-inline-start: 2px;
  animation: blink 1.1s step-end infinite;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* the signature: a red pen stroke through a wrong answer */
.strike {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}
.strike path {
  fill: none;
  stroke: var(--pen-red);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 320;
  stroke-dashoffset: 320;
  animation: strike-draw 260ms 60ms ease-out forwards;
}
@keyframes strike-draw {
  to {
    stroke-dashoffset: 0;
  }
}

.verdict {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-weight: 650;
  margin-bottom: 12px;
  font-size: 0.98rem;
}
.verdict-right {
  color: var(--green);
}
.verdict-wrong {
  color: var(--pen-red);
}
.verdict small {
  font-weight: 500;
  color: var(--ink-soft);
  font-family: var(--font-math);
}

.hint {
  font-size: 0.86rem;
  color: var(--ink-soft);
  margin: 0 0 12px;
}
.hint strong {
  font-family: var(--font-math);
  color: var(--ink);
}

/* worked steps, written into the margin */
.margin-note {
  border-inline-start: 2px solid var(--pen-red);
  padding: 4px 0 4px 14px;
  margin: 0 0 16px;
  list-style: none;
}
.margin-note li {
  font-size: 0.92rem;
  color: var(--ink);
  padding: 5px 0;
  opacity: 0;
  transform: translateY(-4px);
  animation: step-in 240ms ease-out forwards;
}
@keyframes step-in {
  to {
    opacity: 1;
    transform: none;
  }
}

/* ------------------------------------------------------------------ keypad */

.keypad {
  /* pushed into the thumb zone on a short question, sticky on a long one */
  margin-top: auto;
  position: sticky;
  bottom: 0;
  background: var(--paper);
  border-top: 1px solid var(--hairline);
  padding: 10px 0 4px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.key {
  font-family: var(--font-math);
  font-size: 1.25rem;
  min-height: 54px;
  border: 1px solid var(--hairline);
  border-bottom-width: 2px;
  border-radius: var(--radius);
  background: var(--paper-raised);
  color: var(--ink);
  cursor: pointer;
  transition: background 80ms ease, transform 60ms ease;
}
.key:active {
  background: var(--amber-wash);
  transform: translateY(1px);
  border-bottom-width: 1px;
}
.key-wide {
  grid-column: span 2;
}
.key-go {
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 650;
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

/* ----------------------------------------------------------------- roster */

.roster {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(136px, 1fr));
  gap: 10px;
  margin-bottom: var(--square);
}
.roster .card {
  margin: 0;
  padding: 14px;
}
.roster .card-title {
  padding: 0;
}

/* mastery grid */
.grid-wrap {
  overflow-x: auto;
  margin: 0 calc(var(--square) * -1) var(--square);
  padding: 0 var(--square);
}
table.mastery {
  border-collapse: collapse;
  font-size: 0.85rem;
  width: 100%;
}
table.mastery th,
table.mastery td {
  border: 1px solid var(--hairline);
  padding: 0;
  text-align: center;
}
table.mastery thead th {
  font-weight: 600;
  font-size: 0.68rem;
  line-height: 1.2;
  color: var(--ink-soft);
  padding: 6px 4px;
  vertical-align: bottom;
  background: var(--paper-raised);
}
table.mastery th.who {
  text-align: start;
  font-size: 0.85rem;
  color: var(--ink);
  padding: 8px 10px;
  white-space: nowrap;
  position: sticky;
  inset-inline-start: 0;
  background: var(--paper-raised);
}
.cell {
  height: 40px;
  min-width: 44px;
  font-family: var(--font-math);
  font-size: 0.76rem;
  color: var(--ink-soft);
}
.cell-strong {
  background: var(--green-wash);
  color: var(--green);
  font-weight: 650;
}
.cell-mid,
.cell-thin {
  background: var(--amber-wash);
  color: #8a6a00;
}
.cell-low {
  background: var(--pen-red-wash);
  color: var(--pen-red);
  font-weight: 650;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-bottom: var(--square);
}
.legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}
.swatch {
  width: 12px;
  height: 12px;
  border: 1px solid var(--hairline);
}
.swatch-strong {
  background: var(--green-wash);
  border-color: var(--green);
}
.swatch-mid {
  background: var(--amber-wash);
  border-color: var(--amber);
}
.swatch-low {
  background: var(--pen-red-wash);
  border-color: var(--pen-red);
}

/* ------------------------------------------------------------------ chips */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: var(--square);
}
.chip {
  font: inherit;
  font-size: 0.86rem;
  padding: 9px 13px;
  min-height: 42px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--paper-raised);
  color: var(--ink-soft);
  cursor: pointer;
}
.chip[aria-pressed='true'] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

/* ------------------------------------------------------------------ misc */

.stat-big {
  font-family: var(--font-math);
  font-size: 3.4rem;
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat-label {
  color: var(--ink-soft);
  font-size: 0.9rem;
  margin: 6px 0 var(--square);
}

.review {
  list-style: none;
  padding: 0;
  margin: 0 0 var(--square);
}
.review li {
  border-top: 1px solid var(--hairline);
  padding: 11px 0;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-family: var(--font-math);
  font-size: 0.94rem;
}
.review li .got {
  color: var(--pen-red);
  text-decoration: line-through;
}
.review li .want {
  color: var(--green);
}

.empty {
  border: 1px dashed var(--hairline);
  border-radius: var(--radius);
  padding: 20px;
  color: var(--ink-soft);
  font-size: 0.9rem;
  background: var(--paper-raised);
}

.stack > * + * {
  margin-top: 10px;
}
.spacer {
  height: var(--square);
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.offline-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.76rem;
  color: var(--green);
  border: 1px solid var(--green);
  background: var(--green-wash);
  border-radius: var(--radius);
  padding: 5px 9px;
}
.offline-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
}

/* --------------------------------------------------------------- printing */

.paper {
  display: none;
}

@media print {
  @page {
    margin: 16mm;
  }
  body {
    background: #fff;
    color: #000;
    font-size: 11pt;
  }
  .shell,
  .shell::before {
    display: none !important;
  }
  .paper {
    display: block;
  }
  .paper-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    border-bottom: 1.5pt solid #000;
    padding-bottom: 6pt;
    margin-bottom: 14pt;
  }
  .paper-head h1 {
    font-size: 15pt;
    margin: 0;
  }
  .paper-head .meta {
    font-size: 9pt;
    text-align: right;
    line-height: 1.6;
  }
  .paper-fields {
    display: flex;
    gap: 24pt;
    font-size: 10pt;
    margin-bottom: 16pt;
  }
  .paper-fields span {
    flex: 1;
    border-bottom: 0.6pt solid #000;
    padding-bottom: 2pt;
  }
  ol.paper-qs {
    columns: 2;
    column-gap: 22pt;
    padding-inline-start: 18pt;
    margin: 0;
  }
  ol.paper-qs li {
    break-inside: avoid;
    margin-bottom: 15pt;
    font-size: 10.5pt;
  }
  ol.paper-qs .q {
    font-family: var(--font-math);
    font-size: 12pt;
    display: block;
    margin-bottom: 3pt;
  }
  ol.paper-qs .w {
    font-size: 8.5pt;
    color: #444;
  }
  .paper-key {
    break-before: page;
    page-break-before: always;
  }
  ol.paper-key-list {
    columns: 4;
    font-family: var(--font-math);
    font-size: 10pt;
    padding-inline-start: 18pt;
  }
}

/* ------------------------------------------------------ motion preferences */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .strike path {
    stroke-dashoffset: 0;
  }
  .margin-note li {
    opacity: 1;
    transform: none;
  }
}
