:root {
  --ink: #19211f;
  --muted: #66706b;
  --line: #dce4df;
  --paper: #fbfcfa;
  --surface: #ffffff;
  --forest: #245a48;
  --leaf: #7fa35b;
  --clay: #b76548;
  --water: #4f88a5;
  --gold: #d5a94b;
  --shadow: 0 14px 32px rgba(28, 45, 38, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
}

a,
button {
  font: inherit;
}

.tool-header {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  align-items: start;
  gap: 24px;
  min-height: 112px;
  padding: 12px clamp(28px, 3.6vw, 56px);
  border-bottom: 1px solid var(--line);
  background: rgba(251, 252, 250, 0.96);
}

.brand-area {
  display: grid;
  justify-items: start;
  gap: 8px;
}

.brand {
  display: inline-flex;
  align-items: center;
  width: 316px;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--forest);
  color: #fff;
  font-weight: 850;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  line-height: 1.1;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
}

.figure-tabs {
  display: grid;
  grid-template-columns: repeat(3, 96px);
  gap: 8px;
  width: 316px;
}

.figure-tabs button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3f7f3;
  color: var(--forest);
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 850;
  line-height: 1;
}

.figure-tabs button:hover {
  border-color: rgba(36, 90, 72, 0.5);
}

.figure-tabs button.is-active {
  border-color: var(--forest);
  background: var(--forest);
  color: #fff;
}

.tool-header nav {
  display: grid;
  grid-template-columns: repeat(4, 118px);
  align-items: center;
  justify-content: end;
  gap: 10px;
}

.tool-header nav a,
.tool-header nav button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 118px;
  height: 42px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--forest);
  cursor: pointer;
  font-size: 0.98rem;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
}

.tool-shell {
  display: grid;
  grid-template-columns: minmax(380px, 0.78fr) minmax(560px, 1.22fr);
  gap: 18px;
  height: calc(100vh - 112px);
  padding: 18px;
}

.left-stack {
  display: grid;
  grid-template-rows: minmax(250px, 0.95fr) minmax(280px, 1.05fr);
  gap: 18px;
  min-height: 0;
}

.panel {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 16px;
  min-height: 76px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: #f3f7f3;
}

.figure-heading {
  min-height: 96px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--forest);
  font-size: 0.74rem;
  font-weight: 850;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.2;
}

.paper-label {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.panel-heading span {
  align-self: start;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
  white-space: nowrap;
}

pre {
  width: 100%;
  height: calc(100% - 76px);
  margin: 0;
  padding: 18px;
  border: 0;
  outline: 0;
  resize: none;
  background: #fcfdfb;
  color: var(--ink);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 0.92rem;
  line-height: 1.58;
  tab-size: 2;
}

.sheet-wrap {
  height: calc(100% - 76px);
  overflow: auto;
  background: #fcfdfb;
}

.sheet-table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.92rem;
}

.sheet-table th,
.sheet-table td {
  height: 38px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.sheet-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #eef4ef;
  color: #3f4b46;
  font-size: 0.82rem;
  font-weight: 850;
  text-align: left;
}

.sheet-table th:first-child,
.sheet-table td:first-child {
  width: 42px;
  background: #f3f7f3;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.sheet-table input {
  width: 100%;
  height: 37px;
  padding: 0 10px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
}

.sheet-table input:focus {
  box-shadow: inset 0 0 0 2px var(--forest);
  background: #fbfffb;
}

.sheet-table input[data-field="mean"],
.sheet-table input[data-field="se"],
.sheet-table input[data-field="biochar_rate"],
.sheet-table input[data-field="duration_year"],
.sheet-table input[data-field="response_ratio"] {
  font-family: "Cascadia Mono", Consolas, monospace;
  text-align: right;
}

.figure-heading + .figure-stage {
  height: calc(100% - 96px - 70px);
}

pre {
  overflow: auto;
  white-space: pre;
}

.figure-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.figure-stage {
  min-height: 0;
  padding: 18px;
}

#figure-svg {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

#figure-svg[hidden] {
  display: none;
}

.note {
  min-height: 70px;
  margin: 0;
  padding: 12px 18px 16px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

@media (max-width: 1100px) {
  .tool-header {
    grid-template-columns: 1fr;
  }

  .tool-header nav {
    justify-content: start;
  }

  .brand {
    width: min(100%, 316px);
  }

  .figure-tabs {
    width: min(100%, 316px);
  }

  .tool-shell {
    grid-template-columns: 1fr;
    height: auto;
  }

  .left-stack {
    grid-template-rows: 320px 380px;
  }

  .figure-panel {
    min-height: 560px;
  }
}

@media (max-width: 620px) {
  .tool-header nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .tool-header nav a,
  .tool-header nav button {
    width: 100%;
    min-width: 0;
  }

  .figure-tabs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
