:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1b1f24;
  --muted: #5d6670;
  --border: #d8dde3;
  --accent: #1f4e79;
  --accent-text: #ffffff;
  --warn-bg: #fff4d6;
  --warn-text: #6b4a00;
  --error-bg: #fde8e8;
  --error-text: #8a1c1c;
  --str: #0b6e4f;
  --num: #1f4e79;
  --bool: #8a3ffc;
  --null: #6f6f6f;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --panel: #1a1e24;
    --text: #e6e9ed;
    --muted: #9aa4ae;
    --border: #2d333b;
    --accent: #6ea8dc;
    --accent-text: #0b1520;
    --warn-bg: #3a2f10;
    --warn-text: #ffd98a;
    --error-bg: #3b1717;
    --error-text: #ffb3b3;
    --str: #6fd3a8;
    --num: #8cc4ff;
    --bool: #c6a2ff;
    --null: #a0a0a0;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* ---- chrome ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .75rem 16px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
nav { display: flex; gap: .25rem; }
nav a { padding: .35rem .75rem; border-radius: 999px; text-decoration: none; }
nav a[aria-current="page"] { background: var(--accent); color: var(--accent-text); }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.layout-2 { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 860px) { .layout-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; } }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }

/* ---- home ---- */
.home { max-width: 720px; }
.lead { font-size: 1.1rem; color: var(--muted); }
.home-cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin: 1.5rem 0; }
.card-link {
  display: flex; flex-direction: column; gap: .35rem; padding: 16px; text-decoration: none; color: var(--text);
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
}
.card-link strong { color: var(--accent); font-size: 1.1rem; }
.card-link:hover { border-color: var(--accent); }

/* ---- forms ---- */
.field { display: flex; flex-direction: column; gap: .25rem; margin: 0 0 .85rem; min-width: 0; }
.field .label { font-weight: 600; font-size: .9rem; }
.field small { color: var(--muted); }
.check { display: flex; align-items: center; gap: .4rem; margin: 0 0 .6rem; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type="text"], input[type="url"], input[type="email"], input[type="tel"], input[type="password"], input:not([type]), select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--border); border-radius: 8px; background: var(--bg);
}
textarea { resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.grid-2 { display: grid; gap: 0 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 560px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .span-2 { grid-column: span 2; } }

button {
  padding: .5rem .9rem; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-text); cursor: pointer;
}
button.secondary { background: transparent; color: var(--accent); }
button.small { padding: .2rem .55rem; font-size: .85rem; }
button.danger { background: transparent; color: var(--error-text); border-color: var(--border); }
button:disabled { opacity: .5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .75rem 0; }

/* Segmented strip: one row of equal-width buttons that never wraps. */
.chips {
  display: flex; margin: 0 0 1rem;
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.chip {
  flex: 1 1 0; min-width: 0; padding: .55rem .25rem;
  background: transparent; color: var(--text);
  border: 0; border-left: 1px solid var(--border); border-radius: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip:first-child { border-left: 0; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; }

.tabs { display: flex; gap: .25rem; margin: 0 0 .75rem; border-bottom: 1px solid var(--border); }
.tab { background: transparent; color: var(--muted); border: none; border-bottom: 2px solid transparent; border-radius: 0; }
.tab[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }

.warning, .error, .field-error { border-radius: 8px; }
.warning { background: var(--warn-bg); color: var(--warn-text); padding: .6rem .75rem; }
.error { background: var(--error-bg); color: var(--error-text); padding: .6rem .75rem; }
.field-error { color: var(--error-text); min-height: 1.5em; margin: .25rem 0; }

/* ---- QR preview ---- */
.qr-frame { display: flex; justify-content: center; background: #fff; border-radius: 8px; padding: 8px; }
.qr-canvas { width: 100%; max-width: 320px; height: auto; aspect-ratio: 1; image-rendering: pixelated; }
.qr-canvas.stale { opacity: .15; }
.qr-info { color: var(--muted); font-size: .9rem; margin: .5rem 0; }
.payload-box summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
pre.payload, pre.raw {
  white-space: pre-wrap; word-break: break-all; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: .6rem; font-size: .85rem; max-height: 320px; overflow: auto;
}

/* ---- dictionary editor ---- */
.kv-list { list-style: none; margin: 0; padding: 0; }
.kv-container .kv-container { margin-left: 1rem; padding-left: .75rem; border-left: 2px solid var(--border); }
.kv-row { display: grid; grid-template-columns: minmax(0, 1.2fr) 6.5rem minmax(0, 2fr) auto; gap: .35rem; align-items: center; margin: 0 0 .35rem; }
.kv-row input { padding: .35rem .45rem; }
.kv-row select { padding: .35rem .3rem; }
.kv-index { font-family: ui-monospace, monospace; color: var(--muted); }
.kv-value.muted { font-family: ui-monospace, monospace; }
label.kv-value { display: flex; align-items: center; gap: .3rem; }
.json-input { font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }
@media (max-width: 480px) {
  .kv-row { grid-template-columns: minmax(0, 1fr) 5.5rem auto; }
  .kv-row .kv-value { grid-column: 1 / -1; grid-row: 2; }
}

/* ---- admin ---- */
.codes-grid { display: grid; gap: 16px; margin-top: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* ---- reader ---- */
.viewport { position: relative; margin: 0 0 1rem; border-radius: 8px; overflow: hidden; background: #000; }
.viewport video { display: block; width: 100%; max-height: 60vh; object-fit: cover; }
.reticle { position: absolute; inset: 15%; border: 3px solid rgba(255, 255, 255, .85); border-radius: 12px; pointer-events: none; }
.drop-zone {
  display: flex; flex-direction: column; gap: .5rem; padding: 1rem; margin: 0 0 1rem;
  border: 2px dashed var(--border); border-radius: var(--radius); cursor: pointer;
}
.drop-zone.over { border-color: var(--accent); }
.drop-zone input { max-width: 100%; }
#scan-status.error { background: var(--error-bg); color: var(--error-text); padding: .6rem .75rem; border-radius: 8px; }
.result:focus { outline: none; }
.result-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin: 0 0 1rem; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 999px; padding: .15rem .7rem; font-size: .85rem; font-weight: 600; }
dl.details { margin: 0; }
.kv { display: grid; grid-template-columns: 7rem minmax(0, 1fr); gap: .5rem; padding: .4rem 0; border-bottom: 1px solid var(--border); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
ul.plain { list-style: none; margin: 0; padding: 0; }
.pre-line { white-space: pre-line; }
.secret-row { display: inline-flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
code.secret { font-size: 1rem; overflow-wrap: anywhere; }
.url-host { font-size: 1.25rem; margin: 0 0 .5rem; overflow-wrap: anywhere; }
.url-full { font-family: ui-monospace, Consolas, monospace; overflow-wrap: anywhere; background: var(--bg); padding: .5rem; border-radius: 8px; }
dialog.confirm { max-width: min(520px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); color: var(--text); }
dialog.confirm::backdrop { background: rgba(0, 0, 0, .5); }
.contact-card h2 { margin-bottom: .25rem; }

/* ---- tree view ---- */
.tree { font-family: ui-monospace, Consolas, monospace; font-size: .9rem; overflow-wrap: anywhere; }
.tree ul { list-style: none; margin: 0; padding-left: 1.1rem; border-left: 1px solid var(--border); }
.tree summary { cursor: pointer; }
.tree-leaf { padding-left: 1rem; }
.tree-key { font-weight: 600; }
.tree-meta { color: var(--muted); }
.v-str { color: var(--str); }
.v-num { color: var(--num); }
.v-bool { color: var(--bool); }
.v-null { color: var(--null); font-style: italic; }

/* ---- update prompt ---- */
.update-banner {
  position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 20; margin: 0 auto; max-width: 480px;
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .75rem 1rem;
  background: var(--panel); border: 1px solid var(--accent); border-radius: var(--radius); box-shadow: 0 4px 20px rgba(0, 0, 0, .25);
}
.update-banner span { flex: 1 1 auto; }
