:root {
  --bg: #f4f6f6;
  --card: #ffffff;
  --ink: #14302e;
  --ink-soft: #5b6e6c;
  --accent: #0f766e;
  --accent-soft: #d7efec;
  --warn: #b45309;
  --line: #e2e9e8;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, "Segoe UI", Tahoma, Arial, sans-serif;
  line-height: 1.6;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 20px; background: var(--card);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700;
}
.brand-name { font-weight: 800; font-size: 20px; }
.brand-sub { font-size: 12px; color: var(--ink-soft); }

.privacy-pill {
  display: flex; align-items: center; gap: 7px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 13px; font-weight: 600;
  padding: 6px 12px; border-radius: 999px;
}
.privacy-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }

.tabs {
  display: flex; gap: 4px; padding: 10px 20px 0;
  max-width: 860px; margin: 0 auto;
}
.tab {
  flex: 1; border: none; background: transparent; color: var(--ink-soft);
  font: inherit; font-weight: 700; font-size: 15px;
  padding: 10px 6px; cursor: pointer;
  border-bottom: 3px solid transparent;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

main { max-width: 860px; margin: 0 auto; padding: 16px 20px 40px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 17px; }

.capture-hint { color: var(--ink-soft); font-size: 14px; margin-bottom: 12px; }

.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 34px 16px; text-align: center;
  transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { font-size: 34px; margin-bottom: 6px; }
.dz-main { font-weight: 600; margin-bottom: 14px; }
.dz-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.btn {
  font: inherit; font-weight: 700; font-size: 14px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 10px; padding: 10px 18px; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn:active { transform: translateY(1px); }

.hidden { display: none !important; }

.stage { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.canvas-wrap { position: relative; flex: 1 1 320px; min-width: 260px; }
#canvas { width: 100%; border-radius: 10px; display: block; background: #0c1514; }
.overlay-toggle {
  position: absolute; bottom: 10px; inset-inline-start: 10px;
  background: rgba(12,21,20,.75); color: #fff;
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
}
.stage-side { flex: 0 1 220px; display: flex; flex-direction: column; gap: 10px; }
.status { font-size: 14px; color: var(--ink-soft); background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.status.ok { color: var(--accent); }
.status.err { color: var(--warn); }

.modal {
  position: fixed; inset: 0; background: rgba(10,20,19,.6);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal-box { background: var(--card); border-radius: var(--radius); padding: 14px; max-width: 560px; width: 100%; }
#cam-video { width: 100%; border-radius: 10px; background: #000; }
.modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 12px; }

.score-card { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.score-ring-wrap { position: relative; width: 120px; height: 120px; flex: 0 0 auto; }
.score-ring { width: 120px; height: 120px; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--line); stroke-width: 10; }
.ring-val {
  fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round;
  stroke-dasharray: 326.7; stroke-dashoffset: 326.7;
  transition: stroke-dashoffset .8s ease;
}
.score-num {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 800; color: var(--accent);
}
.score-text { flex: 1 1 260px; }
.score-text h2 { margin: 0 0 6px; font-size: 19px; }
.score-text p { margin: 0 0 8px; font-size: 14px; color: var(--ink-soft); }

.fine-print { font-size: 12px; color: var(--ink-soft); }

.metric { padding: 12px 0; border-bottom: 1px solid var(--line); }
.metric:last-child { border-bottom: none; }
.metric-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.metric-name { font-weight: 700; font-size: 14.5px; }
.metric-val { font-weight: 700; color: var(--accent); font-size: 14px; direction: ltr; }
.metric-bar {
  position: relative; height: 8px; border-radius: 999px;
  background: var(--line); margin: 8px 0 6px; direction: ltr;
}
.metric-range {
  position: absolute; top: 0; height: 100%;
  background: var(--accent-soft); border-radius: 999px;
}
.metric-marker {
  position: absolute; top: -4px; width: 4px; height: 16px;
  background: var(--accent); border-radius: 2px; transform: translateX(-50%);
}
.metric-marker.out { background: var(--warn); }
.metric-foot { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-soft); flex-wrap: wrap; gap: 4px; }
.metric-note { font-size: 12.5px; color: var(--ink-soft); margin-top: 4px; }

.clinic-fields { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.clinic-fields label { display: flex; flex-direction: column; font-size: 13px; font-weight: 600; gap: 4px; flex: 1 1 140px; }
.clinic-fields label.wide { flex: 1 1 100%; }
.clinic-fields input {
  font: inherit; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fbfdfd;
}
.clinic-actions { display: flex; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
#summary-text {
  width: 100%; font: inherit; font-size: 13px; line-height: 1.7;
  border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  background: #fbfdfd; resize: vertical;
}

.howto { margin: 0 0 10px; padding-inline-start: 20px; font-size: 14px; color: var(--ink-soft); }
.howto li { margin-bottom: 6px; }

.foot {
  text-align: center; font-size: 12px; color: var(--ink-soft);
  padding: 18px 16px 30px;
}

@media (max-width: 560px) {
  .score-card { flex-direction: column; text-align: center; }
  .score-text h2 { font-size: 17px; }
  .stage-side { flex: 1 1 100%; }
}

/* ===== v2: smile design ===== */
.slot-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.slot {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px;
  display: flex; flex-direction: column; gap: 4px; text-align: center;
}
.slot-thumb {
  aspect-ratio: 3/4; background: var(--bg); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.slot-plus { font-size: 30px; color: var(--line); font-weight: 300; }
.slot-img { width: 100%; height: 100%; object-fit: cover; }
.slot-name { font-weight: 700; font-size: 14px; }
.slot-en { font-size: 11px; color: var(--ink-soft); direction: ltr; }
.slot-hint { font-size: 11.5px; color: var(--ink-soft); min-height: 2.5em; }
.slot-status { font-size: 12px; color: var(--ink-soft); min-height: 1.4em; }
.slot-status.ok { color: var(--accent); }
.slot-status.err { color: var(--warn); }
.slot-btn { width: 100%; padding: 7px 0; font-size: 13px; }

.legend {
  display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px;
  color: var(--ink-soft); margin-bottom: 12px;
}
.legend span { display: flex; align-items: center; gap: 6px; }
.dot-rate { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot-rate.g { background: #16a34a; }
.dot-rate.y { background: #eab308; }
.dot-rate.r { background: #dc2626; }

.cl-section { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; }
.cl-section summary {
  cursor: pointer; font-weight: 700; font-size: 14.5px; padding: 10px 14px;
  color: var(--accent); list-style-position: inside;
}
.cl-item { padding: 10px 14px; border-top: 1px solid var(--line); }
.cl-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cl-num {
  width: 26px; height: 26px; border-radius: 50%; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 700; color: var(--ink-soft); flex: 0 0 auto;
}
.cl-names { flex: 1 1 180px; }
.cl-ar { font-weight: 700; font-size: 14px; }
.cl-en { font-size: 11px; color: var(--ink-soft); direction: ltr; text-align: right; }
.cl-rate { display: flex; gap: 6px; }
.rate {
  width: 26px; height: 26px; border-radius: 50%; cursor: pointer;
  border: 2px solid var(--line); background: #fff; opacity: .45;
}
.rate.g { border-color: #16a34a; }
.rate.y { border-color: #eab308; }
.rate.r { border-color: #dc2626; }
.rate.on { opacity: 1; }
.rate.g.on { background: #16a34a; }
.rate.y.on { background: #eab308; }
.rate.r.on { background: #dc2626; }
.cl-measure { font-size: 12px; padding: 5px 10px; }
.cl-auto { font-size: 13px; color: var(--accent); margin: 6px 0 0; }
.exp-tag {
  display: inline-block; font-size: 10.5px; background: var(--accent-soft);
  border-radius: 999px; padding: 2px 8px; margin-inline-start: 8px;
}
.cl-sub { font-size: 11.5px; color: var(--ink-soft); margin-top: 2px; }
.cl-remark {
  width: 100%; margin-top: 6px; font: inherit; font-size: 12.5px;
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfdfd;
}

.modal-box.wide { max-width: 760px; }
.measure-title { font-weight: 800; font-size: 16px; margin-bottom: 4px; }
.measure-hint { font-size: 13px; color: var(--ink-soft); margin-bottom: 10px; }
.measure-canvas-wrap { text-align: center; }
#measure-canvas { max-width: 100%; border-radius: 10px; cursor: crosshair; background: #0c1514; }
.measure-result { font-weight: 700; color: var(--accent); margin-top: 10px; min-height: 1.4em; text-align: center; }

@media (max-width: 560px) {
  .slot-grid { grid-template-columns: repeat(2, 1fr); }
}

/* v3: Design Studio */
.studio-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 10px 0; font-size: 13px; }
.studio-bar label { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.studio-group { display: flex; gap: 6px; align-items: center; }
.studio-group .btn.active { outline: 2px solid var(--accent); }
.studio-lbl { font-weight: 700; }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); cursor: pointer; padding: 0; }
.swatch.active { outline: 2px solid var(--accent); outline-offset: 2px; }
#studio-canvas { display: block; width: 100%; max-width: 920px; border: 1px solid var(--line); border-radius: 12px; touch-action: none; cursor: crosshair; }

/* v3: Mock-up */
.badge-sim { display: inline-block; background: #fef3c7; color: #92400e; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; vertical-align: middle; }
.shade-row { display: flex; flex-wrap: wrap; gap: 5px; }
.shade-swatch { position: relative; width: 30px; height: 30px; }
.shade-lbl { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 700; color: #44403c; }
#mock-canvas { display: block; width: 100%; max-width: 920px; border: 1px solid var(--line); border-radius: 12px; }
#mock-width, #mock-length { vertical-align: middle; }

/* v3.1: per-tooth editor */
.tooth-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.tooth-chip { min-width: 34px; padding: 4px 8px; border-radius: 8px; border: 1px solid var(--line); background: #f1f5f4; color: #94a3b8; font-size: 12px; font-weight: 700; cursor: pointer; }
.tooth-chip.on { background: #0f766e; border-color: #0f766e; color: #fff; }
.mock-editor { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin: 8px 0; }
.mock-sel { font-weight: 700; font-size: 13px; color: var(--accent); }

/* visual tooth-shape picker */
.shape-pic-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.shape-pic { width: 64px; padding: 6px 6px 4px; background: #20262d; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; text-align: center; }
.shape-pic img { width: 100%; height: 58px; object-fit: contain; display: block; }
.shape-pic span { font-size: 10px; color: #9aa7b0; display: block; margin-top: 3px; }
.shape-pic.active { outline: 2px solid var(--accent); outline-offset: 1px; }
.shape-pic:disabled { opacity: 0.45; cursor: default; }

/* v36: merged Design Studio — per-line lock buttons */
.line-lock { background: none; border: none; cursor: pointer; font-size: 12px; padding: 0 2px; opacity: .75; line-height: 1; }
.line-lock.locked { opacity: 1; }

/* v37: insights — profile analysis, compare, plan */
#profile-canvas { display: block; max-width: 100%; border: 1px solid var(--line); border-radius: 12px; margin-top: 10px; background: #0f172a; }
#profile-measures { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin-top: 12px; }
.ins-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fff; }
.ins-title { font-weight: 800; font-size: 14px; margin-bottom: 4px; }
.ins-value { font-size: 15px; font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.ins-ref { font-size: 12px; color: #475569; margin-bottom: 6px; }
.ins-expl { font-size: 12.5px; line-height: 1.55; color: #334155; }

.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 10px; }
.cmp-imgwrap { position: relative; border: 1px solid var(--line); border-radius: 12px; background: #f8fafc; min-height: 220px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.cmp-imgwrap img { max-width: 100%; max-height: 480px; display: none; }
.cmp-placeholder { color: #94a3b8; font-size: 13px; padding: 30px 10px; text-align: center; }
.cmp-file { cursor: pointer; font-size: 12px; }

.plan-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
.plan-table th, .plan-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; line-height: 1.45; }
.plan-table th { background: var(--accent-soft); color: var(--accent); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.plan-table tr:nth-child(even) td { background: #fafcfc; }
@media (max-width: 760px) {
  .compare-grid { grid-template-columns: 1fr; }
  .plan-table { display: block; overflow-x: auto; }
}

/* v38: insights refinement — marked points, band sliders, scores, what-if, arch */
.pm-steps { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 6px; }
.pm-step { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 99px; border: 1px solid var(--line); background: #fff; font-size: 12px; font-weight: 600; color: #475569; cursor: pointer; }
.pm-step i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.pm-step.done { color: var(--accent); border-color: var(--accent); }
.pm-step.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pm-scale { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 4px 0 8px; font-size: 12.5px; }
.pm-scale-status { font-weight: 700; color: #334155; }
.pm-scale input[type=number] { width: 130px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 12.5px; }
.pm-scale-btn { font-size: 12px; }

.band-wrap { margin: 8px 0 2px; }
.band-track { position: relative; height: 10px; border-radius: 99px; background: #eef2f1; border: 1px solid var(--line); overflow: visible; }
.band-ideal { position: absolute; top: 0; bottom: 0; background: #bbf7d0; border-radius: 99px; border: 1px solid #86efac; }
.band-marker { position: absolute; top: -4px; width: 4px; height: 18px; background: #0f172a; border-radius: 2px; transform: translateX(-2px); }
.band-labels { display: flex; justify-content: space-between; font-size: 10.5px; color: #94a3b8; margin-top: 3px; }
.band-labels .band-now { font-weight: 800; color: #0f172a; }
.band-cap { font-size: 11px; color: #64748b; margin: 2px 0 6px; }

.score-chip { display: inline-flex; align-items: center; gap: 8px; padding: 5px 12px; border-radius: 99px; font-weight: 800; font-size: 13px; margin: 6px 0; }
.score-chip.g { background: #dcfce7; color: #166534; }
.score-chip.y { background: #fef9c3; color: #854d0e; }
.score-chip.r { background: #fee2e2; color: #991b1b; }
.score-num-sm { font-size: 14px; }

.whatif { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 8px; }
.whatif-title { font-size: 11.5px; font-weight: 800; color: #64748b; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 4px; }
.whatif-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12px; color: #334155; margin: 4px 0; }
.whatif-cap { flex: 0 0 100%; font-weight: 600; }
.whatif-row input[type=range] { flex: 1 1 120px; }
.whatif-val { font-weight: 700; text-align: right; }
.whatif-tag { font-size: 11.5px; color: #92400e; background: #fef3c7; border-radius: 8px; padding: 4px 8px; margin-top: 4px; display: inline-block; }
.whatif-reset { font-size: 11px; margin-left: 8px; }

.cite { font-size: 11px; color: #64748b; border-top: 1px solid var(--line); margin-top: 8px; padding-top: 6px; font-style: italic; }
.evidence-badge { display: inline-block; background: #fee2e2; color: #991b1b; font-size: 10.5px; font-weight: 800; padding: 3px 9px; border-radius: 99px; margin: 4px 0; letter-spacing: .3px; }

#arch-canvas { display: block; max-width: 100%; border: 1px solid var(--line); border-radius: 12px; margin-top: 10px; background: #0f172a; touch-action: none; }
#profile-canvas { touch-action: none; }
#cmp-harmony { margin-top: 14px; }
@media (max-width: 760px) {
  .whatif-row { grid-template-columns: 1fr; gap: 2px; }
  .whatif-val { text-align: left; }
}

/* v44: mobile tab bar — 7 tabs scroll sideways instead of crushing */
@media (max-width: 760px) {
  .tabs { overflow-x: auto; padding: 8px 10px 0; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; font-size: 13px; padding: 8px 10px; white-space: nowrap; }
  .studio-group { flex-wrap: wrap; }
}
