:root {
  color-scheme: light dark;

  --bg: light-dark(#FAF8F4, #15091D);
  --bg-wash: light-dark(#F4EFE6, #1B0C25);
  --surface: light-dark(#FFFFFF, #21102D);
  --surface-soft: light-dark(#F3EFE7, #2B173A);
  --text: light-dark(#1C1523, #FCF7F0);
  --text-secondary: light-dark(#4E4559, #DECFE8);
  --text-muted: light-dark(#746A80, #B09BC0);
  --border: light-dark(#E5D9CB, #3F2852);
  --accent: light-dark(#39134C, #F6A47E);
  --accent-hover: light-dark(#2A0D39, #F9B89A);
  --accent-contrast: light-dark(#FCF7F0, #230A30);
  --bubble-self: light-dark(#39134C, #562B6E);
  --bubble-self-text: #FCF7F0;
  --terracotta: light-dark(#B85038, #F6A47E);
  --terracotta-bg: light-dark(rgba(184, 80, 56, 0.08), rgba(246, 164, 126, 0.12));
  --green: light-dark(#1F6B4E, #6ED3A5);

  --font-display: 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;

  --radius-card: 16px;
  --radius-pill: 999px;
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) {
  color-scheme: dark;
}

:root:has(> head > meta[name="color-scheme"][content="light"]) {
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

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

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Brand logotype light/dark switching without JS classes */
.logo-dark {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .logo-light {
    display: none;
  }
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .logo-dark {
    display: block;
  }
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) .logo-light {
  display: none;
}

:root:has(> head > meta[name="color-scheme"][content="dark"]) .logo-dark {
  display: block;
}

.app-shell {
  min-height: 100dvh;
  background: linear-gradient(180deg, var(--bg-wash) 0%, var(--bg) 220px);
}

.center-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.atelier-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 28px 24px;
  box-shadow: 0 12px 32px -12px rgba(28, 21, 35, 0.14);
}

.center-card {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  margin-bottom: 18px;
}

.editorial-heading {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 1.15rem + 0.8vw, 1.65rem);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.25;
}

.subtitle {
  margin: 0 0 22px;
  color: var(--text-secondary);
  font-size: 0.94rem;
  line-height: 1.5;
}

.field-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.mono-input {
  width: 100%;
  padding: 13px 14px;
  font-family: var(--font-mono);
  font-size: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  margin-bottom: 14px;
}

.mono-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.inline-error {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--terracotta-bg);
  border: 1px solid var(--terracotta);
  color: var(--terracotta);
  font-size: 0.86rem;
  line-height: 1.4;
}

.trust-note {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
}

/* Buttons */
button {
  font-family: inherit;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 0.94rem;
  font-weight: 600;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

.btn-outline {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 0.84rem;
  font-weight: 600;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: none;
  padding: 8px 10px;
  font-size: 0.84rem;
  font-weight: 600;
}

.btn-danger {
  background: var(--terracotta-bg);
  color: var(--terracotta);
  border: 1px solid var(--terracotta);
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 0.9rem;
  font-weight: 600;
}

.btn-full {
  width: 100%;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 0.82rem;
  border-radius: 9px;
}

.icon-btn {
  position: relative;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
}

.status-dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

/* Active Room Layout */
.room-layout {
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.room-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

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

.header-logo {
  flex-shrink: 0;
  height: 24px;
  width: auto;
}

.header-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.header-destination {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.connection-pill {
  font-size: 0.72rem;
  color: var(--green);
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.alerts-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
}

.alerts-banner-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.83rem;
  color: var(--text-secondary);
  flex: 1 1 220px;
}

.alerts-banner-copy strong {
  color: var(--text);
}

.alerts-banner-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.message-stream {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.delivery-receipt {
  align-self: center;
  max-width: 92%;
  text-align: center;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.pending-banner {
  padding: 10px 14px;
  border-radius: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.84rem;
  line-height: 1.45;
}

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

.msg-item {
  display: flex;
  flex-direction: column;
  max-width: 86%;
}

.msg-self {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-handler {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-sender {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 4px 4px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.verified-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  font-size: 0.68rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  color: var(--green);
}

.msg-bubble {
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-self .msg-bubble {
  background: var(--bubble-self);
  color: var(--bubble-self-text);
  border-bottom-right-radius: 5px;
}

.msg-handler .msg-bubble {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 5px;
}

.msg-time {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  margin: 4px 4px 0;
}

/* Composer */
.composer-area {
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.moderation-card {
  margin-bottom: 10px;
  padding: 11px 13px;
  border-radius: 12px;
  background: var(--terracotta-bg);
  border: 1px solid var(--terracotta);
}

.moderation-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--terracotta);
  margin-bottom: 4px;
}

.moderation-reason,
.moderation-suggestion {
  margin: 0;
  font-size: 0.84rem;
  color: var(--text);
  line-height: 1.4;
}

.moderation-suggestion {
  margin-top: 4px;
  color: var(--text-secondary);
}

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

.composer-input {
  width: 100%;
  min-height: 44px;
  max-height: 160px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.45;
  resize: none;
}

.composer-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.char-counter {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-muted);
}

.btn-send {
  padding: 9px 18px;
  border-radius: 10px;
}

/* Dialogs */
.atelier-dialog {
  width: min(420px, calc(100vw - 24px));
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.35);
}

.atelier-dialog::backdrop {
  background: rgba(21, 9, 29, 0.55);
  backdrop-filter: blur(2px);
}

.dialog-inner {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dialog-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
}

.dialog-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-label {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.theme-group {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.theme-btn {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
}

.theme-btn[aria-checked="true"] {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setting-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.setting-desc {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
}

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

.ios-steps {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
  line-height: 1.45;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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

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