/* Continuum PWA — mobile-first, light/dark via prefers-color-scheme. */
:root {
  --bg: #f6f8f8;
  --surface: #ffffff;
  --surface-2: #eef3f2;
  --text: #0f1b1d;
  --muted: #56666a;
  --border: #d7e0df;
  --accent: #0f766e;
  --accent-strong: #0b5f58;
  --accent-contrast: #ffffff;
  --accent-soft: #e2f3f0;
  --ok: #047857;
  --ok-soft: #e3f5ec;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --danger: #b42318;
  --danger-soft: #fdeceb;
  --focus: #1d7fd6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 27, 29, .06), 0 4px 16px rgba(15, 27, 29, .05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1214;
    --surface: #121c1f;
    --surface-2: #18252a;
    --text: #e6eeee;
    --muted: #93a5a8;
    --border: #25363b;
    --accent: #2bb3a3;
    --accent-strong: #52c9bb;
    --accent-contrast: #04211e;
    --accent-soft: #10312e;
    --ok: #4ccf93;
    --ok-soft: #0f2d21;
    --warn: #f0b54a;
    --warn-soft: #2f2412;
    --danger: #ff7b6e;
    --danger-soft: #331816;
    --focus: #6cb6ff;
    --shadow: none;
  }
}
* { 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;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.pad { padding: 1rem; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: 1rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: calc(.6rem + env(safe-area-inset-top)) 1rem .6rem;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; font-size: 1.1rem; letter-spacing: .01em; }
.brand img { border-radius: 8px; }
.topbar-actions { display: flex; gap: .5rem; align-items: center; }

main { max-width: 640px; margin: 0 auto; padding: 1rem; outline: none; }
.stack > * + * { margin-top: 1rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.card.soft { background: var(--surface-2); box-shadow: none; }
.row { display: flex; align-items: center; gap: .75rem; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.badge {
  display: inline-flex; align-items: center; gap: .35rem;
  font-size: .8rem; font-weight: 600; padding: .15rem .6rem; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

button, .btn {
  -webkit-appearance: none; appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 44px; padding: .55rem 1rem;
  font: inherit; font-weight: 600; text-decoration: none;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
}
button:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover, button.primary:hover { background: var(--accent-strong); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost, .btn.ghost { background: transparent; }
button.link { min-height: 0; padding: 0; border: 0; background: none; color: var(--accent); font-weight: 600; }
.block { width: 100%; }
.btns { display: flex; flex-wrap: wrap; gap: .5rem; }
.btns > * { flex: 1 1 auto; }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
input, select {
  width: 100%; min-height: 44px; padding: .55rem .75rem;
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
}
input[readonly] { background: var(--surface-2); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; }
.field + .field { margin-top: .75rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.error { color: var(--danger); font-size: .9rem; min-height: 1.2em; margin-top: .4rem; }
.hint { color: var(--muted); font-size: .85rem; margin-top: .3rem; }

.copyrow { display: flex; gap: .5rem; }
.copyrow input { flex: 1; min-width: 0; }
.copyrow button { flex: none; }
.linkblock + .linkblock { margin-top: .75rem; }

.qr {
  display: block; width: 100%; max-width: 280px; margin: .25rem auto .75rem;
  background: #fff; padding: 12px; border-radius: 12px; border: 1px solid var(--border);
}
.qr svg { display: block; width: 100%; height: auto; }

.device-head { display: flex; align-items: center; gap: .75rem; }
.device-icon {
  flex: none; width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 700;
}
.device-detail { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.confirm { margin-top: .75rem; padding: .75rem; border-radius: 10px; background: var(--danger-soft); }
.confirm p { margin-bottom: .6rem; }

.state { text-align: center; padding: 1.5rem 1rem; }
.state .glyph { font-size: 2.2rem; line-height: 1; margin-bottom: .5rem; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.stat { background: var(--surface-2); border-radius: 10px; padding: .6rem; text-align: center; }
.stat b { display: block; font-size: 1.3rem; }
.stat span { font-size: .75rem; color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: .75rem 0; border-top: 1px solid var(--border); }
.list > li:first-child { border-top: 0; }

.steps { margin: .25rem 0 0; padding-left: 1.25rem; }
.steps li + li { margin-top: .35rem; }
details.help { border-top: 1px solid var(--border); padding: .6rem 0; }
details.help:first-of-type { border-top: 0; }
details.help summary { cursor: pointer; font-weight: 600; min-height: 32px; display: flex; align-items: center; }

.banner {
  background: var(--warn-soft); color: var(--warn); font-size: .85rem;
  padding: .5rem 1rem; text-align: center;
}
.banner a { color: inherit; font-weight: 600; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; max-width: 160px; min-height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 600;
}
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a[aria-current="page"] { color: var(--accent); }

.toasts { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20; display: grid; gap: .5rem; width: min(92vw, 420px); }
.toast { background: var(--text); color: var(--bg); padding: .65rem 1rem; border-radius: 10px; font-size: .9rem; box-shadow: var(--shadow); }

@media (min-width: 720px) {
  main { padding: 1.5rem 1rem; }
  h1 { font-size: 1.75rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: rise .18s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}

/* ---- contextual help (src/help.js): (i) button + shared popover; light/dark via tokens */
.row.tight { gap: .35rem; }
.row.center-row { justify-content: center; }
.ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.labelrow { display: flex; align-items: center; gap: .3rem; margin-bottom: .3rem; }
.labelrow label { margin: 0; }
button.tip {
  position: relative; flex: none; vertical-align: middle;
  width: 22px; height: 22px; min-height: 0; padding: 0; margin: 0 0 0 .15rem;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
button.tip svg { width: 18px; height: 18px; }
button.tip::after { content: ""; position: absolute; inset: -11px; } /* 44px touch target */
button.tip { -webkit-tap-highlight-color: transparent; }
button.tip:hover, button.tip[aria-expanded="true"] { color: var(--accent); }
.stat span { display: inline-flex; align-items: center; justify-content: center; flex-wrap: wrap; }
.stat span button.tip { width: 18px; height: 18px; }
.stat span button.tip svg { width: 15px; height: 15px; }
summary button.tip { margin-left: .3rem; }
.helppop {
  position: fixed; z-index: 30; top: 0; left: 0; max-height: min(60vh, 420px); overflow: auto;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; padding: .75rem .9rem;
  box-shadow: 0 8px 28px rgba(15, 27, 29, .18); font-size: .9rem; line-height: 1.45; text-align: left;
  outline: none;
}
.helppop[hidden] { display: none; }
.helppop-title { font-weight: 700; margin: 0 0 .35rem; padding-right: 2rem; }
.helppop:not(.pinned) .helppop-title { padding-right: 0; }
.helppop-body p { margin: 0 0 .5rem; }
.helppop-body p:last-child { margin-bottom: 0; }
button.helppop-close {
  position: absolute; top: .3rem; right: .3rem; width: 36px; height: 36px; min-height: 0; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 1.4rem; line-height: 1;
}
button.helppop-close:hover { background: var(--surface-2); color: var(--text); }
select.lang {
  width: auto; min-height: 36px; padding: .25rem 1.4rem .25rem .5rem; font-size: .85rem; font-weight: 600;
  background: transparent; border-color: var(--border); border-radius: 8px;
}
@media (prefers-color-scheme: dark) {
  .helppop { background: var(--surface-2); border-color: #3a5157; box-shadow: 0 8px 28px rgba(0, 0, 0, .55); }
}

/* device card: keep card padding inside list */
.list > li.card { padding: 1rem; }
