:root {
  --bg: #f4f6f3; --card: #ffffff; --ink: #17201c; --ink2: #56635c; --line: #dfe5e0;
  --accent: #2f7d5b; --accent-ink: #ffffff; --danger: #b8463e; --warn: #9a6a12;
  --on: #2f7d5b; --off: #8a958f; --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101714; --card: #18221e; --ink: #edf2ee; --ink2: #9fb0a7; --line: #2a3832;
    --accent: #4fb386; --accent-ink: #0d1a14; --danger: #e0716a; --warn: #e3b25a;
    --on: #4fb386; --off: #7d8a83;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 0 0 4px; }
p { margin: 6px 0; }
.muted { color: var(--ink2); }
.center { text-align: center; }
.pad { padding: 40px 16px; }
.small-text { font-size: 14px; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.top-right { display: flex; align-items: center; gap: 8px; }
.badge-test { background: var(--warn); color: #fff; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px; }

main { max-width: 720px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.card.narrow { max-width: 420px; margin: 24px auto; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.stack-lg { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 10px; align-items: flex-end; margin-top: 12px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; align-items: center; }
.grow { flex: 1 1 220px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--ink2); }
input {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-width: 0;
}
.row > input { flex: 1 1 160px; }
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.code-input { font-size: 22px; letter-spacing: 4px; max-width: 200px; text-align: center; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block;
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  border-radius: 10px; padding: 10px 16px; min-height: 44px;
}
.btn.ghost { background: transparent; color: var(--accent); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger.ghost { background: transparent; color: var(--danger); }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }

.msg { min-height: 1.4em; font-size: 14px; color: var(--ink2); }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--on); }

.back { display: inline-block; text-decoration: none; font-weight: 600; }

.phone-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.phone-card {
  display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: var(--bg);
}
.phone-card:hover { border-color: var(--accent); }
.status { font-size: 14px; }
.status.on { color: var(--on); }
.status.on::before { content: "● "; }
.status.off { color: var(--off); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.switch { flex-direction: row; align-items: center; gap: 10px; color: var(--ink); font-size: 16px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--bg); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { width: 42px; height: 24px; border-radius: 99px; background: var(--off); position: relative; flex: none; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .track { background: var(--on); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.people { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.people li { display: flex; justify-content: space-between; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 8px 8px 12px; }
.people li.muted { border-style: dashed; padding: 10px 12px; }

.wk-state { font-weight: 600; margin-top: 10px; }
.wk-state.on { color: var(--on); }
.wk-state.off { color: var(--off); }

.checks { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 16px; }
.check input { width: 20px; height: 20px; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; font-size: 15px;
  background: #222; color: #fff; opacity: 0; pointer-events: none; transition: .2s; z-index: 20;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--danger); }
#toast.ok { background: #245c44; }

/* ---------- phone page: editor left, live preview right ---------- */
main { max-width: 1120px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; margin-top: 12px; padding-bottom: 90px; }
.preview-sticky { position: sticky; top: 72px; }
.pv-label { font-weight: 700; margin: 0 0 8px; text-align: center; color: var(--ink2); }
.pv-label.pending { color: var(--warn); }
.pv-phone { background: #050806; border-radius: 38px; padding: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.pv-screen { background: linear-gradient(180deg, #17241f, #0f1a16); color: #eef2ee; border-radius: 28px; min-height: 600px; padding: 14px 16px; display: flex; flex-direction: column; }
.pv-status { display: flex; justify-content: space-between; font-size: 12px; color: #b9c8bf; }
.pv-greet { margin-top: 18px; font-size: 14px; color: #b9c8bf; font-weight: 600; }
.pv-day { font-size: 28px; font-weight: 800; margin-bottom: 14px; }
.pv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pv-tile { background: #24352e; border-radius: 18px; padding: 16px 8px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-weight: 700; font-size: 14px; }
.pv-tile span { font-size: 26px; }
.pv-tile.pv-new { outline: 2px dashed var(--warn); outline-offset: 2px; }
.pv-foot { margin-top: auto; padding-top: 14px; font-size: 13px; color: #b9c8bf; display: flex; flex-direction: column; gap: 4px; }

.changed { border-color: var(--warn) !important; }
.switch.changed { box-shadow: inset 0 0 0 1px var(--warn); }
.people li.pending-add { border-color: var(--warn); }
.people li.pending-remove { border-style: dashed; opacity: .7; }
.people li.pending-remove b { text-decoration: line-through; }
.tag { font-size: 12px; font-weight: 700; color: var(--warn); }
.danger-text { color: var(--danger) !important; border-color: var(--danger) !important; }

.send-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--card);
  border-top: 2px solid var(--warn); box-shadow: 0 -6px 20px rgba(0,0,0,.15); font-weight: 700;
}
.row-tight { display: flex; gap: 8px; }
#toast { bottom: 90px; }

@media (max-width: 860px) {
  .split { grid-template-columns: 1fr; }
  .preview-col { order: -1; }
  .preview-sticky { position: static; }
  .pv-phone { max-width: 300px; margin: 0 auto; }
  .pv-screen { min-height: 460px; }
}
.notice { border-color: var(--warn); }

/* ---------- look picker ---------- */
.looks { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.look { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; text-align: left; cursor: pointer;
  background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 12px; font: inherit; }
.look small { color: var(--ink2); }
.look.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.look.changed { border-color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); }
.look-swatch { width: 100%; height: 54px; border-radius: 8px; margin-bottom: 6px; }
.look-swatch.classic { background: linear-gradient(180deg, #17241f, #0f1a16); box-shadow: inset 0 0 0 6px #24352e; }
.look-swatch.ios { background: linear-gradient(180deg, #1b2a6b, #4b3b9a, #9c4f96, #e38a7b); }

/* ---------- iPhone-style preview ---------- */
.pv-screen.ios { background: linear-gradient(180deg, #1b2a6b 0%, #4b3b9a 35%, #9c4f96 70%, #e38a7b 100%); }
.ios-widget { margin-top: 14px; background: rgba(255,255,255,.2); border: 1px solid rgba(255,255,255,.14); border-radius: 22px; padding: 12px 16px; }
.ios-widget small { color: rgba(255,255,255,.85); font-weight: 600; font-size: 12px; }
.ios-clock { font-size: 46px; font-weight: 300; line-height: 1.05; letter-spacing: -1px; color: #fff; }
.ios-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px 6px; margin-top: 18px; }
.ios-app { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ios-app small { color: #fff; font-size: 10.5px; text-shadow: 0 1px 2px rgba(0,0,0,.4); white-space: nowrap; }
.ios-icon { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; font-size: 24px;
  box-shadow: 0 3px 8px rgba(0,0,0,.25); background: linear-gradient(135deg, #8e8e93, #5a5a5f); }
.i-phone, .i-uber { background: linear-gradient(135deg, #34d859, #1eaa45); }
.i-messages, .i-dart, .i-games { background: linear-gradient(135deg, #3aa0ff, #0a84ff); }
.i-music { background: linear-gradient(135deg, #ff5e7a, #ff2d55); }
.i-photos { background: linear-gradient(135deg, #ffb340, #ff9500); }
.i-settings { background: linear-gradient(135deg, #9ea3ad, #636872); }
.ios-app.pv-new .ios-icon { outline: 2px dashed var(--warn); outline-offset: 2px; }
.ios-dot { width: 7px; height: 7px; border-radius: 50%; background: rgba(255,255,255,.8); margin: auto auto 10px; }
.ios-dock { display: flex; justify-content: space-evenly; background: rgba(255,255,255,.2); border: 1px solid rgba(255,255,255,.14);
  border-radius: 26px; padding: 10px 6px; }

.looks { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.look-swatch.auto { background: linear-gradient(90deg, #ff9500 0 33%, #24352e 33% 66%, #6b4aa3 66%); }
.look-swatch.simple { background: repeating-linear-gradient(180deg, #34d859 0 14px, transparent 14px 20px), #0f1a16; }
/* Starter preview */
.st-hi { font-size: 26px; font-weight: 800; margin: 14px 0 10px; }
.st-list { display: flex; flex-direction: column; gap: 10px; }
.st-tile { display: flex; align-items: center; gap: 14px; border-radius: 20px; padding: 16px 18px; font-size: 22px; font-weight: 800; color: #fff; }
.i-camera, .i-weather { background: linear-gradient(135deg, #8e8e93, #5a5a5f); }
.st-tile span { font-size: 30px; }
.st-tile.pv-new { outline: 2px dashed var(--warn); outline-offset: 2px; }
.st-settings { margin: 14px auto 0; color: #9fb0a7; font-size: 13px; background: #24352e; padding: 6px 12px; border-radius: 10px; width: fit-content; }
