:root {
    --bg: #f7f9f8;
    --surface: #ffffff;
    --surface-muted: #f4f7f5;
    --surface-strong: #edf3ef;
    --ink: #18211d;
    --ink-strong: #111915;
    --muted: #5b685f;
    --border: #cbd5cf;
    --border-light: #dce3df;
    --green: #178447;
    --green-dark: #0e6535;
    --green-soft: #e9f6ee;
    --coral: #dc665f;
    --coral-soft: #fff2f1;
    --amber: #d38b21;
    --blue: #3e6f96;
    --blue-soft: #edf4fb;
    --danger: #b84038;
    --shadow: 0 12px 32px rgba(31, 48, 39, 0.07);
    --radius: 8px;
}

* { box-sizing: border-box; }
html { color-scheme: light; overflow-x: hidden; scroll-behavior: smooth; }
body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    background: linear-gradient(180deg, #fbfcfb 0%, var(--bg) 42%, #f4f7f5 100%);
    color: var(--ink);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
    letter-spacing: 0;
    overflow-x: hidden;
}
button, input, select { font: inherit; letter-spacing: 0; }
button, select, input[type="range"], input[type="checkbox"] { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
    outline: 3px solid rgba(23, 132, 71, 0.22);
    outline-offset: 2px;
}
button:disabled, input:disabled, select:disabled { cursor: not-allowed; opacity: 0.48; }
a { color: inherit; }
[hidden] { display: none !important; }

.site-header {
    position: sticky;
    top: 0;
    z-index: 30;
    border-bottom: 1px solid var(--border-light);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.header-inner, .footer-inner {
    width: calc(100% - 40px);
    max-width: 1440px;
    min-height: 64px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}
.brand { display: inline-flex; align-items: center; }
.brand img { display: block; width: 116px; height: auto; }
.header-actions { display: flex; align-items: center; gap: 18px; }
.tools-link {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    color: #37443d;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
}
.tools-link:hover { color: var(--green-dark); }
.tools-link svg { width: 17px; height: 17px; }
.lang-switch {
    display: inline-flex;
    gap: 3px;
    padding: 3px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: var(--surface-muted);
}
.lang-btn {
    min-width: 44px;
    min-height: 34px;
    padding: 6px 10px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}
.lang-btn.active {
    background: var(--surface);
    color: var(--ink-strong);
    box-shadow: 0 1px 4px rgba(24, 33, 29, 0.1);
}

main {
    width: calc(100% - 40px);
    max-width: 1440px;
    margin: 0 auto;
    padding: 32px 0 64px;
}
.intro {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
    align-items: end;
    gap: 28px;
    margin-bottom: 22px;
}
h1 {
    max-width: 860px;
    margin: 0;
    color: var(--ink-strong);
    font-size: 42px;
    line-height: 1.08;
    font-weight: 800;
    letter-spacing: 0;
}
.intro-copy p {
    max-width: 760px;
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 16px;
}
.privacy-note {
    min-height: 64px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 11px;
    border: 1px solid #c7e1d1;
    border-radius: var(--radius);
    background: var(--green-soft);
    color: #245f3c;
    font-size: 14px;
    font-weight: 700;
}
.privacy-note svg { flex: 0 0 auto; color: var(--green); }

.tool-panel {
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.domain-banner {
    margin: 16px 16px 0;
    padding: 13px 14px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    border: 1px solid #e8bbb8;
    border-radius: var(--radius);
    background: var(--coral-soft);
    color: #8c332e;
    font-size: 14px;
    font-weight: 700;
}
.domain-banner svg { flex: 0 0 auto; margin-top: 1px; }
.workflow-steps {
    min-height: 58px;
    margin: 0;
    padding: 0 22px;
    display: flex;
    align-items: center;
    gap: 32px;
    list-style: none;
    border-bottom: 1px solid var(--border-light);
    background: #fcfdfc;
}
.workflow-steps li { display: flex; align-items: center; gap: 9px; color: #78847d; font-size: 13px; }
.workflow-steps li:not(:last-child)::after { content: ""; width: 36px; height: 1px; margin-left: 22px; background: var(--border); }
.workflow-steps span {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface);
    font-size: 12px;
    font-weight: 800;
}
.workflow-steps .active { color: var(--green-dark); }
.workflow-steps .active span { border-color: var(--green); background: var(--green); color: #fff; }

.editor-grid { display: grid; grid-template-columns: 390px minmax(0, 1fr); min-height: 680px; }
.control-rail {
    min-width: 0;
    padding: 18px;
    border-right: 1px solid var(--border-light);
    background: #fbfcfb;
}
.upload-zone {
    min-height: 142px;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1.5px dashed #9eada4;
    border-radius: var(--radius);
    background: var(--surface);
    text-align: center;
    transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}
.upload-zone:hover, .upload-zone.dragover { border-color: var(--green); background: #f2faf5; }
.upload-zone.dragover { transform: translateY(-2px); }
.upload-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.upload-icon {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    background: var(--green-soft);
    color: var(--green);
}
.upload-icon svg { width: 20px; height: 20px; }
.upload-zone strong { font-size: 14px; color: var(--ink-strong); }
.upload-zone small { max-width: 290px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.source-preview {
    min-height: 72px;
    padding: 9px;
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr) 34px;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: var(--surface);
}
.source-preview img { width: 54px; height: 54px; object-fit: cover; border-radius: 5px; background: var(--surface-muted); }
.source-preview div { min-width: 0; }
.source-preview strong, .source-preview small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-preview strong { color: var(--ink-strong); font-size: 12px; }
.source-preview small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.icon-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: var(--surface);
    color: #48554d;
}
.icon-btn:hover:not(:disabled) { border-color: #aebcb3; background: var(--surface-muted); color: var(--ink-strong); }
.icon-btn.active { border-color: var(--green); background: var(--green-soft); color: var(--green-dark); }
.icon-btn svg { width: 18px; height: 18px; stroke-width: 1.9; }

.preset-wrap { padding: 18px 0; border-bottom: 1px solid var(--border-light); }
.rail-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.rail-heading > strong { font-size: 13px; color: var(--ink-strong); }
.text-btn {
    padding: 4px 0;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
}
.text-btn:hover:not(:disabled) { color: var(--green-dark); }
.text-btn svg { width: 14px; height: 14px; }
.preset-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.preset-btn {
    min-height: 36px;
    padding: 7px 9px;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    background: var(--surface);
    color: #48554d;
    font-size: 12px;
    font-weight: 700;
}
.preset-btn:hover:not(:disabled) { border-color: #aebcb3; }
.preset-btn.active { border-color: #dfa39e; background: var(--coral-soft); color: #8c332e; }

.control-tabs {
    margin: 16px 0;
    padding: 3px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 3px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: var(--surface-muted);
}
.control-tab {
    min-height: 36px;
    padding: 7px 8px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}
.control-tab.active { background: var(--surface); color: var(--ink-strong); box-shadow: 0 1px 4px rgba(24, 33, 29, 0.1); }
.control-panel { animation: reveal 180ms ease both; }
@keyframes reveal { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.field-grid { display: grid; gap: 10px; }
.field-grid.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { min-width: 0; display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > span:first-child, .range-field b { color: #49564e; font-size: 11px; font-style: normal; font-weight: 700; }
.field input[type="number"], .field select {
    width: 100%;
    min-width: 0;
    height: 38px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink-strong);
    font-size: 13px;
    font-weight: 600;
}
.input-unit { position: relative; display: block; }
.input-unit input { padding-right: 40px !important; }
.input-unit em { position: absolute; top: 50%; right: 10px; color: #89938d; font-size: 10px; font-style: normal; transform: translateY(-50%); pointer-events: none; }
.toggle-row {
    min-height: 50px;
    margin: 2px 0 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}
.toggle-row > span:first-child { min-width: 0; }
.toggle-row strong, .toggle-row small { display: block; }
.toggle-row strong { color: #49564e; font-size: 12px; }
.toggle-row small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.toggle {
    position: relative;
    width: 38px;
    height: 22px;
    flex: 0 0 auto;
    border-radius: 12px;
    background: #b8c2bc;
    transition: background 160ms ease;
}
.toggle::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
    transition: transform 160ms ease;
}
.toggle-row input:checked + .toggle { background: var(--green); }
.toggle-row input:checked + .toggle::after { transform: translateX(16px); }
.range-field { display: block; margin-bottom: 16px; }
.range-field > span { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 5px; }
.range-field output { min-width: 38px; color: var(--green-dark); font-size: 11px; font-weight: 800; text-align: right; }
.range-field input[type="range"] { width: 100%; height: 20px; margin: 0; accent-color: var(--green); }
.quality-estimate, .curve-note {
    min-height: 52px;
    padding: 10px 11px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid #c8d9eb;
    border-radius: var(--radius);
    background: var(--blue-soft);
    color: #34536e;
}
.quality-estimate svg, .curve-note svg { width: 18px; height: 18px; flex: 0 0 auto; }
.quality-estimate span, .quality-estimate strong, .quality-estimate small { display: block; min-width: 0; }
.quality-estimate strong { font-size: 12px; }
.quality-estimate small { margin-top: 1px; font-size: 10px; }
.curve-note { margin-top: 8px; color: #34536e; font-size: 11px; line-height: 1.45; }

.preview-area { min-width: 0; display: flex; flex-direction: column; background: var(--surface); }
.preview-toolbar {
    min-height: 58px;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--border-light);
}
.preview-toolbar > div:first-child { min-width: 0; display: flex; align-items: center; gap: 12px; }
.preview-toolbar strong { color: var(--ink-strong); font-size: 13px; }
.status-dot { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.status-dot i { width: 7px; height: 7px; border-radius: 50%; background: #99a39d; }
.status-dot.ready i { background: var(--green); box-shadow: 0 0 0 4px rgba(23, 132, 71, 0.11); }
.preview-actions { display: flex; align-items: center; gap: 7px; }
.view-switch {
    height: 36px;
    padding: 3px;
    display: inline-flex;
    gap: 2px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    background: var(--surface-muted);
}
.view-switch button {
    min-width: 58px;
    padding: 5px 9px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
}
.view-switch button.active { background: var(--surface); color: var(--ink-strong); box-shadow: 0 1px 4px rgba(24, 33, 29, 0.1); }
.model-stage {
    position: relative;
    min-height: 510px;
    flex: 1;
    overflow: hidden;
    background: #edf2ef;
}
.model-stage::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: linear-gradient(rgba(95, 112, 102, 0.06) 1px, transparent 1px), linear-gradient(90deg, rgba(95, 112, 102, 0.06) 1px, transparent 1px);
    background-size: 28px 28px;
    pointer-events: none;
}
.model-stage > canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; }
#heightmapCanvas { object-fit: contain; padding: 34px; image-rendering: auto; }
.stage-empty, .license-overlay, .processing-overlay {
    position: absolute;
    inset: 0;
    z-index: 4;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 26px;
    text-align: center;
}
.stage-empty strong { margin-top: 20px; color: #35423b; font-size: 15px; }
.stage-empty p { max-width: 360px; margin: 7px 0 0; color: var(--muted); font-size: 12px; }
.empty-model { position: relative; width: 128px; height: 88px; transform: rotateX(58deg) rotateZ(-32deg); }
.empty-model span { position: absolute; inset: 0; border: 1px solid rgba(23, 132, 71, 0.42); background: rgba(233, 246, 238, 0.3); }
.empty-model span:nth-child(2) { transform: translate(12px, -10px); }
.empty-model span:nth-child(3) { transform: translate(24px, -20px); }
.empty-model span:nth-child(4) { transform: translate(36px, -30px); border-color: rgba(220, 102, 95, 0.55); }
.license-overlay { z-index: 8; background: rgba(244, 247, 245, 0.9); backdrop-filter: blur(5px); color: #8c332e; }
.license-overlay svg { width: 34px; height: 34px; margin-bottom: 12px; }
.license-overlay strong { font-size: 15px; }
.license-overlay span { margin-top: 5px; color: #71504d; font-size: 12px; }
.processing-overlay { z-index: 9; background: rgba(246, 249, 247, 0.88); color: var(--ink-strong); }
.processing-overlay strong { margin-top: 12px; font-size: 13px; }
.processing-overlay > span:last-child { margin-top: 4px; color: var(--green-dark); font-size: 12px; font-weight: 800; }
.spinner { width: 28px; height: 28px; border: 3px solid #cce3d5; border-top-color: var(--green); border-radius: 50%; animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.model-meta {
    min-height: 66px;
    padding: 10px 16px;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1px;
    border-top: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    background: var(--surface-muted);
}
.model-meta > span { min-width: 0; padding: 2px 12px; border-right: 1px solid var(--border-light); }
.model-meta > span:last-child { border-right: 0; }
.model-meta small, .model-meta strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-meta small { color: var(--muted); font-size: 10px; }
.model-meta strong { margin-top: 3px; color: var(--ink-strong); font-size: 13px; }
.model-meta .valid { color: var(--green-dark); }
.action-bar {
    min-height: 70px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
}
.status-message { min-width: 0; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.status-message svg { width: 16px; height: 16px; flex: 0 0 auto; color: var(--blue); }
.status-message.error { color: var(--danger); }
.status-message.success { color: var(--green-dark); }
.export-actions { display: flex; align-items: center; gap: 8px; }
.btn {
    min-height: 40px;
    padding: 9px 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border-radius: var(--radius);
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}
.btn svg { width: 17px; height: 17px; }
.btn.primary { border: 1px solid var(--green); background: var(--green); color: #fff; }
.btn.primary:hover:not(:disabled) { border-color: var(--green-dark); background: var(--green-dark); }
.btn.secondary { border: 1px solid var(--border); background: var(--surface); color: #37443d; }
.btn.secondary:hover:not(:disabled) { border-color: #aebcb3; background: var(--surface-muted); }

.capability-band { padding: 58px 0 8px; }
.section-copy { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; margin-bottom: 28px; }
.section-copy h2 { margin: 0; color: var(--ink-strong); font-size: 26px; line-height: 1.15; }
.section-copy p { max-width: 520px; margin: 0; color: var(--muted); font-size: 14px; }
.capability-list { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.capability-list article { min-width: 0; padding: 24px 22px 26px; border-right: 1px solid var(--border); }
.capability-list article:last-child { border-right: 0; }
.capability-list svg { width: 22px; height: 22px; color: var(--green); }
.capability-list article:nth-child(2) svg { color: var(--coral); }
.capability-list article:nth-child(3) svg { color: var(--blue); }
.capability-list article:nth-child(4) svg { color: var(--amber); }
.capability-list h3 { margin: 14px 0 6px; color: var(--ink-strong); font-size: 14px; }
.capability-list p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }

.site-footer { border-top: 1px solid var(--border-light); background: var(--surface); }
.footer-inner { min-height: 76px; color: var(--muted); font-size: 12px; }
.footer-link { color: var(--ink); font-weight: 700; text-decoration: none; }
.footer-link:hover { color: var(--green-dark); text-decoration: underline; }
.no-icons [data-lucide] { display: none; }

@media (max-width: 1180px) {
    .editor-grid { grid-template-columns: 350px minmax(0, 1fr); }
    .action-bar { align-items: flex-start; flex-direction: column; }
    .export-actions { width: 100%; justify-content: flex-end; }
}

@media (max-width: 900px) {
    main { width: calc(100% - 32px); padding-top: 26px; }
    .header-inner, .footer-inner { width: calc(100% - 32px); }
    .intro { grid-template-columns: 1fr; align-items: start; }
    h1 { font-size: 36px; }
    .privacy-note { max-width: 520px; }
    .editor-grid { grid-template-columns: 1fr; }
    .control-rail { border-right: 0; border-bottom: 1px solid var(--border-light); }
    .upload-block { display: grid; grid-template-columns: minmax(0, 1fr); }
    .model-stage { min-height: 500px; }
    .capability-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .capability-list article:nth-child(2) { border-right: 0; }
    .capability-list article:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
    .section-copy { align-items: flex-start; flex-direction: column; gap: 10px; }
}

@media (max-width: 620px) {
    .header-inner { min-height: 58px; }
    .brand img { width: 96px; }
    .tools-link span { display: none; }
    .header-actions { gap: 10px; }
    .lang-btn { min-width: 39px; min-height: 32px; padding: 5px 7px; }
    main { width: calc(100% - 24px); padding: 22px 0 46px; }
    h1 { font-size: 30px; }
    .intro-copy p { font-size: 14px; }
    .privacy-note { min-height: 58px; font-size: 12px; }
    .domain-banner { margin: 10px 10px 0; font-size: 12px; }
    .workflow-steps { min-height: 54px; padding: 0 12px; justify-content: space-between; gap: 7px; }
    .workflow-steps li { gap: 6px; font-size: 11px; }
    .workflow-steps li:not(:last-child)::after { display: none; }
    .workflow-steps span { width: 22px; height: 22px; }
    .control-rail { padding: 14px; }
    .upload-zone { min-height: 128px; }
    .preview-toolbar { align-items: flex-start; flex-direction: column; }
    .preview-actions { width: 100%; justify-content: space-between; }
    .view-switch { flex: 1; }
    .view-switch button { min-width: 0; flex: 1; }
    .model-stage { min-height: 380px; }
    #heightmapCanvas { padding: 18px; }
    .model-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 8px 10px; }
    .model-meta > span:nth-child(2) { border-right: 0; }
    .model-meta > span:nth-child(-n+2) { padding-bottom: 8px; border-bottom: 1px solid var(--border-light); }
    .model-meta > span:nth-child(n+3) { padding-top: 8px; }
    .action-bar { padding: 12px; }
    .export-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .btn { min-width: 0; white-space: normal; line-height: 1.2; }
    .btn.primary { grid-column: 1 / -1; }
    .capability-band { padding-top: 44px; }
    .section-copy h2 { font-size: 23px; }
    .capability-list { grid-template-columns: 1fr; }
    .capability-list article { border-right: 0; border-bottom: 1px solid var(--border); }
    .capability-list article:last-child { border-bottom: 0; }
    .footer-inner { min-height: 70px; padding: 14px 0; flex-wrap: wrap; }
}

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