:root {
  color-scheme: dark;
  --bg: #080909;
  --panel: #111311;
  --panel-soft: #171a17;
  --line: #343a34;
  --line-bright: #616961;
  --text: #f1eee5;
  --muted: #aaa99f;
  --gold: #c7a45d;
  --gold-light: #e7cb8d;
  --red: #9d5548;
  --green: #6f9170;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background:
    radial-gradient(circle at 50% -10%, rgba(199, 164, 93, 0.12), transparent 34rem),
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.012) 1px, transparent 1px),
    var(--bg);
  background-size:
    auto,
    48px 48px,
    48px 48px,
    auto;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  color: inherit;
}

button {
  cursor: pointer;
}

.page-shell {
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto;
  padding: 56px 0 36px;
}

.hero {
  max-width: 760px;
  margin: 0 auto 42px;
  text-align: center;
}

.eyebrow,
.step-label {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

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

h1,
h2 {
  font-family: Georgia, "Times New Roman", serif;
}

h1 {
  margin-bottom: 14px;
  font-size: clamp(2.4rem, 7vw, 5.2rem);
  font-weight: 500;
  letter-spacing: 0.025em;
  line-height: 0.95;
  text-shadow: 0 3px 20px rgba(0, 0, 0, 0.8);
}

.hero-copy {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.06rem;
  line-height: 1.7;
}

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 22px;
}

.panel {
  min-width: 0;
  padding: clamp(22px, 4vw, 38px);
  border: 1px solid var(--line);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.025), transparent 40%),
    var(--panel);
  box-shadow: var(--shadow);
}

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

.section-heading h2 {
  margin: 0;
  font-size: clamp(1.55rem, 3vw, 2.25rem);
  font-weight: 500;
}

.section-intro {
  max-width: 760px;
  margin-bottom: 18px;
  color: var(--muted);
  line-height: 1.65;
}

.button {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--line-bright);
  border-radius: 2px;
  background: transparent;
  font-weight: 750;
  transition:
    border-color 140ms ease,
    background 140ms ease,
    color 140ms ease,
    transform 140ms ease;
}

.button:hover {
  border-color: var(--gold);
  color: var(--gold-light);
}

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

.button:focus-visible,
.dot:focus-visible,
.number-button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(231, 203, 141, 0.35);
  outline-offset: 2px;
}

.button-primary {
  min-height: 52px;
  padding-inline: 26px;
  border-color: var(--gold);
  color: #14120d;
  background: var(--gold-light);
}

.button-primary:hover {
  color: #090806;
  background: #f3daa1;
}

.button-primary:disabled {
  cursor: wait;
  opacity: 0.65;
}

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

.count-control {
  display: grid;
  grid-template-columns: max-content max-content 1fr;
  align-items: center;
  gap: 12px 18px;
  padding: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.018);
}

.count-control > label {
  font-weight: 800;
}

.number-field {
  display: grid;
  grid-template-columns: 38px 58px 38px;
  height: 38px;
}

.number-field input {
  width: 100%;
  border: solid var(--line-bright);
  border-width: 1px 0;
  color: var(--text);
  background: #090a09;
  text-align: center;
  -moz-appearance: textfield;
}

.number-field input::-webkit-inner-spin-button,
.number-field input::-webkit-outer-spin-button {
  margin: 0;
  appearance: none;
}

.number-button {
  border: 1px solid var(--line-bright);
  background: var(--panel-soft);
  font-size: 1.2rem;
}

.number-button:hover {
  border-color: var(--gold);
  color: var(--gold-light);
}

.field-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.tile-editors {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(265px, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.tile-card {
  padding: 18px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
}

.tile-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 17px;
}

.tile-title h3 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.1rem;
  font-weight: 500;
}

.tile-badge {
  display: grid;
  width: 31px;
  height: 31px;
  place-items: center;
  border: 1px solid var(--gold);
  color: var(--gold-light);
  font-size: 0.78rem;
  font-weight: 800;
}

.position-control + .position-control {
  margin-top: 15px;
}

.position-label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 750;
  text-transform: uppercase;
}

.position-label output {
  color: var(--text);
}

.dot-track {
  position: relative;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  align-items: center;
  gap: 6px;
}

.dot-track::before {
  position: absolute;
  right: 7%;
  left: 7%;
  z-index: 0;
  height: 2px;
  background: var(--line-bright);
  content: "";
}

.dot {
  position: relative;
  z-index: 1;
  width: 20px;
  height: 20px;
  margin: auto;
  padding: 0;
  border: 5px solid var(--panel-soft);
  border-radius: 50%;
  background: #686d68;
  box-shadow: 0 0 0 1px #8b908b;
}

.dot:hover {
  background: var(--gold-light);
}

.dot.selected {
  background: var(--gold-light);
  box-shadow:
    0 0 0 2px var(--gold),
    0 0 15px rgba(199, 164, 93, 0.55);
}

.position-control.target .dot.selected {
  background: #b8d1b6;
  box-shadow:
    0 0 0 2px var(--green),
    0 0 15px rgba(111, 145, 112, 0.45);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 0.88rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.legend-token {
  display: inline-grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--line-bright);
  color: var(--text);
}

.legend-token.same {
  color: var(--gold-light);
}

.legend-token.opposite {
  color: #d98a7c;
}

.matrix-scroll {
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  border: 1px solid var(--line);
}

.relation-matrix {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  background: #0c0e0c;
}

.relation-matrix th,
.relation-matrix td {
  padding: 10px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.relation-matrix tr:last-child th,
.relation-matrix tr:last-child td {
  border-bottom: 0;
}

.relation-matrix th:last-child,
.relation-matrix td:last-child {
  border-right: 0;
}

.relation-matrix thead th {
  color: var(--muted);
  background: #151815;
  font-size: 0.78rem;
}

.relation-matrix tbody th {
  min-width: 158px;
  color: var(--text);
  background: #151815;
  text-align: left;
  font-size: 0.84rem;
}

.relation-matrix select {
  width: 56px;
  height: 38px;
  border: 1px solid var(--line-bright);
  border-radius: 0;
  background: var(--panel-soft);
  text-align: center;
}

.relation-matrix select[data-value="1"] {
  border-color: #8d7649;
  color: var(--gold-light);
}

.relation-matrix select[data-value="-1"] {
  border-color: #754a44;
  color: #e6a094;
}

.relation-matrix select:disabled {
  border-color: #4e554e;
  color: #c6c9c4;
  opacity: 1;
}

.info-box {
  margin-top: 18px;
  padding: 16px 18px;
  border-left: 3px solid var(--gold);
  color: var(--muted);
  background: rgba(199, 164, 93, 0.07);
  font-size: 0.91rem;
  line-height: 1.6;
}

.info-box strong {
  color: var(--text);
}

.solver-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.solver-status {
  min-height: 24px;
  margin-top: 18px;
  color: var(--muted);
}

.solver-status.error {
  color: #e89b8d;
}

.solver-status.success {
  color: #b8d1b6;
}

.result {
  margin-top: 22px;
  border-top: 1px solid var(--line);
  padding-top: 24px;
}

.result-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.summary-card {
  padding: 16px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
}

.summary-card span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.summary-card strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.55rem;
  font-weight: 500;
}

.combination-box {
  margin-bottom: 20px;
  padding: 18px;
  border: 1px solid #75643e;
  background: rgba(199, 164, 93, 0.07);
}

.combination-box h3,
.steps-title {
  margin-bottom: 10px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.13rem;
  font-weight: 500;
}

.combination {
  margin: 0;
  color: var(--gold-light);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 1rem;
  line-height: 1.8;
  overflow-wrap: anywhere;
}

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

.solution-step {
  display: grid;
  grid-template-columns: 42px minmax(145px, 0.8fr) 1fr;
  align-items: center;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.018);
}

.step-number {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line-bright);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.step-action {
  font-weight: 850;
}

.step-action .arrow {
  color: var(--gold-light);
  font-size: 1.25rem;
}

.step-state {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.state-chip {
  padding: 5px 8px;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #0b0c0b;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.76rem;
}

.state-chip.changed {
  border-color: #75643e;
  color: var(--gold-light);
}

.solved-message {
  padding: 18px;
  border: 1px solid var(--green);
  color: #c9dec7;
  background: rgba(111, 145, 112, 0.09);
}

footer {
  padding: 26px 10px 0;
  color: #72756f;
  font-size: 0.8rem;
  text-align: center;
}

@media (max-width: 720px) {
  .page-shell {
    width: min(calc(100% - 20px), 1160px);
    padding-top: 34px;
  }

  .section-heading,
  .count-control {
    align-items: stretch;
  }

  .section-heading {
    flex-direction: column;
  }

  .section-heading .button {
    align-self: flex-start;
  }

  .count-control {
    grid-template-columns: 1fr;
  }

  .number-field {
    width: 134px;
  }

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

  .solution-step {
    grid-template-columns: 36px 1fr;
  }

  .step-state {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
