:root {
  --ink: #1f2a1f;
  --muted: #647264;
  --line: #d6e0d1;
  --paper: #fffaf0;
  --cream: #f4ead7;
  --sky: #cce8e5;
  --sky-deep: #6da9a5;
  --grass: #73a942;
  --grass-deep: #31572c;
  --soil: #9b6641;
  --shadow: 0 18px 45px rgba(49, 87, 44, 0.12);
  color: var(--ink);
  background: var(--paper);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
  line-height: 1.65;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 0; overflow-x: hidden; background: var(--paper); }
button, input, select { font: inherit; }
button, select, input { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
:focus-visible { outline: 3px solid #e09f3e; outline-offset: 3px; }
[hidden] { display: none !important; }

.site-header {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background: var(--sky);
  border-bottom: 8px solid var(--grass-deep);
}

.site-header::before,
.site-header::after {
  position: absolute;
  z-index: -1;
  content: "";
  width: 180px;
  height: 180px;
  background: rgba(255, 250, 240, 0.52);
  transform: rotate(45deg);
}

.site-header::before { top: -130px; left: 12%; }
.site-header::after { right: 5%; bottom: -160px; }
.header-rail { height: 14px; background: repeating-linear-gradient(90deg, var(--grass) 0 56px, #9acb66 56px 88px); border-bottom: 4px solid rgba(49, 87, 44, 0.25); }
.hero-wrap { display: grid; grid-template-columns: minmax(0, 0.95fr) minmax(300px, 1.05fr); gap: clamp(24px, 5vw, 80px); align-items: center; width: min(1180px, calc(100% - 40px)); min-height: 440px; margin: 0 auto; padding: 56px 0 48px; }
.hero-copy { position: relative; z-index: 1; }
.eyebrow, .section-kicker, .layer-label { margin: 0 0 10px; color: var(--grass-deep); font-size: 0.75rem; font-weight: 800; letter-spacing: 0.14em; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { max-width: 11ch; margin: 0; color: var(--grass-deep); font-size: clamp(2.35rem, 7vw, 5.25rem); line-height: 1.04; letter-spacing: -0.07em; }
.hero-lead { max-width: 28rem; margin: 22px 0 8px; font-size: clamp(1.2rem, 2vw, 1.6rem); font-weight: 800; line-height: 1.45; }
.hero-note { max-width: 34rem; margin: 0; color: #48684e; font-size: 0.95rem; }
.hero-jump { display: inline-flex; align-items: center; gap: 12px; min-height: 46px; margin-top: 28px; padding: 8px 18px; color: var(--paper); background: var(--grass-deep); border-radius: 999px; font-weight: 800; text-decoration: none; box-shadow: 0 5px 0 #233e22; transition: transform 160ms ease, box-shadow 160ms ease; }
.hero-jump:hover { transform: translateY(-2px); box-shadow: 0 7px 0 #233e22; }
.hero-art { position: relative; min-width: 0; }
.hero-art img { display: block; width: 100%; height: auto; max-height: 390px; object-fit: contain; object-position: center; mix-blend-mode: multiply; }
.hero-art-label { position: absolute; right: 5%; bottom: 8%; padding: 10px 12px; color: var(--paper); background: var(--soil); border: 3px solid var(--paper); font-size: 0.72rem; font-weight: 900; line-height: 1.2; letter-spacing: 0.1em; transform: rotate(-6deg); }

main { width: min(1180px, calc(100% - 40px)); margin: 0 auto; }
.workbench, .results, .storage-strip, .guide { padding: clamp(48px, 7vw, 92px) 0; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
.section-heading h2, .storage-strip h2, .guide h2 { margin: 0; font-size: clamp(1.65rem, 3vw, 2.55rem); line-height: 1.2; letter-spacing: -0.055em; }
.section-hint, .shape-summary { margin: 0; color: var(--muted); font-size: 0.88rem; }

.control-board { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 0.75fr); gap: 24px; padding: clamp(20px, 3vw, 36px); background: var(--cream); border: 2px solid var(--ink); box-shadow: 8px 8px 0 var(--soil); }
.control-main { display: grid; gap: 16px; }
.field-row { display: grid; gap: 8px; }
.field-pair { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field-label { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 0.86rem; font-weight: 900; }
.field-label span { color: var(--muted); font-size: 0.74rem; font-weight: 600; }
input[type="number"], select { width: 100%; min-height: 48px; padding: 8px 12px; color: var(--ink); background: var(--paper); border: 2px solid var(--ink); border-radius: 3px; font-size: 1rem; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--grass-deep) 50%), linear-gradient(135deg, var(--grass-deep) 50%, transparent 50%); background-position: calc(100% - 18px) 21px, calc(100% - 12px) 21px; background-repeat: no-repeat; background-size: 6px 6px, 6px 6px; }
.input-with-unit { display: flex; align-items: center; gap: 10px; }
.input-with-unit span { color: var(--muted); font-size: 0.82rem; white-space: nowrap; }
.mode-control { min-width: 0; margin: 0; padding: 0; border: 0; }
.mode-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
.mode-option { display: flex; min-height: 78px; align-items: center; gap: 10px; padding: 12px; background: var(--paper); border: 2px solid var(--line); border-radius: 3px; }
.mode-option:has(input:checked) { border-color: var(--grass-deep); box-shadow: inset 0 -4px 0 var(--grass); }
.mode-option input { flex: 0 0 auto; width: 20px; height: 20px; accent-color: var(--grass-deep); }
.mode-option span { display: grid; gap: 1px; }
.mode-option strong { font-size: 0.95rem; }
.mode-option small { color: var(--muted); font-size: 0.72rem; line-height: 1.35; }
.formula-note { margin: 22px 0 0; padding-top: 15px; color: var(--muted); border-top: 1px dashed #b6c5b4; font-size: 0.78rem; }
.status { min-height: 29px; margin-top: 19px; padding: 8px 12px; color: var(--muted); font-size: 0.85rem; }
.status[data-kind="error"] { color: #9d3527; background: #fff0ed; border-left: 4px solid #d45b49; }
.status[data-kind="success"] { color: var(--grass-deep); background: #edf6e9; border-left: 4px solid var(--grass); }

.results { padding-top: 24px; }
.results-heading { margin-bottom: 18px; }
.results-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.7fr); gap: 24px; align-items: stretch; }
.layer-stage { min-width: 0; padding: clamp(16px, 3vw, 30px); background: #e9f1eb; border: 2px solid var(--grass-deep); box-shadow: var(--shadow); }
.layer-toolbar { display: flex; justify-content: space-between; align-items: start; gap: 16px; margin-bottom: 18px; }
.layer-toolbar h3 { margin: 0; font-size: clamp(1rem, 2vw, 1.35rem); }
.layer-label { margin-bottom: 3px; color: var(--sky-deep); font-size: 0.68rem; }
.layer-nav { display: flex; gap: 7px; }
.icon-button { display: grid; place-items: center; width: 46px; height: 46px; color: var(--grass-deep); background: var(--paper); border: 2px solid var(--grass-deep); border-radius: 3px; font-size: 1.25rem; font-weight: 900; }
.icon-button:hover:not(:disabled) { color: var(--paper); background: var(--grass-deep); }
.layer-preview { display: grid; min-height: min(62vw, 540px); max-height: 540px; place-items: center; overflow: auto; padding: 18px; background: var(--paper); border: 2px solid #b7cbbc; }
.layer-preview:empty::before { content: "DESIGN AREA"; color: #9aab9d; font-size: 0.78rem; font-weight: 800; letter-spacing: 0.16em; }
.layer-preview svg { display: block; width: min(100%, 540px); max-height: 510px; height: auto; }
.layer-preview .canvas-bg { fill: #fffaf0; }
.layer-preview .grid line { stroke: #cfdbd2; stroke-width: 1; }
.layer-preview .block-cell { fill: var(--grass); stroke: var(--grass-deep); stroke-width: 1; }
.layer-strip { display: flex; gap: 7px; overflow-x: auto; margin-top: 15px; padding: 2px 2px 9px; scrollbar-color: var(--grass) transparent; }
.layer-chip { flex: 0 0 auto; min-width: 45px; min-height: 44px; padding: 5px 9px; color: var(--grass-deep); background: var(--paper); border: 2px solid #aec3b0; border-radius: 2px; font-size: 0.82rem; font-weight: 800; }
.layer-chip.is-current { color: var(--paper); background: var(--grass-deep); border-color: var(--grass-deep); }
.layer-chip.is-complete { box-shadow: inset 0 -4px 0 var(--soil); }

.result-side { display: flex; min-width: 0; flex-direction: column; gap: 18px; padding: clamp(20px, 3vw, 30px); background: var(--grass-deep); color: var(--paper); box-shadow: var(--shadow); }
.count-hero { padding-bottom: 23px; border-bottom: 1px solid rgba(255, 250, 240, 0.28); }
.count-hero p { margin: 0; color: #c4dfac; font-size: 0.84rem; font-weight: 800; }
.count-hero strong { display: block; margin: 2px 0 1px; font-size: clamp(2.5rem, 6vw, 4.4rem); line-height: 1; letter-spacing: -0.07em; }
.count-hero span { color: #d7e6cf; font-size: 0.78rem; }
.metric-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin: 0; }
.metric-grid div { display: flex; justify-content: space-between; gap: 10px; padding-bottom: 10px; border-bottom: 1px dotted rgba(255, 250, 240, 0.32); }
.metric-grid dt { color: #c4dfac; font-size: 0.8rem; }
.metric-grid dd { margin: 0; color: var(--paper); font-size: 0.9rem; font-weight: 800; }
.result-actions { display: grid; gap: 9px; margin-top: auto; }
.button-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.button { display: inline-flex; min-height: 46px; align-items: center; justify-content: center; padding: 9px 13px; border: 2px solid transparent; border-radius: 3px; font-size: 0.84rem; font-weight: 900; text-align: center; transition: transform 150ms ease, background 150ms ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button-primary { color: var(--grass-deep); background: var(--paper); border-color: var(--paper); }
.button-secondary { color: var(--paper); background: transparent; border-color: rgba(255, 250, 240, 0.7); }
.button-secondary:hover:not(:disabled) { background: rgba(255, 250, 240, 0.12); }
.button-quiet { color: var(--paper); background: transparent; border-color: transparent; text-decoration: underline; text-underline-offset: 3px; }

.storage-strip { display: flex; align-items: center; justify-content: space-between; gap: 30px; padding-block: 62px; border-block: 2px solid var(--line); }
.storage-strip h2 { font-size: clamp(1.35rem, 3vw, 2rem); }
.storage-strip p:not(.section-kicker) { max-width: 560px; margin: 8px 0 0; color: var(--muted); font-size: 0.86rem; }
.storage-actions { display: grid; grid-template-columns: repeat(3, max-content); gap: 9px; }
.storage-actions .button-primary { color: var(--paper); background: var(--grass-deep); border-color: var(--grass-deep); }
.storage-actions .button-secondary, .storage-actions .button-quiet { color: var(--grass-deep); border-color: var(--grass-deep); }
.storage-actions .button-quiet { border-color: transparent; }
.guide-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-top: 28px; }
.guide-grid article { position: relative; min-width: 0; padding: 24px; background: var(--cream); border-top: 6px solid var(--grass); }
.guide-grid article:nth-child(2) { border-top-color: var(--sky-deep); }
.guide-grid article:nth-child(3) { border-top-color: var(--soil); }
.guide-grid span { color: var(--muted); font-size: 0.75rem; font-weight: 900; letter-spacing: 0.1em; }
.guide-grid h3 { margin: 9px 0 4px; font-size: 1.15rem; }
.guide-grid p { margin: 0; color: var(--muted); font-size: 0.86rem; }

.site-footer { display: grid; gap: 3px; padding: 38px max(20px, calc((100vw - 1180px) / 2)); color: #dce8d9; background: var(--grass-deep); font-size: 0.8rem; }
.site-footer p { margin: 0; }
.site-footer p:first-child { color: var(--paper); font-size: 1rem; font-weight: 900; }
.footer-small { color: #b8d0b4; font-size: 0.72rem; }

@media (max-width: 820px) {
  .hero-wrap { grid-template-columns: 1fr; min-height: auto; padding-top: 46px; }
  .hero-art { max-width: 650px; margin-inline: auto; }
  .hero-art img { max-height: 300px; }
  .control-board, .results-grid { grid-template-columns: 1fr; }
  .result-side { min-height: 0; }
  .storage-strip { align-items: start; flex-direction: column; }
  .storage-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; }
}

@media (max-width: 540px) {
  main, .hero-wrap { width: min(100% - 24px, 1180px); }
  .header-rail { height: 10px; }
  .hero-wrap { gap: 24px; padding: 35px 0 32px; }
  h1 { font-size: clamp(2.25rem, 15vw, 4rem); }
  .hero-lead { margin-top: 16px; font-size: 1.1rem; }
  .hero-art-label { right: 1%; bottom: 3%; }
  .workbench, .results, .storage-strip, .guide { padding-block: 42px; }
  .section-heading { display: block; }
  .section-hint, .shape-summary { margin-top: 10px; }
  .control-board { padding: 18px 15px; box-shadow: 5px 5px 0 var(--soil); }
  .field-pair, .mode-options { grid-template-columns: 1fr; }
  .layer-stage, .result-side { padding: 15px; }
  .layer-preview { min-height: 260px; padding: 10px; }
  .layer-toolbar { align-items: center; }
  .button-row { grid-template-columns: 1fr; }
  .storage-actions, .guide-grid { grid-template-columns: 1fr; }
  .storage-actions { width: 100%; }
}

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

@media print {
  .site-header, .control-board, .status, .result-side, .storage-strip, .guide, .site-footer, .layer-strip, .layer-nav { display: none !important; }
  main { width: 100%; }
  .results { padding: 0; }
  .layer-stage { border: 0; box-shadow: none; }
  .layer-preview { max-height: none; border: 0; }
  .layer-preview svg { width: 160mm; max-height: 240mm; }
}
