:root {
  --bg: #e7ebef;
  --paper: #f9fafb;
  --ink: #1b242d;
  --muted: #5b6876;
  --line: #cfd6dd;
  --accent: #15803d;
  --accent-ink: #ffffff;
  --accent-soft: #dcf3e3;
  --warn-bg: #fff4d6;
  --warn-ink: #7a5300;
  --error-bg: #fde2e1;
  --error-ink: #8a1c17;
  --space-mark: #2f6b42;
  /* The scanner from the logo: slate casing, black display, green laser. These stay the same in dark mode. */
  --slate: #3d4f63;
  --slate-deep: #2a3846;
  --screen: #0c1013;
  --screen-line: #2a333b;
  --screen-ink: #c9d1d8;
  --laser: #3dff6e;
  --laser-glow: rgba(61, 255, 110, 0.5);
  --route: #16b048;
  --map-sea: #dbe3ea;
  --map-land: #f2f4f6;
  --map-coast: #b6c0ca;
  --map-border: #98a4b0;
  --map-grid: #cbd5de;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10161c;
    --paper: #18212a;
    --ink: #e4e9ee;
    --muted: #8d9bab;
    --line: #2a3642;
    --accent: #4ade80;
    --accent-ink: #04140a;
    --accent-soft: #12301d;
    --warn-bg: #3a2e10;
    --warn-ink: #f3d27a;
    --error-bg: #3d1716;
    --error-ink: #ffb3ad;
    --route: #3dff6e;
    --map-sea: #0f151b;
    --map-land: #1e2731;
    --map-coast: #3a4754;
    --map-border: #52606e;
    --map-grid: #18212a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* Elements with a display of their own (the webcam overlay, the result) still hide. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.45;
}

main, .masthead-inner, footer {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Masthead: the slate of the logo, with a laser line along the bottom. */
.masthead {
  position: relative;
  background: linear-gradient(160deg, #475b70 0%, var(--slate) 45%, var(--slate-deep) 100%);
  color: #eef1f4;
  margin-bottom: 28px;
}
.masthead::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--laser) 15%, var(--laser) 85%, transparent);
  box-shadow: 0 0 10px 1px var(--laser-glow);
}
.masthead-inner { display: flex; align-items: center; gap: 18px; padding-top: 28px; padding-bottom: 28px; }
.logo { flex: 0 0 auto; width: clamp(52px, 11vw, 72px); height: auto; }
.masthead h1 { margin: 0; font-size: clamp(1.8rem, 6vw, 2.8rem); letter-spacing: -0.03em; line-height: 1.1; }
.wordmark { font-family: var(--mono); font-weight: 700; }
.wordmark .dash { color: var(--laser); text-shadow: 0 0 8px var(--laser-glow), 0 0 2px var(--laser); }
.tagline { margin: 6px 0 0; color: #b4c0cc; }

button {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
button:hover { border-color: var(--muted); }
/* Primary buttons look like the scanner's display. */
button.primary {
  background: var(--screen);
  border-color: var(--screen);
  color: var(--laser);
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-shadow: 0 0 6px var(--laser-glow);
}
button.primary:hover { border-color: var(--laser); box-shadow: 0 0 0 1px var(--laser), 0 0 14px var(--laser-glow); }
button:focus-visible, .dropzone:focus-within, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.input {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 2px rgba(20, 30, 40, 0.06), 0 8px 24px rgba(20, 30, 40, 0.06);
}

.modes { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.mode[aria-selected="true"] { background: var(--slate); color: #fff; border-color: var(--slate); }

.dropzone {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 180px;
  padding: 24px;
  text-align: center;
  border: 2px dashed var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone > * { position: relative; z-index: 1; }
/* A laser line sweeps the drop zone when hovered, dragged over or reading. */
.dropzone::after {
  content: "";
  position: absolute;
  left: 6%;
  right: 6%;
  top: 50%;
  height: 2px;
  border-radius: 2px;
  background: var(--route);
  box-shadow: 0 0 10px 1px var(--laser-glow);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.dropzone:hover::after, .dropzone.over::after { opacity: 0.55; animation: sweep 2.4s ease-in-out infinite alternate; }
.reading .dropzone::after { opacity: 0.9; animation: sweep 0.7s ease-in-out infinite alternate; }
@keyframes sweep { from { top: 10%; } to { top: 90%; } }
.dropzone:hover, .dropzone.over { border-color: var(--route); }
.dropzone.over { background: var(--accent-soft); }
.drop-title { font-weight: 600; font-size: 1.1rem; }
.drop-hint { color: var(--muted); font-size: 0.92rem; }
kbd {
  font-family: var(--mono);
  font-size: 0.85em;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--bg);
  color: var(--ink);
}

.samples { margin-top: 14px; }
.samples-label { display: block; color: var(--muted); font-size: 0.9rem; margin-bottom: 8px; }
.sample-list { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 4px; }
.sample {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px;
  border-radius: 10px;
  font-size: 0.8rem;
}
.sample:hover { border-color: var(--route); box-shadow: 0 0 0 1px var(--route), 0 0 12px var(--laser-glow); }
.sample img { width: 92px; height: 64px; object-fit: contain; background: #fff; border-radius: 4px; }

.camera {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}
.camera video { width: 100%; height: 100%; object-fit: cover; display: block; }
.reticle {
  position: absolute;
  inset: 22% 12%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
.reticle::after {
  content: "";
  position: absolute;
  left: 4%;
  right: 4%;
  top: 50%;
  height: 2px;
  background: var(--laser);
  box-shadow: 0 0 10px 2px var(--laser-glow);
  opacity: 0;
}
.camera.scanning .reticle { animation: pulse 1.6s ease-in-out infinite; }
.camera.scanning .reticle::after { opacity: 0.9; animation: sweep 1.2s ease-in-out infinite alternate; }
@keyframes pulse { 50% { border-color: var(--laser); } }
.camera-idle { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, 0.55); }
.camera-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 10px; }
.camera-status { color: var(--muted); font-size: 0.92rem; }

#text-form { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
textarea {
  width: 100%;
  font-family: var(--mono);
  font-size: 0.9rem;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  white-space: pre;
  overflow-x: auto;
}

.message { margin: 16px 0 0; padding: 12px 14px; border-radius: 10px; }
.message.error { background: var(--error-bg); color: var(--error-ink); }
.message.info {
  background: var(--screen);
  color: var(--laser);
  font-family: var(--mono);
  text-shadow: 0 0 6px var(--laser-glow);
}
.message.info::after { content: "▍"; margin-left: 2px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.result { margin-top: 24px; display: flex; flex-direction: column; gap: 18px; }

/* Boarding pass card */
.ticket {
  display: grid;
  grid-template-columns: 1fr auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(20, 30, 40, 0.06), 0 8px 24px rgba(20, 30, 40, 0.06);
}
.ticket-main { padding: 18px 20px; min-width: 0; border-top: 4px solid var(--slate); }
/* The stub is the scanner's display: seat number in laser green. */
.ticket-stub {
  position: relative;
  padding: 18px 20px;
  border-left: 2px dashed var(--screen-line);
  background: var(--screen);
  color: var(--screen-ink);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  min-width: 120px;
}
.ticket-stub::before, .ticket-stub::after {
  content: "";
  position: absolute;
  left: -11px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg);
}
.ticket-stub::before { top: -11px; }
.ticket-stub::after { bottom: -11px; }
.ticket-stub .fact .k { color: #7c8a98; }
.ticket-stub .fact .v { color: var(--screen-ink); }
.ticket-head { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 0.9rem; }
.ticket-head .flight { font-family: var(--mono); color: var(--accent); font-weight: 700; }
.route { display: flex; align-items: center; gap: 14px; margin: 10px 0 14px; }
.airport { font-family: var(--mono); font-size: clamp(2rem, 9vw, 3.2rem); font-weight: 700; letter-spacing: 0.02em; line-height: 1; }
.plane { flex: 1; height: 2px; background: repeating-linear-gradient(90deg, var(--route) 0 6px, transparent 6px 12px); position: relative; min-width: 24px; opacity: 0.8; }
.plane::after { content: "✈"; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -55%); background: var(--paper); padding: 0 6px; color: var(--slate); font-size: 1.15rem; }
.ticket-head .airline { margin-left: 10px; }
.ticket-head a, .places a { color: inherit; text-decoration-color: var(--line); text-underline-offset: 3px; }
.ticket-head a:hover, .places a:hover { color: var(--accent); text-decoration-color: currentColor; }
.route { margin-bottom: 6px; }
.places { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.place { display: flex; flex-direction: column; min-width: 0; max-width: 48%; }
.place:last-child { text-align: right; }
.place .city { font-weight: 600; }
.place .airport-name { color: var(--muted); font-size: 0.82rem; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 22px; }
.fact .k { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.fact .v { font-family: var(--mono); font-weight: 600; font-size: 1.05rem; }
.stub-seat { font-family: var(--mono); font-size: 2rem; font-weight: 700; line-height: 1; color: var(--laser); text-shadow: 0 0 10px var(--laser-glow); }
.badge { align-self: flex-start; font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); }
.ticket-stub .badge { background: rgba(61, 255, 110, 0.12); color: var(--laser); border: 1px solid rgba(61, 255, 110, 0.35); }
.status { margin-top: 12px; color: var(--muted); font-size: 0.9rem; }

.date-note { margin: 0 4px; color: var(--muted); font-size: 0.85rem; }
.year-picker { white-space: nowrap; color: var(--ink); }
.year-select { margin-left: 4px; padding: 2px 4px; font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: 6px; }
.pass-count { margin: 0 4px; font-weight: 600; }
.pass { display: flex; flex-direction: column; gap: 14px; }
.pass + .pass { padding-top: 18px; border-top: 2px dashed var(--line); }
.pass-title { margin: 0 4px; font-size: 1.1rem; }
.pass-name { font-family: var(--mono); font-weight: 500; color: var(--muted); }
.fields { display: flex; flex-direction: column; gap: 14px; }
.fields > summary { cursor: pointer; color: var(--muted); font-size: 0.92rem; margin: 0 4px; }
.fields[open] > summary { margin-bottom: 14px; }

.route-map { margin: 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.route-map svg { display: block; width: 100%; height: auto; background: var(--paper); }
.route-map figcaption { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; padding: 10px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 0.85rem; }
.map-credit { font-size: 0.75rem; }
.map-sea { fill: var(--map-sea); }
.map-grid { fill: none; stroke: var(--map-grid); stroke-width: 0.6; }
.map-land path { fill: var(--map-land); stroke: var(--map-coast); stroke-width: 0.8; stroke-linejoin: round; }
.map-land .map-border { fill: none; stroke: var(--map-border); stroke-width: 0.8; stroke-dasharray: 3 2; }
.map-route { fill: none; stroke: var(--route); stroke-width: 2.5; stroke-linecap: round; filter: drop-shadow(0 0 3px var(--laser-glow)); }
.map-airport circle { fill: var(--screen); stroke: var(--route); stroke-width: 2.5; }
.map-airport text { font-family: var(--mono); font-weight: 700; font-size: 14px; fill: var(--ink); paint-order: stroke; stroke: var(--paper); stroke-width: 4px; stroke-linejoin: round; }
.map-airport .map-weather { font-family: var(--sans); font-weight: 600; font-size: 13px; cursor: default; }
.map-airport .map-weather-symbol { stroke: none; }
@media (max-width: 600px) {
  /* The map scales down to about half size: draw its labels bigger to make up for it. */
  .map-airport text { font-size: 24px; stroke-width: 6px; }
  .map-airport .map-weather { font-size: 22px; }
  .map-airport circle { r: 7px; stroke-width: 3.5; }
}

.warnings { background: var(--warn-bg); color: var(--warn-ink); border-radius: 10px; padding: 12px 14px; }
.warnings h3 { margin: 0 0 4px; font-size: 0.95rem; }
.warnings ul { margin: 0; padding-left: 18px; }

/* Field tables */
.details { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 16px 14px; }
.details h2 { font-size: 0.78rem; margin: 18px 0 6px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--slate); }
.details td { padding: 6px 8px 6px 0; border-top: 1px solid var(--line); vertical-align: top; }
.details table { width: 100%; border-collapse: collapse; font-size: 0.92rem; table-layout: fixed; }
.details td.label { color: var(--muted); width: 38%; }
.details td.value { font-family: var(--mono); word-break: break-all; white-space: pre-wrap; width: 32%; }
.details td.meaning { color: var(--muted); }

/* The raw barcode text, on the scanner's display. */
.raw { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.raw h2 { font-size: 1rem; margin: 0 0 8px; }
.raw code {
  display: block;
  font-family: var(--mono);
  font-size: 0.85rem;
  word-break: break-all;
  white-space: pre-wrap;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--screen);
  color: var(--laser);
  text-shadow: 0 0 6px var(--laser-glow);
}
.raw .sp { color: var(--space-mark); text-shadow: none; }
.raw .meta { margin-top: 8px; color: var(--muted); font-size: 0.85rem; }

footer { color: var(--muted); font-size: 0.85rem; padding-top: 32px; padding-bottom: 40px; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-color-scheme: dark) {
  .details h2 { color: var(--muted); }
  .plane::after { color: var(--muted); }
  .ticket-main { border-top-color: #4a5e74; }
}

@media (prefers-reduced-motion: reduce) {
  .dropzone:hover::after, .dropzone.over::after, .reading .dropzone::after,
  .camera.scanning .reticle, .camera.scanning .reticle::after,
  .message.info::after { animation: none; }
}

@media (max-width: 560px) {
  .ticket { grid-template-columns: 1fr; }
  .ticket-stub { border-left: 0; border-top: 2px dashed var(--screen-line); flex-direction: row; align-items: center; justify-content: space-between; }
  .ticket-stub::before, .ticket-stub::after { display: none; }
  .details td.label, .details td.value { width: auto; }
  .details tr { display: grid; grid-template-columns: 1fr; }
  .details td { border-top: 0; padding: 0; }
  .details tr { border-top: 1px solid var(--line); padding: 6px 0; }
}
