@import url('../toolbox/theme.css');

:root {
  color-scheme: light;
  --canvas: #f5f3eb;
  --card: #fffefa;
  --ink: #272e27;
  --muted: #5d665d;
  --line: #dedfd4;
  --green: #274539;
  --green-deep: #1d382e;
  --sage: #e7eddf;
  --clay: #98503a;
  --clay-pale: #f7ebe2;
  --error: #973e2c;
  --control-surface: #fbfbf6;
  --hover-surface: #eeefe7;
  --status-dot: #597a58;
  --radius: 18px;
  --display: Georgia, 'Times New Roman', serif;
  --body: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.screen-reader-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 0.9375rem/1.55 var(--body);
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
button, input { min-width: 0; }
:focus-visible { outline: 2px solid var(--clay); outline-offset: 3px; }
p, dl, dd, h1, h2, h3 { margin: 0; }
fieldset { padding: 0; border: 0; min-inline-size: 0; margin: 0; }

.shell { width: min(1120px, calc(100% - 3.5rem)); margin-inline: auto; }
.masthead { border-bottom: 1px solid var(--line); }
.masthead-inner, .wordmark, .local { display: flex; align-items: center; }
.masthead-inner { min-height: 65px; justify-content: space-between; gap: 1rem; }
.wordmark { min-height: 44px; gap: .55rem; color: var(--green); font-family: 'Avenir Next', system-ui, sans-serif; font-weight: 650; letter-spacing: -.025em; text-decoration: none; }
.wordmark:hover, .wordmark:focus-visible { text-decoration: underline; text-underline-offset: 0.2em; }
.mark {
  flex: 0 0 2rem;
  width: 2rem;
  height: 2rem;
  background: url('../toolbox/brand-mark.png') center / contain no-repeat;
}
.local { gap: 0.44rem; font-size: 0.8rem; color: var(--muted); }
.local span { width: 7px; height: 7px; border-radius: 50%; background: var(--status-dot); }
.site-footer { border-top: 1px solid var(--line); }
.footer-links { display: flex; flex-wrap: wrap; gap: 0 1.5rem; padding-block: .55rem; }
.footer-links a { display: inline-flex; align-items: center; min-height: 44px; color: var(--green); font-weight: 650; text-underline-offset: .2em; }

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  align-items: center;
  gap: 2rem;
  min-height: 224px;
  padding: 2rem 0;
}
.intro h1 { font: 400 clamp(2.9rem, 5.7vw, 5.25rem)/0.99 var(--display); letter-spacing: -0.064em; }
.intro p { margin-top: 1rem; color: var(--muted); font-size: 1.07rem; }
.guide-link { display: inline-flex; align-items: center; min-height: 44px; color: var(--green); text-underline-offset: .2em; }

.swatches { position: relative; height: 143px; overflow: hidden; border-radius: 12px; background: #ebe7d8; }
[data-theme="dark"] .swatches { background: #363b35; }
.swatch { position: absolute; width: 141px; height: 170px; transform: rotate(-12deg); border-radius: 7px; }
.swatch-clay {
  top: 22px;
  left: 18px;
  background: repeating-linear-gradient(90deg, #b87759 0 8px, #dfa88a 8px 17px, #e9c0a3 17px 19px, #dfa88a 19px 25px);
  box-shadow: 0 9px 18px #5e45301f;
}
.swatch-green {
  top: -30px;
  right: 19px;
  width: 155px;
  height: 200px;
  transform: rotate(13deg);
  background-color: #315445;
  background-image:
    radial-gradient(ellipse at 0 50%, transparent 48%, #bec8a2 49% 52%, transparent 54%),
    radial-gradient(ellipse at 100% 50%, transparent 48%, #bec8a2 49% 52%, transparent 54%),
    radial-gradient(ellipse at 50% 0, transparent 49%, #789073 50% 54%, transparent 56%),
    radial-gradient(ellipse at 50% 100%, transparent 49%, #789073 50% 54%, transparent 56%);
  background-size: 35px 42px;
  box-shadow: 0 9px 18px #303e2a2e;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.22fr) minmax(0, 1fr);
  align-items: start;
  gap: 1.25rem;
  padding-bottom: 4rem;
}
.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.planning-example { max-width: 48rem; margin-bottom: clamp(2rem, 6vw, 4rem); padding: clamp(1rem, 3.5vw, 1.6rem); }
.planning-example p { margin-top: .7rem; }
.planning-example a { color: var(--green); text-underline-offset: .2em; }
.input-card { padding: 1.6rem; }
.section-heading h2, .results-header h2 {
  font: 400 clamp(1.65rem, 2.5vw, 2rem)/1.1 var(--display);
  letter-spacing: -0.048em;
}
.section-heading p { margin-top: 0.38rem; color: var(--muted); font-size: 0.87rem; }
.measurement-heading { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 0.85rem 1rem; }
.unit-field { flex: 0 0 136px; }
.feet-example { margin-top: 0.7rem; color: var(--muted); font-size: 0.8rem; }

.field-grid, .roll-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.68rem;
}
.field-grid { margin-top: 1.35rem; row-gap: 0.9rem; }
.field label, legend { display: block; margin-bottom: 0.38rem; font-size: 0.79rem; font-weight: 650; }
.field input, .field select {
  display: block;
  width: 100%;
  height: 44px;
  padding: 0 0.72rem;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  background: var(--control-surface);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.field input::placeholder { color: var(--muted); }
.field select { cursor: pointer; }
.field input[aria-invalid="true"] { border-color: var(--clay); background-color: var(--clay-pale); }
.measurement { position: relative; }
.measurement input { padding-right: 2.5rem; }
.measurement span {
  position: absolute;
  top: 50%;
  right: 0.65rem;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.72rem;
  pointer-events: none;
}
.field-error { margin-top: 0.33rem; color: var(--error); font-size: 0.76rem; }

.pattern-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: start;
  gap: 0.8rem 1rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.match-options { display: flex; gap: 3px; padding: 3px; background: var(--hover-surface); border-radius: 9px; }
.match-options label { position: relative; cursor: pointer; }
.match-options input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.match-options span {
  display: grid;
  min-height: 38px;
  padding: 0 0.85rem;
  border-radius: 7px;
  place-items: center;
  color: var(--muted);
  font-size: 0.81rem;
  font-weight: 650;
}
.match-options input:checked + span { background: var(--green); color: var(--action-ink); }
.match-options input:focus-visible + span { outline: 2px solid var(--clay); outline-offset: 2px; }
.repeat-field { flex: 0 1 145px; }
.pattern-help { max-width: 52ch; margin-top: 0.65rem; color: var(--muted); font-size: 0.8rem; }
.plan-link {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  margin-top: 0.5rem;
  padding: 0.35rem 0.8rem;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  background: var(--sage);
  color: var(--green-deep);
  font-size: 0.83rem;
  font-weight: 660;
  text-decoration: none;
}
.plan-link:hover { background: var(--hover-surface); }
#results-title { scroll-margin-top: 1rem; }

.stock-card { margin-top: 1rem; }
.stock-heading { display: flex; justify-content: space-between; align-items: start; gap: 0.8rem; }
.add-button {
  flex: none;
  min-height: 44px;
  padding: 0 0.84rem;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  background: var(--sage);
  color: var(--green-deep);
  font-weight: 660;
  font-size: 0.84rem;
}
.add-button span { font-size: 1.05em; padding-right: 0.18rem; }
.add-button:hover { background: var(--hover-surface); }
.motif-help { margin-top: 1rem; padding: 0.65rem 0.85rem; border-radius: 8px; background: var(--hover-surface); font-size: 0.81rem; }
.roll { position: relative; padding: 0.2rem 0.85rem 0.85rem; margin-top: 1.25rem; border: 1px solid var(--line); border-radius: 10px; }
.roll legend { max-width: calc(100% - 5rem); padding: 0 0.35rem; color: var(--green); overflow-wrap: anywhere; }
.roll-fields { grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); margin-top: 0.32rem; }
.remove-roll {
  position: absolute;
  top: -1.48rem;
  right: 0.45rem;
  min-height: 34px;
  padding: 0 0.32rem;
  border: 0;
  background: var(--card);
  color: var(--clay);
  font-size: 0.75rem;
}
.remove-roll:hover { text-decoration: underline; }
.roll-status { display: flex; flex-wrap: wrap; gap: 0.25rem 0.7rem; margin-top: 0.65rem; font-size: 0.78rem; color: var(--muted); }
.roll-status strong { color: var(--green); }
.roll[data-status="measure"] .roll-status strong, .roll[data-status="invalid"] .roll-status strong { color: var(--clay); }

.results-card { overflow: hidden; }
.results-header { padding: 1.6rem 1.45rem 1.4rem; background: var(--result-surface); color: #fcfaf1; }
.totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 1.3rem; }
.totals > div { display: flex; flex-direction: column; justify-content: space-between; min-width: 0; padding: 0 0.75rem; border-left: 1px solid #ffffff40; }
.totals > div:first-child { padding-left: 0; border: 0; }
.totals dt { font-size: 0.76rem; color: #e4ebdd; font-weight: 540; }
.totals dd {
  font: 400 clamp(1.75rem, 4vw, 2.7rem)/1.15 var(--display);
  letter-spacing: -0.045em;
  overflow-wrap: anywhere;
  font-variant-numeric: lining-nums tabular-nums;
}
.totals dd.long-number { font-size: 1.25rem; line-height: 1.25; margin-top: 0.35rem; }
.results-body { padding: 1.3rem 1.45rem 1.45rem; }
.result-status { color: var(--muted); font-size: 0.89rem; }
.dimensions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.65rem;
  padding: 0.15rem 0 0.8rem;
}
.result-status:not([hidden]) + #plan .dimensions { padding-top: 0.8rem; margin-top: 0.6rem; border-top: 1px solid var(--line); }
.dimensions dt { color: var(--muted); font-size: 0.76rem; }
.dimensions dd { font-weight: 660; overflow-wrap: anywhere; }
.message { font-size: 0.84rem; color: var(--clay); margin-bottom: 0.6rem; }
.narrow-warning { padding: 0.6rem 0.75rem; border-radius: 8px; background: var(--clay-pale); }
.shopping {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.8rem 0.95rem;
  margin: 0.35rem 0 1.3rem;
  border-radius: 10px;
  background: var(--sage);
  color: var(--green-deep);
}
.shopping h3, .cut-section h3 { font-size: 0.9rem; font-weight: 680; }
.shopping p { margin-top: 0.24rem; font-size: 0.77rem; color: var(--muted); }
.buy-number { font: 400 2.1rem/1 var(--display); text-align: right; overflow-wrap: anywhere; }
.buy-number.long-number { font-size: 1.2rem; }
.muted, .table-note { color: var(--muted); margin-top: 0.22rem; font-size: 0.79rem; }
.table-wrap { overflow: auto; margin-top: 0.58rem; }
table { width: 100%; border-collapse: collapse; font-size: 0.79rem; font-variant-numeric: tabular-nums; }
th, td { padding: 0.46rem 0.33rem; border-bottom: 1px solid var(--line); text-align: right; }
th { background: var(--hover-surface); color: var(--muted); font-weight: 650; }
th:nth-child(2), td:nth-child(2) { text-align: left; overflow-wrap: anywhere; max-width: 115px; }
td:not(:nth-child(2)) { white-space: nowrap; }
.cut-label { display: none; }
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 0.55rem; margin-top: 0.8rem; font-size: 0.77rem; }
.pagination button { padding: 0.35rem 0.5rem; min-height: 36px; border: 1px solid var(--line); border-radius: 6px; color: var(--green); background: var(--card); }
.pagination button:disabled { color: var(--muted); background: var(--hover-surface); }

@media (max-width: 860px) {
  .intro { grid-template-columns: minmax(0, 1fr) 160px; min-height: 180px; }
  .swatch-green { right: -65px; }
  .swatch-clay { left: -28px; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 560px) {
  .shell { width: calc(100% - 2rem); }
  .masthead-inner { min-height: 56px; }
  .intro { display: block; min-height: 0; padding: 2.1rem 0 1.7rem; }
  .intro h1 { font-size: clamp(2.6rem, 11vw, 3.4rem); max-width: 330px; }
  .intro p { margin-top: 0.72rem; font-size: 0.94rem; }
  .swatches { display: none; }
  .workspace { gap: 1rem; padding-bottom: 2rem; }
  .input-card, .results-header, .results-body { padding: 1.05rem; }
  .field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; margin-top: 0.8rem; }
  .field input, .field select { font-size: 1rem; }
  .section-heading p { font-size: 0.82rem; }
  .totals dd { font-size: 2.1rem; }

  .table-wrap table { display: block; }
  .table-wrap thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .table-wrap tbody { display: grid; gap: 0.55rem; }
  .table-wrap tbody tr {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.6rem 0.4rem;
    padding: 0.65rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--control-surface);
  }
  .table-wrap tbody td {
    min-width: 0;
    padding: 0;
    border: 0;
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .table-wrap tbody td:nth-child(2) { grid-column: span 2; max-width: none; }
  .cut-label { display: block; color: var(--muted); font-size: 0.73rem; font-weight: 600; }
  .cut-value { display: block; font-weight: 630; }
}

@media (max-width: 350px) {
  .measurement input { padding-inline: 0.5rem 1.7rem; }
  .measurement span { right: 0.38rem; }
  .stock-heading { flex-wrap: wrap; }
  .totals { gap: 0.4rem; }
  .totals > div { padding-inline: 0.32rem; }
}
