/* Xorra QR — progressive web app styles */

/* Xorra brand fonts: light wordmark, heavy modifier (see xorra-web) */
@font-face {
  font-family: "Logo Light";
  src: url("Oxanium-ExtraLight.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "Logo Heavy";
  src: url("Oxanium-Bold.woff2") format("woff2");
  font-display: swap;
}

:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #16202b;
  --text-dim: #5b6875;
  --accent: #0d6efd;
  --brand-bar: #212529;
  --accent-text: #ffffff;
  --ok: #12a150;
  --border: #d7dee6;
  --shadow: 0 4px 24px rgb(16 32 48 / 0.08);
  --radius: 14px;
  --syn-key: #8f2c8f;
  --syn-str: #0b7a3e;
  --syn-num: #b35c00;
  --syn-bool: #0d63c8;
  --syn-punct: #7a8794;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --surface: #1a2027;
    --surface-2: #232b34;
    --text: #e8edf2;
    --text-dim: #93a1af;
    --accent: #3ea0ff;
    --accent-text: #06121f;
    --brand-bar: #16191d;
    --ok: #2fd379;
    --border: #2c3540;
    --shadow: 0 4px 24px rgb(0 0 0 / 0.35);
    --syn-key: #d48fd4;
    --syn-str: #7ed9a4;
    --syn-num: #f2b46a;
    --syn-bool: #6fb8ff;
    --syn-punct: #7a8794;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: 0 env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Dark brand bar, matching the navbar on www/tools.xorra.com */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: calc(0.9rem + env(safe-area-inset-top)) 1.2rem 0.9rem;
  flex-wrap: wrap;
  background: var(--brand-bar);
  color: #fff;
}

/* Brand cluster: "xorra tools" (hub link) | icon + tool name (tool home).
   Shared pattern; see xorra-web/docs/TOOLS-STYLE-GUIDE.md.
   font-family here sets the flex items' line-box struts: left to the body
   font (taller ascent than Oxanium), the hub link's box outgrows the tool
   link's and align-items:center skews the two text baselines apart. */
.brand {
  display: flex; align-items: center; gap: 0.75rem;
  font-size: 1.4rem; font-family: "Logo Heavy", sans-serif;
}
.brand-link { color: inherit; text-decoration: none; }
.brand-sep { width: 1px; height: 1.4em; background: rgb(255 255 255 / 0.35); flex: none; }
.tool-name { display: flex; align-items: center; gap: 0.35rem; }
/* Box-centered is optically low: Oxanium's caps sit high in its line box.
   Nudge to center the glyph on the cap-to-baseline band. */
.brand-icon { width: 1.2em; height: 1.2em; color: #fff; transform: translateY(-0.08em); }

.logo { font-family: "Logo Light", sans-serif; }
.logo-minor { font-family: "Logo Heavy", sans-serif; }

.tabs {
  display: flex;
  background: rgb(255 255 255 / 0.12);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
  /* More sections than fit: the track scrolls sideways instead of widening
     the header or the page. overflow != visible also zeroes the flex-item
     min-width, letting the track shrink to the space the row has left. */
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  border: 0;
  background: transparent;
  color: rgb(255 255 255 / 0.65);
  font: inherit;
  font-weight: 600;
  padding: 0.4rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.tab.active { background: #fff; color: var(--brand-bar); }

main {
  flex: 1;
  width: min(680px, 100%);
  margin: 0 auto;
  padding: 0 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.panel { display: none; }
.panel.active { display: block; }

.stage {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: grid;
  place-items: center;
}

video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.stage.live video { display: block; }
.stage.live .stage-message { display: none; }

.viewfinder {
  position: absolute;
  inset: 0;
  display: none;
  pointer-events: none;
}

.stage.live .viewfinder { display: block; }

.viewfinder span {
  position: absolute;
  width: 34px;
  height: 34px;
  border: 3px solid rgb(255 255 255 / 0.9);
  border-radius: 6px;
}

.viewfinder span:nth-child(1) { top: 14%; left: 14%; border-right: 0; border-bottom: 0; }
.viewfinder span:nth-child(2) { top: 14%; right: 14%; border-left: 0; border-bottom: 0; }
.viewfinder span:nth-child(3) { bottom: 14%; left: 14%; border-right: 0; border-top: 0; }
.viewfinder span:nth-child(4) { bottom: 14%; right: 14%; border-left: 0; border-top: 0; }

.stage-message { text-align: center; padding: 1.5rem; color: var(--text-dim); }
.stage-message .hint { font-size: 0.85rem; min-height: 1.2em; }

.dropzone { cursor: pointer; border: 2px dashed var(--border); background: var(--surface); }
.dropzone.dragover { border-color: var(--accent); background: var(--surface-2); }
.dropzone:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.drop-icon { width: 44px; height: 44px; opacity: 0.6; }

#preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--surface-2);
}

.stage.has-preview .stage-message {
  position: absolute;
  inset: auto 0 0 0;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  padding: 0.6rem;
  backdrop-filter: blur(6px);
}

.stage.has-preview .drop-icon,
.stage.has-preview p { display: none; }

button.primary {
  border: 0;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-weight: 700;
  padding: 0.55rem 1.4rem;
  border-radius: 999px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
}

button.primary:hover { filter: brightness(1.08); }
button.primary:active { transform: scale(0.97); }

button.ghost {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.85rem;
  padding: 0.25rem 0.8rem;
  border-radius: 999px;
  cursor: pointer;
}

button.ghost:hover { color: var(--text); border-color: var(--text-dim); }

.results h2, .history h2 { font-size: 1rem; margin: 0 0 0.5rem; color: var(--text-dim); }

#results-list, #history-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }

.result-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.9rem 1rem;
  display: grid;
  gap: 0.55rem;
  animation: pop 0.25s ease-out;
}

@keyframes pop {
  from { transform: translateY(6px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.result-text {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95rem;
  word-break: break-word;
  white-space: pre-wrap;
  margin: 0;
}

.result-text a { color: var(--accent); }

.view-tabs { display: flex; gap: 4px; flex-wrap: wrap; }

.view-tab {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.15rem 0.7rem;
  border-radius: 999px;
  cursor: pointer;
}

.view-tab.active {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--text-dim);
}

.j-key { color: var(--syn-key); }
.j-str { color: var(--syn-str); }
.j-num { color: var(--syn-num); }
.j-bool, .j-null { color: var(--syn-bool); font-weight: 600; }
.j-punct { color: var(--syn-punct); }

.result-meta { font-size: 0.78rem; color: var(--text-dim); }

.result-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.result-actions .primary { padding: 0.35rem 1rem; font-size: 0.85rem; }

/* -------------------------------------------------------------- create tab */

.create-layout { display: grid; gap: 1rem; }

@media (min-width: 560px) {
  .create-layout {
    grid-template-columns: minmax(0, 1fr) 236px;
    align-items: start;
  }
}

.create-form {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  display: grid;
  gap: 0.9rem;
}

.type-chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.3rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.chip.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.fields { display: grid; gap: 0.7rem; }
.fields[hidden], #wifi-password-field[hidden] { display: none; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}

.create-form .optional {
  font-weight: normal;
  font-size: 0.72rem;
  opacity: 0.75;
}

.create-form label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
}

.create-form input:not([type="checkbox"]),
.create-form textarea,
.create-form select {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  width: 100%;
}

.create-form textarea { resize: vertical; }

.create-form :is(input, textarea, select):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.pw-row { display: flex; gap: 0.4rem; align-items: center; }
.pw-row input { flex: 1; min-width: 0; }

.create-form label.check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.create-form label.check input { width: auto; }

.create-form .hint {
  margin: 0;
  font-size: 0.78rem;
  font-weight: normal;
  color: var(--text-dim);
}

.advanced { display: grid; gap: 0.7rem; }
.advanced summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
}

.create-out { display: grid; gap: 0.6rem; justify-items: center; }

/* Deliberately white in both themes: QR codes must stay dark-on-light. */
.qr-frame {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.6rem;
  width: 100%;
  max-width: 236px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

#qr-canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

#create-message {
  margin: 0;
  text-align: center;
  font-size: 0.85rem;
  color: #5b6875; /* readable on the always-white frame */
}

.badge {
  flex-shrink: 0;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0 0.45rem;
}

/* ----------------------------------------------------------------- history */

.history-head { display: flex; align-items: center; justify-content: space-between; }

.history-item {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
  background: var(--surface);
  border-radius: 10px;
  padding: 0.5rem 0.8rem;
  font-size: 0.85rem;
  cursor: pointer;
  border: 1px solid transparent;
  min-width: 0; /* grid items don't shrink below content width by default */
}

.history-item:hover { border-color: var(--border); }

.history-item .h-text {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0; /* allow the flex item to shrink below its content width */
}

.history-item time { color: var(--text-dim); font-size: 0.75rem; flex-shrink: 0; }

/* ----------------------------------------------------------- install card */

.install-card[hidden] { display: none; }

.install-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  display: grid;
  gap: 0.6rem;
}

.install-card h2 { font-size: 1rem; margin: 0; }
.install-card p { margin: 0; font-size: 0.88rem; color: var(--text-dim); }

#install-steps {
  margin: 0;
  padding-left: 1.3rem;
  font-size: 0.88rem;
  color: var(--text-dim);
  display: grid;
  gap: 0.3rem;
}

#install-steps[hidden] { display: none; }

.install-actions { display: flex; gap: 0.5rem; align-items: center; }
.install-actions .primary { padding: 0.35rem 1.2rem; font-size: 0.9rem; }

footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.8rem;
  padding: 0.8rem 1rem 1.2rem;
}

footer p { margin: 0; }

footer a { color: var(--text-dim); }
footer .made-in { margin-top: 0.4rem; }
footer .colorado { width: 30px; vertical-align: -4px; }

/* Attributions page (attributions.html, generated from misc/attributions.hbs) */
.attributions { padding-top: 1rem; }
.attributions h2 { font-size: 1.3rem; margin: 0 0 0.5rem; }
.attributions h3 { font-size: 1.05rem; margin: 1.4rem 0 0.5rem; }
.attributions a { color: var(--accent); }

.attributions details {
  margin-bottom: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.9rem;
}

.attributions summary {
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-dim);
}

.attributions .attr-links { margin: 0.5rem 0 0.3rem; font-size: 0.85rem; }
.attributions .attr-note { font-size: 0.85rem; color: var(--text-dim); }

.attributions pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.75rem;
  background: var(--surface-2);
  border-radius: calc(var(--radius) - 6px);
  padding: 0.8rem;
  margin: 0.4rem 0 0.5rem;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 0.55rem 1.2rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 10;
}

#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 480px) {
  header { padding: 0.7rem 0.9rem; }
  .tabs { width: 100%; }
  /* Tighter pills so all three fit 320px-wide screens without overflow;
     grow to share the track but never shrink below the label — the track
     scrolls when the pills genuinely don't fit. */
  .tab { flex: 1 0 auto; padding: 0.4rem 0.5rem; font-size: 0.875rem; }
}
