:root {
  --cream: #f6f1e8;
  --cream-2: #efe8db;
  --ink: #16130f;
  --ink-2: #3b352d;
  --muted: #7d7467;
  --line: rgba(22, 19, 15, 0.12);
  --accent: #d9541e;
  --accent-ink: #ffffff;
  --ok: #2f9e5b;
  --warn: #d9a21e;
  --bad: #c7362c;
  --tile: #1d1a16;
  --radius: 18px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--cream);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}
a { color: inherit; }
button { font: inherit; cursor: pointer; }
.sr { position: absolute; left: -9999px; }

/* ambient paper texture (one living element) */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(60% 50% at 10% 0%, rgba(217, 84, 30, 0.10), transparent 70%),
    radial-gradient(50% 40% at 100% 100%, rgba(217, 84, 30, 0.06), transparent 70%);
  animation: drift 18s ease-in-out infinite alternate;
}
@keyframes drift { from { transform: translate3d(0,0,0); } to { transform: translate3d(0,-2%,0); } }
body.incall::before { display: none; }

header.top {
  position: relative; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 24px; gap: 12px;
}
.brand { white-space: nowrap; display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 700; letter-spacing: -0.01em; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(217,84,30,.15); }
.brand small { font-weight: 500; color: var(--muted); margin-left: 4px; }
.eyebrow { font-family: var(--mono); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }

main { position: relative; z-index: 1; flex: 1; display: flex; flex-direction: column; }
.wrap { width: min(1080px, 100% - 32px); margin: 0 auto; }

/* ---------- landing ---------- */
.hero { padding: 48px 0 24px; display: grid; grid-template-columns: 1.1fr .9fr; gap: 40px; align-items: center; }
.hero h1 { font-size: clamp(40px, 6vw, 72px); line-height: .98; letter-spacing: -0.03em; margin: 12px 0 18px; font-weight: 800; }
.hero h1 em { font-style: normal; color: var(--accent); }
.hero p.lead { font-size: 18px; color: var(--ink-2); max-width: 46ch; margin: 0 0 28px; }
.cta-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 999px;
  padding: 14px 22px; font-weight: 600; font-size: 16px; transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 10px 24px -10px rgba(217,84,30,.6); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 14px 28px -10px rgba(217,84,30,.7); }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { background: rgba(22,19,15,.04); }
.btn-danger { background: var(--bad); color: #fff; }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none !important; }
.join-form { display: flex; gap: 8px; margin-top: 22px; max-width: 460px; }
.join-form input {
  flex: 1; font: inherit; font-size: 16px; padding: 13px 16px; border-radius: 12px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
.join-form input:focus { outline: 2px solid rgba(217,84,30,.4); outline-offset: 1px; }

.preview-card {
  background: var(--tile); border-radius: 24px; aspect-ratio: 4/3; position: relative; overflow: hidden;
  box-shadow: 0 30px 60px -30px rgba(22,19,15,.5);
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 8px; padding: 8px;
}
.preview-card .ptile {
  border-radius: 14px; background: linear-gradient(160deg, #2a251f, #1b1813); position: relative; overflow: hidden;
}
.preview-card .ptile::after {
  content: attr(data-n); position: absolute; left: 12px; bottom: 10px; font-size: 13px; color: rgba(255,255,255,.8);
  background: rgba(0,0,0,.35); padding: 3px 8px; border-radius: 6px;
}
.preview-card .ptile i {
  position: absolute; inset: 0; margin: auto; width: 46%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #efe3d2, #c9b89c 60%, #8e7d63); opacity: .9;
  animation: breathe 4s ease-in-out infinite;
}
.preview-card .ptile:nth-child(2) i { animation-delay: -1s; } .preview-card .ptile:nth-child(3) i { animation-delay: -2s; } .preview-card .ptile:nth-child(4) i { animation-delay: -3s; }
.preview-card .ptile.speaking { box-shadow: inset 0 0 0 2px var(--accent); }
@keyframes breathe { 0%,100% { transform: scale(1); } 50% { transform: scale(1.04); } }

.features { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; padding: 24px 0 48px; }
.feature { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,255,255,.5); }
.feature strong { display: block; margin-bottom: 4px; }
.feature span { color: var(--ink-2); font-size: 15px; }

footer.foot {
  position: relative; z-index: 1; padding: 20px 24px; color: var(--muted); font-size: 13px;
  display: flex; gap: 16px; flex-wrap: wrap; justify-content: space-between; border-top: 1px solid var(--line);
}
body.incall footer.foot { display: none; }

/* ---------- pre-join ---------- */
.prejoin { padding: 24px 0 40px; display: grid; grid-template-columns: 1.2fr .8fr; gap: 32px; align-items: start; }
.cam-preview {
  position: relative; background: var(--tile); border-radius: 24px; aspect-ratio: 16/10; overflow: hidden;
  box-shadow: 0 30px 60px -30px rgba(22,19,15,.5);
}
.cam-preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.cam-preview .overlay {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; color: #fff; text-align: center; padding: 24px; background: rgba(29,26,22,.92);
}
.cam-preview .overlay p { margin: 0; max-width: 38ch; color: rgba(255,255,255,.8); }
.cam-preview .overlay.hidden { display: none; }
.cam-preview .mini-ctl { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 8px; }
.panel { background: rgba(255,255,255,.6); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.panel h2 { margin: 0 0 4px; font-size: 24px; letter-spacing: -0.02em; }
.panel .room { font-family: var(--mono); font-size: 13px; color: var(--muted); word-break: break-all; }
.field { margin-top: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink-2); }
.field input, .field select {
  width: 100%; font: inherit; font-size: 16px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: #fff; color: var(--ink);
}
.field input:focus, .field select:focus { outline: 2px solid rgba(217,84,30,.4); outline-offset: 1px; }
.panel .btn-primary { width: 100%; justify-content: center; margin-top: 20px; padding: 16px; }
.note { margin-top: 12px; font-size: 13px; color: var(--muted); }
.note.warn { color: #8a5a00; }

/* ---------- in-call ---------- */
body.incall { background: #0f0d0b; color: #fff; }
body.incall header.top { display: none; }
.call { flex: 1; display: flex; flex-direction: column; height: 100svh; max-height: 100svh; overflow: hidden; }
body.incall { overflow: hidden; }
.call-top { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; gap: 12px; }
.call-top .brand { color: #fff; }
.call-top .brand small { color: rgba(255,255,255,.55); }
.pill { white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; background: rgba(255,255,255,.08); border-radius: 999px; padding: 6px 12px; font-size: 13px; color: rgba(255,255,255,.85); }
.qdot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.qdot.good { background: var(--ok); } .qdot.fair { background: var(--warn); } .qdot.poor { background: var(--bad); }

.stage { flex: 1; position: relative; padding: 0 12px; min-height: 0; }
.tiles { display: grid; gap: 10px; height: 100%; min-height: 0; position: relative; }
.tiles.n1 { grid-template-columns: 1fr; }
.tiles.n2 { grid-template-columns: minmax(0,1fr) minmax(0,1fr); grid-template-rows: minmax(0,1fr); }
.tiles.n1 { grid-template-rows: minmax(0,1fr); }
.tiles.n3, .tiles.n4 { grid-template-columns: minmax(0,1fr) minmax(0,1fr); grid-template-rows: minmax(0,1fr) minmax(0,1fr); }
.tiles.n5, .tiles.n6 { grid-template-columns: repeat(3, minmax(0,1fr)); grid-template-rows: minmax(0,1fr) minmax(0,1fr); }
.tile {
  position: relative; background: var(--tile); border-radius: 18px; overflow: hidden; min-height: 0;
  box-shadow: inset 0 0 0 2px transparent; transition: box-shadow .2s ease; animation: tilein .3s ease both;
}
@keyframes tilein { from { opacity: 0; transform: scale(.98); } to { opacity: 1; transform: none; } }
.tile.speaking { box-shadow: inset 0 0 0 2px var(--accent); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: var(--tile); }
.tile.mirror video { transform: scaleX(-1); }
.tile.contain video { object-fit: contain; background: #000; }
.tile .name {
  position: absolute; left: 10px; bottom: 10px; font-size: 13px; background: rgba(0,0,0,.45); padding: 4px 9px; border-radius: 8px; display: flex; align-items: center; gap: 6px;
}
.tile .name .mic-off { color: #ffb4ab; }
.tile .avatar {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center; font-size: clamp(28px, 6vw, 64px); font-weight: 700; color: #e9ded0;
  background: radial-gradient(circle at 50% 40%, #2b261f, #1a1713);
}
.tile.camoff .avatar { display: flex; }
.tile.camoff video { visibility: hidden; }
.tile .tap { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(0,0,0,.5); font-weight: 600; }
.tile.needs-tap .tap { display: flex; }

/* self PiP when exactly one remote */
.tiles.spot { grid-template-columns: minmax(0,1fr); grid-template-rows: minmax(0,1fr); }
.tiles.spot .tile.self {
  position: absolute; right: 24px; bottom: 24px; width: min(26vw, 260px); aspect-ratio: 4/3; z-index: 2;
  box-shadow: 0 20px 40px -20px rgba(0,0,0,.8), inset 0 0 0 2px transparent;
}

.waiting {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; padding: 24px; pointer-events: none;
}
.waiting.hidden { display: none; }
.waiting .ring { width: 54px; height: 54px; border-radius: 50%; border: 2px solid rgba(255,255,255,.2); border-top-color: var(--accent); animation: spin 1.2s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.waiting h3 { margin: 6px 0 0; font-size: 20px; letter-spacing: -0.01em; }
.waiting p { margin: 0; color: rgba(255,255,255,.65); font-size: 14px; max-width: 40ch; }
.waiting .btn { pointer-events: auto; margin-top: 6px; }

.controls {
  display: flex; justify-content: center; align-items: center; gap: 10px; padding: 14px 12px calc(14px + env(safe-area-inset-bottom)); flex-wrap: wrap;
}
.ctl {
  width: 56px; height: 56px; border-radius: 50%; border: 0; background: rgba(255,255,255,.1); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; transition: background .15s ease, transform .15s ease; position: relative;
}
.ctl:hover { background: rgba(255,255,255,.18); transform: translateY(-1px); }
.ctl.off { background: var(--bad); }
.ctl.on { background: var(--accent); }
.ctl.leave { background: var(--bad); width: auto; padding: 0 22px; border-radius: 999px; font-weight: 600; gap: 8px; }
.ctl svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ctl .tip {
  position: absolute; bottom: 64px; left: 50%; transform: translateX(-50%); white-space: nowrap; font-size: 12px; background: rgba(0,0,0,.8); padding: 4px 8px; border-radius: 6px; opacity: 0; pointer-events: none; transition: opacity .15s;
}
.ctl:hover .tip { opacity: 1; }
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%) translateY(10px); background: #fff; color: var(--ink); padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  opacity: 0; transition: opacity .2s, transform .2s; z-index: 50; pointer-events: none; box-shadow: 0 12px 30px -10px rgba(0,0,0,.5);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.privacy { text-align: center; font-size: 12px; color: rgba(255,255,255,.45); padding: 0 16px 10px; }

.hidden { display: none !important; }

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; gap: 28px; padding-top: 24px; }
  .features { grid-template-columns: 1fr; }
  .prejoin { grid-template-columns: 1fr; }
  .cam-preview { aspect-ratio: 4/3; }
  .tiles.n2 { grid-template-columns: minmax(0,1fr); grid-template-rows: minmax(0,1fr) minmax(0,1fr); }
  .tiles.n5, .tiles.n6 { grid-template-columns: minmax(0,1fr) minmax(0,1fr); grid-template-rows: repeat(3, minmax(0,1fr)); }
  .tiles.spot .tile.self { width: 34vw; right: 12px; bottom: 12px; }
  .ctl { width: 50px; height: 50px; }
  .ctl .tip { display: none; }
  header.top { padding: 14px 16px; }
}

/* ---------- transcript ---------- */
.stage { display: flex; gap: 10px; }
.stage .tiles { flex: 1; min-width: 0; }
.transcript {
  width: 340px; flex: none; display: flex; flex-direction: column; background: #17140f; border-radius: 18px; padding: 14px; gap: 10px; min-height: 0; color: #fff;
  animation: tilein .25s ease both;
}
.tx-head { display: flex; align-items: center; justify-content: space-between; }
.tx-close { background: transparent; border: 0; color: rgba(255,255,255,.7); font-size: 22px; line-height: 1; padding: 2px 6px; }
.tx-note, .tx-support { font-size: 12px; color: rgba(255,255,255,.55); }
.tx-toggle { padding: 12px 16px; font-size: 15px; justify-content: center; }
.tx-toggle.on { background: var(--ok); }
.tx-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.tx-list li { background: rgba(255,255,255,.06); border-radius: 10px; padding: 8px 10px; }
.tx-list li b { color: var(--accent); font-weight: 600; }
.tx-list li time { float: right; font-family: var(--mono); font-size: 11px; color: rgba(255,255,255,.45); }
.tx-list li.me b { color: #f0c9b5; }
.tx-interim { font-size: 13px; color: rgba(255,255,255,.5); font-style: italic; min-height: 1.2em; }
.tx-dl { color: #fff; border-color: rgba(255,255,255,.25); justify-content: center; padding: 10px 14px; font-size: 14px; }
.tx-dl[disabled] { opacity: .4; }
.tile .name .tx-badge { color: #9fe3b7; font-size: 11px; }
.ctl.on.cc { background: rgba(255,255,255,.25); }
@media (max-width: 860px) {
  .stage { flex-direction: column; }
  .transcript { width: auto; max-height: 42%; }
  .stage.with-tx .tiles { flex: 1; }
}

@media (max-width: 860px) {
  .call-top .brand small { display: none; }
  .call-top { padding: 10px 12px; }
  .call-top .pill { padding: 6px 10px; font-size: 12px; }
  .transcript { max-height: 50%; padding: 10px 12px; gap: 8px; }
  .transcript .tx-note { display: none; }
  .tx-list { min-height: 72px; }
  .tx-toggle { padding: 10px 14px; font-size: 14px; }
}
