/* ===========================================================
   VoiceRoom — Design System
   Trustworthy, calm, utilitarian. No gradients-as-decoration,
   no glow-everything. Precision over spectacle.
=========================================================== */

:root {
  /* Light mode (default) */
  --bg: #f4f5f3;
  --bg-elevated: #ffffff;
  --bg-sunken: #eaebe8;
  --border: #dcded9;
  --border-strong: #c5c8c1;
  --text: #1c1e1b;
  --text-dim: #5c605a;
  --text-faint: #8a8d86;

  --accent: #2a6f4f;       /* deep, calm green — trust, not neon */
  --accent-strong: #1f5a3f;
  --accent-soft: #e3efe8;

  --danger: #a4372e;
  --danger-soft: #f6e6e4;

  --speaking: #34a853;     /* speaking ring */
  --speaking-glow: rgba(52, 168, 83, 0.28);

  --muted-badge: #a4372e;

  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;

  --shadow-card: 0 1px 2px rgba(20, 22, 18, 0.04), 0 8px 24px rgba(20, 22, 18, 0.06);
  --shadow-pop: 0 4px 16px rgba(20, 22, 18, 0.12);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, Helvetica, Arial, sans-serif;

  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #14161a;
  --bg-elevated: #1c1f24;
  --bg-sunken: #0f1114;
  --border: #2b2f36;
  --border-strong: #3a3f47;
  --text: #eceef0;
  --text-dim: #a3a8b0;
  --text-faint: #6c7178;

  --accent: #4caf7d;
  --accent-strong: #63c493;
  --accent-soft: #16281f;

  --danger: #e2685c;
  --danger-soft: #2c1a18;

  --speaking: #4caf7d;
  --speaking-glow: rgba(76, 175, 125, 0.35);

  --muted-badge: #e2685c;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.2), 0 8px 24px rgba(0, 0, 0, 0.32);
  --shadow-pop: 0 4px 20px rgba(0, 0, 0, 0.4);

  color-scheme: dark;
}

* { box-sizing: border-box; }

*[hidden]{
	display:none !important;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

/* Smooth, consistent theme transitions across the whole app */
body, .join-card, .tile, .control-btn, .icon-btn, .field input,
.btn-primary, .room-header, .control-bar, .badge, .tile-mute-btn,
.status-dot, .quality-indicator, .reconnect-banner {
  transition:
    background-color 0.22s ease,
    border-color 0.22s ease,
    color 0.22s ease,
    box-shadow 0.22s ease,
    opacity 0.22s ease,
    transform 0.18s ease;
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input {
  font-family: inherit;
}

.screen {
  height: 100vh;
  width: 100%;
  overflow: hidden;
  position: fixed;
  top: 0;
  left: 0;
}

/* ===================== JOIN SCREEN ===================== */

.join-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 24px;
  opacity: 1;
  transition: opacity 0.22s ease;
}

.join-screen.fading-out {
  opacity: 0;
}

.join-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px 28px;
  box-shadow: var(--shadow-card);
  animation: cardIn 0.42s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.brand-mark {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.brand h1 {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.01em;
}

.tagline {
  color: var(--text-dim);
  font-size: 13.5px;
  margin: 6px 0 26px;
}

.field {
  display: block;
  margin-bottom: 16px;
}

.field span {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field input {
  width: 100%;
  padding: 11px 13px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background: var(--bg-sunken);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.field input:focus {
  border-color: var(--accent);
  background: var(--bg-elevated);
}

.field input::placeholder {
  color: var(--text-faint);
}

.btn-primary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  margin-top: 6px;
  transition: background 0.15s ease, transform 0.1s ease;
}

.btn-primary:hover { background: var(--accent-strong); transform: translateY(-1px); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.join-error {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  animation: errorIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes errorIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.mic-check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-dim);
}

.mic-check .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
  transition: background 0.2s ease;
}

.mic-check .dot.ok { background: var(--speaking); }
.mic-check .dot.err { background: var(--danger); }

.theme-toggle {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-dim);
  transition: color 0.15s ease, border-color 0.15s ease;
}
.theme-toggle:hover { color: var(--text); border-color: var(--border-strong); }

/* ===================== ROOM SCREEN ===================== */

.room-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.room-screen.visible {
  opacity: 1;
}

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.room-title {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 15px;
}

.room-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--speaking);
  box-shadow: 0 0 0 3px var(--speaking-glow);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  border: 1px solid transparent;
}

.icon-btn:hover {
  background: var(--bg-sunken);
  color: var(--text);
  border-color: var(--border);
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn.danger:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.icon-btn.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-color: transparent;
}

/* ---- reconnect banner ---- */

.reconnect-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 0;
  overflow: hidden;
  opacity: 0;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  transition: height 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.22s ease, padding 0.28s ease;
}

.reconnect-banner.visible {
  height: 40px;
  opacity: 1;
  padding: 0 16px;
}

.reconnect-spinner {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid var(--danger);
  border-top-color: transparent;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---- participants grid ---- */

.participants-grid {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  padding: 20px;
  align-content: start;
  scroll-behavior: smooth;
}

.tile {
  background: var(--bg-elevated);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  min-height: 140px;
  justify-content: center;
  animation: tileIn 0.32s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes tileIn {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.tile.speaking {
  border-color: var(--speaking);
  box-shadow: 0 0 0 4px var(--speaking-glow);
}

.tile.leaving {
  animation: tileOut 0.22s cubic-bezier(0.4, 0, 1, 1) forwards;
}

@keyframes tileOut {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.92); }
}

.tile-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  flex-shrink: 0;
  transition: transform 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.tile.speaking .tile-avatar {
  transform: scale(1.08);
}

.tile-name {
  font-size: 13.5px;
  font-weight: 600;
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-name .you-tag {
  color: var(--text-faint);
  font-weight: 500;
}

.tile-badges {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 4px;
}

.badge {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--danger-soft);
  color: var(--muted-badge);
}

.badge svg { width: 12px; height: 12px; }

.tile-controls {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}

.tile-mute-btn {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg-sunken);
  color: var(--text-dim);
  border: 1px solid var(--border);
  transition: all 0.12s ease;
}

.tile-mute-btn:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.tile-mute-btn.active {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}

/* ---- control bar ---- */

.control-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.conn-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
  min-width: 120px;
  flex-wrap: wrap;
}

.status-sep {
  color: var(--text-faint);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}

.status-dot.connected { background: var(--speaking); }
.status-dot.error {
  background: var(--danger);
  animation: pulseDanger 1.4s ease-in-out infinite;
}

@keyframes pulseDanger {
  0%, 100% { box-shadow: 0 0 0 0 rgba(164, 55, 46, 0.4); }
  50% { box-shadow: 0 0 0 5px rgba(164, 55, 46, 0); }
}

.quality-indicator {
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--bg-sunken);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.quality-indicator.quality-high {
  color: var(--speaking);
  border-color: transparent;
  background: var(--accent-soft);
}

.quality-indicator.quality-mid {
  color: #b8860b;
  border-color: transparent;
  background: rgba(184, 134, 11, 0.12);
}

.quality-indicator.quality-low {
  color: var(--danger);
  border-color: transparent;
  background: var(--danger-soft);
}

.control-buttons {
  display: flex;
  gap: 10px;
}

.control-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 24px;
  background: var(--bg-sunken);
  border: 1.5px solid var(--border);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
}

.control-btn:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.control-btn:active {
  transform: scale(0.96);
}

.control-btn.active {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}

.control-btn svg {
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.control-btn.active svg {
  transform: scale(1.1);
}

.self-name {
  font-size: 12.5px;
  color: var(--text-faint);
  font-weight: 500;
  min-width: 120px;
  text-align: right;
}

/* ===================== responsive ===================== */

@media (max-width: 560px) {
  .self-name { display: none; }
  .conn-status { min-width: unset; }
  .control-bar { justify-content: center; gap: 20px; }
}

/* scrollbar, subtle */
.participants-grid::-webkit-scrollbar { width: 8px; }
.participants-grid::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 8px;
}
.participants-grid::-webkit-scrollbar-track { background: transparent; }

/* ===================== SETTINGS PANEL ===================== */

.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.38);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.settings-overlay.visible {
  opacity: 1;
}

.settings-panel {
  width: 100%;
  max-width: 400px;
  max-height: min(600px, 84vh);
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-pop);
  padding: 22px 22px 26px;
  margin: 16px;
  transform: translateY(10px) scale(0.98);
  opacity: 0;
  transition: transform 0.24s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
}

.settings-overlay.visible .settings-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.settings-header h2 {
  font-size: 16px;
  font-weight: 700;
  margin: 0;
}

.settings-section {
  padding: 14px 0;
  border-top: 1px solid var(--border);
}

.settings-section:first-of-type {
  border-top: none;
  padding-top: 0;
}

.settings-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.settings-row .settings-label {
  margin-bottom: 0;
}

.settings-value {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  min-width: 50px;
  text-align: right;
}

.settings-hint {
  font-size: 11.5px;
  color: var(--text-faint);
  margin: 6px 0 0;
  line-height: 1.4;
}

.settings-select {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg-sunken);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235c605a' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 34px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.settings-select:focus {
  border-color: var(--accent);
}

.settings-slider {
  width: 100%;
  height: 4px;
  border-radius: 4px;
  background: var(--border);
  outline: none;
  appearance: none;
  margin: 6px 0;
  cursor: pointer;
}

.settings-slider::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.12s ease;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.settings-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.settings-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.settings-switch {
  width: 40px;
  height: 24px;
  border-radius: 14px;
  background: var(--border-strong);
  position: relative;
  flex-shrink: 0;
  transition: background 0.18s ease;
}

.settings-switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.settings-switch.active {
  background: var(--accent);
}

.settings-switch.active::after {
  transform: translateX(16px);
}
