:root,
body[data-theme="light"] {
  color-scheme: light;
  --page-bg: #eff7fb;
  --surface: #ffffff;
  --surface-muted: #f2f9fc;
  --text: #17364d;
  --muted: #526b7d;
  --border: #c9dce7;
  --primary: #17699b;
  --primary-hover: #12557f;
  --accent: #159fbe;
  --accent-soft: #e2f6fa;
  --result-bg: #e6f7fb;
  --header-bg: #17699b;
  --danger: #b42318;
  --shadow: 0 3px 14px rgb(22 66 91 / 8%);
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--page-bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

body[data-theme="dark"] {
  color-scheme: dark;
  --page-bg: #101b25;
  --surface: #182936;
  --surface-muted: #203644;
  --text: #e6f1f7;
  --muted: #b2c7d3;
  --border: #365364;
  --primary: #2785b8;
  --primary-hover: #3599cb;
  --accent: #56c8df;
  --accent-soft: #173b49;
  --result-bg: #173947;
  --header-bg: #143b55;
  --danger: #ff9a91;
  --shadow: 0 3px 16px rgb(0 0 0 / 20%);
}

.site-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 700px) minmax(0, 1fr);
  min-height: 166px;
  align-items: center;
  gap: 16px;
  padding: 24px clamp(16px, 4vw, 48px);
  background: var(--header-bg);
  color: #ffffff;
  text-align: center;
}

.header-copy {
  grid-column: 2;
  min-width: 0;
  max-width: 700px;
  justify-self: center;
}

.site-header h1 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2rem);
  line-height: 1.35;
}

.site-header p {
  max-width: 680px;
  margin: 10px auto 0;
  color: rgb(255 255 255 / 88%);
}

.theme-control {
  grid-column: 3;
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 8px;
  margin: 0;
  color: rgb(255 255 255 / 90%);
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
}

.theme-control select {
  width: auto;
  min-width: 9.5rem;
  min-height: 40px;
  border-color: rgb(255 255 255 / 55%);
  background: rgb(255 255 255 / 10%);
  color: #ffffff;
}

.theme-control option {
  background: var(--surface);
  color: var(--text);
}

.calculator {
  max-width: 1040px;
  margin: 28px auto 56px;
  padding: 0 22px;
}

fieldset {
  min-width: 0;
  margin: 0 0 20px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

legend {
  padding: 0 8px;
  font-size: 1.12rem;
  font-weight: 750;
}

label {
  display: block;
  margin: 0 0 7px;
  font-weight: 600;
}

.form-field {
  min-width: 0;
}

input[type="text"],
input[type="number"],
select {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

input[type="checkbox"],
input[type="radio"] {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary);
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

button {
  min-height: 46px;
  padding: 10px 18px;
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

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

.storage-error {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--danger);
}

.event-controls {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.event-type-control {
  width: min(100%, 400px);
}

.formation-summary {
  display: flex;
  min-width: 230px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--muted);
  font-weight: 700;
}

.formation-summary strong {
  color: var(--primary);
  font-size: 1.65rem;
}

.section-description {
  margin: 0;
  color: var(--muted);
}

.card-list-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.character-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-muted);
}

.character-card h3 {
  margin: 0 0 14px;
  color: var(--primary);
  font-size: 1rem;
}

.character-card label + label {
  margin-top: 12px;
}

.live-format {
  max-width: 400px;
}

.score-settings-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 16px;
  margin-top: 18px;
}

.multi-score-group {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 10px;
}

.field-help {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 400;
}

[hidden] {
  display: none !important;
}

.reset-button {
  width: 100%;
  background: var(--surface-muted);
  color: var(--text);
  border: 1px solid var(--border);
}

.reset-button:hover {
  background: var(--accent-soft);
}

.bonus-settings-group {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.bonus-note {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.9rem;
}

.point-error {
  min-height: 1.4em;
  margin: 8px 0 0;
  color: var(--danger);
  text-align: center;
}

.range-results {
  margin-top: 0;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

.range-results h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.range-results-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.range-result {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-muted);
}

.range-result > span {
  color: var(--muted);
  font-weight: 700;
}

.range-result strong {
  color: var(--primary);
  font-size: 1.3rem;
  white-space: nowrap;
}

.range-result small {
  margin-left: 4px;
  font-size: 0.78rem;
}

@media (max-width: 760px) {
  .character-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 1280px) {
  .site-header {
    grid-template-columns: minmax(0, 1fr);
    gap: 14px;
    padding: 24px 20px;
  }

  .header-copy,
  .theme-control {
    grid-column: 1;
    justify-self: center;
  }
}

@media (max-width: 520px) {
  .site-header {
    min-height: 0;
    padding: 24px 16px;
  }

  .calculator {
    margin: 18px auto 36px;
    padding: 0 14px;
  }

  fieldset {
    margin-bottom: 16px;
    padding: 17px;
  }

  .event-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .formation-summary {
    min-width: 0;
  }

  .card-list-summary {
    align-items: stretch;
    flex-direction: column;
  }

  .character-grid,
  .score-settings-group,
  .bonus-settings-group,
  .range-results-grid {
    grid-template-columns: minmax(0, 1fr);
  }

}
