:root {
  color-scheme: dark;
  --ink: #f6f1ea;
  --muted: #d9cdc2;
  --accent: #f0c7ad;
  --accent-ink: #2c1812;
  --danger: #ffb2a6;
  --warn: #ffd089;
  --glass: rgba(14, 11, 10, 0.62);
  --line: rgba(246, 241, 234, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #0c0b0a;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
}

.phone {
  position: relative;
  width: min(100vw, 480px);
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(120% 70% at 50% 12%, #4a332b 0%, #1a1412 46%, #0c0b0a 100%);
}

@media (min-width: 760px) {
  .phone {
    height: min(100dvh, 920px);
    border-radius: 32px;
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.45);
  }
}

video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 18%;
  background: transparent;
}

.shade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.28) 0%,
    transparent 24%,
    transparent 52%,
    rgba(0, 0, 0, 0.55) 100%
  );
}

.gate,
.top,
.dock {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 2;
}

.gate {
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 14px;
  padding: 28px 22px calc(28px + env(safe-area-inset-bottom));
  background: linear-gradient(
    to top,
    rgba(12, 10, 9, 0.94) 0%,
    rgba(12, 10, 9, 0.78) 38%,
    rgba(12, 10, 9, 0.15) 100%
  );
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(4.2rem, 18vw, 6rem);
  font-weight: 520;
  letter-spacing: -0.05em;
  line-height: 0.85;
}

.lead {
  margin: 0;
  max-width: 28ch;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.45;
}

#start {
  margin-top: 8px;
  min-height: 58px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.2rem;
  font-weight: 650;
  cursor: pointer;
}

#start:disabled {
  opacity: 0.65;
  cursor: progress;
}

#start:focus-visible,
.controls button:focus-visible,
#send:focus-visible,
#text:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.status {
  min-height: 2.6em;
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.35;
}

.status[data-kind="error"] {
  color: var(--danger);
}

.top {
  top: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 0;
}

.timer {
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
  font-size: 1rem;
  letter-spacing: 0.04em;
}

.timer.warn {
  color: var(--warn);
  border-color: rgba(255, 208, 137, 0.5);
}

.top .status {
  flex: 1;
  min-height: 0;
  padding-top: 6px;
  text-align: right;
}

.dock {
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(8, 7, 6, 0.92), rgba(8, 7, 6, 0.55) 70%, transparent);
}

.caption {
  margin: 0;
  min-height: 1.3em;
  font-size: 1.02rem;
  line-height: 1.35;
}

.log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 22dvh;
  overflow: auto;
  padding-right: 2px;
}

.hint,
.bubble {
  margin: 0;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
}

.bubble {
  max-width: 92%;
  padding: 8px 12px;
  border-radius: 16px;
  font-size: 0.92rem;
  line-height: 1.35;
}

.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-ink);
}

.bubble.persona {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.12);
}

.who {
  display: block;
  margin-bottom: 2px;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  opacity: 0.7;
}

#composer {
  display: flex;
  gap: 8px;
}

#text {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 16px;
}

#send,
.controls button {
  min-height: 48px;
  border-radius: 999px;
  cursor: pointer;
}

#send {
  border: 0;
  padding: 0 16px;
  background: var(--ink);
  color: #1a120e;
  font-weight: 650;
}

#send:disabled,
#mute:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.controls button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  padding: 0 14px;
}

#end {
  background: transparent;
  color: var(--danger);
  border-color: rgba(255, 178, 166, 0.4);
}

.forget {
  align-self: flex-start;
  margin: 2px 0 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.85rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.forget:disabled {
  opacity: 0.5;
  cursor: progress;
}

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

/* Subtle handheld-camera drift so the frame never feels like a still portrait */
/* --drift-w/--drift-h (px) let a differently sized element (the live video laid out under the
   cafe intro) drift by exactly the same amount as a phone-sized one; unset = own box (100%). */
@keyframes camdrift {
  0%   { transform: scale(1.04) translate(0, 0) rotate(0deg); }
  25%  { transform: scale(1.06) translate(calc(var(--drift-w, 100%) * -0.008), calc(var(--drift-h, 100%) * 0.004)) rotate(-0.3deg); }
  50%  { transform: scale(1.05) translate(calc(var(--drift-w, 100%) * 0.006), calc(var(--drift-h, 100%) * -0.005)) rotate(0.2deg); }
  75%  { transform: scale(1.07) translate(calc(var(--drift-w, 100%) * -0.003), calc(var(--drift-h, 100%) * -0.002)) rotate(0.35deg); }
  100% { transform: scale(1.04) translate(0, 0) rotate(0deg); }
}
video { animation: camdrift 26s ease-in-out infinite; will-change: transform; }
@media (prefers-reduced-motion: reduce) { video { animation: none; } }

/* Place picker */
.phone[data-mode="idle"],
.phone[data-mode="connecting"] {
  background-image:
    linear-gradient(to bottom, rgba(12, 10, 9, 0.1), rgba(12, 10, 9, 0.35)),
    var(--place-bg, none),
    radial-gradient(120% 70% at 50% 12%, #4a332b 0%, #1a1412 46%, #0c0b0a 100%);
  background-size: cover, cover, auto;
  background-position: center, center 20%, center;
  transition: background-image 0.4s ease;
}

.places {
  display: flex;
  gap: 10px;
  margin: 2px -22px 0;
  padding: 2px 22px 6px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

.places::-webkit-scrollbar {
  display: none;
}

.place {
  flex: 0 0 104px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 4px 8px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
  scroll-snap-align: start;
  transition: border-color 0.2s, background 0.2s, color 0.2s, transform 0.2s;
}

.place img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 14px;
  display: block;
}

.place span {
  padding: 0 4px;
}

.place[aria-checked="true"] {
  border-color: var(--accent);
  background: rgba(240, 199, 173, 0.16);
  color: var(--ink);
  transform: translateY(-2px);
}

.place:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.phone[data-mode="connecting"] .places {
  pointer-events: none;
  opacity: 0.6;
}

/* Live camera: warm grade, soft vignette and cheap film grain over the stream. */
video { filter: sepia(0.08) saturate(1.06) contrast(1.03) brightness(1.01); }
.grade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 42%, transparent 55%, rgba(20, 10, 0, 0.38) 100%);
}
.grade::after {
  content: "";
  position: absolute;
  inset: -50%;
  opacity: 0.06;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 160px 160px;
  animation: grain 0.9s steps(6) infinite;
  will-change: transform;
}
.phone:not([data-mode="live"]) .grade::after { animation: none; }
@keyframes grain {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-7%, 4%); }
  40% { transform: translate(5%, -6%); }
  60% { transform: translate(-3%, 8%); }
  80% { transform: translate(8%, 2%); }
  100% { transform: translate(-5%, -4%); }
}
@media (prefers-reduced-motion: reduce) { .grade::after { animation: none; } }

.top .sound {
  flex: none;
  width: 36px;
  height: 36px;
  min-height: 0;
  padding: 0;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  font-size: 1rem;
  line-height: 1;
}

.phone[data-ended="farewell"] #gate-status { font-style: italic; opacity: 0.9; }
