/* 網路狀況偵測：自架版（index.html）與 claude.ai 分享版（share.html）共用的樣式 */

/* 版面：手機優先的單欄卡片流；狀態色（綠／橘／紅）只用來表示網路好壞，強調藍只用在可操作的元素 */
:root {
  color-scheme: light;
  --bg: #f3f5f9;
  --card: #ffffff;
  --sunken: #eef1f6;
  --text: #0f172a;
  --muted: #5f6b7d;
  --line: #e2e7ee;
  --accent: #2563eb;
  --ok: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --idle: #94a3b8;
  --solid-accent: #2563eb;
  --solid-ok: #15803d;
  --solid-bad: #dc2626;
  --on-solid: #ffffff;
  --toast: rgba(15, 23, 42, .92);
  --card-edge: transparent;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 20px rgba(15, 23, 42, .05);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0f17;
    --card: #131a26;
    --sunken: #0f1520;
    --text: #e6ebf3;
    --muted: #8b97a8;
    --line: #232d3c;
    --accent: #6aa5ff;
    --ok: #34d399;
    --warn: #fbbf24;
    --bad: #f87171;
    --idle: #64748b;
    --toast: rgba(30, 41, 59, .96);
    --card-edge: #1d2633;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f17;
  --card: #131a26;
  --sunken: #0f1520;
  --text: #e6ebf3;
  --muted: #8b97a8;
  --line: #232d3c;
  --accent: #6aa5ff;
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --idle: #64748b;
  --toast: rgba(30, 41, 59, .96);
  --card-edge: #1d2633;
  --shadow: none;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, p { margin: 0; }

.app {
  max-width: 720px;
  margin: 0 auto;
  padding-block: 20px 28px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid;
  gap: 14px;
}
.top h1 { font-size: 22px; font-weight: 700; letter-spacing: .01em; }
.top p { color: var(--muted); font-size: 13px; margin-top: 2px; }

.card {
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card h2 { font-size: 15px; font-weight: 650; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.hint { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; text-align: right; }
.note { color: var(--muted); font-size: 12px; margin-top: 10px; }

/* 頂部斷線通知 */
.banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  padding: calc(10px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
  background: var(--solid-bad); color: var(--on-solid);
  font-size: 14px; font-weight: 600; text-align: center;
  transform: translateY(-100%);
  transition: transform .3s ease;
}
.banner[data-tone="ok"] { background: var(--solid-ok); }
.banner.show { transform: none; }

/* 檢測對象選單 */
.target { display: grid; gap: 6px; }
.target-row { display: flex; align-items: center; gap: 12px; }
.target-row label { flex: none; font-size: 13px; font-weight: 600; color: var(--muted); }
.select-wrap { position: relative; flex: 1; min-width: 0; }
.select-wrap::after {
  content: ""; position: absolute; right: 16px; top: 50%;
  width: 7px; height: 7px; pointer-events: none;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg);
}
.select-wrap select {
  appearance: none; -webkit-appearance: none;
  width: 100%; min-height: 44px; padding: 0 40px 0 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text); box-shadow: var(--shadow);
  font: inherit; font-size: 16px; font-weight: 600; /* 16px 以上 iOS 點選時才不會自動放大頁面 */
  text-overflow: ellipsis; cursor: pointer;
}
.select-wrap select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.select-wrap select:disabled { cursor: default; opacity: 1; }
.select-wrap:has(select:disabled)::after { display: none; }
.target-info { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }

/* 主狀態 */
.hero { --tone: var(--idle); position: relative; overflow: hidden; }
.hero[data-tone="ok"] { --tone: var(--ok); }
.hero[data-tone="warn"] { --tone: var(--warn); }
.hero[data-tone="bad"] { --tone: var(--bad); }
.hero::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(120% 90% at 0% 0%, color-mix(in srgb, var(--tone) 13%, transparent), transparent 62%);
  transition: background .4s;
}
.hero-main { position: relative; display: flex; align-items: center; gap: 14px; }
.orb {
  width: 54px; height: 54px; flex: none; border-radius: 50%;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--tone) 16%, transparent);
}
.orb::after {
  content: ""; width: 18px; height: 18px; border-radius: 50%;
  background: var(--tone);
  animation: pulse 2s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--tone) 50%, transparent); }
  75%, 100% { box-shadow: 0 0 0 16px transparent; }
}
.hero-text { flex: 1; min-width: 0; }
.hero-title { font-size: 20px; font-weight: 700; color: var(--tone); line-height: 1.3; }
.hero-desc { font-size: 13px; color: var(--muted); margin-top: 2px; }
.grade { flex: none; display: grid; justify-items: center; gap: 4px; }
.signal { display: flex; align-items: flex-end; gap: 3px; height: 22px; }
.signal i { width: 5px; border-radius: 2px; background: var(--line); transition: background .3s; }
.signal i:nth-child(1) { height: 28%; }
.signal i:nth-child(2) { height: 46%; }
.signal i:nth-child(3) { height: 64%; }
.signal i:nth-child(4) { height: 82%; }
.signal i:nth-child(5) { height: 100%; }
.signal i.on { background: var(--tone); }
.grade span { font-size: 12px; font-weight: 600; color: var(--tone); }
.hero-foot {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-top: 14px; padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 13px; color: var(--muted);
}
.hero-foot #lastCheck { font-variant-numeric: tabular-nums; text-align: right; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; color: var(--text); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track {
  width: 38px; height: 22px; border-radius: 11px; background: var(--line);
  position: relative; transition: background .2s; flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px; border-radius: 50%; background: var(--on-solid);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .2s;
}
.switch input:checked + .track { background: var(--solid-accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* 指標 */
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.metric {
  background: var(--card);
  border: 1px solid var(--card-edge);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 11px 12px;
  display: flex; flex-direction: column; min-width: 0;
}
.metric .k { font-size: 12px; color: var(--muted); }
.metric .v {
  font-size: 22px; font-weight: 700; line-height: 1.25;
  font-variant-numeric: tabular-nums;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.metric .u { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric[data-tone="ok"] .v { color: var(--ok); }
.metric[data-tone="warn"] .v { color: var(--warn); }
.metric[data-tone="bad"] .v { color: var(--bad); }
@media (min-width: 640px) {
  .metrics { grid-template-columns: repeat(6, minmax(0, 1fr)); }
}

/* 延遲圖 */
#chart { display: block; width: 100%; height: 150px; }
.chart-target { font-size: 12px; color: var(--muted); margin: -6px 0 8px; overflow-wrap: anywhere; }

/* 測速 */
.speed { text-align: center; }
.speed-value {
  font-size: 52px; font-weight: 750; line-height: 1.1; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.speed-value small { font-size: 15px; font-weight: 600; color: var(--muted); letter-spacing: 0; margin-left: 6px; }
.speed-phase { color: var(--muted); font-size: 13px; margin: 6px 0 12px; min-height: 1.5em; }
.progress { height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width .2s linear; }
.results { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; margin: 14px 0; }
.results div { background: var(--sunken); border-radius: 10px; padding: 8px 4px; }
.results b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.results span { font-size: 11px; color: var(--muted); }

.btn {
  appearance: none; border: 0; cursor: pointer;
  min-height: 44px; padding: 0 18px; border-radius: 12px;
  font: inherit; font-weight: 600;
  background: var(--sunken); color: var(--text);
  touch-action: manipulation;
  transition: transform .1s, opacity .2s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { width: 100%; background: var(--solid-accent); color: var(--on-solid); }
.btn.sm { min-height: 30px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }

/* 鍵值列表 */
.kv { margin: 0; }
.kv .row { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv .row:last-child { border-bottom: 0; padding-bottom: 0; }
.kv dt { color: var(--muted); flex: none; }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; word-break: break-all; }

/* 事件紀錄 */
.log { list-style: none; margin: 0; padding: 0; max-height: 264px; overflow-y: auto; font-size: 13px; }
.log li { display: flex; align-items: flex-start; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.log li:last-child { border-bottom: 0; }
.log li::before { content: ""; width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--idle); flex: none; }
.log li[data-tone="ok"]::before { background: var(--ok); }
.log li[data-tone="warn"]::before { background: var(--warn); }
.log li[data-tone="bad"]::before { background: var(--bad); }
.log li[data-tone="info"]::before { background: var(--accent); }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.log-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 8px 0; }

footer { color: var(--muted); font-size: 12px; text-align: center; padding-top: 4px; }

.toast {
  position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  background: var(--toast); color: var(--on-solid);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; white-space: nowrap;
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 359px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .results { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  .orb::after { animation: none; }
  .banner, .toast, .progress span, .hero::before { transition: none; }
}
