:root {
  color-scheme: dark;
  --surface: rgba(17, 22, 39, 0.94);
  --surface-soft: rgba(35, 42, 70, 0.78);
  --text: #f7f8ff;
  --muted: #a5aec8;
  --line: rgba(164, 176, 221, 0.18);
  --primary: #8068f4;
  --primary-strong: #9b88ff;
  --primary-soft: rgba(139, 116, 255, 0.16);
  --danger: #ff8b8b;
  --danger-soft: rgba(255, 94, 94, 0.12);
  --warning: #ffd479;
  --warning-soft: rgba(255, 194, 77, 0.12);
  --accent: #78baff;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  padding-top: clamp(46px, 7vw, 76px);
}

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

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(2rem, 5vw, 3.55rem);
  line-height: 1;
}

h2 {
  font-size: 1.18rem;
}

h3 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0;
}

.header-actions,
.form-actions,
.section-heading-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.tool-panel,
.result-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.tool-panel {
  padding: 22px;
  margin-bottom: 16px;
}

.section-heading {
  margin-bottom: 18px;
}

.section-heading-row {
  justify-content: space-between;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(230px, 1.15fr) repeat(3, minmax(180px, 1fr));
  gap: 16px;
  align-items: end;
}

.field,
.field-group {
  display: grid;
  gap: 8px;
}

.field span,
.field-group legend {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 750;
}

.field-group {
  min-width: 0;
  border: 0;
  padding: 0;
  margin: 0;
}

.mode-group {
  grid-template-columns: 1fr 1fr;
}

.mode-group legend {
  grid-column: 1 / -1;
}

.segmented-option {
  position: relative;
  min-width: 0;
}

.segmented-option input {
  position: absolute;
  inset: 0;
  opacity: 0;
}

.segmented-option span {
  display: grid;
  min-height: 44px;
  place-items: center;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease;
}

.segmented-option:first-of-type span {
  border-radius: 12px 0 0 12px;
}

.segmented-option:last-of-type span {
  border-radius: 0 12px 12px 0;
  border-left: 0;
}

.segmented-option input:checked + span {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.segmented-option input:focus-visible + span,
.button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.26);
  outline-offset: 2px;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(8, 12, 25, 0.8);
  color: var(--text);
  padding: 0 12px;
}

input::placeholder {
  color: #737e9c;
}

.party-list {
  display: grid;
  gap: 10px;
}

.party-row {
  display: grid;
  grid-template-columns: minmax(170px, 1.2fr) minmax(140px, 0.85fr) minmax(190px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(10, 15, 29, 0.7);
}

.color-inputs {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) 48px;
  gap: 8px;
  align-items: center;
}

input[type="color"].party-color-picker {
  min-height: 44px;
  padding: 3px;
  cursor: pointer;
}

.remove-party {
  min-width: 112px;
}

.button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0 15px;
  font-weight: 850;
  cursor: pointer;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease;
}

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

.button-primary {
  min-width: 180px;
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(128, 104, 244, 0.22);
}

.button-primary:hover {
  background: var(--primary-strong);
}

.button-secondary {
  background: var(--primary-soft);
  border-color: rgba(155, 136, 255, 0.36);
  color: #d8d0ff;
}

.button-ghost {
  background: rgba(8, 12, 25, 0.55);
  border-color: var(--line);
  color: var(--text);
}

.button-danger {
  background: var(--danger-soft);
  border-color: rgba(255, 139, 139, 0.32);
  color: var(--danger);
}

.form-actions {
  justify-content: flex-end;
  margin: 18px 0 22px;
}

.message {
  border-radius: 14px;
  padding: 14px 16px;
  line-height: 1.45;
}

.message ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.message-error {
  margin-bottom: 18px;
  border: 1px solid rgba(255, 139, 139, 0.32);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 700;
}

.message-warning {
  margin: 0 22px 18px;
  border: 1px solid rgba(255, 212, 121, 0.34);
  background: var(--warning-soft);
  color: var(--warning);
  font-weight: 700;
}

.result-panel {
  overflow: hidden;
}

.result-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 22px;
  border-bottom: 1px solid var(--line);
}

.chart-section {
  padding: 22px;
  border-bottom: 1px solid var(--line);
}

.chart-heading {
  margin-bottom: 14px;
}

.chart-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(220px, 0.75fr);
  gap: 24px;
  align-items: center;
}

.seat-chart {
  min-width: 0;
}

.seat-chart-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: 390px;
}

.seat-segment {
  stroke: #11162a;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.seat-label {
  fill: var(--text);
  font-size: 18px;
  font-weight: 850;
  paint-order: stroke;
  stroke: #11162a;
  stroke-linejoin: round;
  stroke-width: 5px;
}

.chart-center-title {
  fill: var(--muted);
  font-size: 15px;
  font-weight: 800;
  text-transform: uppercase;
}

.chart-center-value {
  fill: var(--text);
  font-size: 24px;
  font-weight: 900;
}

.chart-empty {
  display: grid;
  min-height: 220px;
  place-content: center;
  gap: 6px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  color: var(--muted);
  text-align: center;
}

.chart-empty strong {
  color: var(--text);
}

.chart-legend {
  display: grid;
  gap: 8px;
  align-content: center;
}

.legend-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(10, 15, 29, 0.7);
  padding: 8px 10px;
}

.legend-party {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-seats {
  font-variant-numeric: tabular-nums;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(130px, 1fr));
  gap: 10px;
  min-width: min(560px, 100%);
}

.summary-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--surface-soft);
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.summary-item strong {
  display: block;
  margin-top: 4px;
  font-size: 1rem;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  background: rgba(26, 33, 57, 0.92);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

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

tbody tr.failed {
  color: #8d96af;
  background: rgba(28, 22, 29, 0.55);
}

.number {
  font-variant-numeric: tabular-nums;
}

.color-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.color-swatch {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 5px;
  background: var(--party-color);
}

.color-code {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.8rem;
  font-weight: 850;
}

.status-pass {
  background: rgba(69, 203, 148, 0.14);
  color: #70ddb0;
}

.status-fail {
  background: var(--danger-soft);
  color: var(--danger);
}

@media (max-width: 1100px) {
  .app-header,
  .result-heading {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 920px) {

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

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

  .remove-party {
    grid-column: 1 / -1;
    justify-self: end;
  }

  .chart-layout {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 640px) {
  .app-shell {
    padding-top: 18px;
  }

  h1 {
    font-size: 2.3rem;
  }

  .tool-panel {
    padding: 16px;
  }

  .settings-grid,
  .summary-grid,
  .party-row {
    grid-template-columns: 1fr;
  }

  .chart-section {
    padding: 16px;
  }

  .chart-legend {
    grid-template-columns: 1fr;
  }

  .header-actions,
  .form-actions,
  .section-heading-row {
    align-items: stretch;
    flex-direction: column;
  }

  .button,
  .button-primary {
    width: 100%;
  }

  .remove-party {
    min-width: 0;
  }
}
