:root {
  --bg-base: #090e1a;
  --bg-surface: rgba(17, 25, 42, 0.92);
  --bg-surface-strong: #131c31;
  --bg-elevated: rgba(24, 35, 58, 0.9);
  --border-subtle: rgba(212, 168, 83, 0.22);
  --border-strong: rgba(212, 168, 83, 0.45);
  --gold: #d4a853;
  --gold-bright: #f2cf84;
  --gold-soft: rgba(212, 168, 83, 0.14);
  --emerald: #10b981;
  --emerald-bright: #34d399;
  --emerald-soft: rgba(16, 185, 129, 0.15);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, 0.14);
  --info: #38bdf8;
  --info-soft: rgba(56, 189, 248, 0.13);
  --text-main: #f3f6fc;
  --text-muted: #9fb0cb;
  --text-dim: #7386a6;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 9px;
  --shadow-card: 0 18px 44px rgba(0, 0, 0, 0.42);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg-base);
  color: var(--text-main);
  font-family: "Vazirmatn", "IRANSans", "Tahoma", "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.65;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(circle at 15% 10%, rgba(212, 168, 83, 0.14), transparent 42%),
    radial-gradient(circle at 85% 20%, rgba(16, 185, 129, 0.10), transparent 38%),
    radial-gradient(circle at 50% 95%, rgba(56, 189, 248, 0.08), transparent 45%);
}

.app-shell {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 18px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-badge {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, rgba(212, 168, 83, 0.25), rgba(212, 168, 83, 0.08));
  border: 1px solid var(--border-strong);
  color: var(--gold-bright);
}

.brand-text h1 {
  margin: 0;
  font-size: clamp(1rem, 3vw, 1.25rem);
  font-weight: 800;
  color: var(--text-main);
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.pill-test {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--gold-soft);
  border: 1px solid var(--border-subtle);
  color: var(--gold-bright);
  font-size: 0.74rem;
  font-weight: 700;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.role-pill {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--gold-bright);
}

/* Main */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(12px);
}

/* Alerts */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 600;
}

.alert-error {
  background: var(--danger-soft);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fecaca;
}

.alert-info {
  background: var(--info-soft);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #bae6fd;
}

/* Role Gate */
.hero-intro {
  text-align: center;
  padding: 6px 8px 4px;
}

.hero-intro h2 {
  margin: 0 0 6px;
  font-size: clamp(1.18rem, 3.6vw, 1.55rem);
  color: var(--gold-bright);
}

.hero-intro p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.94rem;
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 8px;
}

.role-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.role-card-teacher {
  border-color: rgba(212, 168, 83, 0.35);
}

.role-card-student {
  border-color: rgba(16, 185, 129, 0.32);
}

.card-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.card-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.card-icon-gold {
  background: var(--gold-soft);
  border: 1px solid var(--border-strong);
  color: var(--gold-bright);
}

.card-icon-emerald {
  background: var(--emerald-soft);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: var(--emerald-bright);
}

.card-head h3 {
  margin: 0 0 4px;
  font-size: 1.02rem;
  font-weight: 800;
}

.card-head p {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text-muted);
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-group label {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-muted);
}

.field-group input {
  width: 100%;
  min-width: 0;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(159, 176, 203, 0.25);
  background: rgba(9, 14, 26, 0.8);
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field-group input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212, 168, 83, 0.18);
}

.input-with-action {
  display: flex;
  gap: 8px;
}

.input-with-action input {
  flex: 1;
}

.btn-icon {
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(159, 176, 203, 0.25);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.student-note {
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.22);
  color: #a7f3d0;
  font-size: 0.84rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.94rem;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
  margin-top: auto;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
}

.btn-gold {
  background: linear-gradient(135deg, #d4a853, #b5852e);
  color: #0b101b;
}

.btn-emerald {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #052016;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(159, 176, 203, 0.26);
  color: var(--text-main);
}

.btn-danger-outline {
  background: var(--danger-soft);
  border-color: rgba(239, 68, 68, 0.42);
  color: #fecaca;
}

.btn-mic {
  padding: 14px 16px;
  font-size: 0.96rem;
}

.btn-mic-on {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #041d14;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.22);
}

.btn-mic-off {
  background: rgba(212, 168, 83, 0.15);
  border-color: var(--border-strong);
  color: var(--gold-bright);
}

.btn-mic-locked {
  background: rgba(115, 134, 166, 0.14);
  border-color: rgba(115, 134, 166, 0.3);
  color: var(--text-muted);
}

/* Room View */
.room-view {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 13px 16px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-connecting {
  background: #f59e0b;
  box-shadow: 0 0 10px rgba(245, 158, 11, 0.7);
}

.dot-connected {
  background: #22c55e;
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.8);
}

.dot-disconnected {
  background: #ef4444;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.7);
}

.status-text {
  font-weight: 800;
  font-size: 0.9rem;
}

.speaker-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid rgba(159, 176, 203, 0.2);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.speaker-indicator.speaking-active {
  border-color: rgba(16, 185, 129, 0.5);
  background: var(--emerald-soft);
  color: #a7f3d0;
}

.pulse-ring {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.status-counts {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.count-pill {
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(159, 176, 203, 0.22);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-main);
}

.count-pill-gold {
  background: var(--gold-soft);
  border-color: var(--border-strong);
  color: var(--gold-bright);
}

.audio-playback-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-color: var(--border-strong);
  background: linear-gradient(135deg, rgba(212, 168, 83, 0.16), rgba(17, 25, 42, 0.94));
}

.audio-playback-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.audio-playback-text strong {
  color: var(--gold-bright);
  font-size: 0.94rem;
}

.audio-playback-text span {
  color: var(--text-muted);
  font-size: 0.84rem;
}

.room-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 16px;
  align-items: start;
}

.controls-column,
.roster-column {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.section-title h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
}

.badge-live {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--emerald-soft);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: var(--emerald-bright);
  font-size: 0.76rem;
  font-weight: 800;
}

.perm-pill {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
}

.perm-locked {
  background: rgba(115, 134, 166, 0.16);
  color: var(--text-muted);
}

.perm-granted {
  background: var(--emerald-soft);
  border: 1px solid rgba(16, 185, 129, 0.45);
  color: var(--emerald-bright);
}

.perm-banner {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(9, 14, 26, 0.65);
  border: 1px solid rgba(159, 176, 203, 0.18);
  font-size: 0.87rem;
  color: var(--text-muted);
}

.control-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.helper-hint {
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.hand-queue-card {
  border-color: var(--border-strong);
  background: linear-gradient(180deg, rgba(212, 168, 83, 0.09), var(--bg-surface));
}

.participant-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.participant-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: rgba(9, 14, 26, 0.68);
  border: 1px solid rgba(159, 176, 203, 0.16);
}

.participant-row.is-speaking {
  border-color: rgba(16, 185, 129, 0.55);
  box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.25);
}

.participant-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.participant-name-line {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  font-weight: 800;
  font-size: 0.92rem;
}

.participant-tags {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tag {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}

.tag-teacher {
  background: var(--gold-soft);
  color: var(--gold-bright);
}

.tag-student {
  background: rgba(159, 176, 203, 0.14);
  color: var(--text-muted);
}

.tag-can-speak {
  background: var(--emerald-soft);
  color: var(--emerald-bright);
}

.tag-hand {
  background: rgba(245, 158, 11, 0.2);
  color: #fde68a;
}

.tag-speaking {
  background: rgba(34, 197, 94, 0.24);
  color: #bbf7d0;
}

.participant-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.empty-roster {
  text-align: center;
  padding: 18px 10px;
  color: var(--text-dim);
  font-size: 0.88rem;
}

/* Footer */
.footer {
  text-align: center;
  padding: 10px 8px 4px;
  border-top: 1px solid rgba(159, 176, 203, 0.12);
  color: var(--text-muted);
  font-size: clamp(0.72rem, 2.5vw, 0.85rem);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 820px) {
  .role-grid,
  .room-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .app-shell {
    padding: 12px 12px 16px;
  }

  .topbar,
  .card {
    padding: 14px;
  }

  .footer {
    white-space: normal;
  }
}
