:root {
  --bg: #f4f2ef;
  --card: #ffffff;
  --text: #1c1d21;
  --muted: #6b6e76;
  --line: #e2dfda;
  --accent: #e86a17;
  --accent-dark: #c4540c;
  --talk: #1f9d55;
  --busy: #c0392b;
  --alert: #c62828;
  --shadow: 0 8px 30px rgba(0, 0, 0, .12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --card: #20232a;
    --text: #f1f1f3;
    --muted: #9a9ca3;
    --line: #30333b;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
input, select, button { font: inherit; color: inherit; }
input, select {
  -webkit-user-select: text;
  user-select: text;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
label { display: block; margin: 14px 0; font-weight: 600; font-size: 15px; }
button {
  border: 0;
  border-radius: 12px;
  padding: 12px 18px;
  background: var(--line);
  cursor: pointer;
  font-weight: 600;
}
button.primary { background: var(--accent); color: #fff; }
button.big { width: 100%; padding: 16px; font-size: 18px; }
button.danger-outline { background: transparent; border: 2px solid var(--busy); color: var(--busy); width: 100%; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.error { color: var(--busy); font-weight: 600; }
[hidden] { display: none !important; }

.screen {
  min-height: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 24px);
}

/* setup */
.setup-card { margin-top: 8vh; background: var(--card); border-radius: 22px; padding: 26px 22px; box-shadow: var(--shadow); }
.setup-card h1 { margin: 8px 0 4px; text-align: center; }
.setup-card p { text-align: center; margin-top: 0; }
.logo { text-align: center; }
.logo img { width: 72px; height: 72px; border-radius: 18px; }

/* top bar */
.top { display: flex; justify-content: space-between; align-items: center; }
.conn { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #999; }
.dot.ok { background: var(--talk); }
.dot.bad { background: var(--busy); }
.icon-btn { background: transparent; padding: 8px; display: flex; }

.notice { margin-top: 10px; padding: 10px 12px; border-radius: 12px; background: rgba(232, 106, 23, .14); font-size: 14px; }

/* channel */
.channel { display: flex; align-items: center; justify-content: center; gap: 22px; margin-top: 18px; }
.ch-btn { width: 56px; height: 56px; border-radius: 50%; font-size: 28px; line-height: 1; background: var(--card); box-shadow: var(--shadow); }
.ch-label { display: flex; flex-direction: column; align-items: center; min-width: 90px; }
#chNum { font-size: 44px; font-weight: 800; line-height: 1.1; }

.status { text-align: center; margin: 14px 0 6px; font-weight: 700; font-size: 18px; min-height: 26px; }
.status.rx { color: var(--talk); }
.status.busy { color: var(--busy); }

/* push to talk */
.ptt-wrap { display: flex; justify-content: center; margin: 14px 0 8px; }
.ptt {
  width: min(64vw, 250px);
  height: min(64vw, 250px);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ff9a4d, var(--accent) 55%, var(--accent-dark));
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 18px;
  letter-spacing: .5px;
  box-shadow: 0 14px 40px rgba(232, 106, 23, .45), inset 0 -6px 0 rgba(0, 0, 0, .15);
  transition: transform .08s, box-shadow .08s, background .15s;
  touch-action: none;
  -webkit-touch-callout: none;
}
.ptt.down { transform: scale(.96); }
.ptt.talking { background: radial-gradient(circle at 35% 30%, #4fd18a, var(--talk) 55%, #157a40); box-shadow: 0 14px 44px rgba(31, 157, 85, .55); }
.ptt.busy { background: radial-gradient(circle at 35% 30%, #e86a5c, var(--busy) 60%, #8e2a20); }
.ptt.waiting { opacity: .8; }
.ptt.disabled { filter: grayscale(.8); opacity: .6; }

/* devices */
.devices { margin-top: 16px; background: var(--card); border-radius: 16px; padding: 12px 16px; box-shadow: var(--shadow); }
.devices summary { font-weight: 700; cursor: pointer; }
.devices ul { list-style: none; padding: 0; margin: 10px 0 0; }
.devices li { display: flex; justify-content: space-between; padding: 7px 0; border-top: 1px solid var(--line); }
.devices li.other { color: var(--muted); }
.devices .via { font-size: 12px; color: var(--muted); }

/* admin */
.admin { margin-top: 18px; background: var(--card); border-radius: 16px; padding: 14px 16px 18px; box-shadow: var(--shadow); border: 2px solid rgba(198, 40, 40, .35); }
.admin h2 { margin: 0 0 6px; font-size: 18px; color: var(--alert); }
.admin .row { display: flex; align-items: center; gap: 10px; }
.admin .row select { margin: 0; flex: 1; }
.alert-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.alert-grid button { padding: 16px 8px; color: #fff; background: #b23b3b; font-size: 15px; }
.alert-grid button.Siren { background: #c62828; }
.alert-grid button.Alarm { background: #d84315; }
.alert-grid button.Chime { background: #2e7d32; }
.alert-grid button.None { background: #546e7a; }
.announce { display: flex; gap: 8px; margin-bottom: 12px; }
.announce input { margin: 0; }
.send-state { margin-bottom: 12px; font-weight: 700; color: var(--alert); text-align: center; }

/* overlays */
.overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 24px; }
.overlay.tap { background: rgba(10, 10, 12, .82); flex-direction: column; gap: 14px; text-align: center; color: #eee; }
.overlay.tap .primary { max-width: 340px; }
.overlay.alert { background: var(--alert); color: #fff; z-index: 30; animation: flash 1s infinite alternate; }
@keyframes flash { from { background: #c62828; } to { background: #8e1515; } }
.alert-card { text-align: center; max-width: 480px; }
.alert-icon { font-size: 64px; }
.alert-card h1 { font-size: 40px; margin: 6px 0 12px; letter-spacing: 1px; }
.alert-card p { font-size: 20px; }
.alert-card button { background: #fff; color: var(--alert); margin-top: 18px; }
.sheet-bg { background: rgba(0, 0, 0, .45); align-items: flex-end; padding: 0; z-index: 20; }
.sheet { width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; background: var(--bg); border-radius: 22px 22px 0 0; padding: 16px 18px calc(env(safe-area-inset-bottom) + 22px); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet-head h2 { margin: 0; }
.toggle { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.toggle input { width: 22px; height: 22px; margin: 0; }
input[type=range] { padding: 0; border: 0; background: transparent; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
#adminLogin button, #adminOut { width: 100%; }
