/*
 * German citizenship test — standalone app.
 *
 * Self-contained: this page is served from static/, not built by Gatsby, so it
 * brings its own tokens and its own shell rather than inheriting the site's.
 * The `cq-` prefix keeps it identifiable, and since it is a separate document
 * there is nothing for it to collide with.
 *
 * Images were cropped at build time (tools/build-citizenship-dataset.mjs) to
 * remove the German question stem that upstream bakes into every picture, so
 * nothing German reaches the screen in English mode.
 */

:root {
  color-scheme: light;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-alt: #f1f3f7;
  --text: #15181d;
  --muted: #667085;
  --border: #e3e8ef;
  --accent: #1d4ed8;
  --accent-soft: #eef2ff;
  --good: #0f7a58;
  --good-soft: #e4f5ee;
  --bad: #b42318;
  --bad-soft: #fdeceb;
  --star: #d98a00;
  --bad-solid: #b42318;
  --on-solid: #ffffff;
  --shadow: 12px 22px 38px -24px rgba(16, 24, 40, 0.38);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #0f1115;
    --surface: #181b20;
    --surface-alt: #1f232a;
    --text: #eef1f5;
    --muted: #98a2b0;
    --border: #2b313a;
    --accent: #7ea6ff;
    --accent-soft: #1b2437;
    --good: #5dd6a8;
    --good-soft: #10281f;
    --bad: #ff9b93;
    --bad-soft: #2d1917;
    --star: #ffc65c;
    --bad-solid: #c23b3b;
    --on-solid: #ffffff;
    --shadow: 12px 22px 38px -22px rgba(0, 0, 0, 0.85);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

.cq-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.cq-header-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
}

.cq-header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.cq-tagline {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Language and the filter toggle stay put; the header is the one thing that
   never scrolls away. */
.cq-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

#cq-filters-toggle::after {
  content: "";
  display: inline-block;
  margin-left: 8px;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: translateY(-2px) rotate(45deg);
  transition: transform 0.15s ease;
}

#cq-filters-toggle[aria-expanded="true"]::after {
  transform: translateY(1px) rotate(-135deg);
}

/* Progress is always on screen, so it lives in the sticky header rather than
   inside the collapsible panel. */
.cq-header-progress {
  border-top: 1px solid var(--border);
}

.cq-header-progress[hidden] {
  display: none;
}

.cq-header-progress-inner {
  max-width: 880px;
  margin: 0 auto;
  padding: 10px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cq-main {
  max-width: 880px;
  margin: 0 auto;
  /* Clears the fixed bottom bar, including the iPhone home-indicator area. */
  padding: 22px 20px calc(96px + env(safe-area-inset-bottom));
}

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

.cq-controls {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 18px;
}

.cq-controls[hidden] {
  display: none;
}

/* Bottom tab bar ------------------------------------------------------ */

.cq-tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 26px -20px rgba(16, 24, 40, 0.55);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}

.cq-tabbar[hidden] {
  display: none;
}

.cq-tabbar-inner {
  max-width: 880px;
  margin: 0 auto;
  display: flex;
  align-items: stretch;
  gap: 10px;
}

.cq-tabbar .cq-button {
  flex: 1 1 0;
  min-width: 0;
  padding: 11px 12px;
}

.cq-tabbar #cq-check,
.cq-tabbar #cq-retry {
  flex: 1.6 1 0;
}

.cq-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.cq-toggle,
.cq-filters {
  display: inline-flex;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px;
  gap: 3px;
  flex-wrap: wrap;
}

.cq-toggle button,
.cq-filters button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 550;
  padding: 7px 13px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.cq-toggle button:hover,
.cq-filters button:hover {
  color: var(--text);
}

.cq-toggle button.is-active,
.cq-filters button.is-active {
  background: var(--surface);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.14);
}

.cq-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.cq-field select {
  appearance: none;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
  color: var(--text);
  background-color: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 9px 32px 9px 12px;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 15px center, right 10px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.cq-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  overflow: hidden;
}

.cq-bar > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.25s ease;
}

.cq-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0;
}

/* Each count is an emoji and its number, kept together as one unit. */
.cq-stats span {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
}

.cq-stats-icon {
  font-size: 0.95rem;
  line-height: 1;
}

.cq-stats b {
  color: var(--text);
  font-weight: 650;
}

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

.cq-button {
  appearance: none;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 9px 15px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, color 0.15s ease;
}

.cq-button:hover:not(:disabled) {
  border-color: var(--accent);
}

.cq-button:active:not(:disabled) {
  transform: translateY(1px);
}

.cq-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.cq-button.is-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
}

.cq-button.is-quiet {
  background: transparent;
  color: var(--muted);
}

.cq-button.is-quiet.is-active {
  color: var(--accent);
  border-color: var(--accent);
}

.cq-button.is-danger:hover:not(:disabled) {
  border-color: var(--bad);
  color: var(--bad);
}

/* Reset confirmation ----------------------------------------------------- */

.cq-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  width: min(420px, calc(100% - 32px));
  box-shadow: var(--shadow);
}

.cq-dialog::backdrop {
  background: rgba(9, 12, 18, 0.55);
}

.cq-dialog-wrap {
  padding: 22px;
}

.cq-dialog-title {
  margin: 0 0 8px;
  font-size: 1.1rem;
  font-weight: 650;
}

.cq-dialog-body {
  margin: 0 0 20px;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--muted);
}

.cq-dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.cq-button.is-danger-solid {
  background: var(--bad-solid);
  border-color: var(--bad-solid);
  color: var(--on-solid);
}

.cq-button:focus-visible,
.cq-toggle button:focus-visible,
.cq-filters button:focus-visible,
.cq-option:focus-visible,
.cq-star:focus-visible,
.cq-jump input:focus-visible,
.cq-field select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* question card ------------------------------------------------------ */

.cq-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  animation: cq-rise 0.22s ease both;
}

@keyframes cq-rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .cq-card,
  .cq-result {
    animation: none;
  }
}

.cq-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.cq-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
}

.cq-meta span:not(:first-child) {
  position: relative;
  padding-left: 11px;
}

.cq-meta span:not(:first-child)::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  transform: translateY(-50%);
}

.cq-position {
  font-weight: 650;
  color: var(--text);
}

.cq-star {
  appearance: none;
  border: 0;
  background: none;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--border);
  cursor: pointer;
  padding: 0 2px;
  transition: color 0.15s ease, transform 0.15s ease;
}

.cq-star:hover {
  transform: scale(1.12);
}

.cq-star.is-on {
  color: var(--star);
}

.cq-stem {
  font-size: 1.22rem;
  font-weight: 620;
  line-height: 1.45;
  margin: 12px 0 0;
}

.cq-figure {
  margin: 18px 0 0;
  padding: 14px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.cq-image {
  display: block;
  width: 100%;
  height: auto;
  max-height: 320px;
  object-fit: contain;
}

/* options ------------------------------------------------------------ */

.cq-options {
  list-style: none;
  display: grid;
  gap: 9px;
  margin: 20px 0 0;
  padding: 0;
}

.cq-options.is-panels {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cq-option {
  appearance: none;
  font: inherit;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 13px 15px;
  transition: border-color 0.15s ease, background 0.15s ease,
    transform 0.12s ease;
}

.cq-options.is-panels .cq-option {
  flex-direction: column;
  align-items: stretch;
  padding: 10px;
  gap: 9px;
}

.cq-option:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.cq-option:disabled {
  cursor: default;
}

.cq-letter {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  background: var(--surface-alt);
  color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease;
}

.cq-option-text {
  line-height: 1.45;
}

/*
 * For a question whose options are pictures -- the state maps and the flag
 * question have their markers drawn into the artwork, so the option repeats
 * the number rather than describing anything.
 */
.cq-marker {
  margin-left: auto;
  flex: 0 0 auto;
  min-width: 26px;
  height: 26px;
  padding: 0 7px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  border: 1.5px solid var(--border);
  color: var(--muted);
}

/* One quarter of a grid picture, cropped with background-position so the whole
   picture is fetched once and sliced for free. */
.cq-panel {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  background-repeat: no-repeat;
  background-color: #ffffff;
}

.cq-option.is-chosen {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.cq-option.is-chosen .cq-letter {
  background: var(--accent);
  color: #ffffff;
}

.cq-option.is-correct {
  border-color: var(--good);
  background: var(--good-soft);
}

.cq-option.is-correct .cq-letter {
  background: var(--good);
  color: #ffffff;
}

.cq-option.is-correct .cq-marker {
  border-color: var(--good);
  color: var(--good);
}

.cq-option.is-wrong {
  border-color: var(--bad);
  background: var(--bad-soft);
}

.cq-option.is-wrong .cq-letter {
  background: var(--bad);
  color: #ffffff;
}

.cq-option.is-wrong .cq-marker {
  border-color: var(--bad);
  color: var(--bad);
}

/* result ------------------------------------------------------------- */

.cq-result {
  margin-top: 16px;
  padding: 15px 17px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  animation: cq-rise 0.2s ease both;
}

.cq-result.is-correct {
  border-color: var(--good);
  background: var(--good-soft);
}

.cq-result.is-wrong {
  border-color: var(--bad);
  background: var(--bad-soft);
}

.cq-verdict {
  margin: 0;
  font-weight: 650;
  color: var(--good);
}

.cq-result.is-wrong .cq-verdict {
  color: var(--bad);
}

.cq-explanation {
  margin: 9px 0 0;
  line-height: 1.6;
  font-size: 0.94rem;
}

.cq-jump {
  display: flex;
  align-items: center;
  gap: 9px;
  justify-content: flex-end;
  font-size: 0.78rem;
  color: var(--muted);
  margin: 16px 0 0;
}

.cq-jump input {
  font: inherit;
  width: 92px;
  color: var(--text);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 10px;
}

/* notices and credit -------------------------------------------------- */

.cq-notice {
  margin: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--muted);
  background: var(--surface);
}

.cq-notice[hidden] {
  display: none;
}

.cq-notice.is-error {
  border-color: var(--bad);
  color: var(--bad);
}

.cq-detail {
  opacity: 0.75;
}

.cq-credit {
  border-top: 1px solid var(--border);
  padding: 22px 20px calc(96px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 0.8rem;
  line-height: 1.7;
  color: var(--muted);
}

.cq-credit p {
  max-width: 700px;
  margin: 0 auto 10px;
}

.cq-credit a {
  color: inherit;
  text-decoration: underline;
}

/* Screen-reader-only text: the star button shows a glyph, but the control still
   needs a name. */
.cq-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 560px) {
  .cq-options.is-panels {
    grid-template-columns: minmax(0, 1fr);
  }
}