:root {
  color-scheme: light dark;
  --background: #f1f4f4;
  --surface: #fff;
  --soft: #edf2f2;
  --text: #172927;
  --muted: #536461;
  --border: #d8e2df;
  --control-border: #879a95;
  --accent: #176456;
  --accent-ink: #fff;
  --accent-soft: #e3f1ed;
  --warn: #795016;
  --warn-soft: #fbefd9;
  --danger: #9c3439;
  --plot-bg: #122d2b;
  --plot-line: #56877f;
  --plot-text: #eef9f5;
  --plot-muted: #adccc6;
  --plot-badge: #244842;
  --sans: system-ui, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
  font-family: var(--sans);
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #111716;
    --surface: #192220;
    --soft: #222f2b;
    --text: #edf6f2;
    --muted: #a9bcb5;
    --border: #30423c;
    --control-border: #667f76;
    --accent: #8bd6c3;
    --accent-ink: #10332a;
    --accent-soft: #234039;
    --warn: #f2ca89;
    --warn-soft: #46381f;
    --danger: #f0a5a8;
    --plot-bg: #152d2a;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--text); background: var(--background); font-size: .94rem; line-height: 1.6; }
h1, h2, p { margin: 0; }
button, select, input { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.masthead { background: var(--surface); border-bottom: 1px solid var(--border); }
.masthead-inner, .page { width: min(100% - 64px, 1112px); margin-inline: auto; }
.masthead-inner, .masthead-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.masthead-inner { min-height: 72px; }
.logo, .logo img { display: block; max-width: 100%; }
.indicator, .pill, .badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 3px 10px;
  border-radius: 99px;
  color: var(--muted);
  background: var(--soft);
  font-size: .76rem;
  line-height: 1.65;
  white-space: nowrap;
}
.indicator::before, .timeline-dot {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.indicator[data-state="live"], .badge[data-tone="live"] { color: var(--accent); background: var(--accent-soft); }
.indicator[data-state="error"], .badge[data-tone="warn"] { color: var(--warn); background: var(--warn-soft); }

.page { padding-top: 44px; }
.intro { display: flex; justify-content: space-between; align-items: end; gap: 28px; margin-bottom: 27px; }
.eyebrow { font: 600 .76rem/1.3 var(--mono); color: var(--accent); letter-spacing: .14em; }
h1 { font-size: clamp(2.3rem, 4.9vw, 3.4rem); line-height: 1.2; letter-spacing: -.065em; margin: 10px 0 8px; }
h2 { font-size: 1.06rem; line-height: 1.35; }
.intro-copy, .gate-content > p, .activity-heading p, .dialog-note { color: var(--muted); }
.intro-mark { color: var(--accent); width: 144px; height: 54px; flex: none; }
.intro-mark svg { width: 100%; stroke: currentColor; stroke-width: 1.2; }
.intro-mark svg path + path { opacity: .22; }
.intro-mark circle { fill: var(--background); }

.card {
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 16px;
}
.gate { display: flex; align-items: flex-start; gap: 20px; padding: clamp(20px, 4vw, 36px); }
.gate-content { min-width: 0; }
.gate h2 { font-size: 1.28rem; margin-bottom: 6px; }
.gate-icon, .reading-icon {
  display: grid;
  place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
  flex: none;
}
.gate-icon { width: 48px; height: 48px; border-radius: 13px; }
.gate-icon svg, .reading-icon svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
#login, .copy-row { display: flex; gap: 8px; margin-top: 16px; }
.button, select, input[type="text"], input[type="password"] {
  border: 1px solid var(--control-border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text);
  min-height: 42px;
  padding: 7px 12px;
}
input[type="text"], input[type="password"] { width: min(19rem, 100%); min-width: 0; }
.button { cursor: pointer; white-space: nowrap; font-size: .85rem; font-weight: 650; }
.button:hover { background: var(--soft); }
.button:disabled { cursor: wait; opacity: .68; }
.button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.button.primary:hover { filter: brightness(.92); }
.button.danger { color: var(--danger); }
.feedback { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.feedback:empty { display: none; }
.feedback:not(:empty) { margin-top: 10px; }
.error { color: var(--danger); }

.device-bar { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-bottom: 14px; }
.device-select, .device-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.device-select select { max-width: 100%; width: 14rem; font-weight: 650; text-overflow: ellipsis; }
.device-select select:disabled { opacity: .8; }
.device-select .pill { flex: none; }
#dashboard-message:not(:empty) { margin: 0 0 14px; }
.readings { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 14px; }
.secondary-readings { display: grid; gap: 14px; }
.reading { padding: 17px 20px; }
.reading-heading, .reading-label { display: flex; align-items: center; gap: 9px; }
.reading-heading { justify-content: space-between; }
.reading-icon { width: 32px; height: 32px; border-radius: 9px; }
.reading-icon svg { width: 18px; height: 18px; }
.location {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  min-height: 275px;
  display: flex;
  flex-direction: column;
  padding: 22px;
  color: var(--plot-text);
  border-color: transparent;
  background-color: var(--plot-bg);
  background-image: linear-gradient(#92c8bb0e 1px, transparent 1px), linear-gradient(90deg, #92c8bb0e 1px, transparent 1px);
  background-size: 24px 24px;
}
.location-plot { position: absolute; z-index: -1; width: min(94%, 440px); right: -23px; bottom: 1px; color: var(--plot-line); opacity: .55; pointer-events: none; }
.location-plot svg { display: block; width: 100%; stroke: currentColor; stroke-width: .85; }
.plot-dot { fill: currentColor; }
.location .badge, .location .reading-icon { background: var(--plot-badge); color: var(--plot-text); }
.location .badge[data-tone="live"] { background: #c9efe4; color: #1b4b42; }
.location .badge[data-tone="warn"] { background: #f6dfae; color: #583a0d; }
.location-reading { margin-block: auto; padding-block: 26px; }
.coordinates { font: 650 clamp(1.2rem, 3.35vw, 2.2rem)/1.2 var(--mono); letter-spacing: -.045em; overflow-wrap: anywhere; }
.reading-detail { color: var(--plot-muted); margin-top: 8px; font-size: .86rem; }
.reading-time { color: var(--muted); font-size: .78rem; line-height: 1.55; min-height: 1.21em; }
.location .reading-time { color: var(--plot-muted); }
.metric { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.reading-value { font: 650 1.92rem/1.25 var(--mono); letter-spacing: -.06em; margin-block: 7px 3px; }
.charge-value { font: 700 1.32rem/1.7 var(--sans); letter-spacing: 0; }
meter { width: min(38%, 120px); height: 9px; accent-color: var(--accent); }
meter::-webkit-meter-bar { height: 9px; border: 0; border-radius: 8px; background: var(--soft); }
meter::-webkit-meter-optimum-value { background: var(--accent); border-radius: 8px; }
meter::-moz-meter-bar { background: var(--accent); border-radius: 8px; }

.activity { margin-top: 14px; padding: 20px; }
.activity-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.activity-heading p, .empty { font-size: .84rem; margin-top: 5px; }
.empty { color: var(--muted); margin-top: 14px; padding-top: 13px; border-top: 1px solid var(--border); }
.timeline { list-style: none; padding: 0; margin: 12px 0 0; }
.timeline:empty { display: none; }
.timeline li {
  display: grid;
  grid-template-columns: 9px minmax(7.5rem, .85fr) minmax(12rem, 1.65fr) auto;
  align-items: center;
  gap: 12px;
  padding-block: 9px;
  border-top: 1px solid var(--border);
  font-size: .84rem;
}
.timeline-dot { background: var(--accent); }
.timeline-detail, .timeline time { color: var(--muted); }
.timeline time { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.footer { display: flex; flex-wrap: wrap; gap: 5px 16px; justify-content: space-between; color: var(--muted); margin-block: 21px 25px; font-size: .76rem; }
.footer span:first-child { font-family: var(--mono); }
.footer-separator { margin-inline: 4px; }

dialog { width: min(100% - 32px, 490px); color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 24px; }
dialog::backdrop { background: #0a1716b3; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.dialog-heading h2 { font-size: 1.32rem; margin-top: 5px; }
dialog p { font-size: .88rem; }
dialog fieldset { display: flex; flex-wrap: wrap; gap: 5px 14px; border: 0; margin: 9px 0; padding: 0; }
dialog label { cursor: pointer; }
dialog input[type="checkbox"] { accent-color: var(--accent); margin-inline-start: 0; }
.dialog-note { font-size: .78rem; margin-block: 9px 14px; }
#pair-result > label { display: block; color: var(--muted); font-size: .85rem; margin-top: 11px; }
.copy-row { margin-top: 5px; }
#pair-code { font-family: var(--mono); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 720px) {
  .masthead-inner, .page { width: calc(100% - 36px); }
  .page { padding-top: 30px; }
  .intro { margin-bottom: 21px; }
  .intro-mark { display: none; }
  .readings { grid-template-columns: 1fr; gap: 10px; }
  .secondary-readings { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .location { min-height: 235px; }
  .timeline li { grid-template-columns: 9px 1fr auto; gap: 4px 9px; }
  .timeline time { grid-column: 3; grid-row: 1; }
  .timeline-detail { grid-column: 2 / -1; }
}

@media (max-width: 500px) {
  .masthead-inner { min-height: 62px; }
  .logo { width: 150px; }
  .logo img { height: auto; }
  .masthead-actions { gap: 6px; }
  .indicator { padding-inline: 7px; }
  .device-bar { align-items: stretch; flex-direction: column; gap: 8px; }
  .device-select select { width: 100%; }
  .device-actions .button { flex: 1; }
  .secondary-readings { grid-template-columns: 1fr; }
  .gate { display: block; }
  .gate-icon { margin-bottom: 13px; }
  .activity, .location, .reading { padding: 15px; }
}
