:root {
  --bg: #f4f0e8;
  --paper: rgba(255, 252, 247, 0.9);
  --paper-strong: #fffaf3;
  --ink: #1f2a2e;
  --muted: #687277;
  --line: rgba(31, 42, 46, 0.12);
  --accent: #0d6a6e;
  --accent-2: #b6592f;
  --ok: #24623d;
  --warn: #9d5c00;
  --danger: #8b2e25;
  --shadow: 0 18px 48px rgba(53, 44, 35, 0.12);
  --radius: 20px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(182, 89, 47, 0.18), transparent 26rem),
    radial-gradient(circle at top right, rgba(13, 106, 110, 0.18), transparent 24rem),
    linear-gradient(180deg, #efe6d6 0%, var(--bg) 36%, #eee9dd 100%);
  font-family: "Avenir Next", "Trebuchet MS", "Segoe UI", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

.shell {
  width: min(1180px, calc(100vw - 2rem));
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0 1rem;
}

.brand-link {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  font-size: 1.2rem;
  font-weight: 700;
}

.page-links {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.page-link {
  padding: 0.55rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.45);
  color: var(--muted);
  font-weight: 600;
}

.page-link.current {
  color: white;
  background: var(--accent);
  border-color: transparent;
}

.hero {
  padding: 2rem 1rem 1.5rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent-2);
  font-size: 0.78rem;
  font-weight: 700;
}

h1,
h2,
h3,
h4 {
  font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  margin: 0;
}

h1 {
  font-size: clamp(2.2rem, 4vw, 4rem);
  line-height: 0.98;
  max-width: 16ch;
}

.hero-subtitle {
  margin: 0.55rem 0 0;
  color: var(--accent);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

h2 {
  font-size: 1.4rem;
}

h3 {
  font-size: 1.05rem;
}

h4 {
  font-size: 0.98rem;
}

.lede {
  max-width: 68ch;
  margin: 0.9rem 0 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 1.02rem;
}

.lede.compact {
  font-size: 0.98rem;
}

.panel {
  margin-top: 1rem;
  padding: 1.15rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

.status-panel {
  background: rgba(27, 35, 38, 0.92);
  color: #f2efe8;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.compact-header {
  margin-bottom: 0.75rem;
}

.grid {
  display: grid;
  gap: 1rem;
}

.grid.two,
.picker-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three,
.summary-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.four,
.summary-grid,
.summary-grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.card {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper-strong);
}

.surface-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.surface-card {
  display: block;
  padding: 1.3rem;
  border-radius: 20px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.85), rgba(247, 241, 231, 0.92)),
    radial-gradient(circle at top right, rgba(13, 106, 110, 0.12), transparent 16rem);
  box-shadow: var(--shadow);
  transition: transform 120ms ease, border-color 120ms ease;
}

.surface-card:hover {
  transform: translateY(-2px);
  border-color: rgba(13, 106, 110, 0.28);
}

.surface-link {
  display: inline-flex;
  margin-top: 1rem;
  color: var(--accent);
  font-weight: 700;
}

.notice-card {
  margin-top: 1rem;
  background:
    linear-gradient(180deg, rgba(13, 106, 110, 0.08), rgba(13, 106, 110, 0.02)),
    linear-gradient(120deg, rgba(182, 89, 47, 0.06), transparent 55%);
}

.notice-card h3 {
  margin-top: 0.15rem;
}

.subtle-button {
  padding: 0.58rem 0.85rem;
  background: rgba(31, 42, 46, 0.08);
  color: var(--muted);
}

.subtle-button:hover {
  background: rgba(31, 42, 46, 0.14);
}

.form-card {
  display: grid;
  gap: 0.85rem;
  align-content: start;
}

.picker-panel {
  display: grid;
  gap: 0.8rem;
  align-content: start;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.96rem;
}

label span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  padding: 0.8rem 0.9rem;
  border: 1px solid rgba(31, 42, 46, 0.18);
  border-radius: 14px;
  background: #fffdf9;
  color: var(--ink);
}

textarea {
  min-height: 7rem;
  resize: vertical;
}

.snapshot {
  min-height: 16rem;
}

.actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.9rem;
}

.actions.wrap {
  flex-wrap: wrap;
}

.actions.compact {
  margin-top: 0;
  gap: 0.4rem;
}

.admin-access,
.advanced-tools,
.trace-details {
  border: 1px dashed var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.38);
}

.admin-access {
  margin-top: 1rem;
}

.admin-access summary,
.advanced-tools summary,
.trace-details summary {
  cursor: pointer;
  padding: 0.95rem 1rem;
  color: var(--muted);
  font-weight: 700;
}

.admin-access-body,
.advanced-body {
  padding: 0 1rem 1rem;
}

.advanced-section + .advanced-section {
  margin-top: 1rem;
}

.button {
  padding: 0.8rem 1rem;
  border: 0;
  border-radius: 999px;
  background: rgba(13, 106, 110, 0.12);
  color: var(--ink);
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

.button:hover {
  transform: translateY(-1px);
  background: rgba(13, 106, 110, 0.18);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

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

.button.primary:hover {
  background: #0b5a5d;
}

.button.danger {
  background: rgba(139, 46, 37, 0.13);
  color: var(--danger);
}

.button.danger-inline {
  background: rgba(139, 46, 37, 0.13);
  color: var(--danger);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: rgba(13, 106, 110, 0.12);
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 700;
}

.badge-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge.muted {
  background: rgba(31, 42, 46, 0.08);
  color: var(--muted);
}

.badge.ok {
  background: rgba(36, 98, 61, 0.12);
  color: var(--ok);
}

.badge.warn {
  background: rgba(157, 92, 0, 0.12);
  color: var(--warn);
}

.hint,
.empty,
.muted-text,
.ranking-note {
  color: var(--muted);
  line-height: 1.45;
}

.summary-box {
  padding: 1rem;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(13, 106, 110, 0.08), rgba(13, 106, 110, 0.02));
  border: 1px solid rgba(13, 106, 110, 0.14);
}

.summary-box strong {
  display: block;
  font-size: 1.3rem;
  margin-top: 0.2rem;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 0.7rem 0.55rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.table th {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ranking-card {
  padding: 0.9rem 0 1.1rem;
  border-bottom: 1px solid var(--line);
}

.ranking-card:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.ranking-meta {
  margin: 0.25rem 0 0.6rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.role-builder {
  display: grid;
  gap: 0.9rem;
}

.split-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
}

.choice-list {
  display: grid;
  gap: 0.7rem;
}

.choice-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(248, 244, 236, 0.88));
}

.choice-main {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-width: 0;
}

.choice-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  background: rgba(13, 106, 110, 0.14);
  color: var(--accent);
  font-weight: 800;
  flex-shrink: 0;
}

#status-log {
  margin: 0;
  white-space: pre-wrap;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.9rem;
}

@media (max-width: 980px) {
  .grid.two,
  .grid.three,
  .grid.four,
  .summary-grid,
  .picker-grid,
  .surface-grid {
    grid-template-columns: 1fr;
  }

  .shell {
    width: min(100vw - 1rem, 1180px);
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .actions {
    flex-wrap: wrap;
  }

  .split-header,
  .choice-item {
    flex-direction: column;
    align-items: stretch;
  }

  .panel-header-actions,
  .badge-row {
    justify-content: flex-start;
  }
}
