@font-face { font-family: "Sora"; font-weight: 400; src: url("fonts/sora-400.woff2") format("woff2"); }
@font-face { font-family: "Sora"; font-weight: 600; src: url("fonts/sora-600.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 500; src: url("fonts/ibm-plex-mono-500.woff2") format("woff2"); }

:root {
  --bg: #0b0f14;
  --card: #141b23;
  --field: #1c2530;
  --line: #2c3845;
  --text: #eef2f5;
  --muted: #a3afbb;
  --accent: #3ddc84;
  --on-accent: #06210f;
  --danger: #ff7b72;
  --radius: 12px;
  --sans: "Sora", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
/* A quick second tap is a second tap, not "zoom in" (pinch zoom still works). On every
   element: Safari on iPhone only honors it on the element tapped, so on the page alone a
   heading or plain text could still be double-tapped to zoom. */
*, *::before, *::after { touch-action: manipulation; }
/* ...except where a finger drags something: there, and inside it (the icon in a drag
   handle), the page mustn't scroll or zoom. */
.grip, .grip *, #calib-canvas { touch-action: none; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--sans);
  -webkit-text-size-adjust: 100%;
}

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(32px + env(safe-area-inset-bottom));
}

.top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 20px; min-height: 44px; }
h1 { font-size: 20px; font-weight: 600; margin: 0; }
h2 { font-size: 18px; font-weight: 600; margin: 0; }

.icon-button, .back {
  display: inline-flex; align-items: center; justify-content: center; gap: 2px;
  min-width: 44px; min-height: 44px; color: var(--muted); text-decoration: none;
}
.icon-button svg, .back svg {
  width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.back { justify-content: flex-start; margin-left: -6px; width: 80px; }
.top-actions { display: flex; gap: 4px; margin-right: -10px; }
.top-spacer { width: 80px; }
.icon-button:focus-visible, .back:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

.section { margin-bottom: 28px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 10px; }
.meta { font-size: 14px; color: var(--muted); white-space: nowrap; }

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.primary {
  min-height: 48px; padding: 0 20px;
  border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--on-accent); font-weight: 600;
}
.primary:disabled { opacity: 0.6; }
.wide { width: 100%; }
.link { background: none; border: 0; color: var(--muted); min-height: 44px; padding: 0 4px; }
.secondary {
  min-height: 48px; margin-top: 10px; padding: 0 16px;
  background: var(--field); border: 1px solid var(--line); border-radius: 10px; color: var(--text);
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 0 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.card-title {
  margin: 0 0 4px;
  font-family: var(--mono); font-size: 13px; font-weight: 500; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--muted);
}

label { font-size: 14px; color: var(--muted); margin-top: 6px; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
#accent-row { display: flex; flex-direction: column; gap: 8px; }
label.disabled { opacity: 0.45; }

/* Two-way choice: real radio buttons, drawn as a segmented control. */
.group-label { font-size: 14px; color: var(--muted); margin-top: 6px; }
.segmented {
  position: relative;
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
  background: var(--field); border: 1px solid var(--line); border-radius: 10px;
}
/* The green highlight is one pill that slides to whichever side is checked. */
.segmented::before {
  content: ""; position: absolute; top: 4px; bottom: 4px; left: 4px;
  width: calc(50% - 6px); border-radius: 7px; background: var(--accent);
}
.segmented:has(label:nth-child(2) input:checked)::before { transform: translateX(calc(100% + 4px)); }
.segmented:not(:has(input:checked))::before { opacity: 0; }
.segmented label { margin: 0; position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  position: relative; /* above the pill */
  display: flex; align-items: center; justify-content: center; min-height: 40px;
  border-radius: 7px; color: var(--muted); font-size: 15px; font-weight: 600;
}
.segmented input:checked + span { color: var(--on-accent); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Animate only after the saved value is shown, so the page doesn't slide on load. */
.segmented.animate::before { transition: transform 0.22s ease, opacity 0.15s; }
.segmented.animate span { transition: color 0.22s ease; }
@media (prefers-reduced-motion: reduce) {
  .segmented.animate::before, .segmented.animate span { transition: none; }
}
input:disabled, select:disabled { opacity: 0.45; cursor: not-allowed; }

.advanced { margin-top: 4px; }
.advanced summary {
  min-height: 44px; display: flex; align-items: center; cursor: pointer;
  color: var(--muted); font-size: 14px;
}
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::before {
  content: "▸"; display: inline-block; width: 1.2em; text-align: center; margin-right: 2px;
  transition: transform 0.22s ease;
}
/* .is-open flips as soon as you tap, so the arrow turns while the section slides. */
.advanced.is-open summary::before { transform: rotate(90deg); }
.advanced-body { display: flex; flex-direction: column; gap: 8px; overflow: hidden; }
@media (prefers-reduced-motion: reduce) {
  .advanced summary::before { transition: none; }
}
.signout { text-align: center; margin-top: 24px; }

input[type="text"], input[type="password"], input[type="number"], input[type="date"], select {
  width: 100%; min-height: 48px; padding: 0 12px;
  background: var(--field); border: 1px solid var(--line); border-radius: 10px;
}
/* iOS Safari sizes date fields itself and overflows the card; reset that. */
input[type="date"] {
  -webkit-appearance: none; appearance: none;
  display: block; min-width: 0; max-width: 100%; line-height: 46px;
}
input[type="date"]::-webkit-date-and-time-value { text-align: left; }
input[type="color"] {
  width: 64px; height: 44px; padding: 2px;
  background: var(--field); border: 1px solid var(--line); border-radius: 10px;
}
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; color: var(--text); font-size: 16px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pair > div { display: flex; flex-direction: column; gap: 8px; }

.error { color: var(--danger); font-size: 14px; margin: 0; min-height: 1em; }
.field-error { color: var(--danger); font-size: 13px; }
.status { color: var(--muted); font-size: 14px; text-align: center; min-height: 1.4em; }
.notice { background: var(--card); border: 1px solid var(--danger); border-radius: var(--radius); padding: 12px 16px; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

/* to-dos */
.progress { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.progress .bar { flex: 1; }
.bar { height: 6px; border-radius: 3px; background: var(--field); }
.bar-fill { height: 6px; border-radius: 3px; background: var(--accent); width: 0; transition: width 0.6s ease; }

.add { display: flex; gap: 8px; margin-bottom: 12px; }
.add input { flex: 1; min-width: 0; }

.reminder-form { margin-bottom: 12px; }
.reminder-form .add { margin-bottom: 8px; }
.reminder-when { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 6px; }
.reminder-when select { grid-column: 1 / -1; }
input[type="time"] {
  -webkit-appearance: none; appearance: none; display: block; width: 100%; min-width: 0;
  min-height: 48px; line-height: 46px; padding: 0 12px;
  background: var(--field); border: 1px solid var(--line); border-radius: 10px;
}
input[type="time"]::-webkit-date-and-time-value { text-align: left; }
.reminders { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.reminder {
  display: flex; align-items: center; gap: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 2px 4px 2px 0;
}
.reminder .open {
  flex: 1; min-width: 0; min-height: 56px; padding: 8px 4px 8px 16px; text-align: left;
  background: none; border: 0; color: var(--text); display: flex; flex-direction: column; justify-content: center;
}
.reminder .when { font-size: 14px; color: var(--muted); }
.reminder.editing { border-color: var(--accent); }
.reminder .delete {
  flex: none; width: 44px; height: 44px; border: 0; background: none;
  display: grid; place-items: center; color: var(--muted);
}
.reminder .delete svg { width: 18px; height: 18px; }
.clear-done { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 4px; }
.clear-done .link { color: var(--accent); }
.porch { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.porch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 6px 6px 6px 16px; min-height: 48px;
}
.porch-row .secondary { margin-top: 0; min-height: 40px; }
.porch-row.info { color: var(--muted); }
/* Drag handle: touch-action none so dragging moves the row instead of scrolling the page. */
.todo .grip {
  flex: none; width: 40px; height: 44px; border: 0; background: none; color: var(--muted);
  display: grid; place-items: center; touch-action: none; cursor: grab;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.todo .grip svg { width: 20px; height: 20px; }
.todo.dragging {
  position: relative; z-index: 2; cursor: grabbing;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55); border-color: var(--accent);
}
.todo.shifting { transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1); }
.todo.settling { transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1); }
@media (prefers-reduced-motion: reduce) {
  .todo.shifting, .todo.settling { transition: none; }
}
.todos { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.todo {
  display: flex; align-items: center; gap: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 2px 4px;
}
.todo .toggle, .todo .delete {
  flex: none; width: 44px; height: 44px; border: 0; background: none;
  display: grid; place-items: center; color: var(--muted);
}
.todo .toggle svg { width: 24px; height: 24px; }
.todo .delete svg { width: 18px; height: 18px; }
.todo .text {
  flex: 1; min-width: 0; min-height: 44px; padding: 10px 4px;
  border: 0; background: none; text-align: left; overflow-wrap: anywhere;
}
.todo .text { transition: color 0.3s; }
.todo.done .text { color: var(--muted); }
/* Strike-through as a background line that can be drawn on (see strikeLabel in admin.js). */
.strike { background: linear-gradient(currentColor, currentColor) no-repeat 0 58% / 0% 2px; }
.strike.on { background-size: 100% 2px; }
.strike.animate { transition: background-size var(--strike-ms, 350ms) linear; }
@media (prefers-reduced-motion: reduce) {
  .bar-fill, .strike.animate { transition: none; }
}
.todo .edit { flex: 1; min-width: 0; min-height: 40px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* ---- the display panel (#hud) ----
   Opening it slides the display in from the left while this page eases a third of the
   way right and dims, the way iPhone apps move between screens; closing reverses it. The
   shade trailing the panel's edge softens where the two pages meet. Transforms and
   opacity only, so the phone can animate it smoothly. */
.hud-panel {
  position: fixed; inset: 0; z-index: 20; background: #000;
  transform: translateX(-100%); visibility: hidden;
  transition: transform 460ms cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s 460ms;
}
.hud-panel iframe { display: block; width: 100%; height: 100%; border: 0; }
.hud-panel::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 100%; width: 96px; pointer-events: none;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.85), transparent);
  /* Closing, the shade fades while the panel is still moving (most of its travel happens
     in the first half of the slide), so it's gone before the page underneath settles. */
  opacity: 0; transition: opacity 220ms ease-out;
}
body.hud-open .hud-panel::after { opacity: 1; transition: none; }
.wrap { transition: transform 460ms cubic-bezier(0.2, 0.8, 0.2, 1), opacity 460ms cubic-bezier(0.2, 0.8, 0.2, 1); }
body.hud-open { overflow: hidden; }
/* The page shifted aside mid-slide must never make the page scroll or pan sideways. */
body { overflow-x: hidden; overflow-x: clip; }
body.hud-open .hud-panel { transform: none; visibility: visible; transition: transform 460ms cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s; }
body.hud-open .wrap { transform: translateX(30%); opacity: 0.25; }
body.no-slide .hud-panel, body.no-slide .wrap { transition: none; }  /* opening straight to the display */
@media (prefers-reduced-motion: reduce) {
  .hud-panel, body.hud-open .hud-panel, .wrap { transition: none; }
}

/* password box with a show/hide button inside its right end */
.password-field { position: relative; }
.password-field input { padding-right: 52px; }
.reveal {
  position: absolute; top: 0; right: 0; bottom: 0; width: 48px;
  display: grid; place-items: center;
  background: none; border: 0; border-radius: 10px; color: var(--muted);
}
.reveal svg { width: 22px; height: 22px; }
.reveal[aria-pressed="true"] { color: var(--text); }

/* sign in, or pair this screen: side by side on a wide screen (the projector), else stacked */
.wrap:has(#login:not([hidden])) { max-width: 920px; }
.gate { display: grid; gap: 16px; align-items: start; padding-top: 4vh; }
@media (min-width: 760px) { .gate { grid-template-columns: 1fr 1fr; } }
.gate .card { margin: 0; }
.gate h1 { margin-bottom: 8px; }
.pair-panel { align-items: center; text-align: center; }
.pair-panel .card-title { align-self: stretch; text-align: left; }
.pair-qr { width: 200px; height: 200px; border-radius: 8px; image-rendering: pixelated; }
.pair-code {
  font-family: var(--mono); font-size: 40px; font-weight: 500; letter-spacing: 0.18em;
  margin-right: -0.18em; color: var(--text);
}
.code-input { font-family: var(--mono); font-size: 22px; letter-spacing: 0.15em; text-transform: uppercase; }
a.secondary { display: flex; align-items: center; justify-content: center; text-decoration: none; }

/* paired displays */
.devices { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.device {
  display: flex; flex-direction: column; gap: 8px; padding: 8px 8px 8px 12px;
  background: var(--field); border: 1px solid var(--line); border-radius: 10px;
}
.device-head { display: flex; align-items: center; gap: 4px; min-height: 44px; }
.device-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.device-name { overflow-wrap: anywhere; }
.device-tag {
  margin-left: 8px; padding: 1px 6px; border: 1px solid var(--line); border-radius: 6px;
  font-size: 12px; color: var(--muted); white-space: nowrap;
}
.device-head input { flex: 1; min-width: 0; }
.device .link { flex: none; }
.device .segmented { background: var(--card); }

/* calibrating a projector: full screen over everything */
.calibrate {
  position: fixed; inset: 0; z-index: 50;
  display: flex; flex-direction: column; gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
  background: var(--bg);
}
body.calibrate-open { overflow: hidden; }
.calib-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.calib-top h1 { overflow-wrap: anywhere; }
.calib-top .primary { min-height: 44px; }
.calib-stage { flex: 1; min-height: 180px; position: relative; }
#calib-canvas { position: absolute; inset: 0; touch-action: none; display: block; }
.calib-controls { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 560px; margin: 0 auto; }
.calibrate button:not(.primary) {
  min-height: 48px; padding: 0 10px;
  background: var(--field); border: 1px solid var(--line); border-radius: 10px; color: var(--text);
}
.calibrate button { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.calibrate button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.calibrate button:disabled { opacity: 0.4; }
.calib-select { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 6px; }
.calib-middle { display: grid; grid-template-columns: auto 1fr; gap: 12px; align-items: center; }
.calib-pad {
  display: grid; grid-template-columns: repeat(3, 52px); grid-template-rows: repeat(3, 48px); gap: 4px;
  grid-template-areas: ". up ." "left step right" ". down .";
}
.calib-pad .up { grid-area: up; } .calib-pad .left { grid-area: left; } .calib-pad .step { grid-area: step; font-size: 13px; }
.calib-pad .right { grid-area: right; } .calib-pad .down { grid-area: down; }
.calib-pad button { padding: 0; }
.calib-side { display: flex; flex-direction: column; gap: 6px; }
.calib-zoom { display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; gap: 6px; text-align: center; color: var(--muted); font-size: 14px; }
.calib-zoom button { font-size: 20px; padding: 0; }
.calib-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.device a.secondary { margin-top: 0; min-height: 44px; }

/* Home Assistant setup snippets */
.snippet {
  margin: 0; padding: 10px 12px; overflow-x: auto;
  background: var(--field); border: 1px solid var(--line); border-radius: 10px;
  font: 13px/1.5 var(--mono); color: var(--text); user-select: all;
}
code { font-family: var(--mono); font-size: 0.92em; }
