:root {
  --primary: #129648;
  --primary-hover: #0d7a3a;
  --primary-light: #e6f4ec;
  --primary-text: #129648;
  --danger: #d93025;
  --danger-hover: #b3261e;
  --success: #1e8e3e;
  --warning: #f9ab00;
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #202124;
  --text-secondary: #5f6368;
  --border: #dadce0;
  --border-hover: #bdc1c6;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 8px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
  --max-width: 768px;
}

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

body {
  font-family: 'Roboto', 'Segoe UI', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 16px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

h1 {
  font-size: 28px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 8px;
}

h2 {
  font-size: 20px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 12px;
}

h3 {
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 8px;
}

p {
  margin-bottom: 12px;
  color: var(--text);
}

.text-secondary {
  color: var(--text-secondary);
}

label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.field-label {
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

[data-theme="dark"] label {
  color: var(--text);
}

input[type="text"],
input[type="password"],
input[type="email"],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.2s;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  border-width: 2px;
  padding: 9px 11px;
}

textarea {
  resize: vertical;
  min-height: 80px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow);
}

.btn-secondary {
  background: var(--surface);
  color: var(--primary-text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

.auth-toggle-btn {
  padding: 4px 14px;
  border-radius: 4px;
  font-size: 13px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--primary-text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

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

.auth-toggle-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

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

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: var(--danger-hover);
  box-shadow: var(--shadow);
}

.btn-danger-text {
  background: var(--surface);
  color: var(--danger);
  border: 1px solid var(--border);
}

.btn-danger-text:hover {
  background: var(--danger-light, #fce8e6);
  border-color: var(--danger);
}

.btn-sm {
  padding: 6px 16px;
  font-size: 13px;
}

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

.btn-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.notice {
  background: var(--primary-light);
  border: 1px solid #a3d9b8;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 14px;
  color: var(--text);
}

.notice-warning {
  background: #fef7e0;
  border-color: #f9ab00;
}

.notice-danger {
  background: #fce8e6;
  border-color: #d93025;
}

.notice-success {
  background: #e6f4ea;
  border-color: #1e8e3e;
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}

.badge-open {
  background: #e6f4ea;
  color: #1e8e3e;
}

.badge-closed {
  background: #fce8e6;
  color: #d93025;
}

.badge-single {
  background: #e8f0fe;
  color: #1a73e8;
}

.badge-multiple {
  background: #fce8e6;
  color: #d93025;
}

.badge-yesno {
  background: #f3e8fd;
  color: #9334e6;
}

.badge-ranked {
  background: #fef7e0;
  color: #f29900;
}

.badge-text {
  background: #e6f4ea;
  color: #1e8e3e;
}

.badge-required {
  background: #fce8e6;
  color: #d93025;
}

.badge-optional {
  background: #e6f4ea;
  color: #188038;
}

.error-text {
  color: var(--danger);
  font-size: 14px;
}

.hidden {
  display: none !important;
}

/* Collapsible sections */
details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}

details > summary {
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  background: var(--bg);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

details > summary::before {
  content: '\25B6';
  font-size: 12px;
  transition: transform 0.2s;
}

details[open] > summary::before {
  transform: rotate(90deg);
}

details > summary::-webkit-details-marker {
  display: none;
}

details > .details-content {
  padding: 16px;
}

.details-content h5 {
  font-size: 12px;
  font-weight: 500;
  margin: 12px 0 4px;
  color: var(--text);
}

/* Loading indicator */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
}

.loading::after {
  content: '';
  display: block;
  width: 32px;
  height: 32px;
  margin: 12px auto;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Links */
a {
  color: var(--primary-text);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* Utility */
.mt-0 { margin-top: 0; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.w-full { width: 100%; }

/* Dark theme: auto via prefers-color-scheme, or manual via data-theme="dark" */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #129648;
    --primary-hover: #0d7a3a;
    --primary-light: #1a2e22;
    --primary-text: #8CC642;
    --danger: #f28b82;
    --danger-hover: #f6a9a4;
    --danger-light: #3d2422;
    --success: #81c995;
    --warning: #fdd663;
    --bg: #1a1a1a;
    --surface: #2d2d2d;
    --text: #e8eaed;
    --text-secondary: #9aa0a6;
    --border: #3c4043;
    --border-hover: #5f6368;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-lg: 0 4px 8px rgba(0,0,0,0.4), 0 2px 4px rgba(0,0,0,0.3);
  }
}

[data-theme="dark"] {
  --primary: #129648;
  --primary-hover: #0d7a3a;
  --primary-light: #1a2e22;
  --primary-text: #8CC642;
  --danger: #f28b82;
  --danger-hover: #f6a9a4;
  --danger-light: #3d2422;
  --success: #81c995;
  --warning: #fdd663;
  --bg: #1a1a1a;
  --surface: #2d2d2d;
  --text: #e8eaed;
  --text-secondary: #9aa0a6;
  --border: #3c4043;
  --border-hover: #5f6368;
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-lg: 0 4px 8px rgba(0,0,0,0.4), 0 2px 4px rgba(0,0,0,0.3);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .notice {
    border-color: #3c4043;
  }
  :root:not([data-theme="light"]) .notice-warning {
    background: #3d3520;
    border-color: #5d5028;
  }
  :root:not([data-theme="light"]) .notice-danger {
    background: #3d2422;
    border-color: #5d2e2a;
  }
  :root:not([data-theme="light"]) .notice-success {
    background: #1d3225;
    border-color: #2a4d36;
  }
  :root:not([data-theme="light"]) .badge-open {
    background: #1d3225;
    color: #81c995;
  }
  :root:not([data-theme="light"]) .badge-closed {
    background: #3d2422;
    color: #f28b82;
  }
  :root:not([data-theme="light"]) .badge-single {
    background: #1a2332;
    color: #8ab4f8;
  }
  :root:not([data-theme="light"]) .badge-multiple {
    background: #3d2422;
    color: #f28b82;
  }
  :root:not([data-theme="light"]) .badge-yesno {
    background: #2d1a3d;
    color: #d7a3f6;
  }
  :root:not([data-theme="light"]) .badge-ranked {
    background: #3d3520;
    color: #fdd663;
  }
  :root:not([data-theme="light"]) .badge-text {
    background: #1a2e1a;
    color: #81c995;
  }
  :root:not([data-theme="light"]) .badge-required {
    background: #3d2422;
    color: #f28b82;
  }
  :root:not([data-theme="light"]) .badge-optional {
    background: #1a2e1f;
    color: #81c995;
  }
  :root:not([data-theme="light"]) .ranking-position.gold {
    background: #5d4e00;
    color: #ffd700;
  }
  :root:not([data-theme="light"]) .ranking-position.silver {
    background: #4a4a4a;
    color: #c0c0c0;
  }
  :root:not([data-theme="light"]) .ranking-position.bronze {
    background: #5d3a1a;
    color: #cd7f32;
  }
  :root:not([data-theme="light"]) .ranking-position.normal {
    background: #3c4043;
    color: #9aa0a6;
  }
  :root:not([data-theme="light"]) .pairwise-matrix td.win {
    background: #1d3225;
    color: #81c995;
  }
  :root:not([data-theme="light"]) .pairwise-matrix td.lose {
    background: #3d2422;
    color: #f28b82;
  }
  :root:not([data-theme="light"]) .pairwise-matrix td.tie {
    background: #3d3520;
    color: #fdd663;
  }
  :root:not([data-theme="light"]) .pairwise-matrix td.diagonal {
    background: #3c4043;
  }
  :root:not([data-theme="light"]) .graph-node {
    fill: #1a2e22;
    stroke: #129648;
  }
  :root:not([data-theme="light"]) .graph-node-label {
    fill: #e8eaed;
  }
  :root:not([data-theme="light"]) .graph-edge {
    stroke: #129648;
  }
  :root:not([data-theme="light"]) .graph-arrowhead {
    fill: #129648;
  }
  :root:not([data-theme="light"]) .graph-edge-label {
    fill: #9aa0a6;
  }
  :root:not([data-theme="light"]) .tally-bar {
    background: var(--primary);
  }
  :root:not([data-theme="light"]) .tally-row.winner .tally-bar {
    background: var(--success);
  }
  :root:not([data-theme="light"]) .radio-choice:hover {
    background: var(--primary-light);
  }
  :root:not([data-theme="light"]) .radio-choice.selected {
    background: var(--primary-light);
    border-color: var(--primary);
  }
  :root:not([data-theme="light"]) .ranked-item {
    background: var(--surface);
    border-color: var(--border);
  }
}

[data-theme="dark"] .notice {
  border-color: #3c4043;
}
[data-theme="dark"] .notice-warning {
  background: #3d3520;
  border-color: #5d5028;
}
[data-theme="dark"] .notice-danger {
  background: #3d2422;
  border-color: #5d2e2a;
}
[data-theme="dark"] .notice-success {
  background: #1d3225;
  border-color: #2a4d36;
}
[data-theme="dark"] .badge-open {
  background: #1d3225;
  color: #81c995;
}
[data-theme="dark"] .badge-closed {
  background: #3d2422;
  color: #f28b82;
}
[data-theme="dark"] .badge-single {
  background: #1a2332;
  color: #8ab4f8;
}
[data-theme="dark"] .badge-multiple {
  background: #3d2422;
  color: #f28b82;
}
[data-theme="dark"] .badge-yesno {
  background: #2d1a3d;
  color: #d7a3f6;
}
[data-theme="dark"] .badge-ranked {
  background: #3d3520;
  color: #fdd663;
}
[data-theme="dark"] .badge-text {
  background: #1a2e1a;
  color: #81c995;
}
[data-theme="dark"] .badge-required {
  background: #3d2422;
  color: #f28b82;
}
[data-theme="dark"] .badge-optional {
  background: #1a2e1f;
  color: #81c995;
}
[data-theme="dark"] .ranking-position.gold {
  background: #5d4e00;
  color: #ffd700;
}
[data-theme="dark"] .ranking-position.silver {
  background: #4a4a4a;
  color: #c0c0c0;
}
[data-theme="dark"] .ranking-position.bronze {
  background: #5d3a1a;
  color: #cd7f32;
}
[data-theme="dark"] .ranking-position.normal {
  background: #3c4043;
  color: #9aa0a6;
}
[data-theme="dark"] .pairwise-matrix td.win {
  background: #1d3225;
  color: #81c995;
}
[data-theme="dark"] .pairwise-matrix td.lose {
  background: #3d2422;
  color: #f28b82;
}
[data-theme="dark"] .pairwise-matrix td.tie {
  background: #3d3520;
  color: #fdd663;
}
[data-theme="dark"] .pairwise-matrix td.diagonal {
  background: #3c4043;
}
[data-theme="dark"] .graph-node {
  fill: #1a2e22;
  stroke: #129648;
}
[data-theme="dark"] .graph-node-label {
  fill: #e8eaed;
}
[data-theme="dark"] .graph-edge {
  stroke: #129648;
}
[data-theme="dark"] .graph-arrowhead {
  fill: #129648;
}
[data-theme="dark"] .graph-edge-label {
  fill: #9aa0a6;
}
[data-theme="dark"] .tally-bar {
  background: var(--primary);
}
[data-theme="dark"] .tally-row.winner .tally-bar {
  background: var(--success);
}
[data-theme="dark"] .radio-choice:hover {
  background: var(--primary-light);
}
[data-theme="dark"] .radio-choice.selected {
  background: var(--primary-light);
  border-color: var(--primary);
}
[data-theme="dark"] .ranked-item {
  background: var(--surface);
  border-color: var(--border);
}

/* Theme toggle button */
.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, box-shadow 0.2s;
  padding: 0;
}

.theme-toggle:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
}

/* Home button */
.home-btn {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 1000;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, box-shadow 0.2s;
  text-decoration: none;
}

.home-btn:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
}

.site-logo {
  position: fixed;
  bottom: 16px;
  left: 16px;
  z-index: 9000;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, box-shadow 0.2s, opacity 0.2s;
  opacity: 0.7;
}

.site-logo:hover {
  opacity: 1;
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
}

.site-logo img {
  width: 32px;
  height: 32px;
  display: block;
}

.site-version {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 9000;
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.6;
  user-select: none;
}
