:root {
  color-scheme: light;
  --bg: oklch(1 0 0);
  --surface: oklch(0.97 0 0);
  --surface-strong: oklch(0.94 0.008 110);
  --ink: oklch(0.18 0.01 110);
  --muted: oklch(0.43 0.015 110);
  --line: oklch(0.86 0.008 110);
  --primary: oklch(0.42 0.1 110);
  --primary-dark: oklch(0.34 0.085 110);
  --primary-soft: oklch(0.94 0.035 110);
  --info: oklch(0.46 0.15 255);
  --info-soft: oklch(0.96 0.025 255);
  --warning: oklch(0.73 0.14 75);
  --warning-ink: oklch(0.4 0.11 70);
  --warning-soft: oklch(0.96 0.035 75);
  --danger: oklch(0.58 0.17 25);
  --danger-soft: oklch(0.96 0.03 25);
  --success: oklch(0.43 0.11 145);
  --radius-sm: 8px;
  --radius-md: 12px;
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;
  --space-3xl: 48px;
  --shadow-sm: 0 2px 8px oklch(0.15 0.02 110 / 0.07);
  --z-sticky: 20;
  --z-toast: 50;
  font-family: "Microsoft YaHei UI", "Noto Sans CJK SC", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.65; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }

.skip-link { position: fixed; left: 16px; top: -60px; z-index: 100; padding: 10px 16px; background: var(--ink); color: white; border-radius: 6px; }
.skip-link:focus { top: 12px; }

.site-header { position: sticky; top: 0; z-index: var(--z-sticky); background: oklch(1 0 0 / 0.96); border-bottom: 1px solid var(--line); }
.header-inner { width: min(1400px, calc(100% - 48px)); min-height: 68px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: var(--space-xl); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--primary-dark); font-weight: 800; font-size: 1.2rem; text-decoration: none; }
.brand-mark { width: 30px; height: 30px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
nav { display: flex; align-self: stretch; }
.nav-link { min-width: 110px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: var(--ink); text-decoration: none; font-weight: 600; border-bottom: 3px solid transparent; }
.nav-link.is-active { color: var(--primary-dark); border-bottom-color: var(--primary); }
.nav-count { min-width: 20px; height: 20px; padding: 0 5px; display: inline-grid; place-items: center; background: var(--primary-soft); border-radius: 999px; font-size: .75rem; }

.page-shell { width: min(1400px, calc(100% - 48px)); margin: 0 auto; }
.intro { padding: var(--space-2xl) 0 var(--space-xl); display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-xl); }
.location-label { margin: 0 0 6px; color: var(--primary-dark); font-weight: 700; font-size: .9rem; }
h1 { margin: 0; font-size: 2.2rem; line-height: 1.2; letter-spacing: -0.025em; text-wrap: balance; }
.intro-copy { max-width: 65ch; margin: 10px 0 0; color: var(--muted); font-size: 1.05rem; }
.mode-indicator { flex: none; display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; background: var(--surface); border-radius: 999px; color: var(--muted); font-size: .875rem; }
.mode-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warning); }
.mode-indicator.is-live .mode-dot { background: var(--success); }

.workspace { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(360px, .9fr); gap: var(--space-xl); align-items: start; }
.upload-panel, .result-panel { border-radius: var(--radius-md); }
.upload-panel { padding: var(--space-xl); background: var(--bg); border: 1px solid var(--line); }
.result-panel { min-height: 620px; padding: var(--space-xl); background: var(--surface); box-shadow: var(--shadow-sm); position: sticky; top: 92px; }
.section-heading { display: flex; justify-content: space-between; gap: var(--space-lg); margin-bottom: var(--space-lg); }
.section-heading h2, .history-header h2 { margin: 0; font-size: 1.3rem; line-height: 1.35; }
.section-heading p, .history-header p { margin: 4px 0 0; color: var(--muted); font-size: .92rem; }
.required-note { align-self: start; padding: 3px 8px; border-radius: 999px; background: var(--surface); color: var(--muted); font-size: .78rem; }

.dropzone { min-height: 300px; border: 1.5px dashed oklch(0.62 0.06 110); border-radius: var(--radius-md); background: var(--surface); display: grid; place-items: center; padding: var(--space-lg); cursor: pointer; transition: border-color .2s ease, background-color .2s ease; }
.dropzone:hover, .dropzone.is-dragging { border-color: var(--primary); background: var(--primary-soft); }
.upload-empty { display: flex; flex-direction: column; align-items: center; gap: var(--space-sm); text-align: center; color: var(--muted); }
.upload-empty strong { color: var(--ink); font-size: 1.05rem; }
.upload-icon { width: 54px; height: 54px; margin-bottom: 4px; fill: none; stroke: var(--primary); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.preview-wrap { width: 100%; display: grid; grid-template-columns: minmax(220px, 1fr) minmax(180px, .8fr); gap: var(--space-lg); align-items: center; }
.preview-wrap img { width: 100%; height: 260px; object-fit: contain; background: oklch(0.15 0 0); border-radius: var(--radius-sm); }
.preview-meta { min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-sm); }
.preview-meta strong { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-meta span { color: var(--muted); font-size: .9rem; }
.field-help, .field-error { margin: 8px 0 0; font-size: .85rem; }
.field-help { color: var(--muted); }
.field-error { color: var(--danger); font-weight: 600; }

.crop-fieldset { margin: var(--space-xl) 0 0; padding: 0; border: 0; }
.crop-fieldset legend { margin-bottom: 8px; font-weight: 700; }
.segmented-control { display: grid; grid-template-columns: 1fr 1fr; }
.segmented-control label { position: relative; }
.segmented-control input { position: absolute; opacity: 0; pointer-events: none; }
.segmented-control label > span { min-height: 48px; display: flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); cursor: pointer; font-weight: 700; }
.segmented-control label:first-child > span { border-radius: 9px 0 0 9px; }
.segmented-control label:last-child > span { border-radius: 0 9px 9px 0; border-left: 0; }
.segmented-control input:checked + span { background: var(--primary); color: white; border-color: var(--primary); }
.crop-symbol { font-size: .78rem; width: 24px; height: 24px; display: grid; place-items: center; border: 1px solid currentColor; border-radius: 50%; }

.button { min-height: 48px; padding: 10px 20px; border-radius: 10px; border: 0; display: inline-flex; align-items: center; justify-content: center; gap: 9px; font-weight: 750; cursor: pointer; transition: background-color .18s ease, color .18s ease, transform .18s ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(0); }
.button:disabled { cursor: not-allowed; opacity: .48; }
.button-primary { background: var(--primary); color: white; }
.button-primary:hover:not(:disabled) { background: var(--primary-dark); }
.button-secondary { background: var(--bg); color: var(--primary-dark); border: 1px solid var(--primary); }
.button-secondary:hover:not(:disabled) { background: var(--primary-soft); }
.diagnose-button { width: 100%; margin-top: var(--space-lg); font-size: 1.05rem; }
.diagnose-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }
.text-button { min-height: 44px; padding: 6px 2px; border: 0; background: transparent; color: var(--info); font-weight: 700; cursor: pointer; }
.text-button:hover { text-decoration: underline; }
.danger-text { color: var(--danger); }

:where(a, button, input, [tabindex]):focus-visible { outline: 3px solid var(--info); outline-offset: 3px; }

.privacy-note { margin: var(--space-md) 0 0; display: flex; justify-content: center; align-items: center; gap: 7px; color: var(--info); font-size: .85rem; text-align: center; }
.privacy-note svg { flex: none; width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.progress-panel { margin-top: var(--space-lg); padding: var(--space-lg); background: var(--info-soft); display: flex; gap: var(--space-lg); align-items: center; border-radius: var(--radius-sm); }
.progress-panel strong { display: block; }
.progress-panel p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.progress-leaf { width: 40px; height: 40px; position: relative; flex: none; }
.progress-leaf span { position: absolute; width: 18px; height: 10px; border-radius: 18px 2px; background: var(--primary); transform-origin: right center; animation: leafPulse 1.2s ease-in-out infinite; }
.progress-leaf span:nth-child(1) { left: 3px; top: 6px; transform: rotate(32deg); }
.progress-leaf span:nth-child(2) { right: 2px; top: 16px; transform: rotate(150deg); animation-delay: .18s; }
.progress-leaf span:nth-child(3) { left: 5px; bottom: 2px; transform: rotate(18deg); animation-delay: .36s; }
@keyframes leafPulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

.result-empty { min-height: 570px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.empty-visual { width: 88px; height: 88px; display: grid; place-items: center; border-radius: 50%; background: var(--primary-soft); color: var(--primary); }
.empty-visual svg { width: 56px; height: 56px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.result-empty h2 { margin: var(--space-lg) 0 6px; font-size: 1.25rem; }
.result-empty > p { max-width: 42ch; margin: 0; color: var(--muted); }
.photo-tips { margin: var(--space-xl) 0 0; padding: var(--space-lg) var(--space-xl) var(--space-lg) 40px; text-align: left; background: var(--bg); border-radius: var(--radius-sm); color: var(--muted); }

.result-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-lg); padding-bottom: var(--space-lg); border-bottom: 1px solid var(--line); }
.result-kicker { margin: 0 0 4px; color: var(--muted); font-size: .85rem; font-weight: 700; }
.result-heading h2 { max-width: 26ch; margin: 0; font-size: 1.25rem; line-height: 1.4; text-wrap: pretty; }
.confidence-chip { flex: none; padding: 5px 10px; border-radius: 999px; background: var(--warning-soft); color: var(--warning-ink); font-size: .82rem; font-weight: 800; }
.confidence-chip.high { background: var(--primary-soft); color: var(--primary-dark); }
.confidence-chip.low { background: var(--danger-soft); color: var(--danger); }
.demo-notice { margin: var(--space-lg) 0 0; padding: var(--space-md); display: flex; flex-direction: column; gap: 2px; background: var(--warning-soft); border-radius: var(--radius-sm); color: var(--warning-ink); font-size: .85rem; }
.result-section { padding: var(--space-xl) 0; border-bottom: 1px solid var(--line); }
.result-section h3 { margin: 0 0 var(--space-md); font-size: 1rem; }
.check-list { margin: 0; padding: 0; list-style: none; display: grid; gap: var(--space-sm); }
.check-list li { position: relative; padding-left: 20px; }
.check-list li::before { content: ""; position: absolute; left: 2px; top: .65em; width: 7px; height: 7px; border-radius: 50%; background: var(--primary); }
.candidate-list { display: grid; gap: var(--space-md); }
.candidate-item { padding-bottom: var(--space-md); border-bottom: 1px solid var(--line); }
.candidate-item:last-child { padding-bottom: 0; border-bottom: 0; }
.candidate-top { display: flex; justify-content: space-between; align-items: center; gap: var(--space-md); }
.candidate-index { display: inline-grid; place-items: center; width: 24px; height: 24px; margin-right: 8px; border-radius: 6px; background: var(--bg); font-size: .8rem; font-weight: 800; }
.candidate-confidence { color: var(--muted); font-size: .8rem; font-weight: 700; }
.candidate-item p { margin: 6px 0 0 32px; color: var(--muted); font-size: .86rem; }
.action-groups { display: grid; gap: var(--space-lg); }
.action-group h4 { margin: 0 0 6px; font-size: .9rem; color: var(--primary-dark); }
.action-group ul { margin: 0; padding-left: 20px; }
.safety-callout { margin-top: var(--space-xl); padding: var(--space-md); display: flex; gap: 9px; align-items: flex-start; border: 1px solid oklch(0.72 0.1 255); border-radius: var(--radius-sm); background: var(--info-soft); color: oklch(0.35 0.12 255); }
.safety-callout svg { flex: none; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.safety-callout p { margin: 0; font-size: .83rem; }
.result-actions { margin-top: var(--space-xl); display: flex; align-items: center; justify-content: space-between; gap: var(--space-md); }

.history-section { margin: var(--space-3xl) 0; padding-top: var(--space-xl); border-top: 1px solid var(--line); scroll-margin-top: 88px; }
.history-header { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-lg); }
.history-empty { margin-top: var(--space-lg); padding: var(--space-xl); background: var(--surface); border-radius: var(--radius-sm); color: var(--muted); text-align: center; }
.history-empty p { margin: 0; }
.history-list { margin-top: var(--space-lg); border-top: 1px solid var(--line); }
.history-item { display: grid; grid-template-columns: 86px 90px minmax(200px, 1fr) auto; align-items: center; gap: var(--space-lg); min-height: 76px; padding: var(--space-md) 0; border-bottom: 1px solid var(--line); }
.history-thumb { width: 78px; height: 52px; object-fit: cover; border-radius: 6px; background: var(--surface); }
.history-crop { font-weight: 700; }
.history-summary { min-width: 0; }
.history-summary strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-summary time { color: var(--muted); font-size: .8rem; }
.history-controls { display: flex; gap: var(--space-md); }

.site-footer { padding: var(--space-xl) max(24px, env(safe-area-inset-right)) max(var(--space-xl), env(safe-area-inset-bottom)); border-top: 1px solid var(--line); color: var(--muted); text-align: center; font-size: .82rem; }
.site-footer p { margin: 2px 0; }
.toast { position: fixed; right: 24px; bottom: max(24px, env(safe-area-inset-bottom)); z-index: var(--z-toast); max-width: min(420px, calc(100vw - 32px)); padding: 12px 16px; border-radius: var(--radius-sm); background: var(--ink); color: white; box-shadow: var(--shadow-sm); }

@media (max-width: 1000px) {
  .workspace { grid-template-columns: 1fr; }
  .result-panel { min-height: 0; position: static; }
  .result-empty { min-height: 360px; }
}

@media (max-width: 680px) {
  .header-inner, .page-shell { width: min(100% - 32px, 1400px); }
  .header-inner { min-height: 60px; }
  .brand { font-size: 1.05rem; }
  .brand-mark { width: 26px; height: 26px; }
  .nav-link { min-width: auto; padding: 0 9px; font-size: .88rem; }
  .intro { padding: var(--space-xl) 0 var(--space-lg); align-items: flex-start; flex-direction: column; }
  h1 { font-size: 1.75rem; }
  .intro-copy { font-size: 1rem; }
  .upload-panel, .result-panel { padding: var(--space-lg); }
  .dropzone { min-height: 250px; }
  .preview-wrap { grid-template-columns: 1fr; }
  .preview-wrap img { height: 230px; }
  .preview-meta { align-items: center; text-align: center; }
  .result-heading { flex-direction: column; }
  .history-item { grid-template-columns: 72px minmax(0, 1fr) auto; gap: var(--space-md); }
  .history-thumb { width: 68px; height: 48px; }
  .history-crop { display: none; }
  .history-controls { flex-direction: column; gap: 0; }
  .toast { right: 16px; bottom: 16px; }
}

@media (max-width: 420px) {
  .header-inner, .page-shell { width: min(100% - 24px, 1400px); }
  .nav-link:first-child { display: none; }
  .location-label { font-size: .82rem; }
  h1 { font-size: 1.55rem; }
  .upload-panel, .result-panel { padding: var(--space-md); }
  .dropzone { min-height: 230px; padding: var(--space-md); }
  .segmented-control label > span { min-height: 52px; }
  .result-actions { align-items: stretch; flex-direction: column; }
}

@media print {
  .site-header, .intro, .upload-panel, .history-section, .site-footer, .result-actions, .mode-indicator { display: none !important; }
  .page-shell { width: 100%; }
  .workspace { display: block; }
  .result-panel { box-shadow: none; padding: 0; background: white; }
}

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