:root {
  --bg: #f3f4f6;
  --bg-glow: #e6f6ec;
  --surface: #ffffff;
  --surface-2: #f6f7f9;
  --fg: #111418;
  --muted: #5d6673;
  --line: #e1e4e8;
  --shadow: 0 1px 2px rgb(16 24 40 / .05), 0 8px 24px rgb(16 24 40 / .06);

  --clear: #16a34a;
  --tx: #16a34a;
  --rx: #2563eb;
  --wait: #d97706;
  --stop: #dc2626;
  --idle: #9aa3ae;

  --display-bg: #0f172a;
  --display-fg: #e8f0ff;
  --display-muted: #8ea0bf;

  --radius: 18px;
  --state: var(--idle);
  --level: 0;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0e13;
    --bg-glow: #0f2418;
    --surface: #141920;
    --surface-2: #1a2029;
    --fg: #e9edf2;
    --muted: #8c96a3;
    --line: #242c36;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 8px 24px rgb(0 0 0 / .25);
    --clear: #22c55e;
    --tx: #22c55e;
    --rx: #4f8cff;
    --wait: #f59e0b;
    --stop: #f05252;
    --idle: #5b6573;
    --display-bg: #070a0f;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; min-height: 100%; }
body {
  background: radial-gradient(120% 60% at 50% -10%, var(--bg-glow), transparent 60%) no-repeat, var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
main {
  max-width: 480px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 48px; margin-bottom: 8px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 750; font-size: 19px; letter-spacing: -.01em; color: var(--fg); text-decoration: none; }
.logo-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; background: var(--clear); color: #fff; }
.logo-mark svg { width: 18px; height: 18px; stroke-width: 2.4; }
.topbar-right { display: flex; gap: 6px; }
.pill { font-size: 12.5px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); white-space: nowrap; }
.pill.subtle { color: var(--muted); font-weight: 500; }

/* ---------- generic ---------- */
h1 { font-size: clamp(24px, 6.5vw, 30px); line-height: 1.2; letter-spacing: -.02em; margin: 0 0 10px; }
h2 { font-size: 14px; margin: 0; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.lead { color: var(--muted); margin: 0 0 8px; font-size: 16.5px; }
.error { color: var(--stop); text-align: center; }
.page { animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.btn {
  font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: 12px; cursor: pointer; text-decoration: none;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  transition: transform .08s, filter .15s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--clear); border-color: transparent; color: #fff; box-shadow: 0 6px 18px color-mix(in srgb, var(--clear) 35%, transparent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.big { width: 100%; min-height: 56px; font-size: 17px; border-radius: 14px; margin-top: 16px; }
.btn:disabled { opacity: .6; cursor: default; }
.btn:focus-visible, input:focus-visible, summary:focus-visible, .ptt:focus-visible { outline: 3px solid color-mix(in srgb, var(--clear) 55%, transparent); outline-offset: 2px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 14px 0; box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }

label { display: block; font-weight: 600; margin-bottom: 8px; }
input {
  font: inherit; font-size: 16px; /* 16px stops mobile browsers zooming in */
  width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--fg);
}

.footnote { display: flex; gap: 8px; align-items: flex-start; color: var(--muted); font-size: 13.5px; margin: 14px 2px 0; }
.footnote svg { width: 16px; height: 16px; margin-top: 2px; }

/* ---------- home / join ---------- */
.hero { text-align: center; padding: 28px 4px 4px; }
.hero-mark {
  display: grid; place-items: center; width: 84px; height: 84px; margin: 0 auto 18px; border-radius: 50%;
  background: color-mix(in srgb, var(--clear) 14%, var(--surface)); color: var(--clear);
  box-shadow: 0 0 0 10px color-mix(in srgb, var(--clear) 7%, transparent), 0 0 0 22px color-mix(in srgb, var(--clear) 4%, transparent);
}
.hero-mark svg { width: 36px; height: 36px; }
.hero-mark.muted-mark { color: var(--muted); background: var(--surface-2); box-shadow: none; }
.center .hero { padding-top: 48px; }

.steps { list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0; margin: 28px 0 0; }
.steps li { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; font-size: 13.5px; color: var(--muted); padding: 12px 6px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.steps span { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); color: var(--fg); font-weight: 700; font-size: 13px; }
.form { margin-top: 20px; }
.form .btn.big { margin-top: 14px; }

/* ---------- room states ---------- */
#room[data-state="clear"]   { --state: var(--clear); }
#room[data-state="tx"]      { --state: var(--tx); }
#room[data-state="rx"]      { --state: var(--rx); }
#room[data-state="wait"]    { --state: var(--wait); }
#room[data-state="stop"]    { --state: var(--stop); }
#room[data-state="offline"] { --state: var(--idle); }

.banner { padding: 10px 14px; border-radius: 12px; margin: 4px 0 10px; font-size: 14.5px; font-weight: 500;
  background: color-mix(in srgb, var(--wait) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--wait) 40%, transparent); }

/* radio-style display */
.display {
  background: var(--display-bg); color: var(--display-fg); border-radius: var(--radius); padding: 14px 16px 14px;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / .06), var(--shadow);
  position: relative; overflow: hidden;
}
.display::before { content: ""; position: absolute; inset: 0; background: radial-gradient(100% 120% at 0% 0%, color-mix(in srgb, var(--state) 22%, transparent), transparent 60%); transition: background .3s; pointer-events: none; }
.display > * { position: relative; }
.display-top { display: flex; justify-content: space-between; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; font: 700 11.5px/1 ui-monospace, "SF Mono", Consolas, monospace; letter-spacing: .12em; text-transform: uppercase;
  padding: 6px 9px; border-radius: 6px; background: color-mix(in srgb, var(--state) 22%, transparent); color: color-mix(in srgb, var(--state) 70%, #fff);
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--state); }
#room[data-state="tx"] .chip::before, #room[data-state="rx"] .chip::before { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.display-time { font: 600 14px ui-monospace, "SF Mono", Consolas, monospace; color: var(--display-muted); font-variant-numeric: tabular-nums; }
.display-main { font-size: clamp(24px, 7vw, 30px); font-weight: 750; letter-spacing: -.02em; margin: 12px 0 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.display-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; min-height: 30px; }
.display-sub { color: var(--display-muted); font-size: 14.5px; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 28px; flex: none; }
.bars i { width: 5px; border-radius: 3px; background: var(--state); opacity: .9; height: calc(4px + var(--level) * var(--k) * 24px); transition: height .06s linear; }
#room:not([data-state="tx"]):not([data-state="rx"]) .bars i { opacity: .25; height: 4px; }

/* push-to-talk button */
.ptt-wrap { position: relative; width: min(74vw, 290px); aspect-ratio: 1; margin: 22px auto 6px; }
.ring { position: absolute; inset: -10px; width: calc(100% + 20px); height: calc(100% + 20px); transform: rotate(-90deg); pointer-events: none; }
.ring circle { fill: none; stroke-width: 3.5; }
.ring-bg { stroke: var(--line); }
.ring-fg { stroke: var(--state); stroke-dasharray: 100; stroke-dashoffset: 100; stroke-linecap: round; opacity: 0; transition: stroke-dashoffset .5s linear, opacity .2s; }
#room[data-state="tx"] .ring-fg { opacity: 1; }

.ptt {
  position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  font: inherit; color: var(--fg);
  background: radial-gradient(circle at 50% 35%, var(--surface), var(--surface-2));
  border: 2px solid color-mix(in srgb, var(--state) 45%, var(--line));
  box-shadow: var(--shadow), inset 0 -6px 16px rgb(0 0 0 / .06), 0 0 0 calc(var(--level) * 22px) color-mix(in srgb, var(--state) 22%, transparent);
  user-select: none; -webkit-user-select: none; touch-action: none; -webkit-touch-callout: none;
  transition: transform .1s, background .2s, border-color .2s, color .2s, box-shadow .08s linear;
}
.ptt-icon { width: 54px; height: 54px; stroke-width: 1.8; color: var(--state); transition: color .2s; }
.ptt-label { font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.ptt.pressed { transform: scale(.965); }
#room[data-state="tx"] .ptt { background: radial-gradient(circle at 50% 35%, color-mix(in srgb, var(--tx) 85%, #fff), var(--tx)); border-color: transparent; color: #fff; }
#room[data-state="tx"] .ptt-icon { color: #fff; }
#room[data-state="rx"] .ptt, #room[data-state="stop"] .ptt { color: var(--muted); }
.ptt:disabled { cursor: default; opacity: .7; }
.ptt::after { content: ""; position: absolute; inset: -2px; border-radius: 50%; border: 2px solid var(--state); opacity: 0; }
#room[data-state="tx"] .ptt::after { animation: ripple 1.6s ease-out infinite; }
@keyframes ripple { from { opacity: .5; transform: scale(1); } to { opacity: 0; transform: scale(1.18); } }

.hint { text-align: center; color: var(--muted); font-size: 14px; margin: 14px 0 6px; min-height: 21px; }
kbd { font: 600 12px ui-monospace, Consolas, monospace; padding: 2px 6px; border-radius: 5px; border: 1px solid var(--line); border-bottom-width: 2px; background: var(--surface); }
@media (hover: none) { .hint .kb { display: none; } }

/* members */
.members { list-style: none; margin: 0; padding: 0; }
.members li { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--line); min-height: 52px; }
.members li:first-child { border-top: 0; }
.avatar {
  position: relative; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; flex: none;
  background: hsl(var(--h) 55% 46%); color: #fff; font-weight: 700; font-size: 14px;
}
.members li.talking .avatar { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--state); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 3px var(--surface), 0 0 0 8px color-mix(in srgb, var(--state) 35%, transparent); } }
.members .who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.members .you { color: var(--muted); font-weight: 400; }
.tag { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.tag.talking { color: var(--state); background: color-mix(in srgb, var(--state) 14%, transparent); }
.tag.waiting { color: var(--wait); background: color-mix(in srgb, var(--wait) 14%, transparent); }

/* invite */
.invite summary { display: flex; align-items: center; gap: 10px; min-height: 28px; cursor: pointer; font-weight: 600; list-style: none; }
.invite summary::-webkit-details-marker { display: none; }
.invite summary svg { color: var(--clear); }
.invite .chev { margin-left: auto; color: var(--muted); transition: transform .2s; }
.invite[open] .chev { transform: rotate(180deg); }
.invite-body { padding-top: 12px; }
.link-row { display: flex; gap: 8px; }
.link-row input { flex: 1; min-width: 0; font-size: 14px; font-family: ui-monospace, Consolas, monospace; }
.btn.icon { padding: 10px 12px; }
#qr { display: block; margin: 14px auto 0; background: #fff; padding: 8px; border-radius: 14px; border: 1px solid var(--line); }

/* small phones and short screens */
@media (max-width: 360px) {
  .btn.icon span { display: none; }
  .steps li { font-size: 12.5px; }
}
@media (max-height: 700px) {
  .ptt-wrap { width: min(62vw, 230px); margin-top: 16px; }
  .ptt-icon { width: 44px; height: 44px; }
  .hero { padding-top: 12px; }
  .display-main { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
