/* === Custom Properties === */
:root {
  --bg: #1a1a1a;
  --surface: #242424;
  --surface-hover: #2c2c2c;
  --border: #333;
  --border-light: #3a3a3a;
  --primary: #C49A6C;
  --primary-hover: #d4aa7c;
  --primary-dim: rgba(196, 154, 108, 0.12);
  --secondary: #7EBDC2;
  --text: #e2ddd5;
  --text-muted: #8a8480;
  --text-dim: #666;
  --radius: 6px;
  --font: system-ui, -apple-system, sans-serif;
  --transition: 150ms ease;
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* === Focus === */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* === Typography === */
h1 { font-size: 1.25rem; font-weight: 600; }
h2 { font-size: 1.125rem; font-weight: 600; }
h3 { font-size: 0.9375rem; font-weight: 600; color: var(--text-muted); }
p { color: var(--text-muted); }
a { color: var(--secondary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* === Header === */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.header-tagline {
  font-size: 0.875rem;
  color: var(--text-dim);
}

/* === Layout === */
.app-layout {
  display: flex;
  flex: 1;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  padding: 24px;
  gap: 24px;
}

main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

main > * {
  width: 100%;
  max-width: 640px;
}

/* === Intro === */
.intro {
  margin-bottom: 24px;
  text-align: center;
}

.intro h2 {
  font-size: 1.375rem;
  margin-bottom: 8px;
  color: var(--text);
}

.intro > p {
  font-size: 0.9375rem;
  line-height: 1.6;
  margin-bottom: 12px;
}

.disclaimer {
  font-size: 0.8125rem;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  background: var(--surface);
  text-align: left;
}

.disclaimer strong {
  color: var(--primary);
}

/* === Progress bar === */
.progress-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: 24px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 300ms ease;
}

/* === Decision path === */
.decision-path {
  margin-bottom: 20px;
}

.decision-path h3 {
  margin-bottom: 8px;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.path-list {
  list-style: none;
  padding: 0 0 0 12px;
  border-left: 2px solid var(--border);
}

.path-node {
  position: relative;
  padding: 6px 0 6px 16px;
}

.path-node::before {
  content: '';
  position: absolute;
  left: -7px;
  top: 14px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
  border: 2px solid var(--bg);
}

.path-node:last-child::after {
  content: '';
  position: absolute;
  left: -2px;
  top: 26px;
  bottom: 0;
  width: 2px;
  background: var(--bg);
}

.path-q {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-dim);
  line-height: 1.3;
}

.path-a {
  display: block;
  font-size: 0.875rem;
  color: var(--primary);
  font-weight: 500;
}

.path-skipped {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.6875rem;
  color: var(--text-dim);
  margin-top: 4px;
  opacity: 0.6;
}

.path-skipped-dots {
  display: flex;
  gap: 3px;
}

.path-skipped-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  border: 1px dashed var(--text-dim);
  opacity: 0.5;
}

/* === Question card === */
.question-card {
  min-height: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

.question-text {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
}

.question-number {
  font-size: 0.8125rem;
  color: var(--text-dim);
  margin-bottom: 4px;
}

/* === Options === */
.options-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.option-btn {
  font-family: var(--font);
  font-size: 0.875rem;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform 100ms ease;
  min-height: 44px;
}

.option-btn:hover {
  border-color: var(--border-light);
  background: var(--surface-hover);
}

.option-btn:active {
  transform: scale(0.97);
}

.option-btn[aria-pressed="true"],
.option-btn.selected {
  border-color: var(--primary);
  background: var(--primary-dim);
  color: var(--primary);
}

/* === Scale === */
.scale-grid {
  display: flex;
  gap: 8px;
  align-items: center;
}

.scale-label {
  font-size: 0.8125rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.scale-btn {
  font-family: var(--font);
  font-size: 0.875rem;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), transform 100ms ease;
}

.scale-btn:hover {
  border-color: var(--border-light);
  background: var(--surface-hover);
}

.scale-btn:active {
  transform: scale(0.95);
}

.scale-btn[aria-pressed="true"],
.scale-btn.selected {
  border-color: var(--primary);
  background: var(--primary-dim);
  color: var(--primary);
}

/* === Navigation === */
.quiz-nav {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  justify-content: center;
}

/* === Buttons === */
.btn {
  font-family: var(--font);
  font-size: 0.875rem;
  padding: 8px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  border: 1px solid transparent;
  min-height: 44px;
}

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

.btn-primary {
  background: var(--primary);
  color: #1a1a1a;
  border-color: var(--primary);
  font-weight: 500;
}

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

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--border-light);
  color: var(--text);
}

/* === Sidebar === */
.sidebar {
  width: 260px;
  flex-shrink: 0;
  position: sticky;
  top: 24px;
  align-self: flex-start;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.sidebar h2 {
  margin-bottom: 4px;
}

.sidebar-hint {
  font-size: 0.8125rem;
  margin-bottom: 12px;
}

.sidebar-list {
  list-style: none;
  padding: 0;
}

.sidebar-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.875rem;
  transition: color var(--transition);
}

.sidebar-item:last-child {
  border-bottom: none;
}

.sidebar-item:hover .sidebar-item-name {
  color: var(--primary);
}

.sidebar-item-name {
  color: var(--text);
  transition: color var(--transition);
}

.sidebar-item-score {
  color: var(--text-dim);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.sidebar-item-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.sidebar-camra {
  color: var(--text-dim);
  font-size: 0.75rem;
  text-decoration: none;
  margin-right: 8px;
  transition: color var(--transition);
}

.sidebar-camra:hover {
  color: var(--secondary);
}

/* === Results === */
.results {
  text-align: center;
}

.results h2 {
  margin-bottom: 4px;
}

.results > p {
  margin-bottom: 16px;
}

.results-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  text-align: left;
}

.result-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.result-card:first-child {
  border-color: var(--primary);
  background: var(--primary-dim);
}

.result-card:hover {
  border-color: var(--border-light);
  background: var(--surface-hover);
}

.result-card:first-child:hover {
  border-color: var(--primary-hover);
}

.result-rank {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--primary);
  width: 28px;
  flex-shrink: 0;
  text-align: center;
}

.result-info {
  flex: 1;
  min-width: 0;
}

.result-name {
  font-weight: 500;
  font-size: 1rem;
}

.result-tags {
  font-size: 0.8125rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.result-score {
  font-size: 0.875rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
  font-weight: 500;
}

.results-hint {
  font-size: 0.8125rem;
  color: var(--text-dim);
  margin-bottom: 16px;
}

/* === CAMRA links === */
.camra-link {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--secondary);
  text-decoration: none;
  margin-top: 4px;
  transition: color var(--transition);
}

.camra-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* === Dialog === */
.pub-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  max-width: 440px;
  width: 90%;
  margin: auto;
  position: fixed;
  inset: 0;
  height: fit-content;
}

.pub-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.dialog-inner {
  padding: 24px;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.dialog-header h2 {
  font-size: 1.125rem;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-close:hover {
  color: var(--text);
}

.dialog-body p {
  margin-bottom: 12px;
  line-height: 1.6;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.tag {
  font-size: 0.75rem;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
}

.dialog-link {
  display: inline-block;
  text-decoration: none;
}

/* === Footer === */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  text-align: center;
}

.site-footer p {
  font-size: 0.8125rem;
}

.footer-disclaimer {
  margin-top: 4px;
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* === Utilities === */
.hidden {
  display: none !important;
}

.loading-msg {
  font-size: 0.875rem;
  text-align: center;
  color: var(--text-dim);
}

/* === Reduced motion === */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
  }
}

/* === Responsive === */
@media (max-width: 768px) {
  .app-layout {
    flex-direction: column;
    padding: 16px;
  }

  .sidebar {
    width: 100%;
    position: static;
    max-height: none;
    order: 2;
  }

  main {
    order: 1;
  }

  main > * {
    max-width: none;
  }

  .header-inner {
    flex-direction: column;
    gap: 2px;
  }

  .site-header {
    padding: 12px 16px;
  }

  .scale-grid {
    flex-wrap: wrap;
  }

  .intro h2 {
    font-size: 1.125rem;
  }
}