/* =========================================================
   NIGHTFALL QR
   Nightfall Automotive — Nord Dark Theme
   ========================================================= */

/* ---------- Tokens & base ---------- */

:root {
  color-scheme: dark;
  --bg: #242933;
  --bg-deep: #20242d;
  --panel: #2e3440;
  --panel-light: #353d4c;
  --border: #434c5e;
  --text: #eceff4;
  --muted: #aab4c5;
  --dim: #7d899d;
  --cyan: #88c0d0;
  --purple: #b48ead;
  --green: #a3be8c;
  --red: #bf616a;
  --radius: 12px;
  --font: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* QR codes stay dark-on-light so every scanner can read them */
  --qr-dark: #2e3440;
  --qr-light: #eceff4;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg-deep);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(136, 192, 208, 0.08), transparent 48%),
    var(--bg-deep);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
}

button,
input,
a {
  font: inherit;
}

a {
  color: var(--cyan);
  text-decoration: none;
}

a:hover {
  color: var(--text);
}

.page {
  /* The sticker's canvas reaches past the card for its curl and shadow; never let it widen the page */
  overflow-x: clip;
  display: flex;
  flex-direction: column;
  width: min(960px, calc(100% - 32px));
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 24px 0 18px;
}

main {
  flex: 1;
}

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

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 0 24px;
  margin-bottom: 28px;
  border-bottom: 1px solid rgba(136, 192, 208, 0.16);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
}

.brand:hover {
  color: var(--text);
}

.brand-logo {
  display: block;
  width: auto;
  height: 36px;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  letter-spacing: 0.15em;
}

.brand-copy strong {
  font-size: 15px;
  font-weight: 900;
}

.brand-copy > span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.3em;
}

.page-tag {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.18em;
}

.page-tag strong {
  margin-left: 8px;
  color: var(--purple);
  font-size: 20px;
}

/* ---------- Tool panel ---------- */

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
}

.panel-header {
  padding: 30px 34px;
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--cyan);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.2em;
}

h1 {
  margin: 0;
  color: var(--text);
  font-size: clamp(30px, 4vw, 52px);
  font-weight: 900;
  line-height: 1.08;
  letter-spacing: -0.045em;
}

h1 .accent {
  color: var(--purple);
}

.intro {
  max-width: 650px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.panel-body {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 34px;
  align-items: start;
  padding: 30px 34px;
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 24px;
  min-width: 0;
}

.field {
  width: 100%;
}

.field > label,
.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.field input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}

.field input:focus {
  outline: 2px solid var(--cyan);
  outline-offset: 1px;
}

.field small,
.output small {
  display: block;
  margin-top: 8px;
  color: var(--dim);
  font-size: 12px;
}

.field small.is-error,
.output small.is-error {
  color: var(--red);
}

.field-label em {
  color: var(--dim);
  font-style: normal;
  font-weight: 600;
}

/* ---------- Logo upload ---------- */

.logo-upload {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
}

/* Visually hidden but still focusable, so the label below acts as the button.
   The clip also stops Firefox's file-input internals catching clicks meant for Remove. */
.logo-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  opacity: 0;
}

.logo-button,
.logo-remove,
.download {
  flex: none;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
}

.logo-button:hover,
.logo-remove:hover,
.download:hover {
  border-color: var(--cyan);
}

.logo-input:focus-visible + .logo-button {
  outline: 2px solid var(--cyan);
  outline-offset: 1px;
}

.logo-remove {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.logo-remove:hover {
  border-color: var(--red);
  color: var(--text);
}

.logo-preview {
  flex: none;
  width: 46px;
  height: 46px;
  padding: 5px;
  border-radius: 8px;
  background: var(--qr-light);
  object-fit: contain;
}

.logo-preview[hidden] {
  display: none;
}

.logo-name {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Style ---------- */

.style-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 18px;
}

.swatch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.corners input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 1px;
}

/* ---------- Nord colour picker ---------- */

.nord-picker-wrap {
  position: relative;
  display: inline-flex;
}

/* Kept for "More colours…" only; the same visually-hidden pattern as the logo input */
.nord-picker-native {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  opacity: 0;
}

.nord-picker-trigger {
  width: 46px;
  height: 40px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: pointer;
}

.nord-picker-trigger::before {
  content: "";
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 5px;
  background: var(--swatch);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.nord-picker-trigger:hover,
.nord-picker-trigger[aria-expanded="true"] {
  border-color: var(--cyan);
}

.nord-picker-trigger:focus-visible,
.nord-picker-swatch:focus-visible,
.nord-picker-hex:focus-visible,
.nord-picker-more:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 1px;
}

.nord-picker {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 10;
  display: grid;
  gap: 12px;
  width: 248px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-light);
  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.6);
}

.nord-picker[hidden] {
  display: none;
}

.nord-picker-name {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.nord-picker-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.nord-picker-swatch {
  width: 36px;
  height: 28px;
  padding: 0;
  /* Strong enough to outline the Polar Night swatches against the panel */
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: var(--swatch);
  cursor: pointer;
  transition: transform 120ms ease;
}

.nord-picker-swatch:hover {
  transform: translateY(-1px);
  border-color: var(--text);
}

.nord-picker-swatch[aria-pressed="true"] {
  box-shadow: 0 0 0 2px var(--panel-light), 0 0 0 4px var(--cyan);
}

.nord-picker-custom {
  display: flex;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.nord-picker-hex {
  width: 0;
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: 13px ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

.nord-picker-hex.is-invalid {
  border-color: var(--red);
}

.nord-picker-more {
  flex: none;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
}

.nord-picker-more:hover {
  border-color: var(--cyan);
}

.corners {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-width: 150px;
  color: var(--muted);
  font-size: 13px;
}

.corners output {
  margin-left: 4px;
  color: var(--text);
}

.corners input {
  width: 100%;
  margin: 0;
  accent-color: var(--cyan);
  cursor: pointer;
}

/* Doubled class so it outranks .hold-button, which loads later */
.generate.hold-button {
  min-width: 200px;
  border: 1px solid var(--border);
}

/* ---------- Result & output ---------- */

.result {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 232px;
}

.output {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.output legend {
  margin-bottom: 8px;
  padding: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.2em;
}

.output-row {
  display: flex;
  gap: 10px;
}

.segmented {
  position: relative;
  display: inline-flex;
  flex: none;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

/* Same visually-hidden pattern as the logo input */
.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  opacity: 0;
}

.segmented label {
  padding: 7px 12px;
  border-radius: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.segmented label:hover {
  color: var(--text);
}

.segmented input:checked + label {
  background: rgba(136, 192, 208, 0.16);
  color: var(--cyan);
}

.segmented input:focus-visible + label {
  outline: 2px solid var(--cyan);
  outline-offset: 1px;
}

.download {
  flex: 1;
}

/* The code image carries its own background, border and corners */
.qr-card {
  position: relative;
  line-height: 0;
}

/* Flat preview: lift it off the panel, with a faint light rim so dark backgrounds still show */
.qr-card #qrcode img,
.qr-card .sticker-peel-canvas {
  filter:
    drop-shadow(0 0 1px rgba(236, 239, 244, 0.45))
    drop-shadow(0 10px 18px rgba(0, 0, 0, 0.45));
}

/* The sticker draws its own shadow; keep only the rim on it */
.qr-card .sticker-peel-canvas {
  filter: drop-shadow(0 0 1px rgba(236, 239, 244, 0.45));
}

/* The sticker replaces the flat image; it stays in place, invisible, for layout and screen readers */
.qr-card.is-sticker #qrcode img {
  opacity: 0;
}

.qr-card img,
.qr-card canvas,
.qr-card svg {
  display: block;
}

/* ---------- Footer ---------- */

.page-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 20px 2px 0;
  color: var(--dim);
  font-size: 10px;
  letter-spacing: 0.12em;
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .page-tag {
    display: none;
  }

  .panel-header,
  .panel-body {
    padding: 22px 20px;
  }

  .panel-body {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .controls {
    width: 100%;
  }

  /* No room for the name; the preview shows which logo is in use */
  .logo-name {
    display: none;
  }

  .page-footer {
    flex-direction: column;
    text-align: center;
  }
}
