:root {
  color-scheme: light;
  --bg: #f5f8f6;
  --surface: #ffffff;
  --surface-2: #edf4f6;
  --surface-3: #e7ecf1;
  --ink: #202536;
  --muted: #667085;
  --line: #d9e2e4;
  --line-strong: #bcc8ce;
  --accent: #2c7a68;
  --accent-strong: #195f52;
  --warn: #b86d1f;
  --danger: #bb3e4a;
  --ok: #2e8b57;
  --shadow: 0 14px 35px rgba(32, 37, 54, 0.08);
  /* Widest the page content gets; header and tab bar line up with it on very wide screens. */
  --content-max: 1600px;
  --gutter: clamp(16px, 4vw, 36px);
  --page-inline: max(var(--gutter), calc((100% - var(--content-max)) / 2 + var(--gutter)));
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(222, 240, 235, 0.75), transparent 360px),
    var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

img {
  max-width: 100%;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px var(--page-inline);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(44, 122, 104, 0.14);
}

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

h1 {
  font-size: 1.55rem;
  line-height: 1.1;
}

h2 {
  font-size: 1.1rem;
  line-height: 1.2;
}

h3 {
  font-size: 0.95rem;
  line-height: 1.2;
}

p {
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.45;
}

.header-actions,
.filter-strip,
.stepper,
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.icon-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  white-space: nowrap;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

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

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

.primary-button:disabled,
.primary-button:disabled:hover {
  background: var(--muted);
  cursor: progress;
}

.secondary-button,
.ghost-button {
  border-color: var(--line);
}

.secondary-button:hover,
.ghost-button:hover,
.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.danger-button {
  border-color: rgba(187, 62, 74, 0.24);
  color: var(--danger);
}

.danger-button:hover {
  background: #fff0f1;
  border-color: rgba(187, 62, 74, 0.42);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  min-width: 34px;
  padding: 0;
}

.tab-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px var(--page-inline);
  border-bottom: 1px solid var(--line);
  background: rgba(245, 248, 246, 0.88);
  position: sticky;
  top: var(--header-height, 89px);
  z-index: 18;
}

.tab-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  min-height: 36px;
  padding: 0 14px;
  font-weight: 750;
  white-space: nowrap;
}

.tab-button.is-active {
  border-color: rgba(44, 122, 104, 0.4);
  background: #e8f4ef;
  color: var(--accent-strong);
}

.app-main {
  width: min(var(--content-max), 100%);
  margin: 0 auto;
  padding: 20px var(--gutter) 42px;
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.section-heading p,
.subsection-copy {
  max-width: 90ch;
}

/* In-game ability icon on its coloured circle; the abbreviation shows if the image can't load. */
.ability-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: white;
  font-size: 0.68rem;
  font-weight: 850;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.16);
  flex: 0 0 auto;
  overflow: hidden;
}

.ability-icon.small {
  width: 22px;
  height: 22px;
  font-size: 0.58rem;
}

.ability-img {
  width: 72%;
  height: 72%;
  object-fit: contain;
}

.ability-icon.has-img .ability-abbr {
  display: none;
}

.table-shell {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.table-shell.compact {
  box-shadow: none;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.data-table th,
.data-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: #45505f;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

.data-table tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover {
  background: #fbfdfd;
}

.compact-table {
  min-width: 0;
}

.count-input,
.quantity-input,
.setting-row input,
.filter-strip input,
.filter-strip select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fbfdfd;
}

.count-input,
.quantity-input {
  width: 68px;
  text-align: center;
}

.filter-strip label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

.filter-strip input {
  width: 240px;
}

.filter-strip select {
  width: 160px;
}

.building-name,
.aniimo-name {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.aniimo-head {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
  object-fit: cover;
  flex: 0 0 auto;
}

.aniimo-title {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.aniimo-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.aniimo-title span {
  color: var(--muted);
  font-size: 0.78rem;
}

.aniimo-title .dex-number {
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.skill-list,
.worker-skill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.skill-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 24px;
  padding: 2px 8px 2px 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fbfdfd;
  color: #344054;
  font-size: 0.78rem;
  font-weight: 750;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: #475467;
  font-size: 0.76rem;
  font-weight: 800;
}

.status-pill.ok {
  border-color: rgba(46, 139, 87, 0.22);
  background: #eaf6ef;
  color: #247446;
}

.status-pill.missing {
  border-color: rgba(187, 62, 74, 0.22);
  background: #fff0f1;
  color: #a2333e;
}

.work-model-text {
  color: var(--muted);
  line-height: 1.35;
}

.result-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.8fr);
  gap: 14px;
}

.result-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  box-shadow: 0 8px 22px rgba(32, 37, 54, 0.05);
}

.result-panel h3 {
  margin-bottom: 12px;
}

.worker-results {
  display: grid;
  gap: 10px;
}

.worker-card {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfdfd;
}

.worker-card .aniimo-head {
  width: 46px;
  height: 46px;
}

.worker-card h4 {
  margin: 0;
  font-size: 0.95rem;
}

.worker-card p {
  font-size: 0.86rem;
}

.assignment-list {
  margin: 4px 0 8px;
  padding-left: 18px;
  color: #425466;
  font-size: 0.84rem;
  line-height: 1.45;
}

.empty-state {
  min-height: 72px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 18px;
}

.notice-panel {
  border: 1px solid rgba(187, 62, 74, 0.22);
  border-radius: 8px;
  background: #fff8f3;
  color: #7f3f17;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.notice-panel h3 {
  margin-bottom: 6px;
}

.notice-panel ul {
  margin: 0;
  padding-left: 18px;
}

.is-hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr));
  gap: 14px;
  align-items: start;
}

fieldset {
  min-width: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  box-shadow: 0 8px 22px rgba(32, 37, 54, 0.05);
}

legend {
  padding: 0 6px;
  color: #45505f;
  font-weight: 850;
}

.setting-row {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

.setting-row input {
  width: 100%;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 14px;
  color: #425466;
  font-weight: 700;
  line-height: 1.35;
}

.checkbox-row input,
.use-checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.use-checkbox:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* About the data (page footer) */
.app-footer {
  width: min(var(--content-max), 100%);
  margin: 0 auto;
  padding: 0 var(--gutter) 32px;
}

.about-data {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px 14px;
}

.about-data summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-weight: 800;
}

.about-intro {
  margin: 10px 0 12px;
  font-size: 0.88rem;
}

.source-list {
  display: grid;
  gap: 14px;
}

.source-group h3 {
  margin-bottom: 8px;
  color: #45505f;
}

.source-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
  gap: 10px;
}

.source-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfd;
  min-width: 0;
  overflow-wrap: anywhere;
}

.source-item a {
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.source-item strong {
  color: var(--ink);
}

.source-item p {
  font-size: 0.82rem;
}

.source-item.is-override {
  border-style: dashed;
  border-color: rgba(184, 109, 31, 0.45);
  background: #fffaf3;
}

.source-badge {
  display: inline-block;
  margin-bottom: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  background: #fff0dc;
  color: #7f4a17;
  font-size: 0.72rem;
  font-weight: 800;
}

.source-item.is-override strong {
  display: block;
}

/* Gentle, non-error notice */
/* Requirements table */
.hint-banner {
  margin: 0 0 12px;
  padding: 10px 14px;
  border: 1px solid rgba(44, 122, 104, 0.28);
  border-radius: 8px;
  background: #eef7f3;
  color: var(--accent-strong);
  font-weight: 650;
}

/* Requirements: a horizontal table like the in-game Ability Distribution panel. 13 columns on wide
   screens, wrapping to 7 + 6 and then 5 + 5 + 3 on narrow ones. */
.ability-panel {
  padding: 10px 14px 14px;
}

.ability-grid {
  display: grid;
  grid-template-columns: repeat(13, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.ability-cell {
  display: grid;
  /* The header takes any extra height, so every input in a row lines up. */
  grid-template-rows: 1fr auto;
  min-width: 0;
  box-shadow:
    inset -1px 0 0 var(--line),
    inset 0 -1px 0 var(--line);
}

.ability-cell-head {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 5px;
  padding: 10px 4px 8px;
  background: var(--surface-2);
  box-shadow: inset 0 -1px 0 var(--line);
  cursor: pointer;
  min-width: 0;
}

.ability-cell-name {
  max-width: 100%;
  color: #344054;
  font-size: 0.76rem;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  word-break: keep-all;
}

.ability-cell .requirement-input {
  width: calc(100% - 12px);
  margin: 7px auto 8px;
  text-align: center;
}

.requirement-input {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 4px;
  background: #fff;
  font-size: 1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 1100px) {
  .ability-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .ability-panel {
    padding: 8px 8px 10px;
  }

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

  .ability-cell-head {
    padding: 8px 1px 6px;
  }

  .ability-cell-name {
    font-size: 0.6rem;
    letter-spacing: -0.01em;
  }
}

.requirement-input:focus,
.count-input:focus,
.quantity-input:focus,
.setting-row input:focus,
.setting-row select:focus {
  outline: 2px solid rgba(44, 122, 104, 0.45);
  outline-offset: 1px;
}

/* Homeland capacity */
.capacity-card {
  margin-bottom: 20px;
}

.capacity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
  gap: 4px 24px;
  max-width: 1100px;
}

.capacity-grid .setting-row {
  margin-top: 8px;
}

.capacity-status {
  margin-top: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  background: #eef7f3;
  color: var(--accent-strong);
  font-weight: 650;
}

.capacity-status.is-unknown {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 500;
}

.heading-sub {
  margin-top: 2px;
  font-size: 0.84rem;
  font-style: italic;
}

.type-text {
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

.is-unbuilt .building-name strong {
  color: var(--muted);
  font-weight: 600;
}

.subsection-title {
  margin: 4px 0 4px;
}

.subsection-copy {
  margin-bottom: 12px;
}

/* "Who can work here": the same icon + ability (+ step) layout on every row */
.work-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
}

.work-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.work-skill {
  color: var(--ink);
  font-weight: 700;
}

.work-or {
  color: var(--muted);
  font-size: 0.8rem;
}

.work-note {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.count-cell {
  white-space: nowrap;
}

.count-limit {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-align: center;
}

.building-table tr.is-locked td {
  background: #f7f9fa;
}

.building-table tr.is-locked .building-name strong,
.building-table tr.is-locked .work-model-text {
  color: #98a2b3;
}

.building-table tr.is-locked .count-limit {
  color: var(--warn);
}

.building-table tr.is-locked .ability-icon {
  opacity: 0.55;
}

.count-input:disabled,
.icon-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.table-footnote {
  margin-top: 8px;
  font-size: 0.78rem;
  max-width: 90ch;
}

.building-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 12px;
  padding: 10px 14px;
  border: 1px solid rgba(44, 122, 104, 0.28);
  border-radius: 8px;
  background: #eef7f3;
}

.toolbar-note {
  margin: 0;
  flex: 1 1 280px;
  color: var(--accent-strong);
  font-weight: 650;
}

.toolbar-note.is-prompt {
  color: var(--warn);
}

.building-toolbar .secondary-button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Available Aniimo */
.pool-toggles {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 10px;
  margin-bottom: 14px;
}

.toggle-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  flex: 0 1 320px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
}

.toggle-card:has(input:checked) {
  border-color: rgba(44, 122, 104, 0.5);
  background: #e8f4ef;
}

.toggle-card input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.toggle-card strong {
  display: block;
  color: var(--ink);
}

.toggle-card small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
}

.pool-summary {
  align-self: center;
  margin: 0;
  color: var(--accent-strong);
  font-weight: 700;
}

.use-col {
  width: 56px;
  text-align: center !important;
}

.roster-table label.aniimo-name {
  cursor: pointer;
}

.roster-table tr.is-excluded .aniimo-title strong,
.roster-table tr.is-excluded .skill-list {
  opacity: 0.55;
}

.category-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 800;
  vertical-align: middle;
}

.category-badge.is-prismana {
  background: #fff4d6;
  color: #7a5200;
}

.category-badge.is-legendary {
  background: #efe6ff;
  color: #5b2fa0;
}

.category-badge.is-boss {
  background: #ffe9ea;
  color: #9b2c36;
}

.pool-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-right: 8px;
  white-space: nowrap;
}

.pool-label {
  color: var(--muted);
  font-size: 0.8rem;
}

/* Settings */
.setting-row select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fbfdfd;
  color: var(--ink);
}

.setting-help {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.4;
}

.checkbox-row .setting-help {
  margin-top: 2px;
}

.choice-list {
  display: grid;
  gap: 8px;
}

.choice-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfd;
  cursor: pointer;
}

.choice-card:has(input:checked) {
  border-color: rgba(44, 122, 104, 0.5);
  background: #e8f4ef;
}

.choice-card input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.choice-card strong {
  display: block;
  color: var(--ink);
}

.choice-card small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  line-height: 1.4;
}

.fieldset-intro {
  margin: 2px 0 0;
  font-size: 0.84rem;
}

.advanced-settings {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.advanced-settings summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-weight: 800;
}

/* Optimise results */
.panel-help {
  margin: -6px 0 12px;
  font-size: 0.84rem;
}

.result-panel-wide {
  grid-column: 1 / -1;
}

.notice-panel p {
  color: inherit;
}

.shortfall-list {
  display: grid;
  gap: 4px;
  margin: 8px 0 !important;
}

.shortfall-list li {
  overflow-wrap: anywhere;
}

/* Switch between the best plan that fits and the full plan. */
.plan-switch {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
  padding: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  max-width: 100%;
}

.plan-switch-button {
  min-height: 34px;
  border: 0;
  border-radius: 999px;
  padding: 6px 14px;
  background: transparent;
  color: var(--ink);
  font-weight: 750;
  cursor: pointer;
}

.plan-switch-button.is-active {
  background: var(--accent);
  color: #fff;
}

.plan-switch-button:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

@media (max-width: 520px) {
  .plan-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    border-radius: 12px;
  }

  .plan-switch-button {
    border-radius: 9px;
    white-space: normal;
    line-height: 1.25;
  }
}

.status-pill.idle {
  border-color: rgba(184, 109, 31, 0.25);
  background: #fff6ea;
  color: #8a4f12;
}

tr.is-idle td {
  color: var(--muted);
}

.link-button {
  border: 0;
  padding: 0;
  background: none;
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: underline;
}

.spare-summary {
  margin: 0 0 12px;
  color: var(--ink);
}

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

.spare-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdfd;
  min-width: 0;
}

.spare-group h4 {
  margin: 0;
  font-size: 0.95rem;
}

.spare-intro {
  font-size: 0.82rem;
  margin-bottom: 8px;
}

.spare-note {
  font-size: 0.86rem;
}

.spare-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.spare-item {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.spare-item p {
  margin-top: 2px;
  font-size: 0.82rem;
}

.empty-state .secondary-button {
  margin-top: 10px;
}

/* Calculating overlay */
.calculating-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(245, 248, 246, 0.72);
  backdrop-filter: blur(2px);
}

.calculating-overlay.is-hidden {
  display: none;
}

.calculating-card {
  display: grid;
  justify-items: center;
  gap: 8px;
  max-width: 320px;
  padding: 22px 26px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.calculating-card span:last-child {
  color: var(--muted);
  font-size: 0.88rem;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 4px solid var(--surface-3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
}

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

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

  .tab-bar {
    top: var(--header-height, 142px);
  }

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

@media (max-width: 640px) {
  .filter-strip {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-strip input,
  .filter-strip select {
    width: 100%;
  }

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

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

  /* On phones the header scrolls away so it doesn't take up a third of the screen. */
  .app-header {
    position: static;
  }

  .header-actions .ghost-button,
  .header-actions .danger-button {
    padding: 0 10px;
  }

  .tab-bar {
    top: 0;
  }
}

kbd {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid currentColor;
  border-bottom-width: 2px;
  border-radius: 4px;
  font: inherit;
  font-size: 0.9em;
  line-height: 1.3;
}

/* Processor busy options: a compact comparison table above the plan. */
.options-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 8px 22px rgba(32, 37, 54, 0.05);
}

.options-panel h3 {
  margin-bottom: 6px;
}

.options-table td,
.options-table th {
  padding: 7px 10px;
  white-space: nowrap;
}

.option-row {
  cursor: pointer;
}

.option-row.is-selected td {
  background: #e8f4f0;
}

.option-row.is-selected td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}

.option-row.is-over td {
  color: var(--muted);
}

.option-button {
  min-width: 58px;
  min-height: 32px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}

.option-button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.option-button:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

.best-badge {
  display: inline-block;
  margin-left: 6px;
  border-radius: 999px;
  padding: 1px 7px;
  background: #eaf6ef;
  color: #247446;
  font-size: 0.72rem;
  font-weight: 800;
}

.options-max {
  margin: 10px 0 4px;
  color: var(--ink);
  font-weight: 700;
}

.options-link {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.options-link a {
  color: var(--accent-strong);
  font-weight: 750;
}

/* A processor's own busy % on the Homeland tab. */
.busy-control {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  font-size: 0.78rem;
}

.busy-control input {
  width: 64px;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 6px;
  font: inherit;
}

.busy-control input:focus {
  outline: 2px solid rgba(44, 122, 104, 0.45);
  outline-offset: 1px;
}

.has-own-busy .busy-control input,
.busy-control input:not(:placeholder-shown) {
  border-color: var(--accent);
  color: var(--ink);
  font-weight: 750;
}

/* Personality bonuses. */
.personality-cell {
  white-space: nowrap;
}

.personality-tag {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 8px;
  background: #f3edfb;
  color: #5b3a8a;
  font-size: 0.78rem;
  font-weight: 800;
}

.personality-bonus {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.personality-tip {
  margin: 2px 0 6px;
  color: #5b3a8a;
}

.personality-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.personality-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
  font-size: 0.86rem;
}

.personality-list li:last-child {
  border-bottom: 0;
}

.personality-buildings {
  color: #344054;
}

.personality-weight {
  margin-left: auto;
  color: var(--muted);
  font-size: 0.76rem;
}

.muted {
  color: var(--muted);
}

/* Starter choice, evolution stage badges and notes. */
.starter-card {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 14px;
  margin: 0;
  min-width: 0;
}

.starter-card legend {
  padding: 0 4px;
  font-weight: 800;
}

.starter-card label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
}

.starter-card small {
  flex-basis: 100%;
  color: var(--warn);
}

.tier-badge {
  display: inline-block;
  margin-left: 4px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  vertical-align: middle;
}

.tier-badge.is-final {
  border-color: rgba(44, 122, 104, 0.35);
  color: var(--accent-strong);
}

.roster-note {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.3;
}

.family-note {
  display: block;
  margin-top: 3px;
  color: #5b3a8a;
  font-size: 0.8rem;
  font-weight: 700;
}

.starter-card {
  cursor: default;
}

/* Assumed facility level under the building name ("Lv 2 (max for RV 9)"). */
.building-table .building-name {
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
}

.building-level {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
}

.building-level:empty {
  display: none;
}

/* "Choose these": one block per role requirement (the Aniimo to pick, what they must have and what they
   bring), with one row per target personality; the example Aniimo's cards sit below in a disclosure. */
.choose-title {
  margin: 0 0 4px;
  font-size: 0.9rem;
}

.choose-help {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.choose-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.choose-item {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #fbfdfd;
}

.choose-main {
  min-width: 0;
}

.choose-main > p,
.choose-roles {
  margin: 0;
  line-height: 1.35;
}

.choose-name {
  color: var(--ink);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.choose-count {
  display: inline-block;
  min-width: 2ch;
  color: var(--accent-strong);
  font-weight: 850;
}

.choose-needs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 3px 8px;
  margin-top: 3px !important;
}

.choose-label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.choose-ability {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.8rem;
  font-weight: 800;
}

.choose-ability.is-bonus {
  color: #425466;
  font-weight: 650;
}

.choose-note {
  color: var(--warn);
  font-size: 0.78rem;
  font-weight: 650;
}

.choose-roles {
  display: grid;
  gap: 1px;
  margin-top: 4px !important;
  padding: 4px 0 0;
  border-top: 1px dashed var(--line);
  list-style: none;
  font-size: 0.82rem;
  color: var(--ink);
}

.choose-roles li {
  overflow-wrap: anywhere;
}

.choose-jobs,
.choose-muted {
  color: #5b6b7b;
}

.choose-jobs {
  font-size: 0.78rem;
}

.choose-also {
  margin-top: 4px !important;
  color: #5b6b7b;
  font-size: 0.76rem;
  overflow-wrap: anywhere;
}

.example-label {
  color: var(--muted);
  font-weight: 650;
}

.workforce-details {
  margin-top: 12px;
}

.workforce-details > summary {
  cursor: pointer;
  color: var(--accent-strong);
  font-weight: 750;
  font-size: 0.88rem;
}

.worker-cards {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

@media (max-width: 560px) {
  .choose-item {
    grid-template-columns: 30px minmax(0, 1fr);
    gap: 8px;
  }

  .choose-item .aniimo-head {
    width: 30px;
    height: 30px;
  }
}

/* E-mode choice on the Homeland tab and the power plan in the results. */
.busy-control select {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 4px;
  font: inherit;
  background: var(--surface);
}

#emodePanel .options-max {
  margin-top: 8px;
}
