/* soba — quiet, warm-neutral UI. One accent, used only for "live". */

:root {
  --bg: #0d0d0c;
  --surface: #161614;
  --surface-2: #1e1e1b;
  --line: #2a2a26;
  --text: #edece7;
  --muted: #8f8d85;
  --faint: #5d5b55;
  --accent: #ff6a3d;
  --danger: #e5484d;
  --invert-bg: #edece7;
  --invert-text: #0d0d0c;
  --tile: #141412;

  --r-lg: 18px;
  --r-md: 12px;
  --sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f2ee;
    --surface: #ffffff;
    --surface-2: #ecebe6;
    --line: #dddbd4;
    --text: #151513;
    --muted: #6b6961;
    --faint: #a3a198;
    --invert-bg: #151513;
    --invert-text: #f3f2ee;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
[hidden] { display: none !important; }
a { color: inherit; }
button, input { font: inherit; color: inherit; }
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.025em; }

.ic {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}

/* ---------- brand ---------- */
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-weight: 650; font-size: 17px; letter-spacing: -0.02em; text-decoration: none;
}
.mark {
  position: relative;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--text);
}
.mark::after {
  content: ""; position: absolute; right: -3px; top: -3px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--bg);
}

/* ---------- shared controls ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 24px;
  display: flex; flex-direction: column; gap: 18px;
}
.panel h2 { font-size: 15px; letter-spacing: -0.01em; }
.panel.quiet { background: transparent; }

.field { display: flex; flex-direction: column; gap: 8px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field > span, .field > legend { font-size: 13px; color: var(--muted); padding: 0; }
.field em { font-style: normal; color: var(--faint); margin-left: 4px; }

input:not([type=radio]) {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  outline: none;
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
input::placeholder { color: var(--faint); }
input:focus { border-color: var(--muted); box-shadow: 0 0 0 3px color-mix(in srgb, var(--text) 8%, transparent); }

.seg {
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-md); padding: 3px; gap: 3px;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: grid; place-items: center; height: 36px; border-radius: 9px;
  font-variant-numeric: tabular-nums; color: var(--muted); cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.seg span:hover { color: var(--text); }
.seg input:checked + span { background: var(--surface-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.seg input:focus-visible + span { outline: 2px solid var(--muted); outline-offset: -2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface-2);
  font-weight: 550; text-decoration: none; white-space: nowrap; cursor: pointer;
  transition: transform .12s var(--ease), background .15s var(--ease), opacity .15s;
}
.btn:hover { background: color-mix(in srgb, var(--surface-2) 80%, var(--text)); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--invert-bg); color: var(--invert-text); border-color: transparent; }
.btn.primary:hover { background: color-mix(in srgb, var(--invert-bg) 88%, var(--bg)); }
.btn.primary .ic { width: 18px; height: 18px; transition: transform .2s var(--ease); }
.btn.primary:hover .ic { transform: translateX(2px); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn:focus-visible, .round:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }

.err { margin: -6px 0 0; color: var(--danger); font-size: 13px; }
.hint { margin: -6px 0 0; color: var(--muted); font-size: 13px; }

/* ---------- home ---------- */
.home {
  min-height: 100%;
  max-width: 1080px; margin: 0 auto;
  padding: 28px max(16px, env(safe-area-inset-left)) 28px;
  display: flex; flex-direction: column;
}
.home-grid {
  flex: 1;
  display: grid; gap: 16px;
  grid-template-columns: 1.15fr 1fr;
  grid-template-areas: "pitch create" "pitch join";
  align-content: center;
  padding: 48px 0;
}
.pitch { grid-area: pitch; align-self: center; padding-right: 32px; }
#f-create { grid-area: create; }
#f-join { grid-area: join; }
.pitch h1 { font-size: clamp(36px, 5.4vw, 60px); line-height: 1.02; letter-spacing: -0.045em; }
.dim { color: var(--muted); }
.lede { color: var(--muted); font-size: 17px; margin: 20px 0 0; max-width: 34ch; }
.foot { color: var(--faint); font-size: 13px; }

@media (max-width: 820px) {
  .home-grid { grid-template-columns: 1fr; grid-template-areas: "pitch" "create" "join"; padding: 36px 0 28px; }
  .pitch { padding: 0 0 12px; }
}

/* ---------- lobby ---------- */
.lobby { min-height: 100%; max-width: 1080px; margin: 0 auto; padding: 28px 16px; display: flex; flex-direction: column; }
.lobby-grid { flex: 1; display: grid; grid-template-columns: 1.5fr 1fr; gap: 16px; align-items: center; padding: 32px 0; }
.lobby .preview { aspect-ratio: 16 / 10; }
.eyebrow { margin: 0 0 -12px; font-size: 13px; color: var(--muted); }
.room-id { font-family: var(--mono); font-weight: 500; letter-spacing: -0.02em; word-break: break-all; }
.lobby .room-id { font-size: 26px; }
.occupancy { margin: -10px 0 0; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.preview-ctrl { position: absolute; left: 0; right: 0; bottom: 14px; display: flex; justify-content: center; gap: 10px; }
@media (max-width: 820px) { .lobby-grid { grid-template-columns: 1fr; align-items: start; } }

/* ---------- tiles ---------- */
.tile {
  position: relative; margin: 0; overflow: hidden;
  background: var(--tile);
  border-radius: var(--r-lg);
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  min-width: 0; min-height: 0;
}
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: var(--tile); }
.tile.self video { transform: scaleX(-1); }
.tile.screen video { object-fit: contain; }
.tile .avatar {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: clamp(28px, 6vw, 56px); font-weight: 600; letter-spacing: -0.03em; color: var(--muted);
  background: radial-gradient(circle at 50% 45%, var(--surface-2), var(--tile) 70%);
}
.tile figcaption {
  position: absolute; left: 10px; bottom: 10px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 8px; border-radius: 8px;
  background: rgb(0 0 0 / .45); color: #fff; font-size: 13px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.tile figcaption .ic { width: 15px; height: 15px; color: #ff8b8b; }
.tile.speaking { border-color: color-mix(in srgb, var(--text) 55%, transparent); }

/* ---------- round buttons ---------- */
.round {
  width: 48px; height: 48px; border-radius: 50%;
  display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface-2); cursor: pointer;
  transition: background .15s var(--ease), transform .12s var(--ease), color .15s;
}
.round:hover { background: color-mix(in srgb, var(--surface-2) 80%, var(--text)); }
.round:active { transform: scale(.94); }
.round.off { background: var(--invert-bg); color: var(--invert-text); border-color: transparent; }
.round.danger { background: var(--danger); color: #fff; border-color: transparent; width: 60px; border-radius: 24px; }
.round.danger:hover { background: color-mix(in srgb, var(--danger) 85%, #000); }
.preview .round { background: rgb(0 0 0 / .45); color: #fff; border-color: rgb(255 255 255 / .12); backdrop-filter: blur(8px); }
.preview .round.off { background: #fff; color: #111; }

/* ---------- call ---------- */
.call {
  height: 100dvh; display: grid; grid-template-rows: auto 1fr auto;
  padding: 12px 12px max(12px, env(safe-area-inset-bottom));
  gap: 12px;
}
.call-top { display: flex; align-items: center; gap: 10px; padding: 4px 6px; font-size: 14px; }
.call-top .room-id { font-size: 14px; }
.call-top .count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.live { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent); }

.stage { display: grid; gap: 10px; min-height: 0; }
.stage[data-count="1"] { grid-template-columns: 1fr; }
.stage[data-count="2"] { grid-template-columns: 1fr 1fr; }
.stage[data-count="3"], .stage[data-count="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.stage[data-count="3"] .tile:first-child { grid-row: span 2; }
.stage[data-count="5"], .stage[data-count="6"] { grid-template-columns: repeat(3, 1fr); grid-template-rows: 1fr 1fr; }
.stage[data-count="5"] .tile:first-child { grid-row: span 2; }

/* two people: picture-in-picture for yourself, the other person fills the stage */
.stage[data-count="2"].pip { grid-template-columns: 1fr; position: relative; }
.stage.pip .tile.self {
  position: absolute; right: 14px; bottom: 14px; z-index: 2;
  width: clamp(120px, 22%, 260px); aspect-ratio: 4 / 3; height: auto;
  box-shadow: 0 12px 32px rgb(0 0 0 / .35);
}

@media (orientation: portrait) and (max-width: 820px) {
  .stage[data-count="2"]:not(.pip) { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .stage[data-count="3"], .stage[data-count="4"] { grid-template-columns: 1fr 1fr; }
  .stage[data-count="5"], .stage[data-count="6"] { grid-template-columns: 1fr 1fr; grid-template-rows: repeat(3, 1fr); }
  .stage[data-count="5"] .tile:first-child { grid-row: auto; grid-column: span 2; }
  .stage.pip .tile.self { width: 32%; aspect-ratio: 3 / 4; }
}

.dock { display: flex; justify-content: center; gap: 10px; padding: 4px 0 2px; }
.round .dot { fill: none; stroke: none; }
.round.recording { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.round.recording .dot { fill: var(--danger); }

.rec-badge {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 3px 10px 3px 8px; border-radius: 999px;
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger); font-size: 12px; font-weight: 600; letter-spacing: .04em;
  font-variant-numeric: tabular-nums;
}
.rec-badge i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: blink 1.4s steps(2, jump-none) infinite; }
.call-top .count { margin-left: 0; }
.call-top .rec-badge, .call-top .rec-badge[hidden] + .count { margin-left: auto; }
.call-top .rec-badge:not([hidden]) + .count { margin-left: 4px; }
.tile.recording::before {
  content: "REC"; position: absolute; left: 10px; top: 10px; z-index: 1;
  padding: 2px 8px; border-radius: 6px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; letter-spacing: .06em;
}
@keyframes blink { 50% { opacity: .25; } }

.waiting {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  pointer-events: none;
}
.waiting p { margin: 0; color: #fff; font-size: 15px; text-shadow: 0 1px 12px rgb(0 0 0 / .6); }
.waiting .btn { pointer-events: auto; background: rgb(0 0 0 / .5); color: #fff; border-color: rgb(255 255 255 / .15); backdrop-filter: blur(8px); }

/* ---------- end ---------- */
.end { min-height: 100%; max-width: 1080px; margin: 0 auto; padding: 28px 16px; display: flex; flex-direction: column; }
.end-body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 4px; max-width: 520px; }
.end h1 { font-size: clamp(30px, 4.5vw, 44px); letter-spacing: -0.04em; line-height: 1.05; }
.end .row { margin-top: 28px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 12px);
  background: var(--invert-bg); color: var(--invert-text);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 550;
  opacity: 0; pointer-events: none; transition: opacity .2s var(--ease), transform .2s var(--ease);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- motion ---------- */
.home-grid > *, .lobby-grid > *, .end-body { animation: rise .5s var(--ease) both; }
.home-grid > :nth-child(2) { animation-delay: .05s; }
.home-grid > :nth-child(3) { animation-delay: .1s; }
.stage .tile { animation: fade .35s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes fade { from { opacity: 0; transform: scale(.985); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
