/* SPDX-License-Identifier: AGPL-3.0-or-later */

:root {
  color-scheme: light dark;
  --bg: #f6f6f3;
  --surface: #ffffff;
  --text: #1b1c1f;
  --muted: #55585f;
  --border: #d5d6d9;
  --accent: #1d4ed8;
  --accent-text: #ffffff;
  --accent-soft: #e6ecfc;
  --focus: #1d4ed8;
  --warn-bg: #fff3d1;
  --warn-text: #5a3c00;
  --warn-border: #e7c766;
  --error: #b3261e;
  --ok: #1b6e35;
  --checker: #e9e9e6;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
}

/* Hindi: name the Devanagari system fonts of Windows, Apple platforms and
   Android/Linux after the UI font, so text never depends on a downloaded
   font (font-src is 'none'). */
:root:lang(hi) {
  --font: system-ui, -apple-system, "Segoe UI", "Nirmala UI", "Kohinoor Devanagari", "Devanagari Sangam MN", "Noto Sans Devanagari", Roboto, "Noto Sans", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d22;
    --text: #eceef2;
    --muted: #a8adb7;
    --border: #3a3f48;
    --accent: #8fb0ff;
    --accent-text: #0d1220;
    --accent-soft: #1f2a44;
    --focus: #8fb0ff;
    --warn-bg: #3a2e0c;
    --warn-text: #ffe3a1;
    --warn-border: #7a6220;
    --error: #ffb4ab;
    --ok: #86d99d;
    --checker: #262a31;
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
}

.wrap {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px;
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

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

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

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

/* ---- Header / footer ---- */

header.site {
  padding: 20px 0 8px;
}

.brand {
  margin: 0;
  font-weight: 700;
  font-size: 1.75rem;
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.brand-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
}

.lang {
  font-weight: 600;
}

.lang a {
  display: inline-block;
  padding: 2px 0;
}

.tagline {
  margin: 4px 0 0;
  color: var(--muted);
}

footer.site {
  padding: 8px 0 32px;
  font-size: 0.9375rem;
}

footer.site p {
  margin: 0 0 4px;
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 0 20px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.links a {
  display: inline-block;
  padding: 10px 0;
  min-height: 44px;
}

/* ---- Shown instead of the app when framed ---- */

.framed {
  padding: 24px 16px;
}

/* ---- Update banner ---- */

.update p {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin: 8px 0 0;
  padding: 8px 8px 8px 16px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
  font-weight: 600;
}

/* ---- Steps ---- */

.step {
  margin: 16px 0;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.step h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  font-size: 1.25rem;
  line-height: 1.3;
}

.num {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.9375rem;
  font-weight: 700;
}

.step p {
  margin: 8px 0;
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0 0 12px;
}

label {
  font-weight: 600;
}

/* Small on purpose: it must not push step 2 off a phone's first screen.
   24 px tall still meets the WCAG 2.2 minimum target size. */
.field .request {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25;
}

.field .request a {
  display: inline-block;
  padding: 3px 0;
  min-height: 24px;
}

select,
input[type="text"] {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--muted);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

select {
  /* Native WebKit selects ignore min-height; draw our own chevron. */
  -webkit-appearance: none;
  appearance: none;
  padding-right: 40px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 20px) 50%,
    calc(100% - 14px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  text-overflow: ellipsis;
}

input[aria-invalid="true"] {
  border-color: var(--error);
}

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

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.check input {
  width: 24px;
  height: 24px;
  margin: 0;
  accent-color: var(--accent);
}

.custom {
  margin: 0 0 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.custom legend {
  padding: 0 4px;
  font-weight: 600;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 10px 20px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent);
  font: inherit;
  font-weight: 650;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.button.primary {
  background: var(--accent);
  color: var(--accent-text);
}

.button.wide {
  width: 100%;
}

.button:disabled {
  border-color: var(--border);
  background: var(--border);
  color: var(--muted);
  cursor: not-allowed;
}

.msg {
  min-height: 1.5em;
}

.msg:empty {
  min-height: 0;
  margin: 0;
}

.error {
  color: var(--error);
  font-weight: 600;
}

/* ---- Spec ---- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 12px;
  padding: 0;
  list-style: none;
}

.chip {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.warning {
  padding: 10px 12px;
  border: 1px solid var(--warn-border);
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn-text);
}

.notes p {
  color: var(--muted);
}

.sources {
  margin-top: 8px;
}

.sources summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}

.sources summary::before {
  content: "▸";
  width: 1.25em;
}

.sources[open] summary::before {
  content: "▾";
}

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

.sources .notes p {
  margin: 4px 0 8px;
}

.sources ul {
  margin: 4px 0;
  padding-left: 20px;
}

.sources li {
  margin: 6px 0;
}

.badge {
  display: inline-block;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.8125rem;
  white-space: nowrap;
}

.badge-notice {
  border-color: var(--ok);
  color: var(--ok);
}

/* ---- Upload ---- */

.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
}

.drop.over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.file-input:focus-visible + label {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* ---- Adjust ---- */

.preview-wrap {
  display: flex;
  justify-content: center;
  width: 100%;
}

.preview {
  display: block;
  max-width: 100%;
  border-radius: 4px;
  background: repeating-conic-gradient(var(--checker) 0 25%, transparent 0 50%) 0 0 / 16px 16px;
  box-shadow: 0 0 0 1px var(--border);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.preview:active {
  cursor: grabbing;
}

.hint {
  text-align: center;
  font-size: 0.9375rem;
}

#threshold-out {
  font-variant-numeric: tabular-nums;
  font-weight: 400;
  color: var(--muted);
}

/* ---- Result ---- */

.result {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.result h3 {
  margin: 0 0 12px;
  font-size: 1.125rem;
}

.result-body {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 12px;
}

.result-img {
  display: block;
  max-width: min(100%, 240px);
  height: auto;
  box-shadow: 0 0 0 1px var(--border);
}

.checklist {
  flex: 1 1 200px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.checklist li {
  display: flex;
  gap: 8px;
  margin: 0 0 6px;
  font-variant-numeric: tabular-nums;
}

.checklist li::before {
  flex: none;
  width: 1.25em;
  font-weight: 700;
}

.checklist .pass::before {
  content: "✓";
  color: var(--ok);
}

.checklist .fail::before {
  content: "✗";
  color: var(--error);
}

/* ---- Built pages: landing intro, sources, exam links ---- */

.brand a {
  color: inherit;
  text-decoration: none;
}

.intro,
.page-specs,
.page-sources,
.exam-links {
  margin: 16px 0;
}

.intro h1 {
  margin: 8px 0 4px;
  font-size: 1.375rem;
  line-height: 1.25;
}

.intro .summary {
  margin: 0 0 8px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.page-specs h2,
.page-sources h2,
.exam-links h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.spec-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.spec-table th,
.spec-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.spec-table tbody tr:last-child th,
.spec-table tbody tr:last-child td {
  border-bottom: 0;
}

.spec-table td:nth-child(2),
.spec-table td:nth-child(3) {
  white-space: nowrap;
}

.spec-table td:last-child {
  color: var(--muted);
  min-width: 12em;
}

/* Narrow screens: one card per document, cells labelled from data-label. */
@media (max-width: 559px) {
  .spec-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .spec-table tbody,
  .spec-table tr,
  .spec-table th,
  .spec-table td {
    display: block;
  }

  .spec-table tr {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
  }

  .spec-table tbody tr:last-child {
    border-bottom: 0;
  }

  .spec-table th,
  .spec-table td,
  .spec-table tbody tr:last-child th,
  .spec-table tbody tr:last-child td {
    padding: 2px 12px;
    border-bottom: 0;
  }

  .spec-table td {
    display: flex;
    gap: 8px;
  }

  .spec-table td::before {
    content: attr(data-label);
    flex: none;
    width: 5.5em;
    color: var(--muted);
  }

  .spec-table td:last-child {
    min-width: 0;
  }

  .spec-table td.empty {
    display: none;
  }
}

.page-sources ul,
/* Bullet and link share one grid row that starts at the top, with the same
   padding and line height, so a long exam name that wraps keeps its bullet
   on the first line (an inline-block link puts the bullet on the last). */
.exam-links ul {
  margin: 4px 0;
  padding: 0;
  list-style: none;
}

.exam-links li {
  display: grid;
  grid-template-columns: 20px 1fr;
  align-items: start;
}

.exam-links li::before {
  content: "•";
  padding: 10px 0;
  line-height: inherit;
}

.page-sources li {
  margin: 6px 0;
}

.exam-links a {
  display: block;
  justify-self: start;
  padding: 10px 0;
  min-height: 44px;
}

@media (min-width: 640px) {
  .step {
    padding: 20px 24px;
  }

  .grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Phones: tighter vertical rhythm so an exam page's tool starts on the
   first screen (390x844 is checked by e2e). Desktop is unchanged. */
@media (max-width: 639px) {
  header.site {
    padding: 12px 0 0;
  }

  .brand {
    font-size: 1.5rem;
  }

  .tagline {
    margin-top: 2px;
    font-size: 0.9375rem;
    line-height: 1.4;
  }

  .step,
  .intro,
  .page-specs,
  .page-sources,
  .exam-links {
    margin: 12px 0;
  }

  .intro h1 {
    font-size: 1.25rem;
  }

  .intro .summary {
    font-size: 0.9375rem;
    line-height: 1.4;
  }

  .warning {
    padding: 6px 10px;
    font-size: 0.875rem;
    line-height: 1.4;
  }

  .step h2 {
    margin-bottom: 8px;
  }

  .field {
    margin-bottom: 8px;
  }

  .chips {
    margin-bottom: 8px;
  }

  .notes p {
    font-size: 0.9375rem;
    line-height: 1.4;
  }

  .step p {
    margin: 6px 0;
  }

  .drop {
    padding: 12px;
  }
}

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