/* AnyPing — light/dark, modern, clean. Theme via prefers-color-scheme + [data-theme]. */
:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --border: #e3e8f0;
  --text: #1a2233;
  --text-dim: #63708a;
  --text-faint: #93a0b5;
  --accent: #4f46e5;
  --accent-soft: #eef0fe;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 24px rgba(16,24,40,.06);
  --shadow-lg: 0 4px 12px rgba(16,24,40,.08), 0 16px 48px rgba(16,24,40,.10);
  --good: #16a34a; --okk: #65a30d; --mid: #d97706; --warn: #ea580c; --bad: #dc2626;
  --map-dot: #c9d5e8;
  --radius: 14px;
}
:root[data-theme="dark"], :root[data-theme="dark"] body {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #0f1420;
  --border: #222c3d;
  --text: #e6ecf6;
  --text-dim: #8a99b3;
  --text-faint: #5b6a86;
  --accent: #7c8cff;
  --accent-soft: #1a2138;
  --shadow: none;
  --shadow-lg: 0 8px 40px rgba(0,0,0,.4);
  --good: #34d399; --okk: #a3e635; --mid: #fbbf24; --warn: #fb923c; --bad: #f87171;
  --map-dot: #263349;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f17; --surface: #121826; --surface-2: #0f1420; --border: #222c3d;
    --text: #e6ecf6; --text-dim: #8a99b3; --text-faint: #5b6a86;
    --accent: #7c8cff; --accent-soft: #1a2138; --shadow: none;
    --shadow-lg: 0 8px 40px rgba(0,0,0,.4);
    --good: #34d399; --okk: #a3e635; --mid: #fbbf24; --warn: #fb923c; --bad: #f87171;
    --map-dot: #263349;
  }
}

/* animated ambient background */
.bgfx { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.bgfx::before, .bgfx::after {
  content: ""; position: absolute; width: 66vw; height: 66vw; border-radius: 50%;
  filter: blur(70px); opacity: .28;
}
.bgfx::before {
  left: -18vw; top: -26vw;
  background: radial-gradient(circle, color-mix(in srgb, var(--accent) 22%, transparent), transparent 62%);
  animation: drift1 26s ease-in-out infinite alternate;
}
.bgfx::after {
  right: -20vw; bottom: -28vw;
  background: radial-gradient(circle, color-mix(in srgb, #12b3a6 20%, transparent), transparent 62%);
  animation: drift2 32s ease-in-out infinite alternate;
}
@keyframes drift1 { to { transform: translate(14vw, 10vw) scale(1.15); } }
@keyframes drift2 { to { transform: translate(-12vw, -8vw) scale(1.2); } }
@media (prefers-reduced-motion: reduce) { .bgfx::before, .bgfx::after { animation: none; } }

/* world map — supporting visual, kept compact so it doesn't upstage the tool */
.mapwrap {
  max-width: 560px; margin: 14px auto 0; padding: 6px;
  border-radius: 12px; overflow: hidden; opacity: .9;
}
.mapwrap canvas { display: block; width: 100%; }

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans SC", "Noto Sans JP", sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background .2s, color .2s;
}
.hidden { display: none !important; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace; }

/* header */
.top {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 16px clamp(16px, 4vw, 40px);
  max-width: 1040px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 20px; letter-spacing: -.02em; text-decoration: none; color: var(--text); }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.brand b { color: var(--accent); font-weight: 800; }
.top-ctrl { display: flex; align-items: center; gap: 8px; }
.top-ctrl select, .top-ctrl button {
  font: inherit; font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 7px 10px; cursor: pointer; transition: border-color .15s, color .15s, background .15s;
}
.top-ctrl select:hover, .top-ctrl button:hover { border-color: var(--accent); }
.theme-btn { width: 38px; height: 38px; padding: 0; display: grid; place-items: center; color: var(--text-dim); }
.theme-btn:hover { color: var(--accent); }
.theme-btn svg { display: block; }

/* hero */
main { max-width: 1040px; margin: 0 auto; padding: clamp(12px, 3vw, 28px) clamp(16px, 4vw, 40px) 64px; }
.hero { text-align: center; padding: clamp(16px, 3vw, 32px) 0 clamp(8px, 2vw, 16px); }
.hero h1 { font-size: clamp(22px, 4vw, 34px); font-weight: 800; letter-spacing: -.03em; }
.hero p { color: var(--text-dim); margin-top: 10px; font-size: clamp(14px, 2vw, 16px); }

.search {
  display: flex; align-items: stretch; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 8px; margin: 24px auto 0; max-width: 720px;
  flex-wrap: wrap; transition: border-color .2s, box-shadow .2s;
}
.search:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); box-shadow: var(--shadow), 0 0 0 3px var(--accent-soft); }
/* custom kind dropdown (native select looked ugly on macOS) */
.kind-dd { position: relative; flex-shrink: 0; display: flex; }
.kind-btn {
  display: flex; align-items: center; gap: 7px;
  border: 0; background: transparent; color: var(--text-dim);
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
  padding: 8px 14px; border-right: 1px solid var(--border); outline: none;
  transition: color .15s;
}
.kind-btn:hover { color: var(--text); }
.kind-btn .chev { opacity: .65; transition: transform .18s; }
.kind-dd.open .kind-btn .chev { transform: rotate(180deg); }
.kind-menu {
  position: absolute; top: calc(100% + 10px); left: 0; z-index: 30;
  min-width: 144px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 11px; box-shadow: var(--shadow-lg); padding: 5px;
  opacity: 0; transform: translateY(-6px) scale(.98); transform-origin: top left;
  pointer-events: none; transition: opacity .16s ease, transform .16s cubic-bezier(.2,.8,.2,1);
}
.kind-dd.open .kind-menu { opacity: 1; transform: none; pointer-events: auto; }
.kind-opt {
  padding: 9px 12px; border-radius: 8px; font-size: 14px; color: var(--text);
  cursor: pointer; transition: background .12s; white-space: nowrap;
}
.kind-opt:hover { background: var(--surface-2); }
.kind-opt.sel { color: var(--accent); font-weight: 600; background: var(--accent-soft); }

/* language dropdown in the header (same custom-menu machinery) */
.top-ddbtn {
  display: flex; align-items: center; gap: 8px; height: 38px;
  font: inherit; font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 0 12px; cursor: pointer; transition: border-color .15s, color .15s;
}
.top-ddbtn:hover { border-color: var(--accent); }
.top-ddbtn .globe { color: var(--accent); flex-shrink: 0; }
.top-ddbtn .chev { opacity: .55; flex-shrink: 0; transition: transform .18s; }
.lang-dd.open .top-ddbtn .chev { transform: rotate(180deg); }
.lang-menu {
  left: auto; right: 0; transform-origin: top right;
  min-width: 150px; max-height: 330px; overflow-y: auto;
}
.search input {
  flex: 1; min-width: 160px; border: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 15px; padding: 8px 12px; outline: none;
}
.search input.port { flex: 0 0 88px; min-width: 88px; border-left: 1px solid var(--border); }
.search .go {
  flex-shrink: 0; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--accent); color: #fff; font: inherit; font-weight: 700; font-size: 15px;
  padding: 8px 26px; transition: filter .15s, transform .05s;
}
.search .go { transition: filter .15s, transform .05s, box-shadow .2s; }
.search .go:hover { filter: brightness(1.08); box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 45%, transparent); }
.search .go:active { transform: scale(.98); }
.search .go:disabled { opacity: .6; cursor: default; }

/* status line */
.status { text-align: center; margin: 20px 0 4px; color: var(--text-dim); font-size: 14px; min-height: 22px; }
.status.err { color: var(--bad); font-weight: 600; }
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; margin-right: 7px; }
@keyframes spin { to { transform: rotate(360deg); } }

.share { text-align: center; margin: 8px 0 4px; font-size: 14px; }
.share a { color: var(--accent); text-decoration: none; font-weight: 600; word-break: break-all; }
.share a:hover { text-decoration: underline; }

/* results */
.results { margin-top: 18px; display: flex; flex-direction: column; gap: 8px; }
.head-row, .row {
  display: grid;
  grid-template-columns: minmax(140px, 1.3fr) minmax(96px, .9fr) 200px 96px 64px minmax(104px, 1fr);
  gap: 12px; align-items: center;
}
.head-row { padding: 4px 18px; color: var(--text-faint); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.head-row .r { text-align: right; }
.row {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 18px; box-shadow: var(--shadow);
  animation: rowin .35s cubic-bezier(.2,.8,.2,1);
  transition: transform .15s, box-shadow .15s, border-color .2s;
}
.row:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
@keyframes rowin { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.row.testing { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.row.err, .row.offline { opacity: .82; }

.loc { display: flex; align-items: center; gap: 10px; min-width: 0; }
.loc .flag { font-size: 20px; line-height: 1; flex-shrink: 0; }
.loc .place { min-width: 0; }
.loc .place b { display: block; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loc .place small { color: var(--text-faint); font-size: 12px; }
.rip { color: var(--text-dim); font-size: 13px; }
.rip .live { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-right: 6px; animation: blink 1s infinite; vertical-align: 1px; }
@keyframes blink { 50% { opacity: .25; } }

canvas.wave { display: block; width: 200px; height: 32px; }
.stat { text-align: right; }
.stat .big { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .unit { font-size: 11px; color: var(--text-faint); }
.loss { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.mm { text-align: right; color: var(--text-dim); font-size: 12.5px; }
.badge { text-align: right; }
.badge span { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 20px; }
.b-done { background: color-mix(in srgb, var(--good) 15%, transparent); color: var(--good); }
.b-run  { background: var(--accent-soft); color: var(--accent); }
.b-err, .b-offline, .b-timeout { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.row .errmsg { grid-column: 1 / -1; margin-top: 6px; color: var(--bad); font-size: 12.5px; }

.lat-good { color: var(--good); } .lat-okk { color: var(--okk); }
.lat-mid { color: var(--mid); } .lat-warn { color: var(--warn); } .lat-bad { color: var(--bad); }

/* value tick animation */
.tick { animation: tick .3s ease; }
@keyframes tick { 0% { transform: translateY(-2px); opacity: .5; } 100% { transform: none; opacity: 1; } }

/* about */
.about { margin-top: 48px; padding-top: 28px; border-top: 1px solid var(--border); color: var(--text-dim); }
.about h2 { color: var(--text); font-size: 16px; margin-bottom: 10px; }
.about p { font-size: 14px; line-height: 1.8; max-width: 760px; }

/* minimal footer */
.site-footer { border-top: 1px solid var(--border); background: var(--surface-2); margin-top: 40px; }
.foot-inner {
  max-width: 1040px; margin: 0 auto; padding: 28px clamp(16px, 4vw, 40px);
  display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; flex-wrap: wrap;
}
.foot-brand .brand { font-size: 18px; margin-bottom: 10px; }
.foot-brand p { color: var(--text-dim); font-size: 13px; line-height: 1.7; max-width: 320px; }
.foot-nav { display: flex; flex-direction: column; gap: 8px; }
.foot-nav a { color: var(--text-dim); text-decoration: none; font-size: 14px; transition: color .15s; }
.foot-nav a:hover { color: var(--accent); }
.foot-bar {
  border-top: 1px solid var(--border);
  max-width: 1040px; margin: 0 auto; padding: 14px clamp(16px, 4vw, 40px);
  display: flex; justify-content: space-between; align-items: center; gap: 10px 20px;
  flex-wrap: wrap; color: var(--text-faint); font-size: 12.5px;
}
.foot-recent a { color: var(--text-dim); text-decoration: none; margin-left: 6px; font-variant-numeric: tabular-nums; }
.foot-recent a:not(:last-child)::after { content: " ·"; color: var(--text-faint); }
.foot-recent a:hover { color: var(--accent); }
.foot-home { color: var(--text-dim); text-decoration: none; }
.foot-home:hover { color: var(--accent); }

/* /recent page — buttons of recently tested targets */
.recent-btns {
  max-width: 820px; margin: 24px auto 0; display: flex; flex-wrap: wrap; gap: 10px;
  justify-content: center;
}
.recent-btn {
  color: var(--text); text-decoration: none; font-size: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 16px; transition: border-color .15s, color .15s, box-shadow .15s;
  font-variant-numeric: tabular-nums; box-shadow: var(--shadow);
}
.recent-btn:hover { border-color: var(--accent); color: var(--accent); }
.recent-empty { text-align: center; color: var(--text-faint); margin-top: 24px; }

@media (max-width: 760px) {
  .head-row { display: none; }
  .row { grid-template-columns: 1fr auto; gap: 8px 12px; }
  .row .loc { grid-column: 1; }
  .row .badge { grid-column: 2; }
  .row .rip { grid-column: 1 / -1; order: 5; }
  canvas.wave { grid-column: 1 / -1; width: 100%; order: 6; }
  .row .stat { grid-column: 1; order: 7; text-align: left; }
  .row .loss { grid-column: 2; order: 7; }
  .row .mm { display: none; }
}
