:root {
  --bg: #0f0f13;
  --surface: #1a1a22;
  --border: #2e2e3a;
  --text: #e8e8f0;
  --text-muted: #9a9ab8;
  --accent: #8b85ff;
  --accent-hover: #9d98ff;
  --danger: #e05252;
  --success: #52e09a;
  --warning: #e0b852;
  --radius: 8px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color-scheme: dark;
}

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

html { scroll-behavior: smooth; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0.75rem;
  z-index: 1000;
  background: var(--accent);
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-weight: 600;
}
.skip-link:focus {
  left: 0.75rem;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
}

body.auth-centered {
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.screen {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
}
.screen.screen-app {
  align-items: flex-start;
  justify-content: center;
  padding-top: 0.5rem;
}
.screen[hidden] { display: none !important; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card-wide { max-width: 520px; }

.container {
  width: 100%;
  max-width: 960px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 0 1rem 2rem;
}

.top-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}
.top-bar .timer { margin-left: auto; font-size: 0.875rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.top-bar .danger-btn { margin-left: 0; }
.top-bar-title { margin: 0; font-size: 1.1rem; font-weight: 600; }

.logo { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.02em; color: var(--accent); }
.logo-img { display: block; width: min(160px, 55vw); height: auto; margin: 0 auto 0.25rem; }
.logo-sm { font-size: 1.125rem; font-weight: 700; color: var(--accent); }
.tagline { color: var(--text-muted); font-size: 0.9rem; line-height: 1.45; }
.greeting { color: var(--text-muted); font-size: 0.95rem; }
.status-message[data-tone="success"] { color: var(--success); }
.user-name { color: var(--text-muted); font-size: 0.875rem; }
.error { color: var(--danger); font-size: 0.875rem; }
.muted-msg { color: var(--text-muted); padding: 0.5rem 0; }
.contact-info a { color: var(--accent); }

.site-footer {
  flex-shrink: 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.55;
  padding: 0.85rem 1rem max(1rem, env(safe-area-inset-bottom));
  width: 100%;
  border-top: 1px solid var(--border);
  background: var(--bg);
}
.site-footer p { margin: 0; }
body.auth-centered .site-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  border-top: none;
  background: transparent;
  z-index: 40;
}
body.auth-centered .screen {
  padding-bottom: max(3rem, calc(2rem + env(safe-area-inset-bottom)));
}

.divider { border: none; border-top: 1px solid var(--border); margin: 0.25rem 0; }

.auth-alt {
  text-align: center;
  margin-top: 0.25rem;
}
.auth-alt[hidden] { display: none !important; }

form { display: flex; flex-direction: column; gap: 0.75rem; }
label { font-size: 0.875rem; color: var(--text-muted); }
input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  padding: 0.625rem 0.75rem;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
textarea { resize: vertical; min-height: 80px; }

button[type="submit"], button.primary-btn {
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #0f0f13;
  cursor: pointer;
  font-family: var(--font);
  font-size: 1rem;
  font-weight: 600;
  padding: 0.625rem 1.25rem;
  width: 100%;
}
button[type="submit"]:hover, button.primary-btn:hover { background: var(--accent-hover); }
button[type="submit"]:disabled, button.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

a.primary-btn {
  display: inline-block;
  text-decoration: none;
  text-align: center;
  background: var(--accent);
  border-radius: var(--radius);
  color: #0f0f13;
  font-weight: 600;
  padding: 0.6rem 1rem;
  width: auto;
}
a.primary-btn:hover { background: var(--accent-hover); color: #0f0f13; }

button.secondary-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  width: auto;
}
button.secondary-btn:hover { border-color: var(--accent); color: var(--accent); }

.btn-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  align-items: center;
}
.btn-row .primary-btn { width: auto; flex: 1 1 auto; min-width: 7rem; }

.danger-btn {
  background: transparent;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
}
.danger-btn:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

.link-btn, .btn-link {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.875rem;
  text-decoration: underline;
  padding: 0.25rem;
}

/* Lobby tiles */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}
.tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  padding: 1rem 1.1rem;
  width: 100%;
}
.tile:hover { border-color: var(--accent); }
.tile-name { font-weight: 600; font-size: 1rem; }
.tile-meta { color: var(--text-muted); font-size: 0.8rem; word-break: break-all; }
.tile-role { color: var(--accent); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

/* Dashboard nav */
.category-nav {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.dash-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  margin-left: auto;
}
.cat-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.875rem;
  padding: 0.375rem 0.875rem;
}
.cat-btn:hover { border-color: var(--accent); }
.cat-btn.active { background: var(--accent); border-color: var(--accent); color: #0f0f13; }
.action-toolbar-btn {
  border-radius: var(--radius);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 0.4rem 0.75rem;
}
.action-toolbar-btn:hover { border-color: var(--accent); color: var(--accent); }

.record-list { display: flex; flex-direction: column; gap: 0.5rem; }
.record-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  min-width: 0;
}
.record-row > div:first-child { min-width: 0; flex: 1; }
.record-row-name, .record-label {
  font-weight: 600;
  overflow-wrap: anywhere;
}
.record-row-meta { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.2rem; }
.record-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.action-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.35rem 0.625rem;
}
.action-btn:hover { color: var(--text); border-color: var(--accent); }

.value-box { background: var(--bg); border: 1px solid var(--accent); border-radius: var(--radius); padding: 1rem; }
.value-box.mono-sm { font-size: 0.8rem; white-space: pre-wrap; }
.value-content { font-family: monospace; font-size: 0.95rem; word-break: break-all; }
.timer-inline { color: var(--warning); font-size: 0.875rem; }

.corroboration-info, .requester-info {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
}

.ceremony-participants {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}
.ceremony-host-console {
  grid-column: 1 / -1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}
.ceremony-participant {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
}
.ceremony-participant.authorized { border-color: var(--success); }
.ceremony-participant-photo {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  margin-bottom: 0.5rem;
}
.ceremony-participant-name { font-weight: 600; font-size: 0.9rem; }
.ceremony-participant-role { color: var(--text-muted); font-size: 0.8rem; }
.ceremony-status { margin-top: 0.5rem; font-size: 0.8rem; font-weight: 600; }
.ceremony-export-ready {
  grid-column: 1 / -1;
  text-align: center;
  margin-top: 1rem;
  color: var(--success);
  font-weight: 600;
}

.update-note { color: var(--text-muted); font-size: 0.875rem; }
.update-field-row { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.corroborate-actions { display: flex; gap: 0.75rem; }
.corroborate-actions .primary-btn,
.corroborate-actions button[type="submit"] { width: auto; flex: 1; }

/* Dialog / toast */
.ui-toast-host {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(360px, calc(100vw - 2rem));
  pointer-events: none;
}
.ui-toast {
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.4;
}
.ui-toast.is-error { border-color: var(--danger); }
.ui-toast.is-success { border-color: var(--success); }

.ui-dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2100;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.ui-dialog-backdrop[hidden] { display: none !important; }
.ui-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.ui-dialog h2 { font-size: 1.1rem; margin: 0; }
.ui-dialog-actions { display: flex; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap; }
.ui-dialog-actions .primary-btn,
.ui-dialog-actions .secondary-btn,
.ui-dialog-actions .danger-btn { width: auto; }

/* Install ceremony extras */
.install-wrap {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1rem 3rem;
}
.install-hero {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}
.install-hero .logo-img { margin-bottom: 0.25rem; }
.install-hero-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.install-hero-lead {
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.6;
  max-width: 34rem;
}
.install-hero-steps {
  list-style: none;
  display: grid;
  gap: 0.5rem;
  text-align: left;
  width: 100%;
  margin: 0.5rem 0 0;
  padding: 1rem 1.25rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.install-hero-steps li {
  color: var(--text-muted);
  font-size: 0.875rem;
  line-height: 1.45;
  padding-left: 1.25rem;
  position: relative;
}
.install-hero-steps li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}
.install-hero-steps strong { color: var(--text); font-weight: 600; }
.install-hero-note {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
  border-left: 3px solid var(--warning);
  padding-left: 0.75rem;
  text-align: left;
  width: 100%;
}
.install-attendance {
  width: 100%;
  text-align: left;
  margin-top: 0.25rem;
}
.install-attendance-heading {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.75rem;
}
.install-attendance-group { margin-bottom: 1rem; }
.install-attendance-group-title {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-bottom: 0.5rem;
}
.install-attendance-list { list-style: none; display: grid; gap: 0.75rem; }
.install-attendance-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
}
.install-attendance-item h3 {
  font-size: 0.925rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.2rem;
}
.install-attendance-presence {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 0.45rem;
}
.install-attendance-item ul {
  list-style: disc;
  margin: 0;
  padding-left: 1.1rem;
  color: var(--text-muted);
  font-size: 0.825rem;
  line-height: 1.45;
}
.install-attendance-item li + li { margin-top: 0.2rem; }
.install-cta {
  width: 100%;
  font-size: 1.05rem;
  padding: 0.875rem 1.5rem;
  margin-top: 0.5rem;
}
.install-progress {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.install-progress-bar {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.install-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.install-progress-fill.pct-0 { width: 0%; }
.install-progress-fill.pct-5 { width: 5%; }
.install-progress-fill.pct-8 { width: 8%; }
.install-progress-fill.pct-10 { width: 10%; }
.install-progress-fill.pct-15 { width: 15%; }
.install-progress-fill.pct-17 { width: 17%; }
.install-progress-fill.pct-20 { width: 20%; }
.install-progress-fill.pct-25 { width: 25%; }
.install-progress-fill.pct-30 { width: 30%; }
.install-progress-fill.pct-33 { width: 33%; }
.install-progress-fill.pct-35 { width: 35%; }
.install-progress-fill.pct-40 { width: 40%; }
.install-progress-fill.pct-42 { width: 42%; }
.install-progress-fill.pct-45 { width: 45%; }
.install-progress-fill.pct-50 { width: 50%; }
.install-progress-fill.pct-55 { width: 55%; }
.install-progress-fill.pct-58 { width: 58%; }
.install-progress-fill.pct-60 { width: 60%; }
.install-progress-fill.pct-65 { width: 65%; }
.install-progress-fill.pct-67 { width: 67%; }
.install-progress-fill.pct-70 { width: 70%; }
.install-progress-fill.pct-75 { width: 75%; }
.install-progress-fill.pct-80 { width: 80%; }
.install-progress-fill.pct-83 { width: 83%; }
.install-progress-fill.pct-85 { width: 85%; }
.install-progress-fill.pct-90 { width: 90%; }
.install-progress-fill.pct-92 { width: 92%; }
.install-progress-fill.pct-95 { width: 95%; }
.install-progress-fill.pct-100 { width: 100%; }

.install-step-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
  margin-top: 1rem;
}
.install-step-panel[hidden] { display: none !important; }
.install-step-panel h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}
.install-step-panel p { margin-bottom: 0.75rem; line-height: 1.5; }
.install-step-panel .primary-btn { margin-top: 0.5rem; }
.install-step-panel form .primary-btn { margin-top: 0.25rem; }
#install-progress-wrap[hidden] { display: none !important; }

pre.secret {
  word-break: break-all;
  font-size: 0.8rem;
  background: var(--bg);
  padding: 0.75rem;
  border-radius: 6px;
}
.custodian-row { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }

.install-video-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.install-video-banner[hidden] { display: none !important; }
.install-video-when { display: block; font-size: 0.9rem; color: var(--text-muted); margin-top: 0.15rem; }
#install-daily-frame-wrap { margin-bottom: 1rem; }
#install-daily-frame {
  width: 100%;
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.install-gate {
  text-align: center;
  max-width: 28rem;
  margin: 4rem auto;
  padding: 1.5rem;
}
.provision-wrap { text-align: center; max-width: 28rem; margin: 2rem auto; }
.provision-wrap img { margin: 1rem 0; border-radius: 8px; }

.custodian-main {
  max-width: 32rem;
  margin: 2rem auto;
  padding: 0 1rem 2rem;
}
.custodian-main textarea {
  width: 100%;
  min-height: 6rem;
  font-family: monospace;
}

@media (max-width: 900px) {
  .ceremony-participants { grid-template-columns: repeat(2, 1fr); }
  .dash-actions { margin-left: 0; width: 100%; }
}

@media (max-width: 640px) {
  .ceremony-participants { grid-template-columns: 1fr; }
  .card { padding: 1.5rem 1.25rem; }
  .logo-img { width: min(120px, 50vw); }
  .top-bar .timer { margin-left: 0; width: 100%; }
}
