:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: #17313b;
  background: #eef4f3;
  --ink: #17313b;
  --muted: #61747b;
  --brand: #0f5f68;
  --brand-dark: #0b4650;
  --surface: #ffffff;
  --line: #d7e2e1;
  --warm: #d97706;
  --radius: 18px;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  margin: 0;
  background:
    radial-gradient(circle at 12% 0%, rgba(103, 177, 168, .16), transparent 30rem),
    #eef4f3;
}

button, input { font: inherit; }
button { min-height: 44px; }

button:focus-visible,
input:focus-visible {
  outline: 3px solid #f5b942;
  outline-offset: 2px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px clamp(18px, 3vw, 44px) 16px;
  color: white;
  background: linear-gradient(120deg, #0b4650, #13717a);
  box-shadow: 0 10px 30px rgba(11, 70, 80, .18);
}

.eyebrow {
  margin: 0 0 4px;
  color: #bfe4df;
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .12em;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2.3vw, 2rem);
  line-height: 1.25;
}

.subtitle { margin: 5px 0 0; color: #d7efec; }

.header-chip {
  flex: 0 0 auto;
  padding: 9px 14px;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  font-weight: 700;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 7fr) minmax(320px, 3fr);
  align-items: start;
  gap: 18px;
  min-height: calc(100vh - 112px);
  padding: 18px clamp(14px, 2vw, 28px) 24px;
}

.model-card,
.control-panel > section {
  border: 1px solid rgba(183, 204, 201, .72);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 12px 28px rgba(37, 72, 77, .08);
}

.model-card {
  display: flex;
  align-self: start;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.model-toolbar {
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}

.toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
}

.view-shortcuts { display: flex; flex-wrap: wrap; gap: 6px; }
.view-button { min-height: 38px; padding: 6px 10px; font-size: .9rem; }
.view-button.active { border-color: var(--brand); color: #fff; background: var(--brand); }

.legend { display: flex; flex-wrap: wrap; gap: 10px 18px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 7px; }
.line { display: inline-block; width: 28px; border-top: 3px solid #2563eb; }
.line.measure { border-top: 3px dashed #dc2626; }
.line.curb { border-top: 6px solid #263238; }

.switch-control {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  border-radius: 12px;
  color: var(--brand-dark);
  background: #e9f5f3;
  font-weight: 700;
  cursor: pointer;
}

.switch-control input { width: 22px; height: 22px; accent-color: var(--brand); }

.model-stage {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  min-height: 520px;
  max-height: 760px;
  overflow: hidden;
  background: #f8fbfa;
}

#ggb-container,
#ggb-container > div,
#ggb-container iframe { width: 100% !important; height: 100% !important; }

.photo-panel,
.status-panel {
  position: absolute;
  inset: 0;
}

.photo-panel {
  z-index: 4;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(135deg, #dcebe8, #f5f8f6);
  transition: opacity .45s ease;
}

.photo-panel.is-faded { opacity: .08; pointer-events: none; }
.photo-panel.is-hidden { display: none; }

.photo-panel img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-placeholder {
  display: flex;
  width: min(80%, 620px);
  min-height: 230px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 30px;
  border: 2px dashed #78a39e;
  border-radius: 18px;
  color: #315d61;
  text-align: center;
  background: rgba(255,255,255,.65);
}

.photo-placeholder strong { font-size: 1.3rem; }

.question-card {
  position: absolute;
  left: 50%;
  bottom: 8%;
  display: flex;
  width: min(86%, 660px);
  transform: translateX(-50%);
  flex-direction: column;
  gap: 5px;
  padding: 18px 22px;
  border-radius: 16px;
  color: white;
  background: rgba(11, 70, 80, .9);
  box-shadow: 0 12px 35px rgba(0,0,0,.18);
}

.question-card span { color: #bfe4df; font-weight: 700; }
.question-card strong { font-size: clamp(1.15rem, 2vw, 1.55rem); }

.status-panel {
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  background: #f8fbfa;
}

.status-panel[hidden] { display: none; }

.spinner {
  width: 36px;
  height: 36px;
  border: 4px solid #cde2df;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-panel { z-index: 5; color: #7f1d1d; background: #fff8f7; }
.error-panel button { margin-top: 8px; }

.teaching-boundary {
  margin: 0;
  padding: 11px 16px;
  border-top: 1px solid var(--line);
  color: #445e63;
  text-align: center;
  background: #f0f7f5;
  font-weight: 700;
}

.control-panel {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 14px;
}

.control-panel > section { padding: 16px; }
.step-card { border-top: 5px solid var(--brand) !important; }

.step-topline,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stage-badge {
  padding: 5px 9px;
  border-radius: 999px;
  color: #0a5059;
  background: #dff1ee;
  font-size: .88rem;
  font-weight: 800;
}

.mode-label,
.section-heading span { color: var(--muted); font-size: .9rem; }

.control-panel h2 { margin: 0; font-size: 1.15rem; }
.step-card h2 { margin-top: 12px; font-size: 1.35rem; }
.step-card p { min-height: 2.8em; margin: 7px 0 14px; color: var(--muted); line-height: 1.45; }

.step-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
}

.combine-control {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 10px;
  border-radius: 12px;
  background: #eef8f6;
}

.combine-control button { flex: 0 0 auto; padding: 0 14px; }
.combine-control p { min-height: 0; margin: 0; font-size: .9rem; }

button {
  border: 1px solid #b7cecb;
  border-radius: 11px;
  color: var(--brand-dark);
  background: #fff;
  font-weight: 700;
  cursor: pointer;
}

button:hover { background: #edf6f4; }
button.primary { border-color: var(--brand); color: #fff; background: var(--brand); }
button.primary:hover { background: var(--brand-dark); }
button:disabled { cursor: not-allowed; opacity: .45; }

.parameter-card { display: flex; flex-direction: column; gap: 16px; }

.free-control-card { display: flex; flex-direction: column; gap: 12px; }
.layer-group { min-width: 0; margin: 0; padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
.layer-group legend { padding: 0 5px; color: var(--brand-dark); font-size: .92rem; font-weight: 800; }
.layer-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.layer-option { display: flex; min-height: 38px; align-items: center; gap: 7px; padding: 7px; border-radius: 8px; color: #34545a; background: #f3f8f7; cursor: pointer; font-size: .9rem; }
.layer-option:has(input:checked) { color: var(--brand-dark); background: #dff1ee; font-weight: 700; }
.layer-option input { width: 18px; height: 18px; flex: 0 0 auto; accent-color: var(--brand); }

.slider-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  font-weight: 700;
}

.slider-row output { color: var(--brand); font-variant-numeric: tabular-nums; }
.slider-row input { grid-column: 1 / -1; width: 100%; height: 30px; accent-color: var(--brand); }
.slider-row small { grid-column: 1 / -1; display: flex; justify-content: space-between; color: var(--muted); font-weight: 400; }

.values-card,
.formula-card { transition: opacity .2s ease; }
.is-concealed { display: none; }

.value-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.value-grid div {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
  padding: 10px;
  border-radius: 11px;
  background: #f3f7f6;
}

.value-grid span { color: var(--muted); font-size: .86rem; }
.value-grid strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.value-grid .accent { color: #8a3a05; background: #fff3df; }
.value-grid .alt { color: #075d61; background: #e2f5f2; }

.formula-card h2 { margin-bottom: 11px; }
.formula-block { padding: 12px; border-left: 4px solid #d97706; background: #fff8ed; }
.formula-block + .formula-block { margin-top: 10px; border-left-color: #0d7c79; background: #eefaf8; }
.formula-block.is-concealed { display: none; }
.formula-block h3 { margin: 0 0 7px; font-size: 1rem; }
.formula-block p { margin: 3px 0; }
.formula-main { font-size: 1.25rem; font-weight: 800; }
.formula-block strong { display: block; margin-top: 5px; font-size: 1.15rem; }
.formula-note { margin: 11px 0 0; color: var(--muted); line-height: 1.4; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: minmax(0, 2fr) minmax(310px, 1fr); }
  .legend { font-size: .9rem; }
  .view-button { padding: 6px 8px; font-size: .82rem; }
}

@media (max-width: 899px) {
  .page-header { align-items: flex-start; padding: 16px 18px; }
  .header-chip { display: none; }
  .app-shell { display: flex; flex-direction: column; min-height: 0; padding: 12px; }
  .model-stage { min-height: clamp(390px, 58vw, 560px); }
  .control-panel { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .step-card { grid-column: 1 / -1; }
  .formula-card { grid-column: 1 / -1; }
  .free-control-card { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  .page-header { display: block; }
  .subtitle { font-size: .92rem; }
  .model-toolbar { align-items: flex-start; flex-direction: column; }
  .toolbar-actions { width: 100%; justify-content: space-between; }
  .view-shortcuts { width: 100%; }
  .view-button { flex: 1 1 30%; }
  .legend { font-size: .85rem; }
  .model-stage { min-height: 360px; }
  .control-panel { display: flex; }
  .layer-grid { grid-template-columns: 1fr; }
  .combine-control { align-items: stretch; flex-direction: column; }
  .question-card { bottom: 5%; }
}

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