:root {
  color-scheme: dark;
  --bg: #15191c;
  --panel: #242b2f;
  --panel-2: #15191c;
  --line: #66737a;
  --line-soft: rgb(102 115 122 / 38%);
  --text: #f1e9dc;
  --muted: color-mix(in srgb, #66737a 58%, #f1e9dc);
  --accent: #1aed59;
  --accent-ink: #15191c;
  --highlight: #789184;
  --secondary: #914e54;
  --danger: #914e54;
  --success: #789184;
  --shadow: 0 16px 44px rgb(21 25 28 / 32%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.site-header {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line-soft);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 6px 18px rgb(196 122 68 / 16%);
  font-size: .78rem;
  font-weight: 850;
  letter-spacing: -.05em;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: .9rem; letter-spacing: -.015em; }
.brand small { color: var(--muted); font-size: .72rem; }
.account {
  max-width: 260px;
  padding: 7px 10px;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font-size: .74rem;
  text-align: right;
  overflow-wrap: anywhere;
}

main {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0 72px;
}

.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 36px;
  margin-bottom: 28px;
}

.eyebrow, .step {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: .68rem;
  font-weight: 750;
  letter-spacing: .11em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 12px; font-size: clamp(2.5rem, 6vw, 4.4rem); line-height: .98; letter-spacing: -.055em; max-width: 680px; }
h2 { margin-bottom: 8px; font-size: clamp(1.3rem, 3vw, 1.75rem); letter-spacing: -.03em; }
.intro { max-width: 610px; margin-bottom: 0; color: var(--muted); font-size: 1rem; line-height: 1.55; }

.deadline-card {
  min-width: 225px;
  padding: 13px 15px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: var(--panel);
}

.deadline-card strong, .deadline-card span { display: block; }
.deadline-card span { margin-bottom: 2px; color: var(--muted); font-size: .72rem; }
.deadline-card strong { font-size: .88rem; font-weight: 700; }
.deadline-card.closed { border-color: rgb(145 78 84 / 85%); }

.panel {
  border: 1px solid var(--line-soft);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.loading, .error-panel { padding: 40px; text-align: center; }
.error-panel h1 { max-width: none; font-size: 2rem; letter-spacing: -.035em; }
.spinner { width: 18px; height: 18px; display: inline-block; margin-right: 10px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.tabs { width: fit-content; display: flex; gap: 3px; margin: 0 0 16px; padding: 4px; border: 1px solid var(--line-soft); border-radius: 11px; background: var(--panel); }
.tab { padding: 7px 13px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; font-size: .82rem; font-weight: 650; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent); color: var(--accent-ink); box-shadow: 0 4px 12px rgb(196 122 68 / 14%); }

.ballot-panel, .results-panel, .published-results-panel, .published-ballots-panel { padding: clamp(22px, 3.5vw, 36px); }
.published-results-panel { margin-bottom: 16px; }
.section-copy { max-width: 680px; margin-bottom: 0; color: var(--muted); line-height: 1.5; }
.final-order { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.result-placement {
  min-width: 0;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--panel-2);
}
.result-spot { color: var(--accent); font-size: 1.35rem; font-weight: 850; text-align: center; }
.result-placement strong, .result-placement small { display: block; overflow-wrap: anywhere; }
.result-placement strong { margin-bottom: 3px; }
.result-placement small { color: var(--muted); font-size: .72rem; line-height: 1.35; }
.tie-notice { margin-top: 14px; padding: 14px 16px; border: 1px solid var(--secondary); border-radius: 10px; background: rgb(145 78 84 / 14%); }
.tie-notice strong { color: var(--text); }
.tie-notice p { margin: 5px 0 0; color: var(--muted); line-height: 1.5; }
.published-ballots { display: grid; gap: 8px; }
.published-ballot { border: 1px solid var(--line-soft); border-radius: 10px; background: var(--panel-2); overflow: clip; }
.published-ballot[open] { border-color: var(--line); }
.published-ballot summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 16px; cursor: pointer; }
.published-ballot summary::marker { color: var(--accent); }
.published-ballot summary span { color: var(--muted); font-size: .76rem; }
.published-ranking { display: grid; gap: 0; margin: 0; padding: 0 16px 14px; list-style: none; }
.published-ranking li { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 10px; padding: 9px 0; border-top: 1px solid var(--line-soft); }
.published-rank { color: var(--accent); font-size: .78rem; font-weight: 800; text-align: center; }
.published-ranking strong { font-size: .88rem; }
.published-ranking p { margin: 4px 0 0; color: var(--muted); font-size: .8rem; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.form-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.save-state { padding: 6px 10px; border: 1px solid var(--line-soft); border-radius: 999px; background: var(--panel-2); color: var(--muted); font-size: .72rem; white-space: nowrap; }
.save-state::before { content: ""; width: 6px; height: 6px; display: inline-block; margin-right: 6px; border-radius: 50%; background: var(--accent); vertical-align: 1px; }

.field { display: grid; gap: 7px; }
.field > span { font-weight: 680; font-size: .82rem; }
.field small { color: var(--muted); }
.name-field { width: min(100%, 430px); margin: 0 auto 30px; }

input, textarea {
  width: 100%;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  outline: 0;
  background: var(--panel-2);
  color: var(--text);
  transition: border-color .15s, background-color .15s, box-shadow .15s;
}

input { height: 44px; padding: 0 12px; }
textarea { min-height: 64px; padding: 10px 11px; resize: vertical; line-height: 1.4; }
input:hover, textarea:hover { border-color: var(--line); }
input:focus, textarea:focus { border-color: var(--highlight); box-shadow: 0 0 0 3px rgb(120 145 132 / 24%); }

.ranking-header { margin-bottom: 12px; }
.ranking-header p:last-child { margin-bottom: 0; color: var(--muted); }
.ranking-list { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; counter-reset: ranking; }
.ranking-row {
  counter-increment: ranking;
  display: grid;
  grid-template-columns: 48px minmax(150px, .7fr) minmax(240px, 1.5fr) auto;
  gap: 12px;
  align-items: center;
  padding: 11px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: var(--panel-2);
  transition: border-color .15s, background-color .15s, box-shadow .15s;
}
.ranking-row:hover { border-color: var(--line); }
.ranking-row::before { content: counter(ranking); width: 36px; height: 36px; display: grid; place-items: center; border: 0; background: transparent; color: var(--accent); font-size: .82rem; font-weight: 800; }
.ranking-row.is-dragging {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  border-color: var(--highlight);
  box-shadow: 0 18px 44px rgb(21 25 28 / 65%);
  transform: scale(1.01);
  opacity: .98;
}
.drag-placeholder {
  min-height: 24px;
  border: 2px dashed var(--secondary);
  border-radius: 10px;
  background: rgb(196 122 68 / 18%);
  box-shadow: inset 0 0 0 2px rgb(120 145 132 / 18%);
}
.choice-name { font-size: .9rem; font-weight: 720; overflow-wrap: anywhere; }
.explanation-wrap span { display: block; margin-bottom: 5px; color: var(--muted); font-size: .72rem; }
.drag-handle { width: 36px; height: 36px; padding: 0; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--muted); cursor: grab; touch-action: none; user-select: none; font-size: 1.15rem; line-height: 1; }
.drag-handle:hover:not(:disabled), .drag-handle:focus-visible { border-color: var(--line-soft); background: var(--panel); color: var(--accent); outline: none; }
.drag-handle:active { cursor: grabbing; }
.drag-handle:disabled { opacity: .25; cursor: default; }
body.reordering { cursor: grabbing; user-select: none; }

.form-actions { display: flex; align-items: center; gap: 18px; margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line-soft); }
.form-actions p { margin: 0; color: var(--muted); font-size: .84rem; }
.button { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; padding: 0 16px; border: 1px solid var(--line-soft); border-radius: 8px; text-decoration: none; cursor: pointer; font-size: .84rem; font-weight: 720; transition: transform .15s, border-color .15s, background-color .15s, filter .15s; }
.button.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.button.ghost { background: transparent; color: var(--text); }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button.primary:hover:not(:disabled) { filter: brightness(1.08); }
.button.ghost:hover:not(:disabled) { border-color: var(--line); background: var(--panel-2); }
.button:disabled { opacity: .45; cursor: not-allowed; }
.message { margin-top: 18px; padding: 12px 14px; border-radius: 10px; background: rgb(120 145 132 / 15%); color: var(--success); }
.message.error { background: rgb(145 78 84 / 17%); color: var(--danger); }

.admin-grid { display: grid; grid-template-columns: .8fr 1.2fr; gap: 16px; margin-bottom: 16px; }
.admin-card { padding: clamp(20px, 3vw, 28px); }
.admin-card > p:not(.step) { color: var(--muted); line-height: 1.5; }
.inline-actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }
.admin-card .inline-actions { margin-top: 14px; }
.choice-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0; }
.choice-input-row { display: grid; grid-template-columns: 28px 1fr; align-items: center; gap: 7px; }
.choice-input-row span { color: var(--accent); font-size: .82rem; font-weight: 900; text-align: center; }
.results { display: grid; gap: 8px; }
.submitter-row {
  display: grid;
  grid-template-columns: minmax(140px, .7fr) minmax(180px, 1.3fr);
  gap: 18px;
  align-items: center;
  padding: 13px 16px;
  border: 1px solid var(--line-soft);
  border-radius: 9px;
  background: var(--panel-2);
}
.submitter-row strong { overflow-wrap: anywhere; }
.submitter-row span { color: var(--muted); overflow-wrap: anywhere; }
.empty { padding: 28px; border: 1px dashed var(--line-soft); border-radius: 10px; color: var(--muted); text-align: center; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

footer { padding: 28px 16px 40px; color: var(--muted); font-size: .78rem; text-align: center; }
.hidden { display: none !important; }

@media (max-width: 800px) {
  .hero, .admin-grid { grid-template-columns: 1fr; }
  .deadline-card { min-width: 0; }
  .ranking-row { grid-template-columns: 42px 1fr auto; }
  .explanation-wrap { grid-column: 1 / -1; }
  .form-heading { flex-direction: column; }
  .final-order { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  body { min-height: 100dvh; }
  .site-header {
    width: calc(100% - 16px);
    height: 50px;
    padding: 5px 0;
    gap: 8px;
  }
  .brand { gap: 7px; font-size: .82rem; }
  .brand-mark { width: 32px; height: 32px; border-radius: 8px; font-size: .75rem; }
  .brand small { display: none; }
  .account { max-width: 145px; font-size: .62rem; }
  main {
    width: calc(100% - 12px);
    padding: 5px 0 0;
  }
  .hero {
    display: block;
    margin-bottom: 4px;
  }
  .hero > div:first-child { display: none; }
  .deadline-card {
    min-width: 0;
    height: 32px;
    padding: 4px 9px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 7px;
  }
  .deadline-card span { font-size: .64rem; }
  .deadline-card strong { font-size: .7rem; }
  .tabs { height: 30px; gap: 4px; margin-bottom: 4px; }
  .tab { padding: 3px 11px; font-size: .7rem; }
  .ballot-panel {
    height: calc(100dvh - 125px);
    min-height: 500px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    border-radius: 10px;
    box-shadow: none;
  }
  .ballot-panel .form-heading {
    min-height: 22px;
    margin: 0 0 3px;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
  }
  .ballot-panel .form-heading > div { display: none; }
  .save-state { padding: 3px 7px; font-size: .59rem; }
  .name-field {
    width: min(88%, 340px);
    max-width: 340px;
    margin: 0 auto 4px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
  }
  .name-field > span { display: block; font-size: .66rem; white-space: nowrap; }
  .name-field small { display: none; }
  .name-field input { height: 28px; padding: 0 7px; border-radius: 5px; font-size: 1rem; }
  .ranking-header { display: none; }
  .ranking-list {
    flex: 1;
    min-height: 0;
    grid-template-rows: repeat(12, minmax(0, 1fr));
    gap: 2px;
  }
  .ranking-row {
    min-height: 0;
    grid-template-columns: 24px minmax(68px, .65fr) minmax(105px, 1.35fr) 27px;
    gap: 3px;
    padding: 2px 3px;
    border-radius: 6px;
    cursor: grab;
    touch-action: pinch-zoom;
  }
  .ranking-row:active { cursor: grabbing; }
  .drag-placeholder { border-radius: 6px; }
  .ranking-row::before {
    width: 22px;
    height: 22px;
    font-size: .68rem;
  }
  .choice-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: .82rem;
  }
  .explanation-wrap {
    min-width: 0;
    grid-column: auto;
  }
  .explanation-wrap span { display: none; }
  .explanation-wrap textarea {
    min-height: 24px;
    height: 24px;
    padding: 3px 5px;
    border-radius: 4px;
    resize: none;
    overflow: hidden;
    white-space: nowrap;
    font-size: 1rem;
    line-height: 16px;
    cursor: text;
  }
  .drag-handle {
    width: 25px;
    height: 25px;
    padding: 0;
    border-radius: 5px;
    font-size: .92rem;
  }
  .form-actions {
    min-height: 34px;
    margin-top: 4px;
    padding-top: 0;
    border-top: 0;
    display: block;
  }
  .form-actions .button { width: 100%; min-height: 32px; height: 32px; font-size: .72rem; }
  .form-actions p { display: none; }
  .ballot-panel > .message {
    position: fixed;
    z-index: 10;
    left: 10px;
    right: 10px;
    bottom: 8px;
    margin: 0;
    padding: 8px 10px;
    box-shadow: var(--shadow);
    font-size: .7rem;
  }
  .choice-inputs { grid-template-columns: 1fr; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .submitter-row { grid-template-columns: 1fr; gap: 3px; }
  .published-results-panel, .published-ballots-panel { padding: 14px 10px; border-radius: 10px; box-shadow: none; }
  .results-heading { flex-direction: row; align-items: start; }
  .results-heading .button { min-height: 34px; padding: 0 11px; }
  .result-placement { grid-template-columns: 32px minmax(0, 1fr); gap: 8px; padding: 9px 10px; }
  .result-spot { font-size: 1.05rem; }
  .published-ballot summary { padding: 12px; }
  .published-ranking { padding: 0 12px 10px; }
  footer { display: none; }
}

@media (max-width: 520px) and (max-height: 700px) {
  .site-header { height: 42px; }
  .brand-mark { width: 28px; height: 28px; }
  .deadline-card { height: 27px; }
  .tabs { height: 27px; }
  .ballot-panel {
    height: calc(100dvh - 105px);
    min-height: 455px;
  }
  .ballot-panel .form-heading { display: none; }
}
