/* Layout: sticky masthead + section nav, then grouped test cards (1 column on phone, 2 on wide), then API matrix and report */
:root {
  --bg: #EDEFF4;
  --surface: #FFFFFF;
  --sunken: #F4F5F8;
  --line: #D7DBE4;
  --fg: #151922;
  --muted: #5B6374;
  --accent: #3245C4;
  --accent-fg: #FFFFFF;
  --ok: #1B7A4F;   --ok-bg: #E1F2E8;
  --bad: #B03923;  --bad-bg: #F7E4DF;
  --warn: #855709; --warn-bg: #F5ECD6;
  --idle: #5B6374; --idle-bg: #E6E9EF;
  --font-ui: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1116; --surface: #181B22; --sunken: #13161C; --line: #2A2F3A; --fg: #E7E9EF; --muted: #969DAD;
    --accent: #8C9AFF; --accent-fg: #0F1116;
    --ok: #5CCB95; --ok-bg: #16291F; --bad: #F27D66; --bad-bg: #2E1A16; --warn: #E2B254; --warn-bg: #2B2414;
    --idle: #969DAD; --idle-bg: #23272F;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(env(safe-area-inset-top, 0px) + 120px); }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
h1, h2, h3 { text-wrap: balance; }
p { margin: 0; }
.muted { color: var(--muted); font-size: 14px; }
code, .mono { font-family: var(--font-mono); font-size: 12.5px; }
[hidden] { display: none !important; }

/* masthead */
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.masthead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding-block: 12px 8px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img { border-radius: 10px; flex: none; }
.brand h1 { margin: 0; font-size: 20px; line-height: 1.2; letter-spacing: -0.01em; }
.sub { color: var(--muted); font-size: 13px; }
.env-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.secnav-inner {
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  padding-block: 4px 8px;
}
.secnav-inner::-webkit-scrollbar { display: none; }
.secnav a {
  flex: none; color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600;
  padding: 6px 12px; border-radius: 999px;
}
.secnav a:hover, .secnav a:focus-visible { color: var(--fg); background: var(--surface); outline: none; }

main { display: grid; grid-template-columns: minmax(0, 1fr); gap: 32px; padding-block: 20px 48px; }
main > * { min-width: 0; }

/* chips */
.chip {
  display: inline-flex; align-items: center; gap: 4px; flex: none;
  font-size: 12.5px; font-weight: 600; line-height: 1.5;
  padding: 2px 9px; border-radius: 999px; white-space: nowrap;
  color: var(--idle); background: var(--idle-bg);
}
.chip.ok { color: var(--ok); background: var(--ok-bg); }
.chip.bad { color: var(--bad); background: var(--bad-bg); }
.chip.warn { color: var(--warn); background: var(--warn-bg); }

/* install guide + summary */
.install-guide {
  background: var(--warn-bg); color: var(--fg);
  border-radius: 14px; padding: 16px 18px;
  display: grid; gap: 8px;
}
.install-guide h2 { margin: 0; font-size: 17px; color: var(--warn); }
.install-guide ol { margin: 0; padding-left: 1.3em; display: grid; gap: 4px; }

.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stat b { display: block; font-size: 24px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.ok b { color: var(--ok); }
.stat.bad b { color: var(--bad); }
.stat.warn b { color: var(--warn); }

/* groups & cards */
.group > h2 {
  font-size: 13px; margin: 0 0 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700;
}
.cards { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 860px) { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; } }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  display: grid; gap: 10px;
  min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.card-head > div { min-width: 0; }
.card-head h3 { margin: 0; font-size: 16px; line-height: 1.35; }
.card-head code { color: var(--muted); overflow-wrap: anywhere; }
.desc { color: var(--muted); font-size: 14px; }
.card-body { display: grid; gap: 10px; min-width: 0; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
button, .btn {
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  min-height: 40px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--sunken); color: var(--fg);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button:active { transform: scale(0.97); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
input[type="text"], input[type="number"], textarea, select {
  font: inherit; font-size: 16px; /* 16px stops iOS zoom on focus */
  color: var(--fg); background: var(--sunken);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; min-height: 40px; min-width: 0;
}
input[type="number"] { width: 6em; }
textarea { width: 100%; resize: vertical; }
.btn input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.btn { position: relative; text-decoration: none; }

.kv {
  display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0;
  font-size: 13.5px;
}
.kv dt { color: var(--muted); white-space: nowrap; }
.kv dd { margin: 0; text-align: right; font-family: var(--font-mono); font-size: 12.5px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; min-width: 0; }

.log {
  margin: 0; max-height: 168px; overflow: auto;
  background: var(--sunken); border-radius: 10px; padding: 8px 10px;
  font-family: var(--font-mono); font-size: 12px; line-height: 1.55;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.log .ok { color: var(--ok); }
.log .bad { color: var(--bad); }
.log .warn { color: var(--warn); }

.media-box { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 4 / 3; max-width: 100%; }
.media-box video, .media-box canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }

.meter { height: 12px; background: var(--sunken); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.meter > i { display: block; height: 100%; width: 0%; background: var(--accent); transition: width 60ms linear; }

.level {
  position: relative; width: 150px; height: 150px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--sunken); margin: 0 auto;
}
.level::before, .level::after { content: ""; position: absolute; background: var(--line); }
.level::before { left: 50%; top: 8px; bottom: 8px; width: 1px; }
.level::after { top: 50%; left: 8px; right: 8px; height: 1px; }
.level i {
  position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px;
  border-radius: 50%; background: var(--accent); z-index: 1;
}

.fs-demo {
  display: grid; place-items: center; min-height: 90px; border-radius: 10px;
  background: var(--sunken); border: 1px dashed var(--line); color: var(--muted); font-size: 14px;
}
.fs-demo:fullscreen { background: var(--accent); color: var(--accent-fg); font-size: 22px; }

/* matrix */
.matrix-group { margin-bottom: 16px; }
.matrix-group h3 { font-size: 14px; margin: 0 0 6px; }
.matrix-scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 12px; border-top: 1px solid var(--line); vertical-align: top; }
tr:first-child td { border-top: 0; }
td .m-name { font-weight: 600; }
td .api { font-family: var(--font-mono); font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
td .note { color: var(--warn); font-size: 12.5px; margin-top: 2px; }
td.res { white-space: nowrap; width: 1%; text-align: right; vertical-align: middle; }

.report {
  margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; font-family: var(--font-mono); font-size: 12px; line-height: 1.6;
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 420px; overflow: auto;
  -webkit-user-select: text; user-select: text;
}

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  max-width: min(92vw, 480px);
  background: var(--fg); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18); z-index: 50;
}

.haptic-trigger { position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; overflow: hidden; }

@media (prefers-reduced-motion: reduce) {
  button:active { transform: none; }
  .meter > i { transition: none; }
}
#matrix > p.muted { margin-bottom: 14px; }
