:root {
  color-scheme: light;
  /* Used by verification script */
  --panel-bg: rgba(15, 23, 42, 0.7);
  --background: #ffffff;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --surface-muted: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --divider: #e5e7eb;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eff6ff;
  --success-bg: #ecfdf3;
  --success-text: #047857;
  --warning-bg: #fef3c7;
  --warning-text: #b45309;
  --danger-bg: #fee2e2;
  --danger-text: #b91c1c;
  font-family: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
}

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

body {
  margin: 0;
  background: var(--background);
  color: var(--text-primary);
  font-family: var(--font-family, 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif);
  line-height: 1.55;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font: inherit;
  font-weight: 600;
  padding: 0.55rem 1.15rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
  background: transparent;
  color: var(--text-primary);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.primary-button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.2);
}

.primary-button:hover {
  background: var(--accent-strong);
}

.secondary-button {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--accent);
}

.secondary-button:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.text-button {
  border: none;
  padding: 0;
  background: none;
  color: var(--accent);
}

.text-button:hover {
  text-decoration: underline;
}

.app-shell {
  max-width: 1220px;
  margin: 0 auto;
  padding: 36px 40px 48px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 24px;
}

.page-title h1 {
  margin: 0;
  font-size: 1.9rem;
  font-weight: 700;
}

.page-title p {
  margin: 0.35rem 0 0;
  color: var(--text-secondary);
  font-size: 1.05rem;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.layout {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr) 280px;
  gap: 24px;
  align-items: flex-start;
}

.sidebar,
.info-rail {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel,
.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px 22px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.panel h2,
.info-card h2,
.info-card h3 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--text-primary);
}

.intro-panel h2 {
  font-size: 1.15rem;
}

.intro-panel p,
.panel-caption {
  margin: 0.65rem 0 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.55;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 0.85rem;
}

.room-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.room-list-empty {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.room-card {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  text-align: left;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.room-card:hover {
  border-color: var(--accent);
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
  transform: translateY(-1px);
}

.room-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.room-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.room-card-text h3 {
  margin: 0;
  font-size: 1rem;
}

.room-card-text p {
  margin: 0.35rem 0 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.45;
}

.room-card-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.room-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  font-size: 0.78rem;
}

.pin-toggle {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: none;
  color: var(--text-muted);
  font-size: 1.1rem;
}

.pin-toggle:hover,
.pin-toggle.active {
  color: var(--accent);
}

.room-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.new-room-panel.open {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.18);
}

.new-room {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

input[type='text'],
input[type='password'],
textarea,
select {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  padding: 0.65rem 0.75rem;
  font: inherit;
  color: var(--text-primary);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

textarea {
  resize: vertical;
  min-height: 90px;
  line-height: 1.5;
}

.api-menu {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-bottom: 1.1rem;
}

.api-menu button {
  text-align: left;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  background: var(--surface-subtle);
  border: 1px solid transparent;
  color: var(--text-secondary);
}

.api-menu button:hover {
  border-color: var(--border-strong);
  color: var(--accent);
}

.api-menu button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.2);
}

.api-details {
  border-radius: 14px;
  border: 1px dashed var(--border);
  padding: 1rem 1.1rem;
  background: var(--surface-subtle);
}

.api-card h3 {
  margin: 0 0 0.55rem;
  font-size: 1rem;
}

.api-card p {
  margin: 0 0 0.75rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.api-card ul {
  margin: 0 0 0.75rem;
  padding-left: 1.15rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.45;
}

.api-card li strong {
  color: var(--accent);
}

.api-card pre {
  margin: 0;
  background: #0f172a;
  color: #f8fafc;
  border-radius: 12px;
  padding: 0.75rem;
  font-size: 0.85rem;
  overflow-x: auto;
}

.chat-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.1);
}

.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.chat-header-text {
  flex: 1 1 auto;
  min-width: 0;
}

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

.chat-header-actions[hidden] {
  display: none;
}

.chat-header-actions button {
  white-space: nowrap;
}

.chat-header h2 {
  margin: 0;
  font-size: 1.4rem;
}

.chat-subtitle {
  margin: 0.4rem 0 0;
  color: var(--text-secondary);
  font-size: 0.96rem;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-radius: 12px;
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
  background: var(--surface-subtle);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.status-bar .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.18);
}

.status-bar[data-tone='connected'] {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: rgba(4, 120, 87, 0.25);
}

.status-bar[data-tone='assistant'] {
  background: var(--warning-bg);
  color: var(--warning-text);
  border-color: rgba(194, 65, 12, 0.25);
}

.status-bar[data-tone='error'] {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-color: rgba(185, 28, 28, 0.25);
}

.status-bar[data-tone='pending'] {
  background: var(--accent-soft);
  color: var(--accent);
}

.alert {
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
  font-size: 0.88rem;
  font-weight: 500;
  border: 1px solid rgba(185, 28, 28, 0.25);
  background: var(--danger-bg);
  color: var(--danger-text);
}

.alert[data-tone='info'] {
  border-color: rgba(37, 99, 235, 0.25);
  background: var(--accent-soft);
  color: var(--accent);
}

.alert[data-tone='success'] {
  border-color: rgba(4, 120, 87, 0.25);
  background: var(--success-bg);
  color: var(--success-text);
}

.chat-body {
  min-height: 320px;
}

.message-feed {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 280px;
  max-height: 58vh;
  overflow-y: auto;
}

.message {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  background: var(--surface-subtle);
}

.message.self {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.message.assistant {
  border-color: rgba(4, 120, 87, 0.35);
  background: var(--success-bg);
}

.message .meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.message .meta strong {
  color: var(--text-primary);
}

.message .body {
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--text-primary);
  white-space: pre-wrap;
}

.empty-state {
  border: 1px dashed var(--border-strong);
  border-radius: 14px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--surface);
}

.empty-state-canvas {
  background: var(--surface-subtle);
  border: 1px solid var(--divider);
  border-radius: 12px;
  padding: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-state-input {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 0.85rem 1rem;
  background: var(--surface);
  color: var(--text-muted);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.08);
}

.empty-state-copy h3 {
  margin: 0;
  font-size: 1.12rem;
}

.empty-state-copy p {
  margin: 0.6rem 0 0;
  color: var(--text-secondary);
}

.empty-state-copy h4 {
  margin: 0.8rem 0 0.45rem;
  font-size: 0.95rem;
}

.empty-state-copy ul {
  margin: 0 0 0.65rem;
  padding-left: 1.2rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.45;
}

.empty-state-note {
  margin: 0;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--accent);
}

.composer {
  border-top: 1px solid var(--divider);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.composer textarea {
  min-height: 120px;
}

.composer textarea::placeholder {
  color: var(--text-muted);
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.toggle-assistant {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.toggle-assistant input[type='checkbox'] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.composer-actions-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.model-select {
  width: auto;
  min-width: 160px;
}

.info-rail {
  gap: 18px;
}

.info-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.room-guide h3 {
  margin: 0;
  font-size: 1.05rem;
}

.room-guide-description,
.room-guide p {
  margin: 0.55rem 0 0;
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.55;
}

.room-guide ul {
  margin: 0.6rem 0 0;
  padding-left: 1.2rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.45;
}

.room-guide-note {
  margin: 0.7rem 0 0;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.85rem;
}

.participant-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.participant-count {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.participant-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.participant {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 0.85rem;
}

.participant-empty {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.leaderboard-body {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.6rem 0.75rem;
  background: var(--surface-subtle);
}

.leaderboard-row:hover {
  border-color: var(--accent);
}

.leaderboard-rank {
  font-weight: 700;
  color: var(--accent);
  width: 2.4rem;
  text-align: center;
}

.leaderboard-meta {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.leaderboard-meta strong {
  font-size: 0.95rem;
  color: var(--text-primary);
}

.leaderboard-meta span {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.leaderboard-empty,
.leaderboard-loading,
.leaderboard-error {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.leaderboard-error {
  color: var(--danger-text);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  padding: 24px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
  z-index: 20;
}

.modal-backdrop.visible {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border-radius: 20px;
  padding: 28px 32px;
  max-width: 460px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.15);
}

.modal h2 {
  margin: 0;
  font-size: 1.35rem;
}

.modal p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.modal .actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.modal .secondary {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--accent);
  padding: 0.55rem 1rem;
  border-radius: 10px;
}

.modal .secondary:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.modal .confirm {
  background: var(--accent);
  color: #fff;
  padding: 0.55rem 1.25rem;
  border-radius: 10px;
  border: 1px solid var(--accent);
  font-weight: 600;
}

.modal .status-bar {
  border: none;
  background: none;
  color: var(--text-secondary);
  padding: 0;
  box-shadow: none;
}

.modal .status-bar .dot {
  box-shadow: none;
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: 250px minmax(0, 1fr);
  }

  .info-rail {
    grid-column: 1 / -1;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .info-card {
    flex: 1 1 260px;
  }
}

@media (max-width: 960px) {
  .app-shell {
    padding: 30px 24px 40px;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .chat-panel {
    order: 1;
  }

  .sidebar {
    order: 2;
  }

  .info-rail {
    order: 3;
    flex-direction: column;
  }
}

@media (max-width: 640px) {
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .page-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .chat-header {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-header-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .chat-header-actions button {
    width: 100%;
  }

  .modal {
    padding: 24px 22px;
  }

  button,
  .primary-button,
  .secondary-button {
    width: auto;
  }
}
