:root {
  color-scheme: dark;
  --bg: #080808;
  --bg-top: #180707;
  --panel: rgba(19, 19, 19, 0.94);
  --panel-strong: rgba(28, 28, 28, 0.98);
  --panel-soft: rgba(255, 255, 255, 0.04);
  --ink: #f6f1f1;
  --muted: #c5b6b6;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.18);
  --brand: #d61f2c;
  --brand-deep: #981018;
  --brand-soft: rgba(214, 31, 44, 0.18);
  --success: #9fe0bc;
  --success-bg: rgba(62, 122, 82, 0.2);
  --danger-bg: rgba(170, 34, 45, 0.24);
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.48);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at top left, rgba(214, 31, 44, 0.26), transparent 34%),
    radial-gradient(circle at top right, rgba(214, 31, 44, 0.12), transparent 28%),
    linear-gradient(180deg, var(--bg-top), var(--bg) 36%);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.72), transparent 92%);
  pointer-events: none;
}

button,
input {
  font: inherit;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 34px 0 40px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 10px;
  color: #ff7d7d;
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 9ch;
  margin-bottom: 0;
  font-size: clamp(2.3rem, 5vw, 5rem);
  line-height: 0.9;
  letter-spacing: 0;
  text-transform: uppercase;
}

h2 {
  margin-bottom: 0;
  font-size: 1.05rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.status-pill {
  flex: 0 0 auto;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background:
    linear-gradient(135deg, rgba(214, 31, 44, 0.18), rgba(255, 255, 255, 0.06)),
    rgba(255, 255, 255, 0.03);
  color: #fff0f0;
  padding: 12px 16px;
  font-size: 0.88rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.workspace {
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 18%),
    var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.28);
}

.tab-button {
  min-height: 54px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.tab-button:hover {
  border-color: rgba(214, 31, 44, 0.3);
  background: rgba(214, 31, 44, 0.1);
  color: #ffe2e2;
  transform: translateY(-1px);
}

.tab-button.active {
  border-color: rgba(255, 120, 120, 0.28);
  background: linear-gradient(180deg, rgba(214, 31, 44, 0.28), rgba(120, 8, 16, 0.56));
  color: #fff7f7;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.panel {
  display: none;
  padding: 28px;
}

.panel.active {
  display: block;
}

.stack {
  display: grid;
  gap: 24px;
}

.field-row {
  display: grid;
  gap: 8px;
  max-width: 420px;
}

label {
  color: #ffdddd;
  font-size: 0.83rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

input {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  padding: 0 14px;
  font-weight: 800;
  letter-spacing: 0;
  transition: border-color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.code-input {
  text-transform: uppercase;
}

input:focus {
  border-color: rgba(214, 31, 44, 0.64);
  background: rgba(255, 255, 255, 0.06);
  outline: none;
  box-shadow: 0 0 0 4px rgba(214, 31, 44, 0.14);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-heading span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.candidate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.candidate-card {
  position: relative;
  display: flex;
  min-height: 74px;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.025);
  padding: 14px;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.candidate-card:hover {
  border-color: rgba(214, 31, 44, 0.34);
  background: rgba(214, 31, 44, 0.08);
  transform: translateY(-1px);
}

.candidate-card:has(input:checked) {
  border-color: rgba(255, 120, 120, 0.5);
  background:
    linear-gradient(135deg, rgba(214, 31, 44, 0.22), rgba(255, 255, 255, 0.04)),
    rgba(255, 255, 255, 0.03);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.candidate-card input {
  width: 22px;
  min-height: 22px;
  margin: 0;
  accent-color: var(--brand);
}

.candidate-card strong {
  display: block;
  font-size: 0.98rem;
  line-height: 1.2;
}

.action-row,
.audit-box {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button {
  min-height: 48px;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 900;
  letter-spacing: 0.03em;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.primary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
}

.primary-button {
  border: 1px solid rgba(255, 120, 120, 0.24);
  background: linear-gradient(180deg, #ea2f3d, #8d0c16);
  color: #fff8f8;
  padding: 0 18px;
}

.ghost-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  padding: 0 16px;
}

.ghost-button:hover {
  border-color: rgba(214, 31, 44, 0.32);
  background: rgba(214, 31, 44, 0.08);
}

.compact {
  min-height: 40px;
}

.notice {
  display: none;
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.035);
}

.notice.visible {
  display: block;
}

.notice.success {
  border-color: rgba(159, 224, 188, 0.18);
  background: var(--success-bg);
}

.notice.error {
  border-color: rgba(214, 31, 44, 0.26);
  background: var(--danger-bg);
}

.notice h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 900;
  text-transform: uppercase;
}

.notice p {
  margin-bottom: 8px;
  color: var(--muted);
}

.receipt {
  display: inline-flex;
  border-radius: 8px;
  background: #f3d6d7;
  color: #43080d;
  padding: 5px 8px;
  font-family: "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.9rem;
  font-weight: 900;
}

.results-grid {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.admin-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-candidates {
  margin-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 24px;
}

.admin-controls {
  margin-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 24px;
}

.admin-votes {
  margin-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 24px;
}

.admin-control-grid {
  display: grid;
  gap: 12px;
}

.toggle-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.025);
  padding: 16px;
}

.toggle-copy {
  display: grid;
  gap: 4px;
}

.toggle-copy strong {
  font-size: 0.98rem;
}

.toggle-copy span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.toggle-card input[type="checkbox"] {
  width: 56px;
  min-width: 56px;
  min-height: 32px;
  border-radius: 999px;
  appearance: none;
  background: rgba(255, 255, 255, 0.16);
  cursor: pointer;
  position: relative;
  transition: background 160ms ease, border-color 160ms ease;
}

.toggle-card input[type="checkbox"]::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: #ffffff;
  transition: transform 160ms ease;
}

.toggle-card input[type="checkbox"]:checked {
  background: linear-gradient(90deg, #ff525d, #930d16);
}

.toggle-card input[type="checkbox"]:checked::before {
  transform: translateX(24px);
}

.admin-subsection {
  margin-bottom: 14px;
}

.candidate-admin-list {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.candidate-admin-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.025);
}

.candidate-admin-copy {
  display: grid;
  gap: 4px;
}

.candidate-admin-copy strong {
  font-size: 0.98rem;
}

.candidate-admin-copy span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

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

.hidden {
  display: none !important;
}

.admin-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 14px 16px;
  background:
    linear-gradient(135deg, rgba(214, 31, 44, 0.16), rgba(255, 255, 255, 0.03)),
    rgba(255, 255, 255, 0.03);
  color: #fff1f1;
  font-weight: 900;
}

.result-row {
  display: grid;
  grid-template-columns: minmax(130px, 220px) 1fr auto;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.025);
}

.bar-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff525d, #930d16);
}

.result-count {
  min-width: 72px;
  text-align: right;
  color: #ffe1e1;
  font-weight: 900;
}

@media (max-width: 960px) {
  .app-shell {
    width: min(100% - 24px, 1180px);
  }

  h1 {
    max-width: none;
    font-size: clamp(2.1rem, 8vw, 3.6rem);
  }

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

@media (max-width: 720px) {
  .app-shell {
    padding: 18px 0 28px;
  }

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

  .status-pill {
    width: 100%;
    border-radius: 14px;
  }

  .workspace {
    border-radius: 16px;
  }

  .tabs {
    gap: 8px;
    padding: 12px;
  }

  .tab-button {
    min-height: 48px;
    font-size: 0.82rem;
  }

  .panel {
    padding: 18px 16px 20px;
  }

  .candidate-grid {
    grid-template-columns: 1fr;
  }

  .candidate-card {
    min-height: 68px;
  }

  .action-row,
  .audit-box,
  .admin-actions {
    display: grid;
    width: 100%;
  }

  .action-row > *,
  .audit-box > *,
  .admin-actions > * {
    width: 100%;
  }

  .field-row {
    max-width: none;
  }

  .result-row,
  .admin-summary,
  .candidate-admin-row,
  .toggle-card {
    grid-template-columns: 1fr;
  }

  .result-count {
    text-align: left;
  }

  .candidate-admin-row,
  .toggle-card {
    display: grid;
  }
}
