:root {
  --ink: #0f172a;
  --muted: #64748b;
  --line: #dbe3ee;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eff6ff;
  --danger: #b42318;
  --success: #067647;
  --shadow: 0 24px 70px rgba(15, 23, 42, 0.08);
  --radius: 20px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #fbfcfe;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: #fbfcfe; color: var(--ink); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(37, 99, 235, .24); outline-offset: 2px; }

.site-header {
  width: min(1380px, calc(100% - 40px));
  height: 76px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 760; letter-spacing: -.02em; }
.brand-mark { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
.github-link { display: inline-flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 15px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); text-decoration: none; font-weight: 700; transition: transform .15s ease, border-color .15s ease; }
.github-link:hover { transform: translateY(-1px); border-color: #b8c4d5; }
.github-link svg { width: 18px; height: 18px; fill: currentColor; }

main { width: min(1380px, calc(100% - 40px)); margin: 0 auto; }
.hero { padding: 40px 0 64px; }
.hero-copy { text-align: center; max-width: 760px; margin: 0 auto 30px; }
.hero-copy h1 { margin: 0; font-size: clamp(2.3rem, 4.6vw, 4.6rem); line-height: 1; letter-spacing: -.055em; }
.hero-copy p { margin: 18px auto 0; max-width: 690px; color: var(--muted); font-size: clamp(1rem, 1.6vw, 1.15rem); line-height: 1.65; }

.tool-shell { display: grid; grid-template-columns: minmax(380px, .86fr) minmax(480px, 1.14fr); overflow: hidden; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); box-shadow: var(--shadow); }
.controls { padding: 30px; border-right: 1px solid var(--line); }
.preview-panel { padding: 30px; min-width: 0; background: linear-gradient(180deg, #fbfdff 0%, #f5f8fc 100%); }

.mode-row { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; padding: 5px; margin-bottom: 28px; border-radius: 13px; background: #eef2f7; }
.mode-button { border: 0; border-radius: 9px; min-height: 40px; background: transparent; color: #536173; font-weight: 750; }
.mode-button.is-active { background: #fff; color: var(--ink); box-shadow: 0 2px 8px rgba(15, 23, 42, .08); }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.section-heading.compact { margin-bottom: 14px; }
.section-heading h2, .preview-head h2 { margin: 0; font-size: 1.08rem; letter-spacing: -.02em; }
.section-heading p { margin: 5px 0 0; color: var(--muted); font-size: .86rem; }
.unit-select { color: var(--muted); font-size: .78rem; font-weight: 750; text-transform: uppercase; letter-spacing: .06em; }
.unit-select select { display: block; margin-top: 5px; min-width: 94px; padding: 8px 30px 8px 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink); text-transform: none; letter-spacing: 0; font-weight: 700; }

.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.target-fields { margin-bottom: 14px; }
.field-grid label { display: grid; gap: 7px; }
.field-grid label[hidden] { display: none; }
.field-grid label span { color: #3b4656; font-size: .82rem; font-weight: 690; }
.field-grid label b { color: #8995a5; font-size: .72rem; font-weight: 650; }
.field-grid input { width: 100%; height: 44px; padding: 0 12px; border: 1px solid #cfd8e5; border-radius: 10px; background: #fff; color: var(--ink); transition: border-color .15s ease, box-shadow .15s ease; }
.field-grid input:hover { border-color: #aebacc; }
.field-grid input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .09); outline: 0; }

.divider { height: 1px; background: var(--line); margin: 26px 0; }
.pattern-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.pattern-option { position: relative; display: grid; place-items: center; gap: 7px; min-height: 75px; padding: 9px 4px; border: 1px solid var(--line); border-radius: 11px; color: #5c6878; background: #fff; font-size: .75rem; font-weight: 750; cursor: pointer; transition: border-color .15s ease, background .15s ease, color .15s ease; }
.pattern-option input { position: absolute; opacity: 0; pointer-events: none; }
.pattern-option.is-selected { border-color: #8eb4ff; background: var(--accent-soft); color: #174ea6; }
.pattern-icon { position: relative; width: 34px; height: 23px; display: block; opacity: .86; background-size: 8px 8px; }
.pattern-icon.straight { background: repeating-linear-gradient(90deg, transparent 0 5px, currentColor 5px 6px, transparent 6px 9px); }
.pattern-icon.diamond { background: linear-gradient(45deg, transparent 44%, currentColor 45% 51%, transparent 52%), linear-gradient(-45deg, transparent 44%, currentColor 45% 51%, transparent 52%); background-size: 12px 12px; }
.pattern-icon.cross::before, .pattern-icon.cross::after { content: ""; position: absolute; inset: 10px 2px auto; height: 2px; background: currentColor; box-shadow: 0 -8px currentColor, 0 8px currentColor; }
.pattern-icon.cross::after { transform: rotate(90deg); }
.pattern-icon.wave { background: radial-gradient(11px 6px at 50% 0, transparent 45%, currentColor 48% 56%, transparent 59%); background-size: 14px 10px; }
.pattern-fields { margin-top: 2px; }

.form-message, .action-message { min-height: 20px; margin-top: 12px; color: var(--muted); font-size: .78rem; line-height: 1.45; }
.form-message.error { color: var(--danger); }
.form-message.success, .action-message.success { color: var(--success); }
.primary-actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 3px; }
.primary-button, .secondary-button, .download-button, .ghost-button, .swatch-button { border-radius: 11px; font-weight: 760; transition: transform .15s ease, background .15s ease, border-color .15s ease; }
.primary-button { min-height: 46px; border: 0; background: var(--accent); color: #fff; }
.primary-button:hover { background: var(--accent-dark); transform: translateY(-1px); }
.secondary-button { min-width: 88px; border: 1px solid var(--line); background: #fff; color: #465365; }
.secondary-button:hover, .ghost-button:hover { border-color: #aebacc; }

.preview-head { display: flex; align-items: start; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.eyebrow { display: block; margin-bottom: 5px; color: var(--accent); font-size: .72rem; font-weight: 820; text-transform: uppercase; letter-spacing: .1em; }
.preview-scale { padding: 6px 9px; border-radius: 8px; background: #eaf0f8; color: #617083; font-size: .74rem; font-weight: 720; white-space: nowrap; }
.preview-stage { position: relative; height: 455px; display: grid; place-items: center; padding: 32px; overflow: hidden; border: 1px solid #d9e2ee; border-radius: 15px; background-color: #fff; background-image: linear-gradient(#edf1f6 1px, transparent 1px), linear-gradient(90deg, #edf1f6 1px, transparent 1px); background-size: 20px 20px; }
#preview-svg { display: block; max-width: 100%; max-height: 100%; filter: drop-shadow(0 8px 16px rgba(15, 23, 42, .09)); }
#preview-svg .sheet { fill: rgba(255, 255, 255, .94); stroke: #8fa0b4; stroke-width: .35; vector-effect: non-scaling-stroke; }
#preview-svg .cut { fill: none; stroke: #e11d48; stroke-width: .28; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
#preview-svg .dimension { fill: none; stroke: #2563eb; stroke-width: .3; stroke-dasharray: 2 2; vector-effect: non-scaling-stroke; }

.result-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.result-item { padding: 12px; border: 1px solid var(--line); border-radius: 11px; background: rgba(255,255,255,.82); }
.result-item span { display: block; margin-bottom: 5px; color: var(--muted); font-size: .7rem; }
.result-item strong { font-size: .9rem; letter-spacing: -.01em; }
.download-actions { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-top: 12px; }
.download-button, .ghost-button { min-height: 43px; border: 1px solid #cbd6e5; background: #fff; color: var(--ink); }
.download-button:hover { border-color: #87aaf1; background: #f7faff; }
.ghost-button { padding: 0 14px; color: #526174; }
.swatch-button { width: 100%; min-height: 60px; margin-top: 9px; padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; border: 1px dashed #9cb8e9; background: #f5f9ff; color: #194f9c; text-align: left; }
.swatch-button:hover { border-color: #6d99e8; background: #eef6ff; }
.swatch-button span { font-size: .87rem; }
.swatch-button small { color: #6b7d95; font-size: .72rem; font-weight: 650; }

.content-section { padding: 74px 0; border-top: 1px solid var(--line); }
.content-heading { max-width: 650px; margin-bottom: 28px; }
.content-heading h2, .formula-section h2 { margin: 0; font-size: clamp(1.75rem, 3vw, 2.6rem); letter-spacing: -.04em; }
.steps-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.steps-grid article { padding: 24px; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.steps-grid strong { display: grid; place-items: center; width: 32px; height: 32px; margin-bottom: 35px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); }
.steps-grid h3 { margin: 0 0 8px; font-size: 1rem; }
.steps-grid p { margin: 0; color: var(--muted); line-height: 1.65; font-size: .88rem; }
.formula-section { display: grid; grid-template-columns: 1fr 1fr; align-items: center; gap: 60px; }
.formula-section p { color: var(--muted); line-height: 1.7; }
.formula-card { display: grid; gap: 9px; padding: 20px; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.formula-card code { padding: 13px; border-radius: 9px; background: #f5f7fa; color: #334155; font-size: .82rem; overflow-wrap: anywhere; }

footer { width: min(1380px, calc(100% - 40px)); margin: 0 auto; padding: 30px 0 36px; border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem; text-align: center; }

@media (max-width: 980px) {
  .tool-shell { grid-template-columns: 1fr; }
  .controls { border-right: 0; border-bottom: 1px solid var(--line); }
  .preview-stage { height: 420px; }
  .result-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 700px) {
  .site-header, main, footer { width: min(100% - 24px, 1380px); }
  .site-header { height: 66px; }
  .brand span { font-size: .9rem; }
  .github-link span { display: none; }
  .github-link { width: 42px; justify-content: center; padding: 0; }
  .hero { padding: 30px 0 48px; }
  .hero-copy { margin-bottom: 22px; text-align: left; }
  .hero-copy h1 { font-size: clamp(2.35rem, 12vw, 3.45rem); }
  .hero-copy p { margin-top: 13px; font-size: .96rem; }
  .tool-shell { border-radius: 18px; }
  .controls, .preview-panel { padding: 20px; }
  .field-grid { grid-template-columns: 1fr; gap: 12px; }
  .pattern-picker { grid-template-columns: repeat(2, 1fr); }
  .pattern-option { min-height: 66px; }
  .preview-stage { height: 330px; padding: 22px; }
  .preview-head { align-items: center; }
  .download-actions { grid-template-columns: 1fr 1fr; }
  .ghost-button { grid-column: 1 / -1; }
  .swatch-button { align-items: flex-start; flex-direction: column; gap: 4px; }
  .steps-grid, .formula-section { grid-template-columns: 1fr; }
  .formula-section { gap: 28px; }
  .content-section { padding: 54px 0; }
}

@media (max-width: 430px) {
  .controls, .preview-panel { padding: 16px; }
  .mode-row { margin-bottom: 22px; }
  .section-heading { align-items: center; }
  .preview-stage { height: 280px; }
  .result-grid { grid-template-columns: 1fr 1fr; }
  .result-item { padding: 10px; }
  .primary-actions { grid-template-columns: 1fr; }
  .secondary-button { min-height: 42px; }
}
