@font-face {
  font-family: "Barlow";
  src: url("/fonts/barlow-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Barlow";
  src: url("/fonts/barlow-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Barlow";
  src: url("/fonts/barlow-latin-600-normal.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "Barlow Condensed";
  src: url("/fonts/barlow-condensed-latin-300-normal.woff2") format("woff2");
  font-weight: 300;
  font-display: swap;
}
@font-face {
  font-family: "Barlow Condensed";
  src: url("/fonts/barlow-condensed-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}

/* A tela inteira assume o tom do modo: dá para saber o estado do ar de longe, sem ler. */
:root {
  color-scheme: light dark;
  --field: #dcebf3;
  --ink: #0e2733;
  --accent: #07638f;
  --on-accent: #ffffff;
  --muted: color-mix(in srgb, var(--ink) 68%, var(--field));
  --line: color-mix(in srgb, var(--ink) 22%, var(--field));
  --tray: color-mix(in srgb, #ffffff 62%, var(--field));
  --raised: color-mix(in srgb, #ffffff 45%, var(--field));
  --danger: #a3211a;
}
:root[data-mode="off"] {
  --field: #e6e8e7;
  --ink: #20292d;
  --accent: #46545c;
}
:root[data-mode="heat"] {
  --field: #f7e4d0;
  --ink: #33200f;
  --accent: #a0460a;
}
:root[data-mode="dry"] {
  --field: #d6ebe3;
  --ink: #0e2b24;
  --accent: #0a6a54;
}
:root[data-mode="wind"] {
  --field: #e4ebdb;
  --ink: #222b14;
  --accent: #4b671d;
}
:root[data-mode="auto"] {
  --field: #e5e3f4;
  --ink: #201d3d;
  --accent: #4c43a6;
}

@media (prefers-color-scheme: dark) {
  :root {
    --field: #0f2430;
    --ink: #e4f1f6;
    --accent: #86d3f2;
    --on-accent: #06222e;
    --tray: color-mix(in srgb, #ffffff 7%, var(--field));
    --raised: color-mix(in srgb, #ffffff 11%, var(--field));
    --danger: #ffb4ab;
  }
  :root[data-mode="off"] {
    --field: #1a2023;
    --ink: #e4e9eb;
    --accent: #a9b6bc;
    --on-accent: #12181b;
  }
  :root[data-mode="heat"] {
    --field: #2a1b10;
    --ink: #f8e9dc;
    --accent: #f2ae6e;
    --on-accent: #2a1606;
  }
  :root[data-mode="dry"] {
    --field: #0e2822;
    --ink: #e0f3ec;
    --accent: #7fdac0;
    --on-accent: #06241c;
  }
  :root[data-mode="wind"] {
    --field: #1e2615;
    --ink: #edf3e2;
    --accent: #bbd68a;
    --on-accent: #1a230c;
  }
  :root[data-mode="auto"] {
    --field: #1d1b33;
    --ink: #eceaf9;
    --accent: #b8b2f5;
    --on-accent: #17143a;
  }
}

* {
  box-sizing: border-box;
}

html {
  background: var(--field);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--field);
  color: var(--ink);
  font: 400 1rem/1.4 "Barlow", system-ui, sans-serif;
  transition: background-color 0.4s ease, color 0.4s ease;
}

h1,
h2,
p {
  margin: 0;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

svg {
  display: block;
  width: 24px;
  height: 24px;
}

[hidden] {
  display: none !important;
}

/* Instrumento */
#app {
  display: grid;
  min-height: 100dvh;
  grid-template-rows: auto 1fr auto;
}

.instrument {
  display: grid;
  align-content: start;
  gap: 20px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 20px 28px;
}

h1 {
  font-size: 1.125rem;
  font-weight: 600;
}

#room {
  color: var(--muted);
}

#device {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--raised);
  font-weight: 600;
}

.readout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
}

#target {
  font-family: "Barlow Condensed", "Barlow", system-ui, sans-serif;
  font-size: clamp(7.5rem, 40vw, 10rem);
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  line-height: 0.82;
  letter-spacing: -0.02em;
  color: var(--accent);
  transition: color 0.4s ease;
}

:root[data-mode="off"] #target {
  color: var(--muted);
}

.steppers {
  display: flex;
  gap: 8px;
}

.step {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
}

.step:active:not(:disabled) {
  background: var(--raised);
}

/* Régua: a agulha é o polegar do input range, e as marcas ficam recuadas pela metade dele para coincidirem. */
.scale {
  --thumb: 44px;
  position: relative;
  height: 96px;
  margin: 0 -8px;
}

.ticks,
.room-track {
  position: absolute;
  left: calc(var(--thumb) / 2);
  right: calc(var(--thumb) / 2);
  pointer-events: none;
}

.ticks {
  top: 10px;
  height: 46px;
}

.tick {
  position: absolute;
  top: 0;
  left: calc(var(--position) * 100%);
  width: 1.5px;
  height: 12px;
  margin-left: -0.75px;
  background: var(--line);
}

.tick.major {
  height: 20px;
  background: var(--muted);
}

.tick.major::after {
  content: attr(data-label);
  position: absolute;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--muted);
  font-family: "Barlow Condensed", "Barlow", system-ui, sans-serif;
  font-size: 1rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

#scale {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 52px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: grab;
  touch-action: pan-y;
}

#scale:disabled {
  cursor: not-allowed;
}

#scale:focus-visible {
  outline: none;
}

#scale::-webkit-slider-runnable-track {
  height: 52px;
  background: transparent;
}

#scale::-moz-range-track {
  height: 52px;
  background: transparent;
}

#scale::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: var(--thumb);
  height: 52px;
  border: 0;
  background: linear-gradient(var(--accent), var(--accent)) center top / 4px 40px no-repeat;
}

#scale::-moz-range-thumb {
  width: var(--thumb);
  height: 52px;
  border: 0;
  border-radius: 0;
  background: linear-gradient(var(--accent), var(--accent)) center top / 4px 40px no-repeat;
}

#scale:focus-visible::-webkit-slider-thumb {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 6px;
}

#scale:focus-visible::-moz-range-thumb {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-radius: 6px;
}

:root[data-mode="off"] #scale::-webkit-slider-thumb {
  background-image: linear-gradient(var(--muted), var(--muted));
}

:root[data-mode="off"] #scale::-moz-range-thumb {
  background-image: linear-gradient(var(--muted), var(--muted));
}

.room-track {
  top: 62px;
}

#room-mark {
  position: absolute;
  left: calc(var(--position) * 100%);
  transform: translateX(-50%);
  padding-top: 9px;
  color: var(--ink);
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
}

#room-mark::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 8px;
  height: 8px;
  background: var(--ink);
  transform: translateX(-50%) rotate(45deg);
}

#room-mark.align-start {
  transform: translateX(-4px);
}

#room-mark.align-start::before {
  left: 4px;
}

#room-mark.align-end {
  transform: translateX(calc(-100% + 4px));
}

#room-mark.align-end::before {
  left: calc(100% - 4px);
}

.power {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 60px;
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 1.125rem;
  font-weight: 600;
}

.power[aria-pressed="true"] {
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.setting h2,
.field-label,
.field label,
.segmented legend {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
}

.setting h2 {
  margin-bottom: 8px;
}

.options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(56px, 1fr));
  gap: 4px;
}

.options button {
  display: grid;
  justify-items: center;
  gap: 4px;
  min-height: 68px;
  padding: 10px 2px 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
}

.options button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--on-accent);
}

.options button:active:not([aria-pressed="true"]) {
  background: var(--raised);
}

.display-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#display-status {
  margin-top: 8px;
}

#connect {
  display: block;
  padding: 18px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}

#error,
#schedule-error,
#schedule-list-error {
  color: var(--danger);
  font-weight: 500;
}

#app.disconnected {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 1fr auto;
}

.disconnected .instrument {
  grid-row: auto;
}

.disconnected #logout {
  grid-column: auto;
  background: transparent;
}

.disconnected .readout,
.disconnected .scale,
.disconnected #power,
.disconnected .setting,
.disconnected .tray {
  display: none;
}

/* Programações */
.tray {
  background: var(--tray);
  border-radius: 20px 20px 0 0;
  transition: background-color 0.4s ease;
}

.tray-content {
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 20px 20px;
}

.tray h2 {
  font-family: "Barlow Condensed", "Barlow", system-ui, sans-serif;
  font-size: 1.75rem;
  font-weight: 500;
  line-height: 1.1;
}

#schedule-empty {
  color: var(--muted);
}

#schedule-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

#schedule-list li {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 2px 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

#schedule-list li:last-child {
  border-bottom: 1px solid var(--line);
}

#schedule-list strong {
  font-family: "Barlow Condensed", "Barlow", system-ui, sans-serif;
  font-size: 2rem;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.item-text {
  display: grid;
  min-width: 0;
  line-height: 1.25;
}

.item-text span {
  font-weight: 500;
}

.item-text small {
  color: var(--muted);
  font-size: 0.875rem;
}

.item-text small.failure {
  color: var(--danger);
}

#schedule-list li.off strong,
#schedule-list li.off .item-text span {
  color: var(--muted);
}

.switch {
  display: grid;
  place-items: center;
  min-width: 48px;
  min-height: 44px;
  cursor: pointer;
}

.switch input {
  position: relative;
  width: 44px;
  height: 26px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 13px;
  background: var(--line);
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.switch input::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.15s ease;
}

.switch input:checked {
  background: var(--accent);
}

.switch input:checked::before {
  background: var(--on-accent);
  transform: translateX(18px);
}

.remove {
  display: grid;
  place-items: center;
  width: 40px;
  height: 44px;
  margin-right: -8px;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.remove svg {
  width: 20px;
  height: 20px;
}

.wide-button {
  min-height: 52px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  font-weight: 600;
}

.wide-button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

#schedule-new {
  width: 100%;
}

#logout {
  min-height: 48px;
  border: 0;
  background: var(--tray);
  color: var(--muted);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Formulário em folha que sobe do fim da tela, ao alcance do polegar. */
dialog {
  width: 100%;
  max-width: 100%;
  max-height: 92dvh;
  margin: auto 0 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--field);
  color: var(--ink);
  overflow-y: auto;
}

dialog[open] {
  animation: sheet-up 0.22s ease-out;
}

dialog::backdrop {
  background: rgb(0 0 0 / 0.45);
}

@keyframes sheet-up {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}

#schedule-form {
  display: grid;
  gap: 16px;
  padding: 24px 20px max(20px, env(safe-area-inset-bottom));
}

#schedule-form h2 {
  font-family: "Barlow Condensed", "Barlow", system-ui, sans-serif;
  font-size: 1.75rem;
  font-weight: 500;
  line-height: 1.1;
}

.field,
.on-fields {
  display: grid;
  gap: 6px;
}

.on-fields {
  gap: 16px;
}

.field input,
.field select {
  width: 100%;
  min-height: 48px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--raised);
}

#schedule-time {
  font-family: "Barlow Condensed", "Barlow", system-ui, sans-serif;
  font-size: 1.75rem;
  font-weight: 500;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented legend {
  padding: 0 0 6px;
}

.segmented label {
  position: relative;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented span {
  display: grid;
  place-items: center;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-weight: 600;
}

.segmented input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.days {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.days button {
  aspect-ratio: 1;
  max-height: 48px;
  min-height: 40px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  font-weight: 600;
}

.days button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.hint {
  color: var(--muted);
  font-size: 0.875rem;
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 8px;
  margin-top: 4px;
}

/* Login */
.login-page {
  display: grid;
  align-content: center;
  gap: 24px;
  width: 100%;
  max-width: 400px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 24px 20px;
}

.login-page h1 {
  font-family: "Barlow Condensed", "Barlow", system-ui, sans-serif;
  font-size: 3.5rem;
  font-weight: 300;
  line-height: 1;
  color: var(--accent);
}

.login {
  display: grid;
  gap: 10px;
}

.login label {
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
}

.login input {
  min-height: 52px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--raised);
}

#error:empty {
  display: none;
}

/* No Mac, as programações ficam ao lado do instrumento em vez de abaixo. */
@media (min-width: 860px) {
  #app {
    grid-template-columns: minmax(0, 1fr) minmax(360px, 440px);
    grid-template-rows: 1fr auto;
  }

  .instrument {
    grid-row: 1 / -1;
    max-width: 520px;
    padding-top: 40px;
  }

  .tray {
    border-radius: 0;
  }

  .tray-content {
    padding: 40px 28px 20px;
  }

  #logout {
    grid-column: 2;
  }

  dialog {
    width: 440px;
    margin: auto;
    border-radius: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
