/* Light by default, dark when the device asks for it. Nothing here overrides
   the reader's choice, and `color-scheme` also tells the browser which palette
   to use for anything it draws itself. */
:root {
  color-scheme: light dark;

  --bg: #ffffff;
  --sunken: #f4f4f5;
  --line: #e4e4e7;
  --line-strong: #d0d0d6;
  --text: #16161a;
  --text-dim: #78787f;
  --accent: #2f6fed;
  --accent-wash: #eef3fe;
  --good: #12855a;
  --warn: #96690f;
  --bad: #cf3b32;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e11;
    --sunken: #1b1b20;
    --line: #26262c;
    --line-strong: #38383f;
    --text: #f2f2f5;
    --text-dim: #8c8c96;
    --accent: #6f9bff;
    --accent-wash: #18203a;
    --good: #3ac889;
    --warn: #e0a63c;
    --bad: #ff6f66;
  }
}

* { box-sizing: border-box; }

/* `.gate` and `.banner` set their own display, which would otherwise beat
   the browser's rule for the hidden attribute. */
[hidden] { display: none !important; }

/* Which screen is up. Set in the document head before the first paint and
   thereafter by setScreen(), so there is exactly one thing to look at. */
#gate, main#app { display: none; }
html[data-boot="gate"] #gate { display: grid; }
html[data-boot="app"] main#app { display: flex; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR",
    "Apple SD Gothic Neo", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; color: inherit; }
button:disabled { opacity: .35; cursor: not-allowed; }

main {
  max-width: 420px;
  margin: 0 auto;
  padding: 0 20px calc(28px + env(safe-area-inset-bottom));
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* The header sits at the top; everything else takes the room that is left and
   centres in it, so the controls meet the eye rather than the thumb reaching up
   to a page that is all top and empty bottom. */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 40px;
}

/* ---------- sign-in ---------- */

.gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.gate-card { width: 100%; max-width: 260px; text-align: center; }

.gate-card h1 {
  margin: 0 0 28px;
  font-size: 19px;
  font-weight: 500;
  letter-spacing: .06em;
  color: var(--text);
}

/* Reserves its line so nothing shifts when a message appears. */
.gate-message {
  margin: 16px 0 0;
  min-height: 1.4em;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-dim);
}
.gate-error { color: var(--bad); }

.btn-signin {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.btn-signin:active { background: var(--sunken); }

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  padding: calc(24px + env(safe-area-inset-top)) 0 0;
}

.topbar-title {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .06em;
  color: var(--text-dim);
}

.pill {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 4px 0;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-online { color: var(--good); }
.pill-offline { color: var(--bad); }
.pill-checking { color: var(--warn); }
.pill-checking .dot { animation: blink 1.1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* ---------- offline notice ---------- */

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--sunken);
  color: var(--bad);
  font-size: 13px;
  line-height: 1.5;
}

/* No frames. Four controls do not need boxes drawn around them; the spacing
   groups them, and the page has one subject anyway. */

/* ---------- power and temperature ---------- */

.power-row { display: flex; align-items: center; gap: 20px; }
.power-card--off .power-row { justify-content: center; }

.power-btn {
  flex: 0 0 auto;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--text-dim);
  display: grid;
  place-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s, opacity .15s;
}
.power-glyph { font-size: 24px; line-height: 1; font-weight: 400; }
.power-btn[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.temp-block, .countdown-block { flex: 1; text-align: right; }

.temp-readout {
  font-size: 56px;
  font-weight: 200;
  line-height: 1;
  letter-spacing: -.045em;
  font-variant-numeric: tabular-nums;
}
.temp-unit { font-size: 19px; color: var(--text-dim); margin-left: 3px; letter-spacing: 0; }
.temp-buttons { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }

.countdown-readout {
  font-size: 26px;
  font-weight: 300;
  line-height: 1.3;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.dry-note {
  margin: 14px 0 0;
  text-align: right;
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.btn-round {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: transparent;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.btn-round:active { background: var(--sunken); }

/* ---------- buttons ---------- */

.button-row { display: flex; gap: 8px; }

.btn-ghost {
  flex: 1 1 auto;
  padding: 13px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.btn-ghost:active { background: var(--sunken); }
.btn-small { flex: 0 0 auto; padding: 6px 12px; font-size: 12px; }

/* The leg that is running: its button becomes the label for what is happening,
   so it reads as selected and does not take a press. Beats the disabled dimming
   on purpose — this is not a control that is unavailable, it is a state. */
.btn-ghost.is-running {
  background: var(--accent-wash);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
  opacity: 1;
  cursor: default;
}

/* ---------- home screen hint ---------- */

.install-hint {
  flex: 0 0 auto;
  margin: 20px auto 0;
  padding: 4px 8px;
  border: 0;
  background: transparent;
  font-size: 11px;
  color: var(--text-dim);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* iOS has no way to raise the system prompt, so the only honest thing left is
   to say where the button is. */
.sheet {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  width: calc(100% - 40px);
  max-width: 320px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--sunken);
  text-align: center;
  z-index: 45;
}
.sheet-text {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.8;
  color: var(--text);
}
.sheet-text svg { vertical-align: -3px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  z-index: 40;
  max-width: calc(100% - 40px);
  text-align: center;
}
.toast.bad { background: var(--bad); color: #fff; }
