:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f2f8;
  --text: #11131f;
  --muted: #676c82;
  --border: #e4e6ef;
  --accent: #5b5bf0;
  --accent-2: #9b5cf6;
  --accent-soft: #ececfe;
  --accent-text: #4343d6;
  --success: #16a34a;
  --danger: #e11d48;
  --shadow: 0 1px 2px rgba(17, 19, 31, 0.04), 0 4px 16px rgba(17, 19, 31, 0.05);
  --shadow-lg: 0 2px 4px rgba(17, 19, 31, 0.04), 0 12px 32px rgba(91, 91, 240, 0.12);
  --radius: 16px;
  --sidebar-w: 248px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --warn-text: #b45309;
  --star-text: #b7791f;
  color-scheme: light;
}
/* Dark theme: follows the system unless the user picked one in the sidebar
   (js/main.js sets data-theme="light" or "dark" on <html>). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0c12;
    --surface: #13151d;
    --surface-2: #1a1d27;
    --text: #ecedf4;
    --muted: #8b90a6;
    --border: #242836;
    --accent: #7c7cff;
    --accent-2: #b48cff;
    --accent-soft: #1f2040;
    --accent-text: #a5a6ff;
    --success: #4ade80;
    --danger: #fb7185;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 2px 4px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(124, 124, 255, 0.15);
    --warn-text: #fbbf24;
    --star-text: var(--star);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0c12;
  --surface: #13151d;
  --surface-2: #1a1d27;
  --text: #ecedf4;
  --muted: #8b90a6;
  --border: #242836;
  --accent: #7c7cff;
  --accent-2: #b48cff;
  --accent-soft: #1f2040;
  --accent-text: #a5a6ff;
  --success: #4ade80;
  --danger: #fb7185;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 2px 4px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(124, 124, 255, 0.15);
  --warn-text: #fbbf24;
  --star-text: var(--star);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
h1 { letter-spacing: -0.02em; }

.ico {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  overflow-y: auto;
  z-index: 20;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 20px;
  color: var(--text);
  text-decoration: none;
}
.brand-logo {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 4px 12px rgba(91, 91, 240, 0.35);
}
.brand-logo .ico { width: 18px; height: 18px; }
.brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }

.nav-section {
  margin: 18px 10px 6px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-list a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.nav-list a:hover { background: var(--surface-2); color: var(--text); }
.nav-list a.active { background: var(--accent-soft); color: var(--accent-text); }
.nav-icon { display: inline-flex; }
.nav-icon .ico { width: 18px; height: 18px; }

.sidebar-foot {
  margin-top: auto;
  padding: 16px 6px 0;
  display: grid;
  gap: 12px;
}
.foot-note {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
  font-size: 0.78rem;
  color: var(--muted);
}
.theme-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
}
.theme-switch button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  padding: 6px 4px;
  border: none;
  border-radius: 8px;
  background: none;
  font: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.theme-switch button .ico { width: 15px; height: 15px; }
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 20%, transparent); }

/* ---------- Main ---------- */
.content {
  margin-left: var(--sidebar-w);
  padding: 48px 48px 64px;
}
.app { max-width: 760px; animation: fade-in 0.25s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-head { margin-bottom: 24px; }
.page-head h1 { margin: 0 0 4px; font-size: 1.75rem; }
.page-head p { margin: 0; color: var(--muted); }

/* Home */
.hero { margin-bottom: 32px; }
.hero-title {
  margin: 0 0 8px;
  font-size: clamp(2.2rem, 5vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.035em;
}
.hero-accent {
  background: linear-gradient(110deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}
.hero-sub { margin: 0; color: var(--muted); font-size: 1.05rem; }

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text);
  text-decoration: none;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.tile:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.tile-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin-bottom: 10px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-text);
}
.tile-title { font-weight: 600; }
.tile-desc { font-size: 0.88rem; color: var(--muted); }
.tile-arrow {
  position: absolute;
  top: 20px;
  right: 18px;
  color: var(--muted);
  opacity: 0;
  transform: translateX(-4px);
  transition: opacity 0.18s, transform 0.18s;
}
.tile:hover .tile-arrow { opacity: 1; transform: none; color: var(--accent-text); }

/* Cards & fields */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
}
textarea {
  display: block;
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 14px;
  resize: vertical;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
textarea::placeholder { color: var(--muted); opacity: 0.8; }
textarea:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 0.8rem;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.dropzone {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px;
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.dropzone:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.dropzone strong { color: var(--accent-text); font-weight: 600; }
.dropzone.has-file { border-style: solid; }

/* Result */
.result-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.result-head > .field-label { white-space: nowrap; }
.result-head .field-label { margin: 0; }
.mono {
  display: block;
  min-height: 1.5em;
  max-height: 300px;
  overflow-y: auto;
  font-family: var(--mono);
  font-size: 0.92rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--surface-2);
}
.mono:empty::before { content: "—"; color: var(--muted); }
.status { margin: 10px 0 0; font-size: 0.82rem; color: var(--muted); min-height: 1.2em; }
.status.error { color: var(--danger); }

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.copy-btn .ico { width: 15px; height: 15px; }
.copy-btn:hover { border-color: var(--accent); color: var(--accent-text); }
.copy-btn.copied { border-color: var(--success); color: var(--success); }

/* Segmented control */
.segmented {
  display: inline-flex;
  padding: 4px;
  margin-bottom: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  padding: 7px 18px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--muted);
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Home: search + groups ---------- */
.app-wide { max-width: 1040px; }
.search {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 420px;
  margin-bottom: 28px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  color: var(--muted);
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
.search input { flex: 1; min-width: 0; padding: 12px 0; border: none; outline: none; background: none; font: inherit; color: var(--text); }
.tile-group { margin-bottom: 28px; }
.group-title {
  margin: 0 0 12px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.empty { color: var(--muted); }

/* ---------- Stars + recent ---------- */
:root { --star: #f5a524; }
.tile-wrap { position: relative; display: flex; }
.tile-wrap > .tile { flex: 1; }
.tile-arrow { top: auto; bottom: 18px; }
.tile-star {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.15s, background 0.15s, color 0.15s, transform 0.15s;
}
.tile-star .ico { width: 18px; height: 18px; }
.tile-wrap:hover .tile-star, .tile-star:focus-visible { opacity: 1; }
.tile-star:hover { background: var(--surface-2); color: var(--star); }
.tile-star.on { opacity: 1; color: var(--star); }
.tile-star.on .ico, .star-toggle.on .ico { fill: currentColor; }
.tile-star:active, .head-btn:active { transform: scale(0.9); }
@media (hover: none) { .tile-star { opacity: 0.8; } }

.page-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; margin-bottom: 4px; }
.page-title-row h1 { margin: 0; }
.head-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s, transform 0.15s;
}
.head-btn .ico { width: 15px; height: 15px; }
.head-actions { display: inline-flex; gap: 8px; }
.share-btn:hover { border-color: var(--accent); color: var(--accent-text); }
.share-btn.done { border-color: var(--success); color: var(--success); }
.star-toggle:hover { border-color: var(--star); color: var(--star); }
.star-toggle.on { border-color: color-mix(in srgb, var(--star) 55%, var(--border)); background: color-mix(in srgb, var(--star) 12%, var(--surface)); color: var(--star-text); }

/* Compact shortcut tiles on phones: two per row, icon + name only */
@media (max-width: 800px) {
  #homeStarred .tiles, #homeRecent .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  #homeStarred .tile, #homeRecent .tile { padding: 14px; }
  #homeStarred .tile-icon, #homeRecent .tile-icon { width: 36px; height: 36px; margin-bottom: 8px; border-radius: 10px; }
  #homeStarred .tile-desc, #homeRecent .tile-desc, #homeStarred .tile-arrow, #homeRecent .tile-arrow { display: none; }
  #homeStarred .tile-title, #homeRecent .tile-title { font-size: 0.92rem; line-height: 1.3; padding-right: 22px; }
  #homeStarred .tile-star, #homeRecent .tile-star { top: 8px; right: 6px; }
}

/* Collapsible group headings (sidebar + home) */
.group-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  border: none;
  background: none;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: inherit;
  cursor: pointer;
  border-radius: 6px;
}
.group-toggle:hover { color: var(--text); }
.group-toggle .chev { width: 14px; height: 14px; transition: transform 0.2s ease; }
.collapsed .group-toggle .chev { transform: rotate(-90deg); }
/* Sidebar headings span the full width with the chevron at the right */
.nav-section.group-toggle {
  display: flex;
  width: calc(100% - 20px);
  justify-content: space-between;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.nav-section.group-toggle:hover { color: var(--text); }
.nav-section.group-toggle .chev { opacity: 0; }
.sidebar:hover .nav-section.group-toggle .chev,
.nav-section.group-toggle:focus-visible .chev,
.collapsed > .nav-section.group-toggle .chev { opacity: 1; }
@media (hover: none) { .nav-section.group-toggle .chev { opacity: 1; } }
.tile-group.collapsed { margin-bottom: 16px; }
.tile-group.collapsed .group-title { margin-bottom: 0; }

.link-btn {
  margin-left: 8px;
  padding: 0;
  border: none;
  background: none;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: normal;
  text-transform: none;
  color: var(--accent-text);
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }

/* ---------- Form controls ---------- */
.input {
  width: 100%;
  min-width: 0;
  font: inherit;
  color: inherit;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.input:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
.input.mono-in, textarea.mono-in { font-family: var(--mono); font-size: 0.92rem; }
.input.invalid, textarea.invalid { border-color: var(--danger); }
select.input { cursor: pointer; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.row + .row, .row + .checks, .checks + .row, .field + .field { margin-top: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 140px; min-width: 0; }
.field .field-label { margin: 0; }
.field-label .val { float: right; color: var(--text); font-family: var(--mono); }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.88rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.check input { margin: 0; accent-color: var(--accent); }
.check:has(input:checked) { border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); background: var(--accent-soft); color: var(--accent-text); }
input[type="range"] { width: 100%; accent-color: var(--accent); margin: 6px 0 0; }
input[type="color"] { width: 48px; height: 42px; padding: 0; border: 1px solid var(--border); border-radius: 10px; background: none; cursor: pointer; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn-sm { padding: 8px 14px; font-size: 0.88rem; border-radius: 10px; display: inline-flex; align-items: center; gap: 6px; }
.btn-sm .ico { width: 16px; height: 16px; }
.btn-ghost { border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent-text); }
.card > .field-label:not(:first-child) { margin-top: 16px; }
.card-title { margin: 0 0 12px; font-size: 0.95rem; font-weight: 600; }

/* ---------- Output blocks ---------- */
.mono.pre { white-space: pre; overflow-x: auto; overflow-wrap: normal; }
.mono.tall { max-height: 460px; }
.out-list { display: grid; }
.out-row {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.out-row:first-child { border-top: none; padding-top: 0; }
.out-row:last-child { padding-bottom: 0; }
.out-name { font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.out-val { font-family: var(--mono); font-size: 0.9rem; overflow-wrap: anywhere; min-width: 0; }
.out-val:empty::before { content: "—"; color: var(--muted); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 14px; }
.stat-v { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-l { font-size: 0.8rem; color: var(--muted); }
.kv { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.kv th, .kv td { padding: 8px 0; border-top: 1px solid var(--border); text-align: left; vertical-align: top; }
.kv tr:first-child th, .kv tr:first-child td { border-top: none; }
.kv th { width: 34%; padding-right: 12px; font-weight: 600; color: var(--muted); font-size: 0.82rem; }
.kv td { font-family: var(--mono); overflow-wrap: anywhere; }
.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; font-family: var(--font); vertical-align: middle; }
.badge.ok { background: color-mix(in srgb, var(--success) 16%, transparent); color: var(--success); }
.badge.bad { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.badge.warn { background: color-mix(in srgb, #f59e0b 18%, transparent); color: var(--warn-text); }
.meter { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.meter > span { display: block; height: 100%; width: 0; border-radius: inherit; transition: width 0.25s, background 0.25s; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.two-col > .card { margin-bottom: 0; }
.two-col + .card, .two-col + .two-col { margin-top: 16px; }
.big-out { font-size: 1.15rem; padding: 16px; text-align: center; letter-spacing: 0.02em; }

@media (max-width: 800px) {
  .two-col { grid-template-columns: 1fr; }
  .out-row { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; }
  .out-name { grid-column: 1 / -1; }
  .search { max-width: none; }
}

/* ---------- App-specific ---------- */
/* Number base */
.nb-grid { display: grid; gap: 14px; }
.input-copy { display: flex; gap: 8px; align-items: center; }
.input-copy .input { flex: 1; }
/* Color */
.swatch {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  height: 120px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 2rem;
  font-weight: 700;
}
.swatch span:first-child { color: #fff; }
.swatch span:last-child { color: #000; }
/* QR */
.qr-card { text-align: center; }
.qr-box { display: inline-grid; place-items: center; padding: 8px; background: #fff; border-radius: 12px; border: 1px solid var(--border); }
.qr-box canvas { display: block; width: 240px; max-width: 100%; height: auto; image-rendering: pixelated; }
.qr-actions { justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
a.btn { text-decoration: none; color: var(--text); }
a.btn-primary { color: #fff; }
/* Diff */
.diff-out { white-space: pre-wrap; padding: 8px 0; }
.diff-line { padding: 1px 14px 1px 0; }
.diff-sign { display: inline-block; width: 28px; text-align: center; color: var(--muted); user-select: none; }
.diff-line.ins { background: color-mix(in srgb, var(--success) 15%, transparent); }
.diff-line.del { background: color-mix(in srgb, var(--danger) 13%, transparent); }
.diff-line.ins .diff-sign { color: var(--success); }
.diff-line.del .diff-sign { color: var(--danger); }
.diff-out:not(:has(.diff-line)) { padding: 12px 14px; }
.diff-out ins { text-decoration: none; background: color-mix(in srgb, var(--success) 22%, transparent); border-radius: 3px; }
.diff-out del { background: color-mix(in srgb, var(--danger) 18%, transparent); border-radius: 3px; }
/* Regex */
.re-pattern { display: flex; align-items: center; gap: 6px; font-family: var(--mono); color: var(--muted); font-size: 1.1rem; }
.re-pattern .input { flex: 1; color: var(--text); font-size: 0.92rem; }
.re-out { white-space: pre-wrap; min-height: 160px; }
.re-out mark { color: inherit; border-radius: 3px; padding: 1px 0; }
.re-out mark.m0 { background: color-mix(in srgb, var(--accent) 28%, transparent); }
.re-out mark.m1 { background: color-mix(in srgb, var(--accent-2) 30%, transparent); }
.re-empty { display: inline-block; width: 2px; height: 1em; vertical-align: middle; background: var(--accent); }
.re-list { display: grid; gap: 12px; max-height: 420px; overflow-y: auto; }
.re-item { padding: 12px; border-radius: 12px; background: var(--surface-2); }
.re-item-head { margin-bottom: 4px; font-size: 0.9rem; }
.re-item-head code { font-family: var(--mono); overflow-wrap: anywhere; }
.re-item .kv { margin-top: 6px; }
.muted { color: var(--muted); }
/* GPS */
.gps-control { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.gps-state { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1 1 220px; }
.gps-state-title { font-weight: 600; }
.gps-dot { width: 12px; height: 12px; flex-shrink: 0; border-radius: 50%; background: var(--border); }
.gps-dot.searching { background: #f59e0b; animation: gps-pulse 1.2s ease-in-out infinite; }
.gps-dot.live { background: var(--success); box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 22%, transparent); }
.gps-dot.error { background: var(--danger); }
@keyframes gps-pulse { 50% { opacity: 0.35; } }
.gps-heading-stat { display: flex; align-items: center; gap: 12px; }
.gps-compass { width: 44px; height: 44px; flex-shrink: 0; }
.gps-compass circle { fill: none; stroke: var(--border); stroke-width: 2; }
.gps-compass text { font: 700 8px var(--font); fill: var(--muted); text-anchor: middle; dominant-baseline: middle; }
.gps-compass path { fill: var(--border); transform-origin: 24px 24px; transition: transform 0.4s ease; }
.gps-compass.on path { fill: var(--accent); }
.copy-btn:disabled { opacity: 0.45; cursor: not-allowed; }
/* Compass */
.cmp-card { text-align: center; }
.cmp-wrap { width: min(300px, 100%); margin: 0 auto; }
.cmp-dial { display: block; width: 100%; height: auto; overflow: visible; }
.cmp-rose { transform-origin: 100px 100px; }
.cmp-ring { fill: var(--surface-2); stroke: var(--border); stroke-width: 2; }
.cmp-tick { stroke: var(--muted); stroke-width: 1; opacity: 0.6; }
.cmp-tick-l { stroke: var(--text); stroke-width: 2; }
.cmp-n, .cmp-c { font: 700 16px var(--font); text-anchor: middle; dominant-baseline: middle; fill: var(--text); }
.cmp-n { fill: var(--danger); font-size: 20px; }
.cmp-north { fill: var(--danger); }
.cmp-south { fill: var(--muted); opacity: 0.55; }
.cmp-hub { fill: var(--surface); stroke: var(--text); stroke-width: 2; }
.cmp-lubber { fill: var(--accent); }
.cmp-readout { margin-top: 12px; }
.cmp-deg { font-size: 2.6rem; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.cmp-dir { color: var(--muted); font-weight: 600; }

/* ---------- Install popup ---------- */
.install-sheet {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.04), 0 16px 48px rgba(17, 19, 31, 0.22);
  z-index: 30;
  animation: sheet-up 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes sheet-up { from { transform: translateY(calc(100% + 24px)); opacity: 0; } to { transform: none; opacity: 1; } }
.install-close { position: absolute; top: 8px; right: 8px; width: 34px; height: 34px; color: var(--muted); }
.install-close .ico { width: 18px; height: 18px; }
.install-head { display: flex; align-items: center; gap: 14px; padding-right: 28px; }
.install-icon { width: 52px; height: 52px; border-radius: 14px; flex-shrink: 0; box-shadow: 0 4px 12px rgba(91, 91, 240, 0.3); }
.install-title { font-weight: 700; font-size: 1.02rem; }
.install-text { font-size: 0.88rem; color: var(--muted); line-height: 1.4; }
.install-actions { display: flex; gap: 10px; margin-top: 16px; }
.install-actions .btn { flex: 1; }
.btn {
  font: inherit;
  font-weight: 600;
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
}
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; box-shadow: 0 4px 14px rgba(91, 91, 240, 0.35); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.install-steps { list-style: none; margin: 16px 0 0; padding: 14px; display: grid; gap: 10px; background: var(--surface-2); border-radius: 14px; font-size: 0.92rem; }
.install-steps li { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.step-n { display: inline-grid; place-items: center; width: 22px; height: 22px; margin-right: 4px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 0.75rem; font-weight: 700; }
.kbd { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); font-weight: 600; }
.kbd .ico { width: 15px; height: 15px; color: var(--accent-text); }
.kbd { white-space: nowrap; }

/* Keep the popup compact on small or short screens */
@media (max-width: 380px), (max-height: 560px) {
  .install-sheet { padding: 14px; border-radius: 16px; }
  .install-icon { width: 40px; height: 40px; border-radius: 11px; }
  .install-text { display: none; }
  .install-actions { margin-top: 12px; }
  .install-actions .btn { padding: 9px 12px; }
  .install-steps { margin-top: 12px; padding: 10px 12px; gap: 8px; font-size: 0.86rem; }
}
@media (max-height: 560px) {
  .install-steps { display: flex; flex-wrap: wrap; gap: 8px 20px; }
}

/* ---------- Mobile ---------- */
.topbar, .backdrop { display: none; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }

@media (max-width: 800px) {
  .topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    position: sticky;
    top: 0;
    height: 56px;
    padding: 0 8px;
    background: color-mix(in srgb, var(--surface) 85%, transparent);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    z-index: 10;
  }
  .topbar-title { font-weight: 600; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: none;
  }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, 0.2); }
  body.nav-open .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 20, 0.4);
    backdrop-filter: blur(2px);
    z-index: 15;
  }
  .content { margin-left: 0; padding: 24px 16px 48px; }
  .card { padding: 16px; }
  .page-head h1 { font-size: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
/* Screen Flashlight */
.fl-card { text-align: center; }
.fl-power {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 132px;
  height: 132px;
  margin: 8px auto 4px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.fl-power:hover { box-shadow: var(--shadow-lg); }
.fl-power:active { transform: scale(0.96); }
.fl-power:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.fl-power svg { position: relative; width: 52px; height: 52px; stroke-width: 1.6; }
.fl-glow { position: absolute; inset: 22%; border-radius: 50%; opacity: 0.35; filter: blur(18px); }
.fl-power-label { font-weight: 600; }
.fl-card .status { margin-bottom: 0; }
.fl-help { margin: 8px 0 14px; font-size: 0.9rem; }
.fl-colors { display: flex; flex-wrap: wrap; gap: 10px; }
.fl-color { position: relative; display: grid; justify-items: center; gap: 4px; cursor: pointer; }
.fl-color input { position: absolute; opacity: 0; pointer-events: none; }
.fl-color span {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--c);
  border: 1px solid var(--border);
  box-shadow: inset 0 0 0 3px var(--surface);
}
.fl-color em { font-style: normal; font-size: 0.75rem; color: var(--muted); }
.fl-color input:checked + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.fl-color input:checked ~ em { color: var(--text); font-weight: 600; }
.fl-color input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 4px; }
.fl-warn { color: var(--warn-text); margin-bottom: 0; }
.tip-list { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 0.92rem; }
/* The light itself: real colours on purpose, not theme tokens. */
.fl-overlay { position: fixed; inset: 0; z-index: 1000; background: #000; cursor: pointer; outline: none; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.fl-light { position: absolute; inset: 0; opacity: 0; }
.fl-overlay.flashing .fl-light { transition: none; }
.fl-hint, .fl-caption {
  position: absolute;
  left: 0;
  right: 0;
  text-align: center;
  color: #fff;
  mix-blend-mode: difference;
  pointer-events: none;
}
.fl-hint { bottom: calc(24px + env(safe-area-inset-bottom)); font: 600 0.95rem var(--font); opacity: 0.55; animation: fl-fade 4s ease forwards; }
.fl-caption { bottom: calc(60px + env(safe-area-inset-bottom)); font: 800 1.6rem var(--font); letter-spacing: 0.4em; }
.fl-caption span { opacity: 0.35; }
.fl-caption span.on { opacity: 0.9; }
@keyframes fl-fade { 0%, 60% { opacity: 0.55; } 100% { opacity: 0.18; } }
html.fl-active, html.fl-active body { overflow: hidden; }
/* Bubble Level */
.lv-card { text-align: center; }
.lv-mode { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 8px; }
.lv-dial { display: block; width: min(280px, 100%); height: auto; margin: 0 auto; }
.lv-tube { display: block; width: min(420px, 100%); height: auto; margin: 24px auto; }
.lv-ring { fill: var(--surface-2); stroke: var(--border); stroke-width: 2; }
.lv-guide { fill: none; stroke: var(--border); stroke-width: 1.5; }
.lv-cross { stroke: var(--border); stroke-width: 1.5; }
.lv-target { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 3 3; }
.lv-bubble { fill: color-mix(in srgb, var(--accent) 70%, transparent); stroke: var(--accent); stroke-width: 2; transition: fill 0.2s, stroke 0.2s; }
.lv-card.is-level .lv-bubble { fill: color-mix(in srgb, var(--success) 70%, transparent); stroke: var(--success); }
.lv-readout { margin-top: 12px; }
.lv-deg { font-size: 2.6rem; font-weight: 800; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.lv-card.is-level .lv-deg, .lv-card.is-level .lv-sub { color: var(--success); }
.lv-sub { color: var(--muted); font-weight: 600; }
.lv-actions { justify-content: center; }
/* Sound Meter */
.snd-card { text-align: center; }
.snd-now { font-size: 4rem; font-weight: 800; letter-spacing: -0.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.snd-now small { font-size: 1.2rem; font-weight: 700; color: var(--muted); margin-left: 6px; letter-spacing: 0; }
.snd-level { margin-top: 6px; font-weight: 600; color: var(--muted); }
.snd-level.ok { color: var(--success); }
.snd-level.warn { color: var(--warn-text); }
.snd-level.bad { color: var(--danger); }
.snd-bar { position: relative; height: 12px; margin-top: 18px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.snd-bar span { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--success); }
.snd-bar span[data-level="warn"] { background: #f59e0b; }
.snd-bar span[data-level="bad"] { background: var(--danger); }
.snd-bar i { position: absolute; top: 0; bottom: 0; width: 2px; left: 0; background: var(--text); opacity: 0.6; }
.snd-scale { display: flex; justify-content: space-between; margin-top: 4px; font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.snd-graph { display: block; width: 100%; height: 140px; margin-top: 16px; border-radius: 12px; background: var(--surface-2); }
.snd-ref { margin-top: 12px; }
.snd-ref td { font-family: var(--font); }
/* QR Scanner */
.qs-view { position: relative; overflow: hidden; border-radius: 12px; background: #000; aspect-ratio: 4 / 3; max-height: 60vh; }
.qs-view video { display: block; width: 100%; height: 100%; object-fit: cover; }
.qs-frame { position: absolute; left: 50%; top: 50%; width: min(62%, 62vh); aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 18px; box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35); outline: 3px solid rgba(255, 255, 255, 0.9); outline-offset: -3px; }
.qs-cam-actions { justify-content: center; }
.qs-cam-actions:not(:has(> :not([hidden]))) { display: none; }
.qs-result { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 260px; overflow-y: auto; }
.qs-wifi { margin-top: 12px; }
/* NFC Reader */
.nfc-unsupported p { margin: 0; }
.nfc-wait { text-align: center; }
.nfc-wait p { margin: 10px 0 0; }
.nfc-pulse { display: inline-grid; place-items: center; width: 72px; height: 72px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); animation: gps-pulse 1.6s ease-in-out infinite; }
.nfc-pulse svg { width: 34px; height: 34px; }
.nfc-reads { display: grid; gap: 12px; }
.nfc-read { padding: 12px; border-radius: 12px; background: var(--surface-2); }
.nfc-read-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; font-size: 0.9rem; }
.nfc-read .out-row { border-color: var(--border); }
.nfc-val { white-space: pre-wrap; }
/* Percentage Calculator */
.pc-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; font-size: 1rem; }
.pc-line .pc-in { width: 5.5em; flex: 0 1 5.5em; min-width: 4em; padding-left: 10px; padding-right: 10px; font-family: var(--mono); }
.pc-line .pc-sel { width: auto; flex: 0 0 auto; }
.pc-result { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.pc-out { min-width: 0; font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pc-out.up { color: var(--success); }
.pc-out.down { color: var(--danger); }
.pc-note { margin-bottom: 0; }
/* Unit Converter */
.un-pair { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 12px; align-items: center; margin-top: 14px; }
.un-pair .field + .field { margin-top: 0; }
.un-pair .field .input + .input { margin-top: 2px; }
.un-pair .mono-in { font-size: 1.15rem; }
.un-swap { font-size: 1.2rem; padding: 6px 12px; margin-top: 22px; }
.un-sum { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.un-sum output { min-width: 0; font-size: 1.05rem; font-weight: 600; overflow-wrap: anywhere; }
.un-sum output:empty::before { content: "—"; color: var(--muted); }
.out-row.un-current .out-name { color: var(--accent-text); }
@media (max-width: 560px) {
  .un-pair { grid-template-columns: minmax(0, 1fr); }
  .un-swap { justify-self: center; margin-top: 0; transform: rotate(90deg); }
}
.pc-grp { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
/* Encrypt / Decrypt */
section[data-app="encrypt"] > .segmented { margin-bottom: 16px; }
.enc-keytype { align-self: flex-start; }
section[data-app="encrypt"] .row > .field { flex: 1 1 240px; }
section[data-app="encrypt"] .field > .segmented { margin-bottom: 0; align-self: flex-start; }
section[data-app="encrypt"] .segmented span { white-space: nowrap; }
#encFormatNote { margin: 6px 0 0; }
#encAlgNote { margin: 10px 0 14px; }
.status.enc-warn { color: var(--warn-text); }
.enc-adv { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.enc-adv summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; color: var(--muted); width: max-content; }
.enc-adv summary:hover { color: var(--text); }
.enc-adv[open] summary { margin-bottom: 12px; }
.enc-adv .field + .field, .enc-adv .row + .field, .enc-adv #encRawParams + .field { margin-top: 14px; }
.enc-adv #encRawParams { margin-top: 14px; }
.enc-out { white-space: pre-wrap; overflow-wrap: anywhere; min-height: 64px; max-height: 360px; overflow-y: auto; }
.enc-out:empty::before { content: "—"; color: var(--muted); }
#encGo { display: inline-flex; align-items: center; gap: 8px; }
#encGo .ico { width: 18px; height: 18px; }
