/* ============================================================
   TOKENS
   ============================================================ */
:root {
  --paper:        #ECEBE4;
  --paper-raised: #F6F5F0;
  --ink:          #15181A;
  --ink-soft:     #4A4E4A;
  --grid-line:    #CBCCC1;
  --signal:       #2F6F4E;
  --signal-soft:  #DCE8DF;
  --alert:        #B33F2E;

  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --sans: 'Inter', -apple-system, system-ui, sans-serif;

  --module: 8px; /* base grid module, echoes a QR "pixel" */
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(var(--grid-line) 1px, transparent 1px) 0 0 / 100% 32px,
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px) 0 0 / 32px 100%,
    var(--paper);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--sans);
  position: relative;
}

@media (prefers-reduced-motion: no-preference) {
  .corner, .btn-generate__arrow, .status-dot { transition: all 0.25s ease; }
}

/* subtle grain so the flat paper tone doesn't feel sterile */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: var(--signal); color: var(--paper-raised); }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px clamp(20px, 5vw, 48px);
  border-bottom: 1px solid var(--grid-line);
}

.topbar__mark {
  display: flex;
  gap: 4px;
}
.mark-dot {
  width: 8px;
  height: 8px;
  border: 1.5px solid var(--ink);
  background: transparent;
}
.mark-dot--solid { background: var(--ink); }

.topbar__label {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.12em;
}

.topbar__status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 0 3px var(--signal-soft);
}
.status-dot--active { background: var(--alert); box-shadow: 0 0 0 3px #f2ded9; }

/* ============================================================
   STAGE / LAYOUT
   ============================================================ */
.stage {
  position: relative;
  z-index: 1;
  max-width: 980px;
  margin: 0 auto;
  padding: clamp(40px, 7vw, 88px) clamp(20px, 5vw, 48px) 60px;
  display: grid;
  gap: 48px;
}

@media (min-width: 860px) {
  .stage {
    grid-template-columns: 0.9fr 1.1fr;
    align-items: start;
    gap: 56px;
  }
}

.eyebrow {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  color: var(--signal);
  margin: 0 0 14px;
  text-transform: uppercase;
}

.headline {
  font-family: var(--mono);
  font-weight: 700;
  font-size: clamp(34px, 5.4vw, 54px);
  line-height: 1.04;
  letter-spacing: -0.01em;
  margin: 0 0 20px;
}

.sub {
  font-size: 15.5px;
  line-height: 1.6;
  color: var(--ink-soft);
  max-width: 40ch;
  margin: 0;
}

/* ============================================================
   PANEL / FORM
   ============================================================ */
.panel {
  background: var(--paper-raised);
  border: 1px solid var(--grid-line);
  padding: clamp(20px, 3vw, 32px);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.form { display: flex; flex-direction: column; gap: 16px; }

.form__label {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  text-transform: uppercase;
}

.input-row {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--ink);
  background: var(--paper);
}

.input-row__prefix {
  padding: 0 4px 0 14px;
  color: var(--signal);
  font-family: var(--mono);
  font-weight: 600;
}

.input-row input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 14px 14px 14px 6px;
  font-family: var(--mono);
  font-size: 14.5px;
  color: var(--ink);
  outline: none;
  min-width: 0;
}
.input-row input::placeholder { color: #9a9d93; }
.input-row:focus-within {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

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

.control {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.control label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  text-transform: uppercase;
}
.control select {
  border: 1px solid var(--grid-line);
  background: var(--paper);
  padding: 10px 10px;
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--ink);
  outline: none;
}
.control select:focus-visible { outline: 2px solid var(--signal); outline-offset: 1px; }

.btn-generate {
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: none;
  background: var(--ink);
  color: var(--paper-raised);
  font-family: var(--mono);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.03em;
  padding: 15px 18px;
  cursor: pointer;
}
.btn-generate:hover { background: var(--signal); }
.btn-generate:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.btn-generate__arrow { display: inline-block; }
.btn-generate:hover .btn-generate__arrow { transform: translate(2px, -2px); }

/* ============================================================
   VIEWFINDER — the signature element
   ============================================================ */
.viewfinder {
  position: relative;
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background:
    repeating-linear-gradient(45deg, transparent 0 10px, rgba(21,24,26,0.025) 10px 11px);
}

.corner {
  position: absolute;
  width: 22px;
  height: 22px;
  border: 2.5px solid var(--ink);
  opacity: 0.35;
}
.corner--tl { top: 0; left: 0; border-right: none; border-bottom: none; }
.corner--tr { top: 0; right: 0; border-left: none; border-bottom: none; }
.corner--bl { bottom: 0; left: 0; border-right: none; border-top: none; }
.corner--br { bottom: 0; right: 0; border-left: none; border-top: none; }

.viewfinder--active .corner {
  opacity: 1;
  border-color: var(--signal);
}

.viewfinder__empty {
  text-align: center;
  color: var(--ink-soft);
  font-family: var(--mono);
}
.viewfinder__empty p { margin: 4px 0; font-size: 13px; }
.viewfinder__empty p:first-of-type { color: var(--ink); font-weight: 600; }
.empty-hint { font-size: 11.5px !important; color: #9a9d93 !important; }

.empty-grid {
  display: grid;
  grid-template-columns: repeat(3, 14px);
  grid-template-rows: repeat(3, 14px);
  gap: 4px;
  margin: 0 auto 16px;
  width: fit-content;
}
.empty-grid span {
  background: var(--grid-line);
}
.empty-grid span:nth-child(1),
.empty-grid span:nth-child(5),
.empty-grid span:nth-child(9) {
  background: var(--ink-soft);
}

.qrcode-canvas {
  display: none;
  background: #fff;
  padding: 16px;
  line-height: 0;
}
.qrcode-canvas img, .qrcode-canvas canvas {
  display: block;
  image-rendering: pixelated;
}
.viewfinder--active .qrcode-canvas { display: block; }
.viewfinder--active .viewfinder__empty { display: none; }

/* ============================================================
   RESULT ACTIONS
   ============================================================ */
.result-actions {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px dashed var(--grid-line);
  padding-top: 18px;
}
.result-actions--visible { display: flex; }

.result-actions__url {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-soft);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60%;
}

.btn-download {
  flex-shrink: 0;
  border: 1.5px solid var(--ink);
  background: transparent;
  color: var(--ink);
  font-family: var(--mono);
  font-weight: 600;
  font-size: 13px;
  padding: 10px 16px;
  cursor: pointer;
}
.btn-download:hover { background: var(--ink); color: var(--paper-raised); }
.btn-download:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

/* ============================================================
   FOOTER
   ============================================================ */
.footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 24px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-soft);
  border-top: 1px solid var(--grid-line);
}
.footer a { color: var(--signal); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 520px) {
  .controls { grid-template-columns: 1fr; }
  .result-actions { flex-direction: column; align-items: stretch; }
  .result-actions__url { max-width: 100%; }
}
