/* Plotwist. Page in whatsapp.com's palette; phone = WhatsApp chat (landing, demo) or a standard iOS app (create flow, Apple HIG). */
:root {
  --page: #fcf5eb;
  --ink: #1c1e21;
  --ink2: #5e5e5e;
  --green: #25d366;
  --tint: #1daa61;
  --wall: #efeae2;
  --in: #ffffff;
  --out: #d9fdd3;
  --time: #667781;
  --grouped: #f2f2f7;
  --card: #ffffff;
  --sep: rgba(60, 60, 67, 0.22);
  --label2: rgba(60, 60, 67, 0.6);
  --fill: rgba(118, 118, 128, 0.12);
  --bar: rgba(249, 249, 249, 0.94);
  --red: #ff3b30;
  --bezel: #1c1e21;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #111b21; --ink: #e9edef; --ink2: #8696a0; --tint: #21c063;
    --wall: #0b141a; --in: #202c33; --out: #005c4b; --time: #8696a0;
    --grouped: #000000; --card: #1c1c1e; --sep: rgba(84, 84, 88, 0.6); --label2: rgba(235, 235, 245, 0.6);
    --fill: rgba(118, 118, 128, 0.24); --bar: rgba(28, 28, 30, 0.94); --red: #ff453a; --bezel: #2a3942;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #111b21; --ink: #e9edef; --ink2: #8696a0; --tint: #21c063;
  --wall: #0b141a; --in: #202c33; --out: #005c4b; --time: #8696a0;
  --grouped: #000000; --card: #1c1c1e; --sep: rgba(84, 84, 88, 0.6); --label2: rgba(235, 235, 245, 0.6);
  --fill: rgba(118, 118, 128, 0.24); --bar: rgba(28, 28, 30, 0.94); --red: #ff453a; --bezel: #2a3942;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 17px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex; flex-direction: column;
}
code { font: 0.85em ui-monospace, SFMono-Regular, Menlo, monospace; }
.err { color: var(--red) !important; }
[hidden] { display: none !important; }

/* ---- page: logo, tagline, the two buttons ---------------------------------------- */
.intro { order: -1; padding: 28px 20px 24px; display: flex; flex-direction: column; align-items: flex-start; }
.intro h1 { margin: 0 0 10px; line-height: 0; }
.intro .logo { width: 150px; height: auto; }
.tagline { margin: 0; font-size: 40px; line-height: 1.05; font-weight: 800; letter-spacing: -0.025em; color: var(--ink); }
.cta { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px;
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity 0.4s, transform 0.4s; }
body.ready .cta { opacity: 1; transform: none; pointer-events: auto; }
.cta-btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 26px;
  border-radius: 999px; border: 1.5px solid var(--ink); cursor: pointer; text-decoration: none;
  font: 600 17px -apple-system, BlinkMacSystemFont, sans-serif; color: var(--ink); background: transparent;
  transition: background 0.15s, transform 0.1s;
}
.cta-btn:active { transform: scale(0.97); }
.cta-btn.primary { background: var(--green); color: #1c1e21; }
.cta-btn.primary:hover { background: #1fbe5b; }
.cta-btn.secondary:hover { background: rgba(28, 30, 33, 0.06); }

/* ---- the phone ----------------------------------------------------------------- */
.device { position: relative; display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; background: var(--wall); }
.device[data-mode="app"] { background: var(--grouped); }
@media (min-width: 600px) and (min-height: 640px) {
  body { min-height: 100vh; align-items: center; justify-content: center; padding: 24px; }
  .device {
    width: 390px; height: min(844px, calc(100dvh - 48px));
    border-radius: 52px; border: 11px solid var(--bezel);
    box-shadow: 0 30px 80px rgba(28, 30, 33, 0.22);
  }
  .intro { padding: 0 0 28px; align-items: center; text-align: center; }
  .cta { justify-content: center; }
}
@media (min-width: 900px) and (min-height: 640px) {
  body { flex-direction: row; gap: 72px; }
  .intro { order: 0; padding: 0; align-items: flex-start; text-align: left; max-width: 400px; }
  .intro .logo { width: 210px; }
  .tagline { font-size: 64px; }
  .cta { justify-content: flex-start; margin-top: 32px; }
}
body.over .device { outline: 3px dashed var(--green); outline-offset: 4px; }

/* headers: WhatsApp chat header in chat mode, iOS nav bar in app mode */
.nav {
  flex: none; z-index: 2; display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 6px 12px; background: var(--bar);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--sep);
}
.device[data-mode="chat"] .app-nav, .device[data-mode="app"] .imsg-nav { display: none; }
.nav-side { width: 64px; flex: none; }
.imsg-nav { gap: 10px; padding-left: 8px; }
.wa-back { color: var(--tint); font-size: 30px; font-weight: 300; line-height: 1; width: 14px; }
.wa-who { flex: 1; display: flex; flex-direction: column; line-height: 1.2; }
.wa-who b { font-size: 16px; font-weight: 600; }
.wa-who small { font-size: 12px; color: var(--time); }
.wa-icons { display: flex; gap: 22px; color: var(--tint); padding-right: 6px; }
.wa-icons svg { width: 22px; height: 22px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: #fff; display: grid; place-items: center; overflow: hidden; box-shadow: inset 0 0 0 0.5px var(--sep); }
.avatar img { width: 29px; height: 29px; object-fit: contain; }
.name { font-size: 12px; color: var(--ink); }
.name span { color: var(--label2); }
.nav-back { all: unset; cursor: pointer; width: 64px; color: var(--tint); font-size: 17px; }
.nav-back[aria-hidden="true"] { visibility: hidden; }
.nav-title { flex: 1; text-align: center; font-weight: 600; font-size: 17px; }

.thread { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; }
.thread > * { flex-shrink: 0; }

.screen { display: none; flex-direction: column; }
.screen.active { display: flex; animation: slide-in 0.28s ease-out; }
.screen.active.backwards { animation-name: slide-back; }
@keyframes slide-in { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }
@keyframes slide-back { from { opacity: 0; transform: translateX(-28px); } to { opacity: 1; transform: none; } }
.screen > * { flex-shrink: 0; }

/* ---- WhatsApp chat (landing + demo) ------------------------------------------------- */
.imsg { padding: 10px 14px 18px; }
.stamp {
  align-self: center; margin: 4px 0 12px; padding: 4px 10px; border-radius: 8px;
  background: var(--in); color: var(--time); font-size: 12px; text-align: center;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
}
.stamp b { font-weight: 500; }
.msgs { display: flex; flex-direction: column; gap: 3px; }
.msg {
  position: relative; max-width: 80%; padding: 6px 9px 7px; border-radius: 8px;
  font-size: 16px; line-height: 1.32; overflow-wrap: anywhere; color: var(--ink);
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  animation: pop 0.22s ease-out;
}
.msg.them { align-self: flex-start; background: var(--in); }
.msg.me { align-self: flex-end; background: var(--out); }
.msg.first { margin-top: 6px; }
.msg.first.them { border-top-left-radius: 0; }
.msg.first.me { border-top-right-radius: 0; }
.msg .time { float: right; margin: 6px 0 -4px 10px; font-size: 11px; color: var(--time); }
.msg.me .time::after { content: " ✓✓"; color: #53bdeb; letter-spacing: -2px; }
.msg.media { padding: 3px; }
.msg.media img, .msg.media video { display: block; border-radius: 6px; }
.msg.media img { max-width: 240px; max-height: 420px; }
.msg.media .time { position: absolute; right: 9px; bottom: 7px; margin: 0; color: #fff; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); float: none; }
.msg.typing { display: flex; gap: 4px; padding: 12px 13px; }
.msg.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--time); animation: blink 1.2s infinite; }
.msg.typing i:nth-child(2) { animation-delay: 0.2s; }
.msg.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.3; } 30% { opacity: 1; } }
@keyframes pop { from { transform: translateY(6px) scale(0.97); opacity: 0; } to { transform: none; opacity: 1; } }
.note { font-size: 12px; color: var(--time); margin: 8px 4px; text-align: center; }

/* ---- iOS app screens (Apple HIG: grouped inset lists) --------------------------------- */
.ios { padding: 0 0 28px; }
.large-title { margin: 14px 20px 4px; font-size: 34px; font-weight: 700; letter-spacing: 0.01em; line-height: 1.15; }
.lead { margin: 2px 20px 6px; font-size: 15px; color: var(--label2); }
.group-label { margin: 22px 36px 7px; font-size: 13px; text-transform: uppercase; color: var(--label2); letter-spacing: 0.01em; }
.group { margin: 0 16px; background: var(--card); border-radius: 10px; overflow: hidden; }
.group-foot { margin: 7px 36px 0; font-size: 13px; color: var(--label2); }
.group-foot:empty { display: none; }
.group-foot.center { text-align: center; margin: 10px 16px 0; }
.secondary-label { color: var(--label2); font-size: 15px; }

.row {
  position: relative; display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 8px 16px; font-size: 17px; background: none; width: 100%;
  border: 0; color: var(--ink); text-align: left; font-family: inherit;
}
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 0.5px solid var(--sep); }
.row.icon-row + .row.icon-row::before { left: 59px; }
button.row { cursor: pointer; }
button.row:active { background: var(--fill); }
.row-label { flex: 1; }
.row-detail { color: var(--label2); font-size: 15px; }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row-text small { font-size: 13px; color: var(--label2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-link { color: var(--tint); cursor: pointer; }
.row-field {
  display: block; width: 100%; border: 0; background: none; color: var(--ink); resize: vertical;
  padding: 11px 16px; font: 17px/1.35 -apple-system, BlinkMacSystemFont, sans-serif;
}
.row-field:focus, .row input:focus { outline: none; }
.row-field.mono { font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; padding: 8px 0 12px; }
.chevron { color: var(--label2); opacity: 0.6; font-size: 20px; line-height: 1; }
.check { color: var(--tint); font-weight: 600; visibility: hidden; }
.selected .check { visibility: visible; }
.icon { flex: none; width: 31px; height: 31px; border-radius: 7px; display: grid; place-items: center; font-size: 18px; }

.disclosure { display: block; padding: 0 16px; }
.disclosure summary { min-height: 44px; display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none; }
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary::after { content: "›"; margin-left: auto; color: var(--label2); font-size: 20px; transition: transform 0.2s; }
.disclosure[open] summary::after { transform: rotate(90deg); }
.disclosure pre { margin: 0 0 12px; white-space: pre-wrap; font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--label2); max-height: 300px; overflow: auto; }

/* chat rows: delete control, speaker, message */
.msg-row { gap: 10px; padding-top: 6px; padding-bottom: 6px; }
.del {
  flex: none; width: 22px; height: 22px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--red); color: #fff; font: 700 18px/20px -apple-system, sans-serif; padding: 0;
}
.add {
  flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: #34c759; color: #fff; font: 700 18px/1 -apple-system, sans-serif;
}
.msg-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.msg-fields input { border: 0; background: none; padding: 1px 0; font-family: inherit; color: var(--ink); width: 100%; }
.msg-fields .who { font-size: 13px; font-weight: 600; }
.msg-fields .what { font-size: 17px; }

/* segmented control */
.segmented { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--fill); gap: 2px; }
.segmented button {
  border: 0; background: none; border-radius: 7px; padding: 5px 11px; cursor: pointer;
  font: 500 13px -apple-system, BlinkMacSystemFont, sans-serif; color: var(--ink);
}
.segmented button[aria-pressed="true"] { background: var(--card); box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04); font-weight: 600; }
.segmented button:disabled { opacity: 0.35; cursor: default; }

/* switch */
.switch { position: relative; flex: none; width: 51px; height: 31px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 16px; background: var(--fill); transition: background 0.2s; }
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 3px 1px rgba(0, 0, 0, 0.06); transition: transform 0.2s;
}
.switch input:checked + span { background: #34c759; }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:disabled + span { opacity: 0.4; }

/* cast */
.face { flex: none; width: 40px; height: 40px; border-radius: 50%; overflow: hidden; display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 17px; }
.face img { width: 100%; height: 100%; object-fit: cover; }
.thumb { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; }
.portrait-row { justify-content: center; padding: 12px 16px; }
.portrait-row img { width: 150px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 12px; cursor: zoom-in; }
.cast-section.drop-over .group { box-shadow: 0 0 0 2px var(--tint); }

/* spinners and centred states */
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--fill); border-top-color: var(--label2); animation: spin 0.8s linear infinite; }
.spinner.big { width: 34px; height: 34px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-state { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 18px 20px; color: var(--label2); font-size: 15px; }
.center-state.tall { flex-direction: column; gap: 14px; min-height: 60vh; text-align: center; color: var(--ink); }
.center-state.tall b { font-size: 20px; }
.media-card { display: flex; justify-content: center; padding: 12px; background: var(--card); }
.media-card img { max-width: 100%; max-height: 360px; border-radius: 8px; }
.making-cast { display: flex; gap: 10px; margin-bottom: 6px; }
.making-cast img { width: 64px; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 10px; animation: bob 1.6s ease-in-out infinite; }
.making-cast img:nth-child(2) { animation-delay: 0.2s; }
.making-cast img:nth-child(3) { animation-delay: 0.4s; }
@keyframes bob { 50% { transform: translateY(-5px); } }

/* ---- video with chat bubbles over the bottom ----------------------------------------- */
.result-player { display: flex; justify-content: center; margin: 10px 16px 0; }
.player { position: relative; line-height: 0; }
.player video { width: 270px; max-width: 75vw; aspect-ratio: 9 / 16; background: #000; border-radius: 12px; object-fit: contain; }
.msg.media .player video { width: 250px; border-radius: 6px; }
.bubbles {
  position: absolute; left: 8px; right: 8px; bottom: 56px; line-height: 1.25;
  display: flex; flex-direction: column; gap: 3px; pointer-events: none;
}
.bub {
  align-self: flex-start; max-width: 84%; padding: 5px 9px 6px; border-radius: 8px;
  background: rgba(255, 255, 255, 0.97); color: #111b21; font-size: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28); transition: opacity 0.3s;
}
.bub b { display: block; font-size: 12px; font-weight: 600; margin-bottom: 1px; }
.bub.first { border-top-left-radius: 0; }
.bub.me { align-self: flex-end; background: rgba(217, 253, 211, 0.97); }
.bub.me.first { border-top-left-radius: 8px; border-top-right-radius: 0; }
.bub.new { animation: pop 0.22s ease-out; }
.bub.old1 { opacity: 0.8; }
.bub.old2 { opacity: 0.5; }

.script-row { align-items: flex-start; gap: 10px; font-size: 15px; cursor: pointer; }
.script-row time { flex: none; width: 34px; color: var(--label2); font-size: 13px; font-variant-numeric: tabular-nums; padding-top: 2px; }
.script-row b { flex: none; font-weight: 600; }
.script-row.now { background: var(--fill); }

/* ---- bottom bar: the one action for this screen ---------------------------------------- */
.bar {
  flex: none; z-index: 2; padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bar); border-top: 0.5px solid var(--sep);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
}
.buttons { display: flex; gap: 8px; }
.bar .primary, .bar .secondary {
  flex: 1; display: flex; align-items: center; justify-content: center; min-height: 50px;
  text-decoration: none; cursor: pointer; border: 0; border-radius: 14px; padding: 0 14px;
  font: 600 17px -apple-system, BlinkMacSystemFont, sans-serif;
}
.bar .primary { background: var(--tint); color: #fff; }
.bar .primary:disabled { opacity: 0.4; cursor: default; }
.bar .primary.armed { background: var(--red); }
.bar .secondary { background: var(--fill); color: var(--tint); flex: 0.7; }
