:root {
  --ink: #211b18;
  --muted: #6f625a;
  --paper: #fbf7ef;
  --paper-deep: #efe2ce;
  --line: #d9cbb9;
  --sage: #547866;
  --sage-dark: #25483a;
  --rose: #b55e5a;
  --gold: #c0913f;
  --blue: #355b7a;
  --white: #fffdf8;
  --shadow: 0 24px 70px rgba(50, 35, 23, 0.14);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Manrope", system-ui, sans-serif;
}

button,
input {
  font: inherit;
}

.site-header {
  position: fixed;
  inset: 0 0 auto;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px clamp(18px, 4vw, 56px);
  background: rgba(251, 247, 239, 0.88);
  border-bottom: 1px solid rgba(33, 27, 24, 0.1);
  backdrop-filter: blur(16px);
}

.brand {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  color: var(--white);
  text-decoration: none;
  background: var(--ink);
  border-radius: 50%;
  font-family: "Cinzel", Georgia, serif;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0;
}

.main-nav {
  display: flex;
  gap: 10px;
}

.main-nav a,
.hero__button,
button {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  color: var(--white);
  text-decoration: none;
  background: var(--sage-dark);
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

.main-nav a:hover,
.hero__button:hover,
button:hover {
  background: var(--sage);
}

.hero {
  position: relative;
  min-height: 92vh;
  display: grid;
  align-items: center;
  padding: 112px clamp(20px, 6vw, 84px) 58px;
  overflow: hidden;
}

.hero__art {
  position: absolute;
  inset: 84px clamp(16px, 4vw, 48px) 24px;
  border: 1px solid rgba(33, 27, 24, 0.12);
  border-radius: 8px;
  background:
    radial-gradient(circle at 82% 22%, rgba(192, 145, 63, 0.32), transparent 24%),
    linear-gradient(135deg, rgba(181, 94, 90, 0.2), transparent 40%),
    var(--white);
  box-shadow: var(--shadow);
}

.grid-paper {
  position: absolute;
  inset: 0;
  opacity: 0.5;
  background-image:
    linear-gradient(rgba(84, 120, 102, 0.18) 1px, transparent 1px),
    linear-gradient(90deg, rgba(84, 120, 102, 0.18) 1px, transparent 1px);
  background-size: 42px 42px;
}

.ink-line {
  position: absolute;
  height: 3px;
  background: var(--ink);
  transform-origin: left center;
}

.ink-line--one {
  width: 42%;
  right: 9%;
  top: 31%;
  transform: rotate(-7deg);
}

.ink-line--two {
  width: 26%;
  right: 19%;
  top: 42%;
  background: var(--rose);
  transform: rotate(-7deg);
}

.ink-line--three {
  width: 34%;
  right: 13%;
  top: 55%;
  background: var(--blue);
  transform: rotate(-7deg);
}

.hero__content {
  position: relative;
  max-width: 900px;
}

.hero__eyebrow,
.section-kicker {
  margin: 0 0 18px;
  color: var(--rose);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  max-width: 880px;
  margin: 0 0 24px;
  font-family: "Cinzel", "Libre Baskerville", Georgia, serif;
  font-size: clamp(3rem, 6.4vw, 5.8rem);
  line-height: 0.98;
  letter-spacing: 0;
  text-wrap: balance;
}

.hero__button {
  width: max-content;
  min-width: 170px;
}

.method {
  min-height: 100vh;
  padding: 28px clamp(18px, 4vw, 56px) 56px;
  background: linear-gradient(180deg, var(--paper), var(--paper-deep));
}

.method__intro {
  max-width: 780px;
  margin-bottom: 28px;
}

h2 {
  margin: 0 0 12px;
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: clamp(2rem, 4vw, 3.4rem);
  letter-spacing: 0;
}

.method__intro p:last-child {
  max-width: 660px;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 14px;
  margin-bottom: 22px;
}

.controls label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

input {
  width: 112px;
  min-height: 44px;
  padding: 8px 10px;
  color: var(--ink);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.button-secondary {
  color: var(--sage-dark);
  background: transparent;
  border-color: var(--sage);
}

.button-secondary:hover {
  color: var(--white);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 22px;
  align-items: start;
}

.table-panel,
.results {
  background: rgba(255, 253, 248, 0.82);
  border: 1px solid rgba(33, 27, 24, 0.12);
  border-radius: 8px;
  box-shadow: 0 16px 50px rgba(50, 35, 23, 0.1);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  padding: 0 0 12px;
}

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

th,
td {
  min-width: 116px;
  height: 94px;
  border: 1px solid var(--line);
  text-align: center;
  vertical-align: middle;
}

th {
  height: 56px;
  color: var(--sage-dark);
  background: rgba(84, 120, 102, 0.12);
  font-weight: 800;
}

td.corner-cell,
td.supply-cell,
td.demand-cell {
  min-width: 104px;
  font-weight: 800;
  background: rgba(192, 145, 63, 0.12);
}

.total-corner {
  position: relative;
  min-width: 116px;
  height: 94px;
  padding: 0;
  overflow: hidden;
  background: rgba(192, 145, 63, 0.12);
}

.total-corner::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 145%;
  height: 2px;
  background: var(--ink);
  transform: rotate(39deg);
  transform-origin: left top;
}

.total-corner__supply,
.total-corner__demand {
  position: absolute;
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 1.15rem;
  font-weight: 700;
}

.total-corner__supply {
  top: 16px;
  right: 14px;
}

.total-corner__demand {
  left: 14px;
  bottom: 16px;
}

.cost-cell {
  position: relative;
  background:
    repeating-linear-gradient(135deg, rgba(84, 120, 102, 0.08) 0 7px, transparent 7px 16px),
    var(--white);
  transition: box-shadow 160ms ease, background-color 160ms ease;
}

.cost-cell input {
  width: 58px;
  min-height: 34px;
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 4px 6px;
  border-color: transparent;
  background: rgba(255, 253, 248, 0.8);
  font-weight: 800;
}

.allocation {
  display: inline-grid;
  min-width: 62px;
  min-height: 40px;
  place-items: center;
  margin-top: 18px;
  color: var(--blue);
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 1.55rem;
  font-weight: 700;
}

.allocation.is-active {
  color: var(--ink);
  background: rgba(192, 145, 63, 0.22);
  border-radius: 8px;
}

.nw-marker {
  position: absolute;
  z-index: 3;
  top: 35px;
  left: -27px;
  width: 38px;
  height: 34px;
  background: #f4d533;
  border: 2px solid var(--ink);
  border-radius: 5px;
  box-shadow: 0 4px 0 var(--ink), 0 8px 16px rgba(33, 27, 24, 0.22);
  pointer-events: none;
}

.nw-marker::before,
.nw-marker::after {
  content: "";
  position: absolute;
  background: var(--ink);
}

.nw-marker::before {
  width: 16px;
  height: 8px;
  top: 12px;
  left: 9px;
  border-radius: 6px 2px 2px 6px;
}

.nw-marker::after {
  width: 14px;
  height: 14px;
  top: 9px;
  left: 18px;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.is-northwest {
  outline: 3px solid #f4d533;
  outline-offset: -4px;
}

.is-northwest-row,
.is-northwest-column {
  background:
    linear-gradient(rgba(244, 213, 51, 0.16), rgba(244, 213, 51, 0.16)),
    var(--white);
}

.cost-cell.is-northwest-row,
.cost-cell.is-northwest-column {
  background:
    linear-gradient(rgba(244, 213, 51, 0.2), rgba(244, 213, 51, 0.2)),
    repeating-linear-gradient(135deg, rgba(84, 120, 102, 0.08) 0 7px, transparent 7px 16px),
    var(--white);
}

.is-northwest-row.is-northwest-column {
  background:
    linear-gradient(rgba(244, 213, 51, 0.32), rgba(244, 213, 51, 0.32)),
    repeating-linear-gradient(135deg, rgba(84, 120, 102, 0.08) 0 7px, transparent 7px 16px),
    var(--white);
}

th.is-northwest-column,
td.corner-cell.is-northwest-row,
td.supply-cell.is-northwest-row,
td.demand-cell.is-northwest-column {
  background: rgba(244, 213, 51, 0.24);
}

.is-drop-ready {
  box-shadow: inset 0 0 0 5px rgba(244, 213, 51, 0.75);
}

.is-cancelled-row,
.is-cancelled-col {
  position: relative;
}

.is-cancelled-row::after,
.is-cancelled-col::before {
  content: "";
  position: absolute;
  z-index: 2;
  background: rgba(33, 27, 24, 0.78);
  pointer-events: none;
}

.is-cancelled-row::after {
  left: 8px;
  right: 8px;
  top: 50%;
  height: 3px;
  transform: translateY(-50%);
}

.is-cancelled-col::before {
  top: 8px;
  bottom: 8px;
  left: 50%;
  width: 3px;
  transform: translateX(-50%);
}

.supply-drag {
  cursor: grab;
  user-select: none;
}

.supply-drag:active {
  cursor: grabbing;
}

.remaining-trail {
  display: block;
  min-height: 22px;
  margin-top: 6px;
  color: var(--blue);
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 1rem;
  font-weight: 700;
}

.edge-input {
  width: 86px;
  text-align: center;
  font-weight: 800;
}

.results {
  padding: 22px;
}

.results h3 {
  margin: 0 0 18px;
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 1.5rem;
}

dl {
  display: grid;
  gap: 14px;
  margin: 0;
}

dl div {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

dt {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

dd {
  margin: 5px 0 0;
  font-family: "Libre Baskerville", Georgia, serif;
  font-size: 1.7rem;
  font-weight: 700;
}

.status {
  margin-top: 18px;
  padding: 14px;
  color: var(--sage-dark);
  background: rgba(84, 120, 102, 0.13);
  border-radius: 8px;
  line-height: 1.5;
}

.status.is-warning {
  color: #7a352c;
  background: rgba(181, 94, 90, 0.15);
}

@media (max-width: 860px) {
  .site-header {
    align-items: flex-start;
    gap: 14px;
  }

  .main-nav a {
    min-height: 40px;
    padding-inline: 12px;
    font-size: 0.86rem;
  }

  .hero {
    min-height: 88vh;
  }

  .hero__art {
    inset: 86px 10px 22px;
  }

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

  .results {
    order: -1;
  }
}

@media (max-width: 560px) {
  .site-header {
    padding: 12px;
  }

  .brand {
    width: 42px;
    height: 42px;
  }

  .hero {
    padding-inline: 18px;
  }

  h1 {
    font-size: clamp(2.28rem, 12vw, 4.2rem);
  }

  .controls {
    align-items: stretch;
  }

  .controls label,
  .controls button {
    flex: 1 1 150px;
  }

  input {
    width: 100%;
  }
}
