:root {
  --bg: #0b0d10;
  --panel: #161a20;
  --line: #2a313b;
  --text: #f2f4f7;
  --muted: #98a2b3;
  --danger: #d92d20;
  --warning: #dc6803;
  --ok: #079455;
  --test: #475467;
  --blue: #1570ef;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Sarabun", sans-serif;
  font-size: 17px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

body {
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  max-width: 520px;
  margin: 0 auto;
}

h1 { font-size: 22px; margin: 8px 0 8px; }
p { margin: 8px 0; }
.muted { color: var(--muted); font-size: 14px; }
.center { text-align: center; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: none; }
#who-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: #fdb022; color: #1d1d1d; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }

/* ---------- banners ---------- */
.banner { border-radius: 12px; padding: 10px 12px; margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.banner.bad { background: #55160c; color: #fecdca; border: 1px solid var(--danger); }
.banner.warn { background: #4e1d09; color: #fedf89; border: 1px solid var(--warning); }

/* ---------- generic buttons ---------- */
.btn {
  display: block; width: 100%;
  min-height: 52px; margin: 12px 0 0;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text);
  font: inherit; font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--blue); border-color: var(--blue); }
.btn:disabled { opacity: .5; }

/* ---------- status ---------- */
.status {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px;
}
.status .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--ok); flex: none; }
.status-text { flex: 1; min-width: 0; }
#status-title { font-weight: 700; }
.status.broadcasting { border-color: var(--danger); background: #3a0f0a; }
.status.broadcasting .dot { background: var(--danger); animation: pulse 1s infinite; }
.status.talking { border-color: var(--blue); background: #0b2350; }
.status.talking .dot { background: var(--blue); animation: pulse 1s infinite; }
.btn.stop { width: auto; min-height: 44px; margin: 0; padding: 0 18px; background: #fff; color: #101828; border: none; }

@keyframes pulse { 50% { opacity: .3; } }

.hint { text-align: center; color: var(--muted); font-size: 14px; margin: 14px 0 8px; }

/* ---------- preset hold buttons ---------- */
.presets { display: grid; gap: 12px; }

.preset {
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  width: 100%; min-height: 92px; padding: 14px 18px;
  border: none; border-radius: var(--radius);
  color: #fff; text-align: left; font: inherit;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.preset.danger { background: var(--danger); }
.preset.warning { background: var(--warning); }
.preset.ok { background: var(--ok); }
.preset.test { background: var(--test); }
.preset:disabled { filter: grayscale(.8); opacity: .45; cursor: not-allowed; }

.preset .fill {
  position: absolute; inset: 0;
  background: rgba(255, 255, 255, .32);
  transform: scaleX(0); transform-origin: left center;
  pointer-events: none;
}
.preset .label { position: relative; font-size: 24px; font-weight: 800; letter-spacing: .2px; }
.preset .desc { position: relative; font-size: 14px; opacity: .92; margin-top: 2px; }
.preset.holding { outline: 3px solid #fff; outline-offset: 2px; }
.preset:focus-visible, .talk:focus-visible, .btn:focus-visible { outline: 3px solid #84caff; outline-offset: 2px; }

/* ---------- talk ---------- */
.talk-wrap { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; }
.talk {
  width: 150px; height: 150px; border-radius: 50%;
  border: none; background: var(--blue); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font: inherit; font-weight: 700; font-size: 15px;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.talk.connecting { background: #53389e; }
.talk.live { background: var(--danger); box-shadow: 0 0 0 8px rgba(217, 45, 32, .35); }
.talk:disabled { opacity: .45; cursor: not-allowed; }

.meter { width: 180px; height: 8px; border-radius: 4px; background: var(--line); margin: 14px 0 8px; overflow: hidden; }
#talk-level { height: 100%; width: 0; background: #32d583; transition: width 60ms linear; }

.foot { text-align: center; margin-top: 22px; }

/* ---------- misc ---------- */
.spinner {
  width: 40px; height: 40px; margin: 40px auto 8px;
  border: 4px solid var(--line); border-top-color: var(--blue); border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom));
  max-width: 488px; margin: 0 auto;
  padding: 12px 14px; border-radius: 12px;
  background: #fff; color: #101828; font-weight: 600; font-size: 15px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4);
}
.toast.bad { background: #fee4e2; color: #7a271a; }
.toast.ok { background: #d1fadf; color: #054f31; }

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .status .dot, .spinner { animation: none !important; }
}
