:root {
  --bg: #0b0e0c;
  --panel: #12160f;
  --panel-2: #171c14;
  --line: #262e20;
  --ink: #ecede4;
  --muted: #8b958c;
  --stable: #35d2a0;
  --amber: #e8a33d;
  --danger: #e2543a;
  --display: 'Fraunces', serif;
  --body: 'Inter', system-ui, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.05;
  background-image: radial-gradient(circle at 1px 1px, #fff 1px, transparent 0);
  background-size: 3px 3px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 1;
}

.mark {
  font-family: var(--mono);
  font-weight: 600;
  letter-spacing: 0.14em;
  font-size: 0.8rem;
  color: var(--stable);
}

.top-note {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.02em;
}

main {
  flex: 1;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 4.5rem 1.5rem 3rem;
  position: relative;
  z-index: 1;
}

.hero h1 {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(2rem, 5vw, 3.1rem);
  line-height: 1.12;
  letter-spacing: -0.01em;
  margin: 0 0 1.1rem;
}

.hero h1 em {
  font-style: italic;
  font-weight: 400;
  color: var(--danger);
}

.lede {
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--muted);
  max-width: 56ch;
  margin: 0 0 2.2rem;
}

#search {
  display: flex;
  gap: 0.6rem;
  position: relative;
}

#addr {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--body);
  font-size: 1rem;
  padding: 0.85rem 1rem;
  border-radius: 3px;
  outline: none;
  transition: border-color 0.15s ease;
}

#addr:focus {
  border-color: var(--stable);
}

#search button {
  background: var(--stable);
  color: #06110d;
  border: none;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.03em;
  padding: 0 1.4rem;
  border-radius: 3px;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
}

#search button:hover { background: #4be3b3; }
#search button:active { transform: scale(0.97); }
#search button:focus-visible, #addr:focus-visible, .chip:focus-visible { outline: 2px solid var(--stable); outline-offset: 2px; }

.suggestions {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  right: 4.6rem;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
  z-index: 5;
}

.suggestions button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--ink);
  font-family: var(--body);
  font-size: 0.9rem;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.suggestions button:last-child { border-bottom: none; }
.suggestions button:hover { background: var(--panel); color: var(--stable); }

.hint {
  margin: 1rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.chip {
  background: none;
  border: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 0.76rem;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.chip:hover { border-color: var(--stable); color: var(--stable); }

.result, .empty, .loading {
  margin-top: 3rem;
  padding-top: 2.2rem;
  border-top: 1px solid var(--line);
  animation: rise 0.5s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.readout {
  display: flex;
  align-items: center;
  gap: 2.5rem;
  flex-wrap: wrap;
}

.gauge-wrap { flex: 1; min-width: 260px; }

#gauge { width: 100%; height: auto; overflow: visible; }

.gauge-track { stroke: var(--line); stroke-width: 2; }
.gauge-tick { stroke: var(--line); stroke-width: 1; }
.gauge-tick-mid { stroke: var(--muted); stroke-width: 1.5; }

#gauge-needle {
  fill: var(--stable);
  transition: cx 0.7s cubic-bezier(0.2, 0.8, 0.2, 1), fill 0.5s ease;
}

.gauge-labels {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 0.3rem;
  padding: 0 0.5rem;
}

.value-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 140px;
}

.value-num {
  font-family: var(--display);
  font-size: 3.2rem;
  font-weight: 500;
  line-height: 1;
  transition: color 0.5s ease;
}

.value-unit {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.3rem;
}

.value-class {
  font-family: var(--mono);
  font-size: 0.74rem;
  letter-spacing: 0.05em;
  margin-top: 0.6rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--line);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.2rem 2rem;
  margin-top: 2.4rem;
}

.detail { display: flex; flex-direction: column; gap: 0.25rem; }

.detail-label {
  font-family: var(--mono);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.detail-val {
  font-family: var(--mono);
  font-size: 0.92rem;
  color: var(--ink);
}

.map-wrap {
  margin-top: 2.4rem;
  position: relative;
}

#map {
  height: 340px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  overflow: hidden;
}

.map-empty {
  position: absolute;
  top: 0.8rem; left: 0.8rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  pointer-events: none;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem 1.4rem;
  margin-top: 0.6rem;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
}

.map-legend span { display: inline-flex; align-items: center; gap: 0.4rem; }
.map-legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.map-legend-note { opacity: 0.7; }

.infra-panel {
  margin-top: 2rem;
  padding-top: 1.6rem;
  border-top: 1px solid var(--line);
}

.infra-panel h3 {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.15rem;
  margin: 0 0 0.3rem;
}

.infra-sub {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0 0 0.9rem;
}

.infra-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }

.infra-item {
  display: grid;
  grid-template-columns: 5.5rem 1fr auto auto;
  align-items: center;
  gap: 0.8rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  font-size: 0.85rem;
}

.infra-type {
  font-family: var(--mono);
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.infra-name { font-weight: 500; }

.infra-val { font-family: var(--mono); font-weight: 600; white-space: nowrap; }

.infra-dist {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
}

.infra-empty {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
}

@media (max-width: 640px) {
  .infra-item { grid-template-columns: 1fr; gap: 0.25rem; }
}

.provenance {
  margin-top: 2rem;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--muted);
  border-left: 2px solid var(--line);
  padding-left: 1rem;
}

.provenance a { color: var(--stable); }
.provenance code {
  font-family: var(--mono);
  background: var(--panel);
  padding: 0.05rem 0.35rem;
  border-radius: 2px;
  color: var(--ink);
}

.empty p { margin: 0 0 0.5rem; }
.empty-sub { color: var(--muted); font-size: 0.9rem; }

.loading:not([hidden]) {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-family: var(--mono);
  color: var(--muted);
  font-size: 0.9rem;
}

.pulse {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--stable);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.1); }
}

.about {
  margin-top: 4.5rem;
  padding-top: 2.2rem;
  border-top: 1px solid var(--line);
}

.about h2 {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.3rem;
  margin: 0 0 1rem;
}

.about p {
  color: var(--muted);
  line-height: 1.65;
  font-size: 0.94rem;
  max-width: 62ch;
}

.about .limits { color: var(--ink); }
.about .limits strong { color: var(--amber); }

footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem 1.5rem;
  padding: 1.5rem 2rem;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--muted);
  position: relative;
  z-index: 1;
}

@media (prefers-reduced-motion: reduce) {
  .result, .empty, .loading, #gauge-needle, .pulse { animation: none !important; transition: none !important; }
}

@media (max-width: 640px) {
  .top { padding: 1.2rem 1.2rem; flex-direction: column; align-items: flex-start; gap: 0.3rem; }
  main { padding: 3rem 1.2rem 2.5rem; }
  .readout { gap: 1.5rem; }
  .value-block { align-items: flex-start; }
  .detail-grid { grid-template-columns: 1fr; }
  .suggestions { right: 0; }
}
