:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #17202e;
  --muted: #5f6b7d;
  --line: #dfe4ec;
  --accent: #0a6cc4;
  --accent-ink: #ffffff;
  --accent-soft: #e6f1fb;
  --ok: #12805c;
  --ok-soft: #e0f5ec;
  --bad: #c0392b;
  --bad-soft: #fbe9e7;
  --warn: #a8660a;
  --warn-soft: #fdf1dc;
  --code: #eef1f6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 6px 20px rgba(20, 30, 50, .05);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c;
    --card: #171e29;
    --text: #e6ebf3;
    --muted: #93a0b4;
    --line: #283243;
    --accent: #4aa3f0;
    --accent-ink: #06121f;
    --accent-soft: #14273a;
    --ok: #4cc79b;
    --ok-soft: #12342a;
    --bad: #ff8a7a;
    --bad-soft: #3a1c19;
    --warn: #f0b45a;
    --warn-soft: #382a10;
    --code: #1f2836;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, kbd, pre { font-family: var(--mono); font-size: .92em; }
code { background: var(--code); padding: .1em .38em; border-radius: 5px; }

.muted { color: var(--muted); }

.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }

/* ---------- header ---------- */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-in { display: flex; align-items: center; gap: 18px; min-height: 58px; flex-wrap: wrap; padding-top: 6px; padding-bottom: 6px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.25rem; color: var(--text); }
.brand:hover { text-decoration: none; color: var(--accent); }
.brand svg { color: var(--accent); }
.nav { display: flex; flex-wrap: wrap; gap: 2px; flex: 1; }
.nav a { color: var(--text); padding: 6px 10px; border-radius: 8px; font-size: .95rem; }
.nav a:hover { background: var(--accent-soft); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.myip { font-size: .9rem; white-space: nowrap; }

/* ---------- layout ---------- */
.main { flex: 1; padding-top: 28px; padding-bottom: 40px; }
.hero { padding: 12px 0 20px; }
.hero h1, .tool h1 { margin: 0 0 6px; font-size: 1.9rem; line-height: 1.2; }
.lead { margin: 0 0 18px; color: var(--muted); font-size: 1.05rem; max-width: 70ch; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.prose { margin-top: 28px; }
.prose h2 { margin-top: 0; font-size: 1.2rem; }
.prose p, .prose li { max-width: 80ch; }
.prose ul { padding-left: 1.2em; }

.footer { border-top: 1px solid var(--line); background: var(--card); font-size: .88rem; }
.footer-in { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 14px; padding-bottom: 14px; }

/* ---------- home ---------- */
.mycard { display: grid; gap: 10px; margin-bottom: 26px; }
.bigip { display: block; font-size: 2rem; font-family: var(--mono); word-break: break-all; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.tile { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; color: var(--text); transition: transform .12s, border-color .12s, box-shadow .12s; box-shadow: var(--shadow); }
.tile:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-2px); }
.tile h2 { margin: 0 0 6px; font-size: 1.15rem; color: var(--accent); }
.tile p { margin: 0; color: var(--muted); font-size: .94rem; }

/* ---------- forms ---------- */
.tool-form { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
label { display: flex; flex-direction: column; gap: 4px; font-size: .86rem; color: var(--muted); }
label.grow { flex: 1 1 260px; }
label.check { flex-direction: row; align-items: center; gap: 6px; padding-bottom: 10px; color: var(--text); font-size: .92rem; }
input[type="text"], input[type="number"], select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; min-height: 42px; min-width: 0;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); padding: 10px 20px; min-height: 42px;
  display: inline-block;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-ghost { background: var(--accent-soft); color: var(--accent); }
.btn-lg { padding: 13px 34px; font-size: 1.1rem; }
.examples { margin: 10px 2px 0; color: var(--muted); font-size: .9rem; }
.chip { font: inherit; font-size: .86rem; cursor: pointer; background: var(--card); color: var(--accent); border: 1px solid var(--line); border-radius: 999px; padding: 2px 11px; margin: 2px 2px; }
.chip:hover { border-color: var(--accent); }
.hint { margin: 0; font-size: .82rem; color: var(--muted); }

/* ---------- results ---------- */
.result { margin-top: 18px; }
.result[hidden] { display: none; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 14px; overflow-x: auto; }
.panel h3 { margin: 0 0 8px; font-size: 1rem; }
.alert { padding: 11px 14px; border-radius: 10px; background: var(--bad-soft); color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent); }
.note { padding: 9px 13px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); margin-top: 10px; }
.spinner { display: inline-block; width: 15px; height: 15px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 7px; }
@keyframes spin { to { transform: rotate(360deg); } }

table.t { width: 100%; border-collapse: collapse; font-size: .94rem; }
table.t th { text-align: left; color: var(--muted); font-weight: 600; font-size: .82rem; padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t tr:last-child td { border-bottom: 0; }
table.t td.num, table.t th.num { text-align: right; font-family: var(--mono); white-space: nowrap; }
table.t td.mono { font-family: var(--mono); word-break: break-all; }

.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .82rem; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; display: flex; flex-direction: column; }
.stat-l { color: var(--muted); font-size: .8rem; }
.stat-v { font-size: 1.05rem; }
.stat-v b { font-size: 1.35rem; font-family: var(--mono); }

pre.raw { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: .86rem; line-height: 1.5; max-height: 640px; overflow: auto; }

/* ---------- speedtest ---------- */
.speed { display: grid; grid-template-columns: minmax(260px, 1.2fr) minmax(220px, 1fr); gap: 22px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.speed-main { text-align: center; }
.gauge { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin-bottom: 10px; }
.gauge-num { font-size: 4.2rem; font-weight: 700; font-family: var(--mono); line-height: 1; }
.gauge-unit { color: var(--muted); }
.progress { height: 8px; background: var(--code); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .25s linear; }
.speed-phase { min-height: 1.6em; margin: 6px 0 14px; }
.speed-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- calculators ---------- */
.calc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.calc-card { display: flex; flex-direction: column; gap: 12px; }
.calc-card h2 { margin: 0; font-size: 1.1rem; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { grid-template-columns: 1fr 1fr 1fr; }
.calc-out { margin: 0; font-size: 1.02rem; }
.calc-out:empty { display: none; }
.calc-out .big { font-size: 1.35rem; font-weight: 700; }

@media (max-width: 720px) {
  .speed { grid-template-columns: 1fr; padding: 16px; }
  .gauge-num { font-size: 3.2rem; }
  .hero h1, .tool h1 { font-size: 1.55rem; }
  .myip { width: 100%; }
  .tool-form { padding: 12px; }
  .btn { width: 100%; }
  .chip { min-height: 30px; }
}
