/* Matee — app chrome.
 * The worksheet itself carries no styling from here: it is an SVG whose every
 * coordinate comes from the layout engine, so nothing in this file can change
 * what lands on the paper. That separation is deliberate — CSS drift is the
 * usual reason a print layout stops matching its preview.
 */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fbfbfc;
  --ink: #16181d;
  --ink-soft: #5b6270;
  --ink-faint: #8b929f;
  --line: #e2e5ea;
  --line-strong: #cdd2da;
  --accent: #2b5cd9;
  --accent-ink: #ffffff;
  --warn: #9a5b00;
  --warn-bg: #fff6e6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 20, 30, .06), 0 8px 24px rgba(16, 20, 30, .06);
  /* -apple-system and Segoe UI both carry Arabic; Noto Sans Arabic and Tahoma
     cover the rest, so the interface reads properly in all three languages. */
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Arabic", Tahoma, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f25;
    --surface-2: #21252c;
    --ink: #eef0f4;
    --ink-soft: #a7aeba;
    --ink-faint: #7b8391;
    --line: #2c313a;
    --line-strong: #3a414c;
    --accent: #6f96f5;
    --accent-ink: #0e1116;
    --warn: #f0b45e;
    --warn-bg: #33270f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .28);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

.hidden { display: none !important; }

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 9px;
  background: var(--ink);
  color: var(--surface);
  flex: none;
}
.brand-text { font-weight: 680; font-size: 17px; letter-spacing: -.02em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.lang-select {
  width: auto;
  min-height: 36px;
  padding: 6px 10px;
  font: 600 13.5px var(--sans);
}

.brand-text em {
  display: block;
  font: 400 12px/1.3 var(--sans);
  font-style: normal;
  color: var(--ink-faint);
  letter-spacing: 0;
}

/* ------------------------------------------------------------------ layout */

.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 16px calc(28px + env(safe-area-inset-bottom));
  display: grid;
  gap: 18px;
  /* minmax(0, 1fr), never a bare 1fr: a plain 1fr track is minmax(auto, 1fr)
     and will happily grow past the viewport to fit its content, which is how a
     phone ends up scrolling sideways. */
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

@media (min-width: 940px) {
  .layout { grid-template-columns: minmax(0, 1fr) minmax(340px, 420px); }
  .preview-pane { position: sticky; top: 76px; }
}

.wizard, .preview-pane {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.wizard { padding: 16px; }

/* ----------------------------------------------------------------- stepper */

.stepper {
  display: flex;
  gap: 6px;
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.stepper::-webkit-scrollbar { display: none; }

.stepper button {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-soft);
  font: 600 12.5px var(--sans);
  padding: 7px 11px;
  border-radius: 99px;
  white-space: nowrap;
  cursor: pointer;
}
.stepper li.done button { color: var(--ink); }
.stepper li.active button {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
}

.step-body > h2 { font-size: 19px; margin-bottom: 4px; }
.step-body > .lede { margin: 0 0 16px; color: var(--ink-soft); font-size: 14px; }

.wizard-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.step-count { font-size: 13px; color: var(--ink-faint); }

/* ----------------------------------------------------------------- buttons */

.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font: 600 14.5px var(--sans);
  padding: 10px 16px;
  border-radius: 9px;
  cursor: pointer;
  min-height: 42px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-soft); }
.btn.ghost:hover { background: var(--surface-2); }

/* ------------------------------------------------------------------ fields */

.field { margin-bottom: 16px; }
.field > label, .field-label {
  display: block;
  font-size: 13px;
  font-weight: 620;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.field .note { font-size: 12.5px; color: var(--ink-faint); margin: 6px 0 0; }

input[type="text"], select {
  width: 100%;
  font: 500 15px var(--sans);
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 10px 12px;
  min-height: 42px;
}
input[type="text"]:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Segmented control — the workhorse of this wizard. Big tap targets, no menus. */
.segmented { display: flex; flex-wrap: wrap; gap: 6px; }
/* One option per line, for long labels like the story types. */
.segmented.stacked { flex-direction: column; }
.segmented.stacked button { text-align: start; }

.segmented button {
  appearance: none;
  flex: 1 1 auto;
  min-width: 62px;
  min-height: 40px;
  padding: 8px 10px;
  font: 600 14px var(--sans);
  color: var(--ink-soft);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  cursor: pointer;
}
.segmented button[aria-pressed="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--surface);
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  font-size: 14.5px;
  cursor: pointer;
}
.switch input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.switch span small { display: block; color: var(--ink-faint); font-size: 12.5px; }

input[type="range"] { width: 100%; accent-color: var(--accent); height: 30px; }

.row { display: flex; gap: 10px; align-items: center; }
.row > * { min-width: 0; }

/* ----------------------------------------------------------------- presets */

.preset-grid { display: grid; gap: 10px; }
.preset {
  display: block;
  width: 100%;
  text-align: start;
  padding: 13px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--surface-2);
  cursor: pointer;
  color: inherit;
}
.preset:hover { border-color: var(--accent); }
.preset[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.preset strong { display: block; font-size: 15px; margin-bottom: 2px; }
.preset span { font-size: 13px; color: var(--ink-soft); }

/* ----------------------------------------------------------------- columns */

.col-card {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 13px;
  margin-bottom: 12px;
  background: var(--surface-2);
}
.col-card > header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.col-card > header h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); }
.col-card .skill-hint { font: 500 12.5px var(--sans); color: var(--ink-faint); }

/* ----------------------------------------------------------------- preview */

.preview-pane { padding: 14px; }
.preview-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.preview-head h2 { font-size: 15px; }
.readout { font: 500 12.5px var(--sans); color: var(--ink-faint); }

.paper {
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  overflow: hidden;
  aspect-ratio: 210 / 296;
  box-shadow: 0 2px 10px rgba(16, 20, 30, .10);
}
.paper svg { display: block; width: 100%; height: 100%; }

.warnings { margin: 10px 0 0; font-size: 13px; color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 9px 11px; }
.warnings:empty { display: none; }

.preview-actions { display: flex; gap: 8px; margin-top: 12px; }
.preview-actions .btn { flex: 1; padding: 10px 8px; }

.hint { margin: 10px 0 0; font-size: 12.5px; color: var(--ink-faint); }
.hint:empty { display: none; }

.saved-list { list-style: none; margin: 10px 0 0; padding: 0; }
.saved-list li { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.saved-list li span { flex: 1; font-size: 14px; }
.saved-list .btn { min-height: 34px; padding: 6px 10px; font-size: 13px; }

.summary { list-style: none; margin: 0 0 16px; padding: 0; font-size: 14px; }
.summary li { display: flex; justify-content: space-between; gap: 14px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.summary li b { font-weight: 620; }
.summary li span { color: var(--ink-soft); text-align: end; }

/* ------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 14px);
  background: var(--ink);
  color: var(--surface);
  font: 600 14px var(--sans);
  padding: 11px 16px;
  border-radius: 99px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 50;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --------------------------------------------------------------------- rtl */

/* Flexbox and grid mirror themselves from the dir attribute, so the only work
   left is the handful of places that name a physical side, plus the islands of
   Latin text — the sheet preview, the sheet code, the worksheet headings —
   which stay left-to-right whatever the interface is doing. */
[dir="rtl"] .brand-text em,
[dir="rtl"] .field .note,
[dir="rtl"] .switch span small { text-align: start; }

[dir="rtl"] input[dir="ltr"],
[dir="rtl"] [dir="ltr"] { text-align: left; }

[dir="rtl"] .paper { direction: ltr; }

/* ------------------------------------------------------------------- print */

.print-area { display: none; }

@media print {
  /* A4 with no browser margin: the sheet supplies its own, sized for the
     non-printable strip that every home printer reserves at the paper edge. */
  @page { size: A4; margin: 0; }

  html, body { background: #fff; margin: 0; padding: 0; }
  body > *:not(.print-area) { display: none !important; }

  .print-area { display: block; }
  .print-sheet {
    width: 210mm;
    height: 296mm;
    overflow: hidden;
  }
  /* Break BEFORE each sheet after the first, rather than after every sheet.
     A trailing "break-after" on the last sheet is the classic way to emit a
     blank final page: engines differ on whether the :last-child override wins,
     and a forced break with nothing following it still starts a page. With
     break-before there is never a break after the final sheet to mishandle. */
  .print-sheet + .print-sheet { page-break-before: always; break-before: page; }
  .print-sheet svg { display: block; width: 210mm; height: 296mm; }

  /* Keep the grey problem numbers grey instead of letting the browser
     "helpfully" drop them to save ink. */
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
