:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #ecebe6;
  --ink: #151515;
  --ink-2: #5d5c58;
  --ink-3: #9a9893;
  --line: rgba(0, 0, 0, 0.08);
  --danger: #c4361b;
  --accent: #151515;
  --accent-ink: #ffffff;
  --safari: #2f7a3e;
  --safari-soft: #ffe23d;
  --watts: #e8622c;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.06);
  --pad: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111111;
    --surface: #1b1b1b;
    --surface-2: #262626;
    --ink: #f2f1ed;
    --ink-2: #b3b1ab;
    --ink-3: #75736e;
    --line: rgba(255, 255, 255, 0.09);
    --accent: #f2f1ed;
    --accent-ink: #111111;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
img, video { display: block; max-width: 100%; }

.page {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) var(--pad) calc(env(safe-area-inset-bottom) + 120px);
}

/* ---------- Header ---------- */
.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  margin: 0 calc(-1 * var(--pad)); padding: calc(env(safe-area-inset-top) + 8px) var(--pad) 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
}
.page > .bar { margin-top: calc(-1 * (env(safe-area-inset-top) + 8px)); }
.bar h1 { font-size: 17px; font-weight: 600; margin: 0; flex: 1; min-width: 0; text-align: center; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; color: var(--ink);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.armed { background: var(--danger); color: #fff; width: auto; padding: 0 14px; border-radius: 20px; font-size: 14px; font-weight: 600; }

/* ---------- Lock ---------- */
.lock { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.lock form { width: 100%; max-width: 300px; text-align: center; }
.lock h1 { font-size: 22px; font-weight: 600; margin: 0 0 6px; letter-spacing: -0.02em; }
.lock p { color: var(--ink-2); margin: 0 0 24px; font-size: 15px; }
.code {
  width: 100%; text-align: center; font-size: 30px; letter-spacing: 0.4em; padding: 14px 0 14px 0.4em;
  border-radius: 14px; border: 1px solid var(--line); background: var(--surface); outline: none;
}
.code:focus { border-color: var(--ink-3); }
.lock .err { color: var(--danger); font-size: 14px; min-height: 20px; margin-top: 10px; }

/* ---------- Home ---------- */
.home { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; gap: 14px; padding: 24px var(--pad) calc(env(safe-area-inset-bottom) + 24px); max-width: 560px; margin: 0 auto; }
.home .wordmark { color: var(--ink-3); font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; text-align: center; margin-bottom: 10px; }
.brand-tile {
  display: flex; align-items: flex-end; justify-content: space-between;
  height: 30vh; min-height: 170px; max-height: 260px; padding: 22px; border-radius: 26px;
  font-size: 30px; font-weight: 700; letter-spacing: -0.03em; text-align: left;
  box-shadow: var(--shadow); transition: transform 0.12s ease;
}
.brand-tile:active { transform: scale(0.98); }
.brand-tile small { display: block; font-size: 14px; font-weight: 500; letter-spacing: 0; opacity: 0.8; margin-top: 2px; }
.brand-tile .arrow { width: 28px; height: 28px; opacity: 0.85; }
.tile-safari { background: var(--safari-soft); color: #173d1f; }
.tile-watts { background: var(--watts); color: #fff3ea; }

/* ---------- Feed ---------- */
.empty { text-align: center; color: var(--ink-3); padding: 18vh 24px 0; font-size: 15px; }
.empty strong { display: block; color: var(--ink-2); font-weight: 600; font-size: 17px; margin-bottom: 4px; }
.feed { display: flex; flex-direction: column; gap: 18px; margin-top: 4px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-media { position: relative; background: #000; aspect-ratio: 9 / 16; max-height: 70vh; width: 100%; }
.card-media img, .card-media video { width: 100%; height: 100%; object-fit: cover; }
.card-media.small { aspect-ratio: auto; height: 120px; display: flex; }
.card-media.small img { width: 68px; height: 120px; flex: none; }
.card-status { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 14px; font-weight: 500; background: rgba(0, 0, 0, 0.35); text-align: center; padding: 16px; }
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.card-head { display: flex; align-items: baseline; gap: 10px; }
.card-title { font-weight: 600; flex: 1; letter-spacing: -0.01em; }
.card-date { color: var(--ink-3); font-size: 13px; white-space: nowrap; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }

.pending-row { display: flex; gap: 14px; padding: 14px; align-items: center; }
.pending-row .thumb { width: 54px; height: 96px; border-radius: 10px; background: var(--surface-2); flex: none; object-fit: cover; }
.pending-row .meta { flex: 1; min-width: 0; }
.pending-row .meta .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pending-row .meta .s { color: var(--ink-2); font-size: 14px; }
.chev { width: 18px; height: 18px; color: var(--ink-3); flex: none; }

/* ---------- Caption copy ---------- */
.caption {
  position: relative; width: 100%; text-align: left; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--surface-2); border-radius: 14px; padding: 12px 14px 32px; font-size: 15px; line-height: 1.45;
}
.caption .copy-hint {
  position: absolute; right: 10px; bottom: 8px; display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; color: var(--ink-2);
}
.caption .copy-hint svg { width: 14px; height: 14px; }
.caption:active { filter: brightness(0.96); }
.caption.copied .copy-hint { color: var(--safari); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 48px; padding: 0 20px; border-radius: 24px; font-weight: 600; font-size: 16px;
  background: var(--surface-2); color: var(--ink); white-space: nowrap;
}
.btn svg { width: 19px; height: 19px; }
.btn:active { filter: brightness(0.93); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.sm { height: 38px; padding: 0 14px; font-size: 14px; border-radius: 19px; }
.btn.grow { flex: 1; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.link { color: var(--ink-2); font-size: 14px; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }

.cost { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }
.cost b { color: var(--ink-2); font-weight: 600; }

.fab {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 10;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  height: 56px; padding: 0 26px; border-radius: 28px;
  background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 16px;
  display: inline-flex; align-items: center; gap: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
}
.fab svg { width: 20px; height: 20px; }
.fab:active { transform: translateX(-50%) scale(0.97); }

/* ---------- Sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 20; animation: fade 0.18s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; margin: 0 auto; max-width: 560px;
  background: var(--bg); border-radius: 24px 24px 0 0;
  padding: 10px var(--pad) calc(env(safe-area-inset-bottom) + 16px);
  animation: up 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
  max-height: 92dvh; overflow-y: auto;
}
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--ink-3); opacity: 0.4; margin: 0 auto 12px; }
.sheet h2 { font-size: 20px; margin: 0 0 12px; letter-spacing: -0.02em; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }

.field { position: relative; }
.field textarea {
  width: 100%; min-height: 120px; resize: none; border: 1px solid var(--line); outline: none;
  background: var(--surface); border-radius: 16px; padding: 14px 14px 56px; font-size: 16px; line-height: 1.45;
}
.field textarea:focus { border-color: var(--ink-3); }
.field .tools { position: absolute; left: 10px; right: 10px; bottom: 10px; display: flex; gap: 8px; align-items: center; }
.mic {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); color: var(--ink);
}
.mic svg { width: 19px; height: 19px; }
.mic.rec { background: var(--danger); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
.mic.busy { opacity: 0.6; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(196, 54, 27, 0.18); } }
.tools .hint { color: var(--ink-3); font-size: 13px; flex: 1; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 4px; }
.chips .label { width: 100%; color: var(--ink-2); font-size: 13px; }
.chip {
  height: 36px; padding: 0 14px; border-radius: 18px; font-size: 14px; font-weight: 500;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-2);
}
.chip.on { background: var(--watts); border-color: var(--watts); color: #fff; }

.sheet .actions { display: flex; gap: 10px; margin-top: 16px; }

/* ---------- Job ---------- */
.stage { display: flex; flex-direction: column; gap: 16px; }
.frame {
  position: relative; margin: 0 auto; border-radius: 20px; overflow: hidden; background: var(--surface-2);
  aspect-ratio: 9 / 16; width: min(100%, calc(64dvh * 9 / 16));
}
.frame img, .frame video { width: 100%; height: 100%; object-fit: cover; }
.frame .veil {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  color: #fff; background: rgba(0, 0, 0, 0.42); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  text-align: center; padding: 20px;
}
.frame.blank .veil { background: transparent; color: var(--ink-2); backdrop-filter: none; }
.veil .label { font-weight: 600; }
.veil .sub { font-size: 13px; opacity: 0.8; font-variant-numeric: tabular-nums; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; opacity: 0.85; }
@keyframes spin { to { transform: rotate(360deg); } }

.quote { text-align: center; color: var(--ink-2); font-size: 15px; line-height: 1.5; padding: 0 8px; }
.quote .who { display: block; font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.what { text-align: center; color: var(--ink-3); font-size: 13px; padding: 0 12px; }
.error { color: var(--danger); font-size: 14px; text-align: center; }
.feedback { display: flex; flex-direction: column; gap: 10px; }
.feedback .field textarea { min-height: 92px; }
.center { display: flex; justify-content: center; }

details.prompt { color: var(--ink-3); font-size: 13px; }
details.prompt summary { cursor: pointer; text-align: center; list-style: none; }
details.prompt summary::-webkit-details-marker { display: none; }
details.prompt p { white-space: pre-wrap; margin: 10px 0 0; color: var(--ink-2); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 14px); z-index: 50;
  transform: translate(-50%, calc(-100% - 60px)); transition: transform 0.25s ease, visibility 0.25s; visibility: hidden;
  background: var(--accent); color: var(--accent-ink); padding: 10px 18px; border-radius: 20px;
  font-size: 14px; font-weight: 600; pointer-events: none; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }
