:root {
  --bg: #101114;
  --surface: #181a1f;
  --surface-raised: #20232a;
  --text: #f6f7f8;
  --muted: #a9adb7;
  --line: #30343d;
  --accent: #e82127;
  --accent-soft: rgba(232, 33, 39, 0.14);
  --success: #5bd49b;
  --radius: 22px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 50% -10%, rgba(232, 33, 39, 0.18), transparent 34rem),
    var(--bg);
}

button, input { font: inherit; }
button { color: inherit; }
button:disabled { cursor: default; opacity: .7; }

.app-header,
main,
footer {
  width: min(100% - 32px, 760px);
  margin-inline: auto;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 92px;
  padding-top: env(safe-area-inset-top);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 14px;
  background: linear-gradient(145deg, #282b33, #17191e);
  color: var(--accent);
  font-size: 24px;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: .16em;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 20px; letter-spacing: -.02em; }

.ghost-button,
.text-button {
  border: 0;
  background: none;
  cursor: pointer;
}
.ghost-button {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.04);
  font-weight: 650;
}
.text-button { padding: 8px; color: #ff777a; font-size: 14px; }

.install-dialog {
  width: min(100% - 28px, 500px);
  max-height: calc(100dvh - 28px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 22px;
  color: var(--text);
  background: #181a1f;
  box-shadow: 0 28px 90px rgba(0,0,0,.62);
}
.install-dialog::backdrop { background: rgba(0,0,0,.72); backdrop-filter: blur(5px); }
.install-dialog-card { padding: 24px; }
.install-dialog-heading { display: flex; align-items: start; justify-content: space-between; gap: 18px; }
.install-dialog-heading h2 { margin-bottom: 0; font-size: 24px; }
.dialog-close {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  background: #111318;
  cursor: pointer;
  font-size: 26px;
  line-height: 1;
}
.install-help-intro { margin: 22px 0 14px; color: #d9dbe0; line-height: 1.55; }
.install-steps { margin: 0; padding-left: 24px; color: #d9dbe0; line-height: 1.55; }
.install-steps li + li { margin-top: 10px; }
.install-tip { margin: 20px 0; padding: 14px; border-radius: 14px; color: var(--muted); background: #111318; font-size: 13px; line-height: 1.5; }
.primary-button {
  width: 100%;
  padding: 13px 16px;
  border: 0;
  border-radius: 13px;
  color: white;
  background: var(--accent);
  cursor: pointer;
  font-weight: 750;
}

main { display: grid; gap: 16px; padding: 16px 0 40px; }

.hero,
.calculator-card,
.note-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(34,37,44,.96), rgba(23,25,30,.96));
  box-shadow: 0 20px 60px rgba(0,0,0,.24);
}

.hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 220px;
  padding: clamp(24px, 6vw, 48px);
  overflow: hidden;
  position: relative;
}
.hero::after {
  position: absolute;
  width: 240px;
  height: 240px;
  right: -100px;
  bottom: -150px;
  border-radius: 50%;
  background: rgba(232,33,39,.16);
  filter: blur(10px);
  content: "";
}
.hero h2 { margin-bottom: 8px; font-size: clamp(36px, 9vw, 60px); letter-spacing: -.055em; }
.finish-time { margin-bottom: 0; color: var(--muted); }

.battery-visual { display: flex; align-items: center; margin-left: 20px; z-index: 1; }
.battery-shell {
  display: grid;
  width: 90px;
  height: 154px;
  align-items: end;
  padding: 7px;
  overflow: hidden;
  position: relative;
  border: 3px solid rgba(255,255,255,.78);
  border-radius: 18px;
}
.battery-fill {
  width: 100%;
  height: 80%;
  border-radius: 10px;
  background: linear-gradient(#ff6267, var(--accent));
  transition: height .25s ease;
}
.battery-shell span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 800; text-shadow: 0 2px 8px #000; }
.battery-tip { width: 9px; height: 38px; border-radius: 0 8px 8px 0; background: rgba(255,255,255,.78); }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.metrics article { padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.metrics span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.metrics strong { font-size: 18px; }

.calculator-card { padding: clamp(22px, 5vw, 36px); }
.section-heading { display: flex; align-items: start; justify-content: space-between; margin-bottom: 24px; }
.section-heading h2, .note-card h2 { margin-bottom: 0; font-size: 24px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.field { display: grid; gap: 9px; color: #d9dbe0; font-size: 14px; }
.input-with-unit { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 14px; background: #111318; overflow: hidden; }
.input-with-unit:focus-within { border-color: #8a8f9a; box-shadow: 0 0 0 3px rgba(255,255,255,.06); }
.input-with-unit input { min-width: 0; width: 100%; padding: 14px; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 17px; font-weight: 700; }
.input-with-unit span { padding-right: 14px; color: var(--muted); white-space: nowrap; }
.field small, .check-field small { color: var(--muted); line-height: 1.45; }

.soc-panel { margin: 28px 0 22px; padding: 20px; border-radius: 17px; background: #121419; }
.soc-row { display: flex; justify-content: space-between; align-items: center; }
.soc-row label { color: #d9dbe0; font-size: 14px; }
.soc-row output { color: #ff777a; font-size: 18px; font-weight: 800; }
.target-row { margin-top: 20px; }
input[type="range"] { width: 100%; margin: 10px 0 0; accent-color: var(--accent); }

details { border-top: 1px solid var(--line); }
summary { padding: 20px 0 4px; color: #d9dbe0; cursor: pointer; font-weight: 700; }
.details-content { margin-top: 18px; }
.check-field { display: flex; grid-column: 1 / -1; gap: 12px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: #111318; }
.check-field input { width: 19px; height: 19px; margin: 1px 0 0; accent-color: var(--accent); }
.check-field span { display: grid; gap: 5px; }

.validation-message { margin: 20px 0 0; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); color: #ff9a9d; }
.note-card { padding: 24px; }
.note-card h2 { margin-bottom: 10px; }
.note-card p { margin-bottom: 0; color: var(--muted); line-height: 1.6; }

footer { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0 calc(28px + env(safe-area-inset-bottom)); color: var(--muted); font-size: 12px; }
#connectionStatus { color: var(--success); }
#connectionStatus.offline { color: #ffbd66; }

@media (max-width: 620px) {
  .app-header, main, footer { width: min(100% - 22px, 760px); }
  .app-header { min-height: 78px; }
  .hero { min-height: 190px; padding: 24px 20px; }
  .hero h2 { font-size: clamp(34px, 11vw, 48px); }
  .battery-shell { width: 62px; height: 108px; border-radius: 13px; }
  .battery-tip { width: 7px; height: 28px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metrics article:last-child { grid-column: 1 / -1; }
  .field-grid { grid-template-columns: 1fr; }
  .check-field { grid-column: auto; }
  footer { flex-direction: column; }
  .install-dialog { margin-bottom: max(14px, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
