/* Tessera — warm stone paper, ink type, and mosaic tiles in terracotta, ochre, teal and lapis. */

@font-face {
  font-family: "Fraunces";
  src: url("/fonts/fraunces-latin-opsz-normal.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("/fonts/fraunces-latin-opsz-italic.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

:root {
  --paper: #f6f2ea;
  --surface: #fffdf9;
  --surface-2: #f1ece2;
  --ink: #1d1b18;
  --ink-2: #4a453e;
  --muted: #776f64;
  --line: #e6dfd2;
  --line-strong: #d6ccbb;

  --accent: #b4472a;
  --accent-hover: #9c3a20;
  --on-accent: #fff8f2;
  --focus: #2e4a7d;

  --tile-1: #c65a3a; /* terracotta */
  --tile-2: #d9a441; /* ochre */
  --tile-3: #2f6f6a; /* teal */
  --tile-4: #2e4a7d; /* lapis */
  --tile-5: #ddd3c3; /* stone */

  --success-bg: #e2efe6;
  --success: #276043;
  --warn-bg: #f8ecd2;
  --warn: #7f520a;
  --error-bg: #f7e0d8;
  --error: #9e2f1b;

  --font-display: "Fraunces", "Iowan Old Style", "Palatino", Georgia, serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --radius-lg: 22px;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 1px 2px rgb(40 30 20 / 0.04), 0 10px 30px -14px rgb(40 30 20 / 0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14120f;
    --surface: #1c1a16;
    --surface-2: #25221d;
    --ink: #f3eee6;
    --ink-2: #d2cabd;
    --muted: #9d9588;
    --line: #2e2a24;
    --line-strong: #3d372f;

    --accent: #e07a55;
    --accent-hover: #ea9270;
    --on-accent: #1d0f08;
    --focus: #8aa8e6;

    --tile-1: #d86b49;
    --tile-2: #e0b354;
    --tile-3: #4f9a92;
    --tile-4: #5d7cc2;
    --tile-5: #34302a;

    --success-bg: #1a2d22;
    --success: #86cfa3;
    --warn-bg: #30250f;
    --warn: #ebbd62;
    --error-bg: #361a14;
    --error: #f2917a;

    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 12px 32px -16px rgb(0 0 0 / 0.6);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-underline-offset: 3px; }
strong { font-weight: 600; }

h1, h2, h3 { font-family: var(--font-display); font-optical-sizing: auto; font-weight: 560; letter-spacing: -0.015em; color: var(--ink); margin: 0; }
h1 { font-size: clamp(1.75rem, 6vw, 2.25rem); line-height: 1.1; }
h2 { font-size: 1.3rem; line-height: 1.25; }
h3 { font-size: 1.05rem; line-height: 1.3; }

.icon { width: 1.2em; height: 1.2em; flex: none; }

/* Mosaic tile tones, shared by the logo, artwork and accents */
.m1 { fill: var(--tile-1); background: var(--tile-1); }
.m2 { fill: var(--tile-2); background: var(--tile-2); }
.m3 { fill: var(--tile-3); background: var(--tile-3); }
.m4 { fill: var(--tile-4); background: var(--tile-4); }
.m5 { fill: var(--tile-5); background: var(--tile-5); }

/* ---------- Shell ---------- */

.shell {
  max-width: 600px;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}
.shell.wide { max-width: 1160px; }

.site-header, .topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  margin-bottom: 8px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.logo-mark { width: 28px; height: 28px; }
.chip {
  font-family: var(--font-body);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 2px 8px;
}

.site-footer {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 40px;
  font-size: 0.8rem;
  color: var(--muted);
}

/* ---------- Hero & home ---------- */

.hero { padding: 8px 0 28px; }
.hero-art {
  height: 92px;
  margin: 0 -16px 22px;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, #000 30%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 30%, transparent 100%);
}
.mosaic { display: block; width: 100%; height: 100%; }

.eyebrow {
  margin: 0 0 10px;
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
}
.hero h1 { font-size: clamp(2.1rem, 9vw, 3.1rem); line-height: 1.04; letter-spacing: -0.025em; font-weight: 520; }
.hero h1 em { font-style: italic; font-weight: 420; color: var(--accent); }
.lede { margin: 16px 0 26px; font-size: 1.06rem; color: var(--ink-2); }

.desktop-hint {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 0.92rem;
}
.desktop-hint[hidden] { display: none; }
.desktop-hint .icon { margin-top: 2px; color: var(--tile-4); }

.section { margin: 8px 0 20px; }
.section-title {
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 12px;
}

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.step {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.step p { margin: 4px 0 0; color: var(--ink-2); font-size: 0.95rem; }
.step-tile {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: #fff;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.05rem;
  transform: rotate(-3deg);
}
.step:nth-child(2) .step-tile { transform: rotate(2deg); color: #2a1f08; }
.step:nth-child(3) .step-tile { transform: rotate(-1deg); }

.note {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin: 0 0 16px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px dashed var(--line-strong);
  color: var(--ink-2);
  font-size: 0.9rem;
}
.note p { margin: 0; }
.note .icon { margin-top: 2px; color: var(--tile-3); }

.disclosure { padding: 0; }
.disclosure > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  cursor: pointer;
  list-style: none;
  font-weight: 600;
}
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure .chevron { color: var(--muted); transition: transform 0.2s ease; }
.disclosure[open] .chevron { transform: rotate(90deg); }
.disclosure form { padding: 0 18px 18px; }

/* ---------- Cards & common blocks ---------- */

.card, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card { padding: 22px; }
.panel { padding: 22px 24px; }
.panel.narrow { max-width: 640px; margin-left: auto; margin-right: auto; }
.panel > h1 { margin-bottom: 8px; }

.muted { color: var(--muted); }
.fine { font-size: 0.84rem; color: var(--muted); margin: 12px 0 0; }
.center { text-align: center; }
.small { font-size: 0.82rem; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--font-mono); font-size: 0.9em; word-break: break-all; }

.flash {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-weight: 500;
}
.flash .icon { margin-top: 2px; }
.flash-success { background: var(--success-bg); color: var(--success); }
.flash-error { background: var(--error-bg); color: var(--error); }

.notice {
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  margin: 0 0 14px;
  font-size: 0.92rem;
}
.error-text { color: var(--error); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-body);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  vertical-align: middle;
  background: var(--surface-2);
  color: var(--muted);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-registered { background: var(--success-bg); color: var(--success); }
.badge-captured, .badge-registering { background: var(--warn-bg); color: var(--warn); }
.badge-failed { background: var(--error-bg); color: var(--error); }

/* ---------- Forms & buttons ---------- */

.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 550; font-size: 0.92rem; color: var(--ink-2); }
label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 450; }
.optional { font-weight: 400; color: var(--muted); font-size: 0.85em; }

input, select, textarea {
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
input[type="file"] { padding: 10px; background: var(--surface-2); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent);
}
.code-input {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  letter-spacing: 0.12em;
  text-align: center;
  text-transform: uppercase;
  padding: 14px;
}
.code-input::placeholder { letter-spacing: 0.12em; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 10px 20px;
  min-height: 44px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 45%, transparent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line-strong); }
.btn-secondary:hover { border-color: var(--ink-2); }
.btn-quiet { background: var(--surface-2); color: var(--ink-2); }
.btn-quiet:hover { color: var(--ink); }
.btn-lg { min-height: 56px; font-size: 1.08rem; padding: 14px 26px; }
.btn-sm { min-height: 34px; padding: 5px 14px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.65; cursor: progress; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--ink-2); cursor: pointer; }
.linklike:hover { color: var(--ink); }

/* ---------- Device page ---------- */

.progress {
  list-style: none;
  display: flex;
  gap: 6px;
  margin: 4px 0 16px;
  padding: 0;
}
.progress-step {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}
.progress-step::before {
  content: "";
  height: 4px;
  border-radius: 4px;
  background: var(--line-strong);
}
.progress-step.is-done::before { background: var(--tile-3); }
.progress-step.is-current::before { background: var(--accent); }
.progress-step.is-current { color: var(--ink); }
.progress-dot { display: none; }
.progress-label { display: block; }

.device-card { padding-top: 20px; }
.device-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 18px; }
.device-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--surface-2);
  color: var(--ink-2);
}
.device-icon .icon { width: 26px; height: 26px; }
.device-title { flex: 1; min-width: 0; }
.device-title h1 { font-size: 1.45rem; overflow-wrap: anywhere; }
.device-title p { margin: 2px 0 0; color: var(--muted); font-size: 0.9rem; }
.device-title .badge { margin-top: 10px; }

.field { margin: 0 0 18px; }
.field-label {
  display: block;
  font-size: 0.74rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 7px;
}
.copy-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 8px 8px 14px;
}
.copy-row code { flex: 1; min-width: 0; font-size: 0.86rem; }
.copy-row .btn { min-width: 34px; padding-left: 9px; padding-right: 9px; }
.copy-row [data-label] { display: none; }
.btn.is-copied { background: var(--success-bg); color: var(--success); }
@media (min-width: 440px) {
  .copy-row .btn { padding-left: 14px; padding-right: 14px; }
  .copy-row [data-label] { display: inline; }
}

.prompt { margin: 0 0 14px; color: var(--ink-2); }

.files { display: grid; gap: 10px; margin-bottom: 20px; }
.file {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}
.file:hover { border-color: var(--accent); }
.file:active { background: var(--surface-2); }
.file-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 11px;
  color: #fff;
}
.file-icon .icon { width: 22px; height: 22px; }
.file-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-text span { font-size: 0.84rem; color: var(--muted); }
.file-action {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
}

.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px 20px; margin: 0 0 16px; }
.meta.grid { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.meta dt { font-size: 0.8rem; color: var(--muted); }
.meta dd { margin: 3px 0 0; font-weight: 550; overflow-wrap: anywhere; }

.working { display: flex; align-items: center; gap: 14px; padding: 8px 0; color: var(--ink-2); }
.working p { margin: 0; }
.spinner {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--line-strong);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.bookmark .icon { width: 1em; height: 1em; vertical-align: -2px; margin-right: 6px; }

.message { text-align: center; padding-top: 0; overflow: hidden; }
.message-art {
  height: 64px;
  margin: 0 -22px 22px;
  -webkit-mask-image: linear-gradient(to bottom, #000 20%, transparent 100%);
  mask-image: linear-gradient(to bottom, #000 20%, transparent 100%);
}
.message p { color: var(--ink-2); margin: 10px 0 20px; }

/* ---------- Admin ---------- */

.admin .topbar { border-bottom: 1px solid var(--line); margin-bottom: 24px; }
.topnav { display: flex; align-items: center; gap: 20px; font-size: 0.92rem; }
.topnav a { color: var(--ink-2); text-decoration: none; }
.topnav a:hover { color: var(--ink); }
.topnav form { margin: 0; }

.page-head { margin-bottom: 18px; }
.page-head h1 { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.back { display: inline-block; margin-bottom: 8px; font-size: 0.88rem; color: var(--muted); text-decoration: none; }
.back:hover { color: var(--ink); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.stat-tile { position: absolute; top: 16px; right: 16px; width: 14px; height: 14px; border-radius: 4px; transform: rotate(8deg); }
.stat-value { font-family: var(--font-display); font-size: 2.1rem; font-weight: 560; line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }

.panel-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inline-form input { width: auto; min-height: 34px; padding: 6px 12px; font-size: 0.88rem; }
.inline-form input.short { width: 80px; }

.table-wrap { overflow-x: auto; margin: 0 -24px; padding: 0 24px; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
td { padding: 13px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
tbody tr:last-child td { border-bottom: 0; }
.strong-link { color: var(--ink); font-weight: 600; text-decoration: none; }
.strong-link:hover { color: var(--accent); }
.cell-title { display: block; font-weight: 550; }
.cell-sub { display: block; font-size: 0.8rem; color: var(--muted); margin-top: 2px; max-width: 320px; }
.row-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.row-actions form { margin: 0; }

.usage { display: inline-flex; align-items: center; gap: 10px; white-space: nowrap; }
.usage-bar { width: 72px; height: 6px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.usage-bar span { display: block; height: 100%; border-radius: 6px; background: var(--tile-3); }
.usage-text { font-variant-numeric: tabular-nums; font-size: 0.88rem; }

.codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.code-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
}
.code-chip code { flex: 1; font-size: 0.95rem; letter-spacing: 0.04em; word-break: normal; }
.code-chip .cell-sub { margin: 0; }

.empty { padding: 18px; border: 1px dashed var(--line-strong); border-radius: var(--radius); text-align: center; color: var(--ink-2); }
.empty p { margin: 0 0 12px; }
.empty p:last-child { margin: 0; }

.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); gap: 28px; margin-top: 6px; }
.split form { border-top: 1px solid var(--line); padding-top: 18px; }
.split .btn { align-self: flex-start; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }

.login { max-width: 420px; margin: 24px auto; padding-top: 0; overflow: hidden; }
.login h1 { margin-bottom: 6px; }
.login .muted { margin: 0 0 20px; }

@media (min-width: 720px) {
  .hero { padding-top: 16px; }
  .hero-art { height: 120px; margin-left: 0; margin-right: 0; border-radius: 0; }
  .card { padding: 28px; }
  .message-art { margin: 0 -28px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0.01ms !important; }
}
