:root {
  color-scheme: light;
  --ink: #14201c;
  --muted: #62706a;
  --paper: #fbfaf5;
  --panel: #ffffff;
  --line: #d8ded7;
  --green: #256f52;
  --green-dark: #174b38;
  --blue: #235c9f;
  --gold: #b67816;
  --coral: #c94d3c;
  --mint: #e8f5ee;
  --sky: #e8f0fb;
  --amber: #fff4dc;
  --rose: #fdeceb;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: #eef3ee;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(90deg, rgba(20, 32, 28, 0.05) 1px, transparent 1px),
    linear-gradient(180deg, #fbfaf5 0%, #edf4f6 100%);
  background-size: 28px 28px, auto;
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
}

.screen {
  min-height: 100vh;
  padding: 24px;
}

.hidden {
  display: none !important;
}

.load-screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 22px;
  align-items: center;
}

.load-copy {
  max-width: 640px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

.load-copy h1,
.topbar h1 {
  margin: 0;
  max-width: 760px;
  font-size: 3.2rem;
  line-height: 1.04;
  letter-spacing: 0;
}

.tagline {
  max-width: 600px;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.55;
}

.load-panel,
.input-panel,
.note-panel,
.run-panel,
.result-panel,
.candidate-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 18px 42px rgba(23, 40, 34, 0.08);
}

.load-panel {
  display: grid;
  gap: 14px;
  padding: 22px;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

.load-panel h2 {
  margin: 0;
  font-size: 1.2rem;
}

.load-panel p {
  min-height: 3em;
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #dbe2dd;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--blue), var(--gold));
  transition: width 180ms ease;
}

.primary-button,
.secondary-button,
.text-button,
.mode-button,
.icon-button {
  min-height: 42px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  padding: 0 18px;
  background: var(--green);
  color: white;
}

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

.secondary-button {
  padding: 0 18px;
  border: 1px solid #bdd0c4;
  background: var(--mint);
  color: var(--green);
}

.secondary-button:hover {
  background: #dbeee5;
}

.primary-button.wide {
  width: 100%;
  min-height: 50px;
}

.text-button {
  background: transparent;
  color: var(--blue);
}

.work-screen {
  display: grid;
  gap: 18px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 4px;
}

.topbar h1 {
  font-size: 2rem;
}

.status-pill,
.step-pill,
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 5px 10px;
  background: #eef2ef;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
  white-space: nowrap;
}

.status-pill.ready,
.badge.good {
  background: var(--mint);
  color: var(--green);
}

.status-pill.warn,
.badge.warn {
  background: var(--amber);
  color: #8a5a0f;
}

.status-pill.bad {
  background: var(--rose);
  color: var(--coral);
}

.input-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.55fr);
  gap: 18px;
}

.input-panel,
.note-panel,
.run-panel,
.result-panel,
.candidate-panel {
  padding: 18px;
}

.input-panel {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

select,
input {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  min-height: 126px;
  resize: vertical;
  padding: 12px;
  line-height: 1.5;
}

select:focus,
input:focus,
textarea:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(35, 92, 159, 0.18);
}

.target-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.mode-group {
  display: inline-grid;
  grid-template-columns: repeat(3, 1fr);
  min-width: 248px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2ef;
}

.mode-button {
  min-height: 44px;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--muted);
}

.mode-button:last-child {
  border-right: 0;
}

.mode-button.active {
  background: var(--green);
  color: white;
}

.token-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f8f5;
}

.token-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 900;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  min-height: 34px;
  background: transparent;
  color: var(--coral);
  font-size: 1.35rem;
}

.token-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 42px;
}

.token-chip {
  min-height: 34px;
  max-width: 100%;
  border: 1px solid #c7d0ca;
  border-radius: 8px;
  padding: 5px 10px;
  background: white;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.token-chip.selected {
  border-color: var(--blue);
  background: var(--sky);
  color: #143c68;
}

.hint,
.source-line,
.empty-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}

.hint.bad {
  color: var(--coral);
}

.note-panel h2,
.panel-title h2,
.run-head h2 {
  margin: 0;
  font-size: 1.04rem;
}

.note-panel dl {
  display: grid;
  gap: 14px;
  margin: 14px 0 0;
}

.note-panel dt {
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.note-panel dd {
  margin: 4px 0 0;
  color: var(--ink);
  line-height: 1.45;
}

.run-panel {
  display: grid;
  gap: 14px;
}

.run-head,
.panel-title,
.candidate-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.run-head p {
  margin: 5px 0 0;
  color: var(--muted);
}

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

.candidate-panel {
  grid-column: 1 / -1;
}

.result-main {
  margin: 14px 0 8px;
  font-size: 1.08rem;
  line-height: 1.58;
}

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

.candidate-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 5px solid #cbd6cf;
  border-radius: 8px;
  background: var(--paper);
}

.candidate-card.picked {
  border-left-color: var(--blue);
  background: #f1f6fc;
}

.candidate-card h3 {
  margin: 0;
  font-size: 1rem;
}

.candidate-card p {
  margin: 0;
  line-height: 1.5;
}

.badge-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.badge.pick {
  background: var(--sky);
  color: var(--blue);
}

.badge.rank {
  background: #f2ebff;
  color: #62479d;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(20, 32, 28, 0.42);
}

.info-dialog {
  width: min(620px, 100%);
  max-height: min(720px, calc(100vh - 36px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(20, 32, 28, 0.24);
}

.dialog-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.dialog-head h2 {
  margin: 0;
  font-size: 1.12rem;
}

.dialog-body {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.dialog-body p {
  margin: 0;
  color: var(--ink);
  line-height: 1.55;
}

@media (max-width: 880px) {
  .load-screen,
  .input-grid,
  .results {
    grid-template-columns: 1fr;
  }

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

  .target-row {
    grid-template-columns: 1fr;
  }

  .mode-group {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 560px) {
  .screen {
    padding: 14px;
  }

  .load-copy h1 {
    font-size: 2.25rem;
  }

  .topbar h1 {
    font-size: 1.55rem;
  }

  .load-panel,
  .input-panel,
  .note-panel,
  .run-panel,
  .result-panel,
  .candidate-panel {
    padding: 14px;
  }

  .candidate-head,
  .panel-title,
  .run-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .badge-row {
    justify-content: flex-start;
  }
}
