:root {
  --bg0: #0b0f14;
  --bg1: #121821;
  --bg2: #1a2330;
  --text: #e7eef7;
  --muted: #8fa3b8;
  --accent: #3dd6c6;
  --accent-dim: rgba(61, 214, 198, 0.18);
  --warn: #f0b429;
  --danger: #ff6b6b;
  --line: rgba(255, 255, 255, 0.08);
  --radius: 20px;
  --dock-h: 76px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(900px 480px at 12% -8%, #1d3a3a 0%, transparent 55%),
    radial-gradient(700px 420px at 92% 0%, #1c2a44 0%, transparent 50%),
    linear-gradient(180deg, var(--bg0), #070a0e 85%);
  padding-bottom: calc(var(--dock-h) + var(--safe-bottom) + 1rem);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body.standalone {
  /* Extra top breathing room under iOS status bar in installed mode */
  padding-top: 0;
}

.shell {
  width: min(720px, calc(100% - 1.25rem));
  margin: 0 auto;
  padding: calc(0.85rem + var(--safe-top)) 0 1.5rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 1rem;
  animation: rise 420ms ease both;
}
.eyebrow {
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  font-size: 0.68rem;
  margin: 0 0 0.25rem;
  font-weight: 650;
}
.topbar h1 {
  margin: 0;
  font-size: clamp(1.35rem, 5vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.topbar-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.35rem;
}
.freshness {
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
}

.pill {
  display: inline-flex;
  align-items: center;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.28rem 0.75rem;
  font-size: 0.78rem;
  text-transform: capitalize;
  font-weight: 600;
}
.mode-pill[data-mode="driving"] { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-dim); }
.mode-pill[data-mode="charging"] { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.mode-pill[data-mode="sleeping"] { color: var(--muted); }

.hero-gauge {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
  margin-bottom: 1rem;
  animation: rise 480ms ease both;
  animation-delay: 40ms;
}
.gauge {
  --soc: 0;
  position: relative;
  width: min(220px, 58vw);
  aspect-ratio: 1;
  margin: 0.2rem auto 0.4rem;
}
.gauge-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    conic-gradient(
      from -90deg,
      var(--accent) calc(var(--soc) * 1%),
      rgba(255, 255, 255, 0.08) 0
    );
  mask: radial-gradient(circle at center, transparent 62%, #000 63%);
  -webkit-mask: radial-gradient(circle at center, transparent 62%, #000 63%);
  filter: drop-shadow(0 0 18px rgba(61, 214, 198, 0.22));
}
.gauge-core {
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  background: color-mix(in srgb, var(--bg1) 92%, transparent);
  border: 1px solid var(--line);
  display: grid;
  place-content: center;
  text-align: center;
  gap: 0.1rem;
}
.gauge-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.gauge-value {
  margin: 0;
  font-size: clamp(2.4rem, 10vw, 3.1rem);
  font-weight: 760;
  letter-spacing: -0.04em;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.gauge-range {
  margin: 0.2rem 0 0;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}
.preheat-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-top: 0.15rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg1) 90%, transparent);
}
.preheat-form { margin: 0; flex: 0 0 auto; }
button.preheat-btn {
  -webkit-appearance: none;
  appearance: none;
  width: 72px;
  height: 72px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  display: grid;
  place-items: center;
  gap: 0.05rem;
  cursor: pointer;
  padding: 0.3rem;
  margin: 0;
  font: inherit;
  line-height: 1;
  transition: transform 120ms ease, background-color 180ms ease, border-color 180ms ease, color 180ms ease, box-shadow 180ms ease;
  -webkit-tap-highlight-color: transparent;
}
button.preheat-btn:active { transform: scale(0.96); }
button.preheat-btn:disabled { opacity: 0.55; cursor: wait; }
button.preheat-btn .thermo-icon {
  width: 34px;
  height: 34px;
  display: block;
}
button.preheat-btn .thermo-body,
button.preheat-btn .thermo-fill,
button.preheat-btn .thermo-bulb {
  fill: currentColor;
}
button.preheat-btn .thermo-marks {
  fill: none;
  stroke: currentColor;
}
button.preheat-btn .preheat-label {
  font-size: 0.68rem;
  font-weight: 780;
  letter-spacing: 0.08em;
  color: inherit;
}
button.preheat-btn.is-off {
  color: #8b97a8;
  background-color: #151c27;
  background-image: none;
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: none;
}
button.preheat-btn.is-on {
  color: #ff4d4f;
  background-color: rgba(255, 77, 79, 0.14);
  background-image: none;
  border-color: rgba(255, 77, 79, 0.55);
  box-shadow: 0 0 0 1px rgba(255, 77, 79, 0.2), 0 10px 24px rgba(255, 60, 60, 0.22);
  animation: preheat-pulse 1.8s ease-in-out infinite;
}
.preheat-meta {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 0;
}
.preheat-meta .k {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.preheat-meta strong {
  font-size: 1.02rem;
  font-weight: 650;
}
button.preheat-btn.is-pending {
  animation: none;
  opacity: 0.6;
}
@keyframes preheat-pulse {
  0%, 100% { box-shadow: 0 0 0 1px rgba(255, 77, 79, 0.2), 0 10px 24px rgba(255, 60, 60, 0.18); }
  50% { box-shadow: 0 0 0 2px rgba(255, 77, 79, 0.35), 0 12px 28px rgba(255, 60, 60, 0.32); }
}

.hero-stats > div,
article,
.panel {
  background: color-mix(in srgb, var(--bg1) 90%, transparent);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.hero-stats > div {
  padding: 0.85rem 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-height: 64px;
}
.hero-stats .k {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.hero-stats strong {
  font-size: 1.05rem;
  font-weight: 650;
  word-break: break-word;
}
.hero-stats strong.on { color: var(--warn); }

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}
article {
  padding: 1rem 1.05rem;
  animation: rise 520ms ease both;
  animation-delay: 80ms;
}
article h2,
.panel summary {
  margin: 0 0 0.75rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
dl { margin: 0; display: grid; gap: 0.55rem; }
dl > div { display: flex; justify-content: space-between; gap: 1rem; align-items: baseline; }
dt { color: var(--muted); font-size: 0.92rem; }
dd { margin: 0; text-align: right; font-weight: 560; font-variant-numeric: tabular-nums; }

.map iframe {
  width: 100%;
  height: 200px;
  border: 0;
  border-radius: 14px;
  filter: grayscale(0.15) contrast(1.05);
  pointer-events: none;
}
.coords, .muted { color: var(--muted); font-size: 0.86rem; }
.maps-btn {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  margin-top: 0.55rem;
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--accent);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
}

.panel {
  margin-bottom: 0.75rem;
  padding: 0.2rem 1rem 0.85rem;
  animation: rise 560ms ease both;
  animation-delay: 120ms;
}
.panel summary {
  list-style: none;
  cursor: pointer;
  padding: 0.85rem 0 0.35rem;
  user-select: none;
}
.panel summary::-webkit-details-marker { display: none; }
.panel summary::after {
  content: "›";
  float: right;
  transform: rotate(90deg);
  color: var(--accent);
  font-size: 1.1rem;
  line-height: 1;
}
.panel[open] summary::after { transform: rotate(-90deg); }

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}
.list li {
  padding: 0.65rem 0;
  border-top: 1px solid var(--line);
}
.list li:first-child { border-top: 0; }
.list li > div {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.2rem;
}
.list small {
  color: var(--muted);
  font-size: 0.78rem;
  font-family: var(--mono);
  word-break: break-word;
}

.links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.links a {
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.45rem 0.8rem;
  font-size: 0.85rem;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}
.links a:hover { border-color: var(--accent); color: var(--accent); }

.install-hint {
  margin: 1rem 0 0;
  padding: 0.85rem 1rem;
  border-radius: 16px;
  border: 1px dashed color-mix(in srgb, var(--accent) 40%, transparent);
  background: var(--accent-dim);
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.35;
}

.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 1.6fr 1fr 1fr;
  gap: 0.55rem;
  padding: 0.7rem 0.85rem calc(0.7rem + var(--safe-bottom));
  background: color-mix(in srgb, #0b0f14 82%, transparent);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.dock form { margin: 0; }
.dock button,
.dock a.dock-btn {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  min-height: 48px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--bg2);
  background-image: none;
  color: var(--text);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
  padding: 0.7rem 0.6rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}
.dock-primary button {
  background: linear-gradient(180deg, #4ae0d0, #2bb8aa);
  color: #041314;
  border-color: transparent;
  box-shadow: 0 8px 24px rgba(61, 214, 198, 0.28);
}
.dock button.ghost,
.dock a.dock-btn.ghost {
  background: transparent;
  background-image: none;
  color: var(--text);
}
.dock a.dock-btn:link,
.dock a.dock-btn:visited,
.dock a.dock-btn:hover,
.dock a.dock-btn:active {
  color: var(--text);
  text-decoration: none;
}
.dock button:active,
.dock a.dock-btn:active { transform: scale(0.98); }
.dock button:disabled { opacity: 0.55; }

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

@media (min-width: 720px) {
  .shell { width: min(980px, calc(100% - 2rem)); padding-top: 1.5rem; }
  .hero-gauge {
    grid-template-columns: 240px 1fr;
    align-items: center;
  }
  .gauge { margin: 0; width: 220px; }
  .grid { grid-template-columns: 1fr 1.1fr; }
  .dock {
    left: 50%;
    transform: translateX(-50%);
    width: min(720px, calc(100% - 2rem));
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 22px 22px 0 0;
  }
}

@media (display-mode: standalone) {
  body { background-attachment: fixed; }
}
