:root {
  --bg: #f6f1ea;
  --ink: #2b2622;
  --muted: #7a7068;
  --card: #fffdf9;
  --accent: #c2410c;
  --line: #e4dbcf;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

/* Login */
#login { align-items: center; justify-content: center; padding-left: 16px; padding-right: 16px; }
.card { width: 100%; max-width: 340px; background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.card h1 { margin: 0 0 4px; font-size: 24px; font-weight: 650; }
.card label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.card input { font-size: 17px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); -webkit-user-select: text; user-select: text; }
.card button { padding: 12px; border: 0; border-radius: 10px; background: var(--ink); color: #fff; font-weight: 600; }
.card.has-passkey button[type="submit"] { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.error { margin: 0; color: #b91c1c; font-size: 14px; }

/* App */
.topbar { display: flex; align-items: center; justify-content: flex-end; padding: 14px 16px 8px; min-height: 40px; }
.people { display: flex; gap: 6px; font-size: 13px; color: var(--muted); }
.people .who { display: inline-flex; align-items: center; gap: 4px; }
.people .who::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #16a34a; }

.stage { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px 12px; }
.paper { position: relative; background: #fff; border-radius: 6px; box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 6px 24px rgba(60,40,20,.10); overflow: hidden; }
.paper canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.zoom { position: absolute; inset: 0; transform-origin: 0 0; }
.zoom.easing { transition: transform .18s ease-out; }
.zoom-out { position: absolute; left: 8px; bottom: 8px; z-index: 5; padding: 6px 12px; font: inherit; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.92); color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,.12); cursor: pointer; }
/* The base layer is the frame's own 800x480 pixels. */
#base.crisp, .viewer-img.crisp { image-rendering: pixelated; }
.offline { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,.75); color: var(--muted); font-weight: 600; }
.hint { margin: 10px 0 0; font-size: 13px; color: var(--muted); }
@media (orientation: landscape), (min-width: 700px) { .hint { display: none; } }
.portrait-canvas .hint { display: none; } /* a portrait canvas already suits an upright phone */

.toolbar { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 8px 12px 14px; flex-wrap: wrap; }
.tools, .opts { display: flex; gap: 6px; align-items: center; }
.tool, .opt { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; border: 1px solid var(--line); background: var(--card); padding: 0; }
.tool.active, .opt.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.opt:disabled { opacity: .35; }
.dot { display: block; width: 10px; height: 10px; border-radius: 50%; background: var(--ink); }
.dot.colour { width: 26px; height: 26px; border: 2px solid rgba(0,0,0,.15); }
.popwrap { position: relative; }
.pop { position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%); z-index: 10;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px;
  box-shadow: 0 8px 30px rgba(60,40,20,.18); }
.pop.sizes { display: flex; gap: 6px; align-items: center; }
.size { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 10px; border: 1px solid transparent; background: none; padding: 0; }
.size span { display: block; border-radius: 50%; background: var(--ink); }
.size.active { border-color: var(--ink); }
.pop.swatches { display: grid; grid-template-columns: repeat(7, 36px); gap: 8px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 2px solid rgba(0,0,0,.12); padding: 0; }
.swatch.active { outline: 3px solid var(--ink); outline-offset: 2px; }
.clear { height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--accent); font-weight: 600; }

/* Short landscape phones: tighten everything so the canvas gets the room. */
@media (orientation: landscape) and (max-height: 500px) {
  .topbar { min-height: 28px; padding: 2px 16px; font-size: 14px; }
  .toolbar { padding: 4px 12px; gap: 8px; }
  .tool, .opt { width: 38px; height: 38px; }
  .dot.colour { width: 22px; height: 22px; }
  .clear { height: 38px; }
  .pop.swatches { grid-template-columns: repeat(7, 32px); gap: 6px; }
  .swatch { width: 32px; height: 32px; }
}

/* Narrow portrait phones: keep the colour grid on screen. */
@media (max-width: 420px) {
  .pop.swatches { grid-template-columns: repeat(7, 30px); gap: 6px; padding: 8px; }
  .swatch { width: 30px; height: 30px; }
}

/* Settings */
.topbar { gap: 12px; }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; border: 0; background: none; color: var(--muted); padding: 0; border-radius: 10px; }
.panel { background: var(--bg); overflow-y: auto; -webkit-user-select: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; position: sticky; top: 0; background: var(--bg); }
.panel-head h2 { margin: 0; font-size: 20px; font-weight: 650; }
.done { border: 0; background: none; font-weight: 600; font-size: 17px; color: var(--accent); padding: 8px; }
.panel-body { width: 100%; max-width: 520px; margin: 0 auto; padding: 0 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.frame-card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.frame-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.frame-title h3 { margin: 0; font-size: 17px; }
.frame-state { font-size: 13px; color: var(--muted); }
.frame-state.ok { color: #15803d; }
.frame-state.off { color: #b91c1c; }
.frame-detail { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; border-top: 1px solid var(--line); font-size: 15px; }
.frame-card > .row:first-child { border-top: 0; }
.row.times { justify-content: flex-start; }
.card-sub { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--line, #e7e1d6); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.note.card-note { text-align: left; margin: 2px 0 8px; }
.frame-card details.more { margin: 4px 0 6px; }
.frame-card details.more summary { cursor: pointer; font-size: 14px; color: var(--muted); padding: 6px 0; }
.row select, .row input[type="time"] { font: inherit; font-size: 15px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
.row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--ink); }
.frame-actions { display: flex; align-items: center; gap: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.frame-actions.stacked { flex-direction: column; align-items: flex-start; gap: 6px; }
.frame-actions.stacked:has(.saved:empty) { gap: 0; }
.frame-actions button, .notify-buttons button { white-space: nowrap; }
.notify-buttons:not(:has(button:not([hidden]))) { display: none; }
.secondary { height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 600; }
.saved { font-size: 13px; color: var(--muted); }
.note { margin: 0; font-size: 13px; color: var(--muted); text-align: center; }
.logout { align-self: center; border: 0; background: none; color: var(--accent); font-weight: 600; padding: 10px; }
#frames { display: flex; flex-direction: column; gap: 14px; }

/* Passkeys */
.passkey-btn { padding: 12px; border: 0; border-radius: 10px; background: var(--ink); color: #fff; font-weight: 600; }
.or { margin: -4px 0; text-align: center; font-size: 13px; color: var(--muted); }
.passkey-list { list-style: none; margin: 0; padding: 0; }
.passkey-list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; border-top: 1px solid var(--line); font-size: 15px; }
.passkey-list .when { font-size: 13px; color: var(--muted); }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 8px 0 8px 8px; }

/* Wifi in the frame card */
.wifi { border-top: 1px solid var(--line); }
.wifi > .row { border-top: 0; }
.wifi-now { font-size: 14px; color: var(--muted); text-align: right; }
.wifi-saved { list-style: none; margin: 0 0 4px; padding: 0; }
.wifi-saved li { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; font-size: 15px; padding-left: 12px; }
.wifi-saved .tag { font-size: 13px; color: var(--muted); }
.wifi-add summary { min-height: 40px; display: flex; align-items: center; color: var(--accent); font-weight: 600; cursor: pointer; list-style: none; }
.wifi-add summary::-webkit-details-marker { display: none; }
.wifi-add[open] { padding-bottom: 8px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin: 6px 0; }
.field input { font: inherit; font-size: 16px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); -webkit-user-select: text; user-select: text; }
.hint-small { margin: 0 0 4px; font-size: 13px; color: var(--muted); }
.wifi-msg { display: block; min-height: 1.2em; margin: 0 0 6px; }

/* Renaming a frame */
.frame-detail { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.link-btn.rename { padding: 4px 0; font-size: 13px; }
.rename-form { display: flex; gap: 8px; margin: 0 0 8px; }
.rename-form input { flex: 1; min-width: 0; font: inherit; font-size: 16px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); -webkit-user-select: text; user-select: text; }

/* Top bar buttons, toast */
.topbar .spacer { flex: 1; }
.topbar { justify-content: flex-start; }
.toast { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 8px 14px; border-radius: 999px; font-size: 14px; font-weight: 600; pointer-events: none; white-space: nowrap; }

/* Library */
.tabs { display: flex; gap: 6px; background: var(--line); padding: 3px; border-radius: 10px; }
.tab { flex: 1; border: 0; background: none; padding: 8px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.shot { border: 0; padding: 0; background: none; text-align: left; display: flex; flex-direction: column; gap: 4px; }
.shot img { width: 100%; aspect-ratio: 5 / 3; object-fit: cover; background: #fff; border-radius: 8px; border: 1px solid var(--line); }
.shot img.portrait { object-fit: contain; background: var(--line); }
.shot span { font-size: 12px; color: var(--muted); }
.viewer-img { width: 100%; aspect-ratio: 5 / 3; background: #fff; border-radius: 8px; border: 1px solid var(--line); }
.viewer-actions { display: flex; align-items: center; gap: 10px; justify-content: center; }
.as-btn { display: inline-grid; place-items: center; text-decoration: none; color: var(--ink); }

/* Alerts above the canvas */
.alerts { display: flex; flex-direction: column; gap: 6px; padding: 0 12px; }
.alerts:empty { display: none; }
.alert { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px; border-radius: 10px; font-size: 14px; line-height: 1.3;
  background: #fef3c7; color: #78350f; border: 1px solid #fcd34d; }
.alert.urgent { background: #fee2e2; color: #7f1d1d; border-color: #fca5a5; }
.alert .msg { flex: 1; border: 0; background: none; color: inherit; text-align: left; padding: 0; font: inherit; }
.alert .x { border: 0; background: none; color: inherit; font-size: 20px; line-height: 1; padding: 4px 8px; opacity: .7; }
.note.warn { color: #b45309; font-weight: 600; }
@media (orientation: landscape) and (max-height: 500px) { .alert { padding: 4px 6px 4px 10px; font-size: 13px; } }

/* Frame batteries in the top bar */
.batteries { display: flex; gap: 12px; font-size: 13px; color: var(--muted); margin-left: 8px; }
.batt { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.batt svg { display: block; }
.batt.low { color: #b91c1c; font-weight: 600; }

/* Status corner of the canvas (kept clear for the frame's icons) */
/* The frames' status bubble: same place, size and icons as on the frame (raster.js NOTCH) */

/* Add a picture: editing */
.picture-preview { touch-action: none; cursor: grab; }
.viewer-img.portrait { aspect-ratio: 3 / 5; width: auto; height: min(60vh, 520px); display: block; margin: 0 auto; }
.pic-edit { display: grid; gap: 6px; }
.pic-edit label { display: grid; grid-template-columns: 90px 1fr; align-items: center; gap: 10px; font-size: 14px; }
.pic-edit input[type="range"] { width: 100%; }
.pic-buttons { display: flex; gap: 10px; align-items: center; justify-content: center; margin-top: 4px; }

/* Straighten */
.straighten { display: grid; gap: 10px; }
.st-box { position: relative; width: 100%; max-height: 60vh; margin: 0 auto; touch-action: none; }
.st-box canvas, .st-box svg { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 6px; }
.st-h { position: absolute; width: 28px; height: 28px; margin: -14px 0 0 -14px; border-radius: 50%; background: rgba(255,255,255,.35);
  border: 3px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.5), 0 2px 6px rgba(0,0,0,.4); touch-action: none; cursor: grab; }
.screen.straightening .picture-preview, .screen.straightening .pic-edit, .screen.straightening .tabs,
.screen.straightening #picture-use, .screen.straightening .panel-body > .note { display: none; }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.pic-buttons { flex-wrap: wrap; }

/* Power saving (frame settings) */
.power .windows { list-style: none; margin: 0; padding: 0; }
.power .windows li { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 15px; }
.power .windows input[type="time"] { font: inherit; padding: 4px 6px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.power .windows .remove-window { margin-left: auto; font-size: 14px; }
.power .add-window { display: block; margin: 4px 0 8px; font-size: 15px; }
.day-strip { margin: 6px 0 12px; }
.day-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: #f3d9a4; }
.day-bar i { flex: 1; background: #f3d9a4; }
.day-bar i.off { background: #4b5375; }
.day-ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 3px; }
.life { margin: 10px 0 6px; padding: 12px; border-radius: 12px; background: #f6f1ea; }
.life-head { margin: 0 0 10px; font-size: 16px; }
.life-meter { position: relative; height: 10px; border-radius: 5px; background: #e4dbcf; margin-bottom: 22px; }
.life-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 5px; background: #3f7d4e; transition: width .25s; }
.life-ticks span { position: absolute; top: 14px; transform: translateX(-50%); font-size: 11px; color: var(--muted); white-space: nowrap; }
.life-ticks span::before { content: ""; position: absolute; left: 50%; top: -8px; width: 1px; height: 6px; background: #b9ad9c; }
.life-ticks span:last-child { transform: translateX(-100%); }
.life-ticks span:last-child::before { left: auto; right: 0; }
.goal { margin: 10px 0 4px; }
.goal-q { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
.goal-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.goal-chips .chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-size: 14px; cursor: pointer; }
.goal-chips .chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.goal-list { list-style: none; margin: 8px 0 0; padding: 0; }
.goal-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.goal-list li span { flex: 1; }
.goal-list li small { color: var(--muted); }
.goal-list li.goal-ok { color: var(--muted); }

/* Notifications */
.notify-buttons { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.nudge { position: absolute; left: 50%; top: 56px; transform: translateX(-50%); z-index: 20; display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center;
  width: min(360px, 92vw); box-sizing: border-box; padding: 12px 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line);
  box-shadow: 0 6px 20px rgba(0,0,0,.12); font-size: 14px; }
.nudge span { flex: 0 0 100%; line-height: 1.35; }
.nudge button { white-space: nowrap; }
.phones-head { color: var(--muted); font-size: 13px; }
.note.card-note:empty, #notify-phones:empty { display: none; }
.power-drop > summary { list-style: none; cursor: pointer; gap: 12px; padding: 12px 0; }
.power-drop > summary::-webkit-details-marker { display: none; }
.power-drop .power-sum { color: var(--muted); font-size: 14px; text-align: right; margin-left: auto; }
.power-drop > summary::after { content: ""; width: 7px; height: 7px; flex: none; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: translateY(-2px) rotate(45deg); transition: transform .15s; }
.power-drop[open] > summary::after { transform: translateY(2px) rotate(-135deg); }
.power-drop[open] .power-sum { display: none; }
.power-drop .power { padding: 0 0 8px; }
.power-drop .row:has(select.rate) { flex-direction: column; align-items: stretch; gap: 6px; padding: 10px 0; }
.power .row select.rate { max-width: none; width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.power-drop .add-window { text-align: left; }
.day-tz { font-size: 11px; color: var(--muted); text-align: right; }

/* How a frame hangs */
.frame-turn { margin: 8px 0; padding: 8px 10px; border-radius: 10px; background: #fde8e8; color: #b91c1c; font-size: 14px; }
.tilt-up { display: block; margin: 2px 0 6px; padding: 4px 0; }
#shape-card .tabs { margin: 6px 0 0; }

/* Pull to refresh */
.pull { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 8px); transform: translate(-50%, -60px); z-index: 30; pointer-events: none;
  padding: 6px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); font-size: 13px; color: var(--muted); transition: background .15s; }
.pull.ready { background: var(--ink); color: #fff; border-color: var(--ink); }
