:root {
  --bg0: #0f1c24;
  --bg1: #173040;
  --card: rgba(255, 255, 255, 0.06);
  --line: rgba(255, 255, 255, 0.12);
  --text: #e8f1f4;
  --muted: #9bb3be;
  --accent: #3ecfb2;
  --accent-2: #f0a46a;
  --danger: #ff7b7b;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  font-family: "Segoe UI", "Avenir Next", "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  /* Solid fill so iOS PWA never shows white letterboxing in safe areas */
  background-color: var(--bg0);
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  color: var(--text);
  background-color: var(--bg0);
  background-image:
    radial-gradient(1200px 600px at 10% -10%, #2a6f7a55, transparent),
    radial-gradient(900px 500px at 100% 0%, #8a4b2a44, transparent),
    linear-gradient(160deg, var(--bg0), var(--bg1));
  background-attachment: fixed;
}

.shell {
  width: min(860px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 3rem;
  display: grid;
  gap: 1rem;
}

/* Inset content only — keep the dark background edge-to-edge */
@media (display-mode: standalone), (display-mode: minimal-ui) {
  .shell {
    padding-top: max(1.25rem, env(safe-area-inset-top, 0px));
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom, 0px));
  }
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.icon-btn {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--line);
  font-size: 1.15rem;
  line-height: 1;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(4, 12, 16, 0.72);
  backdrop-filter: blur(6px);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-panel {
  width: min(420px, 100%);
  max-height: min(90vh, 680px);
  overflow-x: hidden;
  overflow-y: auto;
  padding: 1.25rem 1.35rem 1.4rem;
}

/* Controls: bottom sheet that slides up */
#controlsOverlay.modal-overlay {
  place-items: end center;
  padding: 0;
  background: rgba(4, 12, 16, 0);
  transition: background 0.28s ease;
}

#controlsOverlay.is-open {
  background: rgba(4, 12, 16, 0.72);
}

#controlsOverlay .controls-panel {
  width: min(480px, 100%);
  max-height: min(92vh, 760px);
  margin: 0 auto;
  border-radius: 22px 22px 0 0;
  padding: 0.85rem 1.15rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
  transform: translateY(110%);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

#controlsOverlay.is-open .controls-panel {
  transform: translateY(0);
}

#controlsOverlay .controls-panel::before {
  content: "";
  display: block;
  width: 2.75rem;
  height: 0.3rem;
  margin: 0.15rem auto 0.85rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.25rem;
}

.settings-section {
  margin-top: 1.15rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
  min-width: 0;
}

.settings-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.modal-panel h3 {
  margin: 0;
  font-size: 0.8rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.settings-hint {
  margin: 0 0 0.9rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.account-email {
  margin: 0;
  padding: 0.85rem 0.95rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.22);
  font-size: 1rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.settings-meta {
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
}

.settings-form {
  display: grid;
  gap: 0.85rem;
  min-width: 0;
}

.field {
  display: grid;
  gap: 0.4rem;
  min-width: 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.field input,
.field select {
  width: 100%;
  min-width: 0;
}

.ghost-btn {
  flex: 0 0 auto;
  padding: 0.4rem 0.7rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
}

.primary-btn {
  width: 100%;
  margin-top: 0.15rem;
}

.device-name {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 1rem;
}

h1,
h2 {
  margin: 0.2rem 0 0;
  font-weight: 650;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

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

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.pill {
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  border: 1px solid var(--line);
}

.pill-on {
  background: color-mix(in srgb, var(--accent) 25%, transparent);
  color: var(--accent);
}

.pill-off {
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 0.75rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}

input,
select,
button {
  font: inherit;
}

input,
select {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  padding: 0.7rem 0.8rem;
  min-width: 0;
  max-width: 100%;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 0.7rem 1rem;
  background: linear-gradient(135deg, var(--accent), #2aa7d6);
  color: #062028;
  font-weight: 700;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.05);
}

.row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.row select {
  flex: 1;
}

.hero {
  display: grid;
  gap: 1.15rem;
}

.temps {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: end;
}

.temp {
  margin: 0;
  font-size: clamp(2.6rem, 9vw, 4.5rem);
  line-height: 1;
  font-weight: 700;
}

.temp-secondary {
  font-size: clamp(2.1rem, 7vw, 3.4rem);
  color: color-mix(in srgb, var(--text) 88%, var(--muted));
}

.controls-launch {
  width: 100%;
  min-height: 4.25rem;
  margin-top: 0.15rem;
  border-radius: 16px;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.label {
  margin: 0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
}

.status-chip {
  min-width: 0;
  padding: 0.75rem 0.85rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.22);
}

.status-chip[hidden] {
  display: none;
}

.status-value {
  margin: 0.35rem 0 0;
  font-size: 1.15rem;
  font-weight: 650;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.controls-panel {
  width: min(440px, 100%);
}

.controls-section-label {
  margin: 0.35rem 0 0.65rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.modes {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
  margin: 0;
}

.modes button {
  min-height: 3.4rem;
  padding: 0.85rem 0.75rem;
  font-size: 1.05rem;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  border: 1px solid var(--line);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.modes button:nth-child(5) {
  grid-column: 1 / -1;
}

.modes button.active {
  background: color-mix(in srgb, var(--accent-2) 40%, transparent);
  border-color: var(--accent-2);
  color: #fff;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent-2) 50%, transparent);
}

.setpoints {
  display: grid;
  gap: 0.85rem;
  margin: 0;
}

.stepper-card {
  padding: 0.95rem 1rem 1.05rem;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.22);
}

.stepper-card[hidden] {
  display: none;
}

.stepper-card .label {
  font-size: 0.85rem;
  margin-bottom: 0.55rem;
}

.stepper {
  display: grid;
  grid-template-columns: 4.25rem 1fr 4.25rem;
  align-items: center;
  gap: 0.75rem;
  margin: 0;
}

.stepper button {
  width: 100%;
  min-height: 4.25rem;
  padding: 0;
  border-radius: 14px;
  font-size: 2rem;
  line-height: 1;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
  border: 1px solid var(--line);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.stepper-value {
  text-align: center;
  font-size: clamp(2.4rem, 10vw, 3.2rem);
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.error {
  color: var(--danger);
}

@media (max-width: 640px) {
  .shell {
    width: min(860px, calc(100% - 1.25rem));
    padding: 1.25rem 0 2rem;
  }

  @media (display-mode: standalone), (display-mode: minimal-ui) {
    .shell {
      padding-top: max(1rem, env(safe-area-inset-top, 0px));
      padding-bottom: max(1.25rem, env(safe-area-inset-bottom, 0px));
    }
  }

  .temps,
  .row {
    grid-template-columns: 1fr 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  #controlsOverlay .controls-panel {
    width: 100%;
    max-width: none;
    border-radius: 22px 22px 0 0;
  }

  .modal-head h2 {
    font-size: 1.4rem;
  }

  .icon-btn {
    width: 3rem;
    height: 3rem;
    font-size: 1.25rem;
  }

  .modes {
    gap: 0.75rem;
  }

  .modes button {
    min-height: 3.75rem;
    font-size: 1.15rem;
    border-radius: 14px;
  }

  .stepper {
    grid-template-columns: 4.75rem 1fr 4.75rem;
    gap: 0.85rem;
  }

  .stepper button {
    min-height: 4.75rem;
    font-size: 2.35rem;
    border-radius: 16px;
  }

  .stepper-value {
    font-size: clamp(2.8rem, 12vw, 3.6rem);
  }

  .controls-launch {
    min-height: 4.75rem;
    font-size: 1.45rem;
  }

  .status-value {
    font-size: 1.25rem;
  }
}
