/* ===== ОСНОВА ===== */
:root {
  --bg: #0a0908;
  --surface: #161310;
  --surface-2: #1f1b17;
  --surface-3: #2a2520;
  --border: #2a2520;
  --border-subtle: #1a1714;
  --text: #f3ede3;
  --text-muted: #8a8276;
  --text-dim: #5a5449;
  --accent: #d4805c;
  --accent-hover: #e09372;
  --accent-glow: rgba(212, 128, 92, 0.15);
  --speaking: #6db474;
  --danger: #c75545;
  --serif: 'Instrument Serif', Georgia, serif;
  --sans: 'Manrope', -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

button { font-family: inherit; font-size: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input { font-family: inherit; color: inherit; }
.hidden { display: none !important; }

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0.04;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ===== ЛОББИ ===== */
.lobby {
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 800px 500px at 30% 20%, rgba(212, 128, 92, 0.07), transparent),
    radial-gradient(ellipse 600px 400px at 80% 80%, rgba(212, 128, 92, 0.04), transparent),
    var(--bg);
  padding: 24px;
}

.lobby-card { width: 100%; max-width: 440px; animation: fadeInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1); }

@keyframes fadeInUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

.brand { text-align: center; margin-bottom: 40px; }

.brand-mark {
  display: inline-flex;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  margin-bottom: 12px;
}

.brand-title {
  font-family: var(--serif);
  font-size: 64px;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1;
  font-style: italic;
  color: var(--text);
}

.brand-sub {
  margin-top: 8px;
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}

.form { display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 8px; }

.field label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.field input[type="text"] {
  height: 44px;
  padding: 0 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

.field input[type="text"]::placeholder { color: var(--text-dim); }
.field input[type="text"]:focus { border-color: var(--accent); background: var(--surface-2); }

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
}

.tab {
  flex: 1;
  height: 36px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: 7px;
  transition: all 0.2s;
}

.tab:hover { color: var(--text); }
.tab.active { background: var(--surface-3); color: var(--text); }

.generated-code-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 4px 4px 16px;
  height: 44px;
}

.generated-code {
  flex: 1;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--accent);
}

.generated-code.placeholder {
  color: var(--text-dim);
  letter-spacing: 0;
  font-family: var(--sans);
  font-size: 13px;
}

.regen-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border-radius: 7px;
  color: var(--text-muted);
  transition: all 0.2s;
}

.regen-btn:hover { color: var(--accent); background: var(--surface-3); }

.hint { font-size: 12px; color: var(--text-dim); line-height: 1.4; margin-top: -2px; }

.primary-btn {
  margin-top: 8px;
  height: 48px;
  background: var(--accent);
  color: #1a1108;
  font-weight: 600;
  font-size: 15px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s;
}

.primary-btn:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 8px 24px var(--accent-glow); }
.primary-btn:active { transform: translateY(0); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.primary-btn svg { transition: transform 0.2s; }
.primary-btn:hover svg { transform: translateX(2px); }

.error-msg { min-height: 18px; font-size: 13px; color: var(--danger); text-align: center; margin-top: -4px; }

.recent-rooms { margin-top: 8px; border-top: 1px solid var(--border-subtle); padding-top: 16px; }

.recent-rooms summary {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.recent-rooms summary::-webkit-details-marker { display: none; }
.recent-rooms summary::after { content: '+'; float: right; font-size: 14px; }
.recent-rooms[open] summary::after { content: '−'; }

.recent-rooms ul { list-style: none; margin-top: 10px; display: flex; flex-direction: column; gap: 4px; }

.recent-rooms li {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text-muted);
}

.recent-rooms li:hover { background: var(--surface); color: var(--text); }

.lobby-footer {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* ===== КОМНАТА ===== */
.room { background: var(--bg); }

.room-header {
  height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.room-info { display: flex; align-items: center; gap: 12px; }

.room-label { font-size: 10px; letter-spacing: 0.15em; color: var(--text-dim); font-weight: 600; }
.room-code { font-family: var(--mono); font-size: 14px; font-weight: 500; color: var(--accent); letter-spacing: 0.1em; }

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface);
  border-radius: 6px;
  transition: all 0.2s;
}

.copy-btn:hover { color: var(--text); background: var(--surface-2); }
.copy-btn.copied { color: var(--speaking); }

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

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); transition: background 0.3s; }
.status.connecting .status-dot { background: var(--accent); animation: pulse 1.5s infinite; }
.status.connected .status-dot { background: var(--speaking); }
.status.error .status-dot { background: var(--danger); }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.status-text { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-muted); }

.participants-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 40px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.participants {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  max-width: 1200px;
  width: 100%;
}

.participant {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 24px 20px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  position: relative;
  transition: border-color 0.3s, box-shadow 0.3s;
  animation: fadeInUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.participant.speaking {
  border-color: var(--speaking);
  box-shadow: 0 0 0 1px var(--speaking), 0 0 30px rgba(109, 180, 116, 0.15);
}

.participant.muted .avatar { opacity: 0.5; }

.avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--serif);
  font-size: 28px;
  font-style: italic;
  color: var(--bg);
  background: var(--accent);
  transition: all 0.3s;
  position: relative;
}

.participant.speaking .avatar { background: var(--speaking); }

.participant.speaking .avatar::after {
  content: '';
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 2px solid var(--speaking);
  animation: ring 1.2s ease-out infinite;
}

@keyframes ring { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(1.25); opacity: 0; } }

.participant-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  text-align: center;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.participant-name.you::after { content: ' (ты)'; color: var(--text-dim); font-weight: 400; }

.mute-indicator {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--danger);
  color: var(--text);
  display: none;
  align-items: center;
  justify-content: center;
}

.participant.muted .mute-indicator { display: flex; }

/* Слайдер громкости на карточке участника */
.participant-volume {
  width: 100%;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.participant-volume.local { visibility: hidden; }

.participant-volume input[type="range"] { flex: 1; }

.participant-volume .vol-value {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--mono);
  min-width: 32px;
  text-align: right;
}

.participant-volume .vol-icon {
  color: var(--text-dim);
  display: flex;
}

.empty-state { text-align: center; color: var(--text-dim); padding: 60px 20px; grid-column: 1 / -1; }
.empty-state h3 { font-family: var(--serif); font-size: 28px; font-weight: 400; font-style: italic; color: var(--text-muted); margin-bottom: 8px; }
.empty-state p { font-size: 14px; }

/* ===== КОНТРОЛЫ ===== */
.controls {
  border-top: 1px solid var(--border-subtle);
  background: var(--surface);
  padding: 20px 24px;
  flex-shrink: 0;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 900px;
  margin: 0 auto;
}

.control-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 72px;
  height: 64px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  transition: all 0.2s;
  flex-shrink: 0;
}

.control-btn:hover { background: var(--surface-3); border-color: var(--accent); }

.control-btn .btn-label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.mic-btn.muted {
  background: rgba(199, 85, 69, 0.15);
  border-color: var(--danger);
  color: var(--danger);
}
.mic-btn.muted .btn-label { color: var(--danger); }

.leave-btn:hover { background: rgba(199, 85, 69, 0.15); border-color: var(--danger); color: var(--danger); }
.leave-btn:hover .btn-label { color: var(--danger); }

/* Полоска уровня микрофона между кнопками */
.mic-meter {
  flex: 1;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
  min-width: 60px;
}

.mic-meter-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--speaking) 0%, var(--accent) 70%, var(--danger) 100%);
  border-radius: 3px;
  transition: width 0.05s linear;
}

/* Ползунки общие */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: var(--surface-3);
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
  transition: transform 0.15s;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--accent);
  border-radius: 50%;
  border: none;
  cursor: pointer;
  transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); }
input[type="range"]::-moz-range-thumb:hover { transform: scale(1.2); }

/* Меньший слайдер в карточке участника */
.participant-volume input[type="range"] { height: 3px; }
.participant-volume input[type="range"]::-webkit-slider-thumb { width: 12px; height: 12px; }
.participant-volume input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; }

/* Селекты для выбора устройств */
.select-wrap {
  position: relative;
  width: 100%;
}

.select-wrap::after {
  content: '';
  position: absolute;
  right: 14px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 1.5px solid var(--text-muted);
  border-bottom: 1.5px solid var(--text-muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 100%;
  height: 40px;
  padding: 0 36px 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
  text-overflow: ellipsis;
}

select:hover { border-color: var(--accent); }
select:focus { border-color: var(--accent); }
select option { background: var(--surface-2); color: var(--text); }

/* ===== ПАНЕЛЬ НАСТРОЕК ===== */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 50;
  opacity: 0;
  animation: fadeIn 0.2s forwards;
}

.settings-overlay.hidden { display: none; }

@keyframes fadeIn { to { opacity: 1; } }

.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 100vw;
  background: var(--surface);
  border-left: 1px solid var(--border-subtle);
  z-index: 60;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  animation: slideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.settings-panel.hidden { display: none; }

@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
}

.settings-header h2 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 28px;
  color: var(--text);
}

.settings-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text-muted);
  transition: all 0.15s;
}

.settings-close:hover { background: var(--surface-2); color: var(--text); }

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.setting-row { display: flex; flex-direction: column; gap: 8px; }

.setting-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.setting-head label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.setting-value {
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
  font-family: var(--mono);
}

.setting-hint { font-size: 12px; color: var(--text-dim); line-height: 1.4; }

.setting-marks {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  margin-top: 2px;
}

.setting-divider { height: 1px; background: var(--border-subtle); }

/* Кнопка горячей клавиши */
.hotkey-btn {
  padding: 6px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
  transition: all 0.15s;
}

.hotkey-btn:hover { border-color: var(--accent); background: var(--surface-3); }
.hotkey-btn.recording { border-color: var(--accent); background: var(--accent-glow); color: var(--accent-hover); animation: pulse 1s infinite; }

/* Переключатель (switch) */
.toggle-row {
  flex-direction: row !important;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.toggle-text { flex: 1; }
.toggle-text label { display: block; font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 4px; }

.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }

.switch-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--surface-3);
  border-radius: 24px;
  transition: 0.2s;
}

.switch-slider::before {
  content: '';
  position: absolute;
  height: 18px;
  width: 18px;
  left: 3px;
  top: 3px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(20px); background: var(--bg); }

/* ===== ЧАТ ===== */
.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 360px;
  max-width: 100vw;
  background: var(--surface);
  border-left: 1px solid var(--border-subtle);
  z-index: 40;
  display: flex;
  flex-direction: column;
  animation: slideIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-panel.hidden { display: none; }

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.chat-header h2 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 28px;
  color: var(--text);
}

.chat-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  color: var(--text-muted);
  transition: all 0.15s;
}

.chat-close:hover { background: var(--surface-2); color: var(--text); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-empty {
  margin: auto;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 24px;
}

.chat-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: fadeInUp 0.2s ease-out;
}

.chat-msg.own { align-items: flex-end; }

.chat-msg-meta {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 11px;
}

.chat-msg-author {
  font-weight: 600;
  color: var(--accent);
}

.chat-msg.own .chat-msg-author { color: var(--speaking); }

.chat-msg-time {
  color: var(--text-dim);
  font-family: var(--mono);
}

.chat-msg-body {
  background: var(--surface-2);
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.4;
  max-width: 85%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.chat-msg.own .chat-msg-body {
  background: var(--surface-3);
  border-radius: 10px 10px 2px 10px;
}

.chat-msg-system {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: 0.05em;
  padding: 4px 0;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  height: 40px;
  padding: 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

#chat-input::placeholder { color: var(--text-dim); }
#chat-input:focus { border-color: var(--accent); }

.chat-send {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #1a1108;
  border-radius: 10px;
  transition: all 0.15s;
  flex-shrink: 0;
}

.chat-send:hover { background: var(--accent-hover); }
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* Точка-уведомление о новом сообщении на кнопке "чат" */
.unread-dot {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  display: none;
  box-shadow: 0 0 0 2px var(--surface);
  animation: pulse 1.5s infinite;
}

.unread-dot.visible { display: block; }

.chat-btn { position: relative; }

/* ===== АДАПТИВ ===== */
@media (max-width: 600px) {
  .brand-title { font-size: 52px; }
  .control-row { gap: 8px; flex-wrap: wrap; }
  .mic-meter { order: 5; flex: 1 0 100%; }
  .participants-wrap { padding: 24px 16px; }
  .room-header { padding: 0 16px; }
  .controls { padding: 16px; }
  .settings-panel { width: 100vw; border-left: none; }
  .chat-panel { width: 100vw; border-left: none; }
}
