:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --border: #e8e8e8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

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

body {
  margin: 0;
  min-height: 100vh;
}

#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 1.25rem 3rem;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0 0.75rem;
  flex-wrap: wrap;
}

.brand {
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.mode-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
}

.mode-toggle button {
  font: inherit;
  padding: 0.4rem 0.9rem;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
}

.mode-toggle button:hover {
  color: var(--text);
}

.mode-toggle button.active {
  background: var(--text);
  color: var(--surface);
}

.sticky-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  padding: 0.75rem 0 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.sticky-header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.sticky-header .quiz-desc {
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
  max-width: 65ch;
}

.admin-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-start;
}

.admin-meta label {
  font-size: 0.8rem;
  color: var(--muted);
  display: block;
  margin-bottom: 0.2rem;
}

.admin-meta input[type='text'],
.admin-meta textarea {
  font: inherit;
  width: 100%;
  max-width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.admin-meta textarea {
  min-height: 3.5rem;
  resize: vertical;
}

.field-group {
  flex: 1 1 200px;
}

.sticky-header .toolbar {
  margin-top: 0.85rem;
}

.file-sync-hint {
  margin: 0.75rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  max-width: 65ch;
  line-height: 1.45;
}

.file-sync-hint strong {
  font-weight: 600;
  color: var(--text);
}

.file-sync-hint.muted {
  opacity: 0.92;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}

.btn {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  color: var(--text);
}

.btn:hover {
  border-color: #ccc;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

thead th {
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0.65rem 0.85rem;
  background: #f6f6f6;
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover td {
  background: #fcfcfc;
}

.col-rank {
  width: 3.5rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.col-score {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  white-space: nowrap;
}

.members {
  margin: 0;
  padding-left: 1.1rem;
  color: var(--text);
}

.members li {
  margin: 0.1rem 0;
}

.points-cell {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.points-cell .score {
  min-width: 2.5rem;
}

.stepper {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.stepper button {
  width: 1.85rem;
  height: 1.85rem;
  padding: 0;
  font-size: 1.1rem;
  line-height: 1;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  color: var(--text);
}

.stepper button:hover {
  background: #f0f0f0;
}

.stepper .minus {
  color: var(--danger);
}

.stepper .plus {
  color: var(--success);
}

.delta-input {
  width: 3.25rem;
  font: inherit;
  padding: 0.25rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-align: center;
}

.member-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.member-inputs input {
  font: inherit;
  font-size: 0.88rem;
  padding: 0.3rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  width: 100%;
  max-width: 14rem;
  background: var(--surface);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
}

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

.modal input[type='password'] {
  width: 100%;
  font: inherit;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 0.75rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0 0 0.5rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 640px) {
  .members {
    font-size: 0.88rem;
  }

  thead th:nth-child(3),
  tbody td:nth-child(3) {
    min-width: 8rem;
  }
}
