/*
  One stylesheet for the app's page and for every widget's page, since a
  widget is a part of the app's own screen alone. Light and dark follow the
  phone; framed, a widget is told which by what frames it (widget.js).
*/
:root {
  color-scheme: light dark;
  --bg: #f5f2ea;
  --card: #fffdf8;
  --ink: #1f1d18;
  --soft: #6d675b;
  --line: #e3ddcf;
  --lit: #ffd35c;
  --lit-ink: #33270a;
  --window: #cfe3ee;
  --shade: #b9ad95;
  --warn: #9a3412;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130f;
    --card: #1f1d18;
    --ink: #f1ede2;
    --soft: #a59f90;
    --line: #322f27;
    --lit: #f4c44f;
    --lit-ink: #2a1f04;
    --window: #2b3a44;
    --shade: #6f6757;
    --warn: #fdba74;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(40px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
main, .top { max-width: 44rem; margin: 0 auto; }
h1, h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }

.top { display: flex; align-items: center; gap: 12px; padding: 6px 0 18px; flex-wrap: wrap; }
.top h1 { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; margin-right: auto; }
main > div > section, .settings, .start { margin-top: 26px; }
main > div > section:first-of-type { margin-top: 4px; }
h2 { font-size: 0.82rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--soft); margin-bottom: 10px; }

button, .button, input { font: inherit; color: inherit; }
button, .button {
  appearance: none;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--bg);
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font-weight: 650;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  touch-action: manipulation;
}
button.quiet { background: none; color: var(--ink); border-color: var(--line); }
button.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; font-weight: 650; border-radius: 4px; }
button:disabled { opacity: 0.5; cursor: default; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
input:not([type]), input[type="text"] {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
  min-width: 0;
  width: 100%;
}

.note { color: var(--soft); font-size: 0.95rem; }
.note[role="alert"], .trouble { color: var(--warn); }
#said { margin-bottom: 14px; }
.hint { color: var(--soft); font-size: 0.9rem; }
.banner { background: var(--card); border: 1px dashed var(--line); border-radius: 14px; padding: 10px 14px; font-size: 0.95rem; margin-bottom: 18px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Home or out ── */
.presence { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.presence button { background: none; border-color: transparent; color: var(--soft); padding: 0.35rem 0.95rem; }
.presence button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

/* ── Lights and plugs ── */
.room { font-size: 0.95rem; font-weight: 700; margin: 16px 0 8px; }
.room:first-child { margin-top: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.25rem, 1fr)); gap: 10px; }
.tile { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 18px; min-height: 6.6rem; display: grid; transition: background-color 0.18s, border-color 0.18s; }
.tile[data-on] { background: var(--lit); border-color: var(--lit); color: var(--lit-ink); }
.tile[data-away] { opacity: 0.55; }
.tile-press { all: unset; box-sizing: border-box; cursor: pointer; display: grid; grid-template-rows: auto 1fr auto; gap: 2px; padding: 12px 14px 14px; border-radius: 18px; min-width: 0; touch-action: manipulation; }
.tile-press:disabled { cursor: default; }
.tile-press:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.tile[data-on] .tile-press { padding-bottom: 14px; }
.tile:has(.dim, .whites) .tile-press { padding-bottom: 4px; }
.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; margin-bottom: 8px; opacity: 0.55; }
.tile[data-on] .icon { fill: currentColor; fill-opacity: 0.18; opacity: 1; }
.tile-name { font-weight: 650; overflow-wrap: anywhere; line-height: 1.25; align-self: end; }
.tile-state { font-size: 0.85rem; color: var(--soft); }
.tile[data-on] .tile-state { color: inherit; opacity: 0.75; }

.dim { --at: 50%; appearance: none; -webkit-appearance: none; display: block; width: calc(100% - 28px); height: 24px; margin: 0 14px 6px; background: none; cursor: pointer; touch-action: pan-y; }
.dim::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: linear-gradient(to right, var(--lit-ink) var(--at), color-mix(in srgb, var(--lit-ink) 22%, transparent) var(--at)); }
.dim::-moz-range-track { height: 6px; border-radius: 3px; background: linear-gradient(to right, var(--lit-ink) var(--at), color-mix(in srgb, var(--lit-ink) 22%, transparent) var(--at)); }
.dim::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%; background: var(--lit-ink); border: 0; }
.dim::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--lit-ink); border: 0; }

.whites { display: flex; gap: 8px; margin: 2px 14px 12px; }
.white { width: 26px; height: 26px; padding: 0; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--lit-ink) 30%, transparent); background: #fff; position: relative; }
.white::after { content: ""; position: absolute; inset: -9px; }
.white[data-kelvin="2700"] { background: #ffb866; }
.white[data-kelvin="3500"] { background: #ffd9a8; }
.white[data-kelvin="4500"] { background: #fff4e3; }
.white[data-kelvin="6500"] { background: #dbe8ff; }
.white[aria-pressed="true"] { border-color: var(--lit-ink); box-shadow: 0 0 0 2px var(--lit), 0 0 0 4px var(--lit-ink); }

/* ── Blinds ── */
.part-blinds { display: grid; gap: 10px; }
.blind { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px 14px; }
.blind[data-away] { opacity: 0.55; }
.blind-words { display: grid; min-width: 0; }
.pane { width: 34px; height: 40px; border-radius: 6px; background: var(--window); border: 2px solid var(--ink); overflow: hidden; display: block; }
.shade { display: block; background: var(--shade); border-bottom: 2px solid var(--ink); transition: height 0.4s; box-sizing: content-box; }
.blind-to { display: inline-flex; background: var(--bg); border-radius: 999px; padding: 3px; }
.to { background: none; border-color: transparent; color: var(--soft); padding: 0.35rem 0.75rem; font-size: 0.92rem; }
.to[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
@media (max-width: 26rem) {
  .blind { grid-template-columns: auto 1fr; }
  .blind-to { grid-column: 1 / -1; justify-self: start; }
}

/* ── Doors and windows ── */
.part-doors { display: grid; gap: 8px; }
.door { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px 14px; }
.door[data-away] { opacity: 0.55; }
.pills { display: inline-flex; gap: 6px; align-items: center; }
.lock-press { padding: 0.3rem 0.9rem; font-size: 0.9rem; margin-left: 4px; }
.pill { font-size: 0.85rem; font-weight: 650; padding: 0.2rem 0.65rem; border-radius: 999px; background: var(--bg); color: var(--soft); }
.pill[data-loud] { background: var(--lit); color: var(--lit-ink); }

/* ── Temperatures ── */
.air { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px 14px; display: grid; gap: 0; }
.air .tile-name { align-self: start; font-size: 0.9rem; }
.degrees { font-size: 2rem; font-weight: 750; letter-spacing: -0.03em; line-height: 1.15; font-variant-numeric: tabular-nums; }

[data-busy] { transition: opacity 0.2s; }

/* ── The first page ── */
.start { display: grid; gap: 18px; justify-items: start; }
.lead { font-size: 1.25rem; line-height: 1.35; max-width: 26rem; font-weight: 600; }
.brands { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.paste { display: grid; gap: 10px; margin-top: 12px; max-width: 26rem; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.paste label { display: grid; gap: 4px; font-size: 0.9rem; font-weight: 650; }
.paste label > * { font-weight: 400; }
.paste label > span { font-weight: 650; }
.code { display: grid; gap: 8px; max-width: 26rem; border-top: 1px solid var(--line); padding-top: 18px; }
.code label { font-size: 0.92rem; color: var(--soft); }
.code input { width: 9rem; letter-spacing: 0.12em; }
.code-shown { font-size: 1.7rem; font-weight: 750; letter-spacing: 0.12em; font-variant-numeric: tabular-nums; margin-top: 10px; }

/* ── Settings ── */
.settings { border-top: 1px solid var(--line); padding-top: 22px; display: grid; gap: 10px; justify-items: start; }
.settings > * { max-width: 100%; }
.settings h2 { margin: 0; }
.settings h3 { font-size: 1.02rem; margin-top: 18px; }
.rows { display: grid; gap: 8px; width: 100%; }
.rows li { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.row-words { display: grid; margin-right: auto; min-width: 0; }
.things li { display: grid; grid-template-columns: auto minmax(0, 1.2fr) minmax(0, 1fr); align-items: end; }
.things li .tile-state { grid-column: 2 / -1; }
.things label { display: grid; gap: 3px; min-width: 0; }
.things label span { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--soft); }
.things input[type="checkbox"] { align-self: center; }
select { font: inherit; color: inherit; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 0.5rem 0.5rem; min-width: 0; width: 100%; height: 2.45rem; }
.things input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--ink); }
#settings-connect, #start-connect { width: 100%; }

/* ── A widget's page: the part alone, on whatever frames it ── */
.widget-page { background: transparent; padding: 2px; }
.widget-page .note { padding: 6px 2px; }

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