/* Telsiz — a family car cabin at night.
   Palette (named):
     --night      true black, OLED off, night driving
     --headlight  warm amber — speaking glow + primary action
     --dashboard  cool dim gray chrome
     --brake      muted red, reserved strictly for "you are muted"
     --moonlight  warm off-white text
     --seatline   dim outline for empty seats                          */

:root {
  --night: #000000;
  --headlight: #ffb454;
  --headlight-soft: rgba(255, 180, 84, 0.28);
  --dashboard: #8a9099;
  --dashboard-dim: #4a4f57;
  --brake: #c24a44;      /* muted red — reserved STRICTLY for "you are muted" */
  --signal-poor: #8c4a46; /* dim brick — poor connection / errors / Leave, distinct from --brake */
  --moonlight: #ece7dd;
  --seatline: #23262c;
  --panel: #101216;

  --font-display: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display",
    "Nunito", "Comfortaa", system-ui, sans-serif;
  --font-body: system-ui, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--night);
  color: var(--moonlight);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

.display { font-family: var(--font-display); letter-spacing: 0.02em; }
.hidden { display: none !important; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}
:focus-visible {
  outline: 2px solid var(--headlight);
  outline-offset: 3px;
  border-radius: 6px;
}

/* ------------------------------------------------------------- screens -- */

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  gap: 24px;
  max-width: 480px;
  margin: 0 auto;
}

/* --------------------------------------------------------------- home -- */

.home-brand { text-align: center; margin-top: 8vh; }
.brand-mark { width: 72px; height: 72px; color: var(--headlight); }
.home-brand h1 { font-size: 3rem; font-weight: 700; }
.tagline { color: var(--dashboard); margin-top: 4px; }

#home-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 340px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { color: var(--dashboard); font-size: 0.9rem; }

input[type="text"] {
  background: var(--panel);
  border: 1px solid var(--seatline);
  border-radius: 14px;
  color: var(--moonlight);
  font: inherit;
  font-size: 1.15rem;
  padding: 14px 16px;
  width: 100%;
}
input[type="text"]:focus-visible { outline-offset: 0; }

.join-row { display: flex; gap: 10px; }
.code-input {
  flex: 1;
  text-transform: uppercase;
  font-size: 1.6rem;
  text-align: center;
  letter-spacing: 0.35em;
}

.btn {
  min-height: 56px;
  padding: 12px 22px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--seatline);
  color: var(--moonlight);
  font-size: 1.05rem;
}
.btn-primary {
  background: var(--headlight);
  border-color: var(--headlight);
  color: #201200;
  font-weight: 700;
}
.btn-ghost { background: transparent; }
.btn-danger { border-color: var(--signal-poor); color: var(--signal-poor); }

.error-text { color: var(--signal-poor); text-align: center; max-width: 340px; }
.hint { color: var(--dashboard); font-size: 0.88rem; }

/* --------------------------------------------------------------- room -- */

.status-strip {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
}
.room-code { font-size: 1.7rem; letter-spacing: 0.3em; flex: 1; }
.badge {
  border: 1px solid var(--seatline);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.8rem;
  color: var(--dashboard);
}
.badge-dim { opacity: 0.55; }
.badge-warn { color: var(--headlight); border-color: var(--headlight-soft); }

/* ---------------------------------------------------------- car cabin -- */

.cabin {
  width: 100%;
  max-width: 380px;
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 26px 20px;
  border: 2px solid var(--seatline);
  border-radius: 48px 48px 34px 34px; /* windshield curve up top */
  align-content: center;
  position: relative;
}
.cabin::before { /* dashboard line */
  content: "";
  position: absolute;
  top: 16px; left: 24px; right: 24px;
  height: 2px;
  border-radius: 2px;
  background: var(--seatline);
}

.seat {
  min-height: 108px;
  border-radius: 26px 26px 18px 18px; /* headrest curve */
  border: 2px solid var(--seatline);
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--dashboard);
  position: relative;
  transition: box-shadow 0.18s ease, border-color 0.18s ease, transform 0.18s ease, opacity 0.3s ease;
}
.seat.occupied { border-color: var(--dashboard-dim); color: var(--moonlight); background: var(--panel); }
.seat.speaking {
  border-color: var(--headlight);
  box-shadow: 0 0 24px 2px var(--headlight-soft), inset 0 0 18px rgba(255, 180, 84, 0.12);
  transform: scale(1.03);
}
.seat.lost { opacity: 0.45; }
.seat.joining { animation: seat-in 0.35s ease; }
@keyframes seat-in { from { opacity: 0; transform: scale(0.92); } }

.seat-name {
  font-family: var(--font-display);
  font-size: 1.2rem;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.seat-sub { font-size: 0.72rem; color: var(--dashboard); }
.seat-glyphs { display: flex; align-items: center; gap: 6px; min-height: 14px; }
.path-glyph { font-size: 0.68rem; color: var(--dashboard); letter-spacing: 0.08em; }

.q-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--dashboard-dim);
  display: inline-block;
}
.q-dot.good { background: #6fae6f; }
.q-dot.fair { background: var(--headlight); }
.q-dot.poor { background: var(--signal-poor); }

.seat .muted-glyph { color: var(--brake); font-size: 0.72rem; }

/* --------------------------------------------------------- mute button -- */

.mute-btn {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  border: 3px solid var(--headlight);
  background: rgba(255, 180, 84, 0.08);
  color: var(--headlight);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font-display);
  font-size: 1.1rem;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.mute-btn .mic-icon { width: 42px; height: 42px; }
.mic-slash { display: none; }
.mute-btn[aria-pressed="true"] {
  border-color: var(--brake);
  color: var(--brake);
  background: rgba(194, 74, 68, 0.1);
}
.mute-btn[aria-pressed="true"] .mic-slash { display: block; }

.room-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* -------------------------------------------------------------- sheets -- */

.sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
}
.sheet-panel {
  background: var(--panel);
  border: 1px solid var(--seatline);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  padding: 24px 20px max(24px, env(safe-area-inset-bottom));
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sheet-panel h2 { font-size: 1.4rem; }

input[type="range"] {
  width: 100%;
  accent-color: var(--headlight);
  min-height: 32px;
}

.device-select {
  width: 100%;
  min-height: 48px;
  background: var(--panel);
  border: 1px solid var(--seatline);
  border-radius: 12px;
  color: var(--moonlight);
  font: inherit;
  font-size: 1rem;
  padding: 10px 12px;
}
.device-select:disabled { opacity: 0.6; }

.vu-wrap {
  position: relative;
  height: 18px;
  border-radius: 9px;
  background: var(--night);
  border: 1px solid var(--seatline);
  overflow: hidden;
}
.vu-bar {
  height: 100%;
  width: 0%;
  background: var(--headlight);
  border-radius: 9px;
  transition: width 0.06s linear;
}
.vu-threshold {
  position: absolute;
  top: -2px; bottom: -2px;
  width: 2px;
  background: var(--moonlight);
  left: 30%;
}

/* --------------------------------------------------------- pocket lock -- */

.pocket {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 40px 0 60px;
  touch-action: none;
}
.pocket-status {
  display: flex;
  gap: 10px;
  align-items: center;
  opacity: 0.22;
  color: var(--dashboard);
}
.pocket-status .mic-slash { display: none; }
.pocket-status.muted .mic-slash { display: block; }
.pocket-status.muted { color: var(--brake); }

.pocket-unlock {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 1px solid rgba(138, 144, 153, 0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: rgba(138, 144, 153, 0.4);
  font-size: 0.62rem;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}
.pocket-ring {
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  background: conic-gradient(var(--headlight) calc(var(--held, 0) * 1turn), transparent 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 5px), #000 calc(100% - 4px));
}

/* -------------------------------------------------------------- toasts -- */

.toasts {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
  width: min(92vw, 400px);
}
.toast {
  background: var(--panel);
  border: 1px solid var(--seatline);
  border-radius: 14px;
  padding: 12px 16px;
  text-align: center;
  animation: toast-in 0.25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
  .seat, .mute-btn, .vu-bar { transition: none; }
  .seat.speaking { transform: none; }
  .seat.joining, .toast { animation: none; }
}
