/* Dental Chart — light clinical studio (mint + blue) */

:root {
  --dc-bg: #eef3f9;
  --dc-bg-tint-a: rgba(0, 194, 168, 0.10);
  --dc-bg-tint-b: rgba(47, 124, 255, 0.08);
  --dc-surface: #ffffff;
  --dc-surface-2: #f6f9fd;
  --dc-surface-sunken: #eef3f9;
  --dc-border: #e2e9f2;
  --dc-border-strong: rgba(0, 194, 168, 0.45);
  --dc-text: #0f1b2d;
  --dc-text-soft: #3c4a60;
  --dc-text-muted: #7c8aa1;
  --dc-mint: #00c2a8;
  --dc-mint-strong: #02a890;
  --dc-mint-soft: rgba(0, 194, 168, 0.12);
  --dc-blue: #2f7cff;
  --dc-blue-soft: rgba(47, 124, 255, 0.12);
  --dc-amber: #f59e0b;
  --dc-amber-soft: rgba(245, 158, 11, 0.12);
  --dc-rose: #f43f5e;
  /* Muted dark red for IPR lines and labels on the tooth chart. */
  --dc-ipr-color: #8a4e4e;
  --dc-ipr-glow: rgba(138, 78, 78, 0.18);
  --dc-radius: 20px;
  --dc-radius-md: 14px;
  --dc-radius-sm: 10px;
  --dc-shadow-sm: 0 1px 2px rgba(15, 27, 45, 0.05), 0 2px 8px rgba(15, 27, 45, 0.04);
  --dc-shadow: 0 8px 30px rgba(28, 55, 90, 0.10), 0 2px 8px rgba(28, 55, 90, 0.06);
  --dc-shadow-lg: 0 20px 60px rgba(28, 55, 90, 0.16);
  --dc-glow: 0 0 0 4px rgba(0, 194, 168, 0.14);
  /* Fraction of the tooth cell the icon box occupies. Applies uniformly to every
     tooth so they render at the same height. Custom PNG letterboxing is collapsed
     via --dc-tooth-art-inset (see .tooth--custom-image). */
  --dc-tooth-icon-width: 100%;
  /* Fallback selection inset for built-in SVG teeth (no letterboxing).
     Custom PNG art uses --dc-tooth-art-inset (computed per tooth in JS). */
  --dc-select-inset: 6%;
  /* Height of the FDI number row — the number's line box plus its margins. Keep
     in step with .tooth__number; IPR values are placed just outside this row. */
  --dc-tooth-number-row: 21px;
  /* Contact gap — every adjacent pair (including midlines) uses this exact
     width. IPR click targets stay larger via ::before. */
  --dc-ipr-contact-gap: 8px;
  /* Shared crown height fallback (overridden on .dental-chart with cqw). */
  --dc-tooth-slot-height: 8.5rem;
  /* Extra collapse when a neighbor tooth is excluded / midline is closed. */
  --dc-tooth-collapse-pull: 12px;
  --dc-tooth-midline-pull: 12px;
  --dc-font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", system-ui, sans-serif;
}

html:has(.dental-page) {
  height: auto;
  min-height: 100%;
  overflow-y: auto;
}

body:has(.dental-page) {
  height: auto;
  min-height: 100%;
  overflow-y: auto;
  background: var(--dc-bg);
  background-image:
    radial-gradient(ellipse 70% 50% at 15% -10%, var(--dc-bg-tint-a), transparent 60%),
    radial-gradient(ellipse 60% 50% at 100% 0%, var(--dc-bg-tint-b), transparent 55%);
  background-attachment: fixed;
  color: var(--dc-text);
  font-family: var(--dc-font);
  -webkit-font-smoothing: antialiased;
}

body:has(.dental-page) .app-main {
  min-height: 100dvh;
  height: auto;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

body:has(.dental-page) .app-header {
  flex-shrink: 0;
}

body:has(.dental-page) .app-shell,
body:has(.dental-page) .app-shell__content {
  height: auto;
  overflow: visible;
}

/* page shell */

.dental-page {
  width: min(96%, 100% - 1.5rem);
  max-width: none;
  margin: 0 auto;
  padding: 1.5rem 0 1.5rem;
  box-sizing: border-box;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: visible;
}

/* Header */

.dental-header {
  margin-bottom: 1.25rem;
  flex-shrink: 0;
}

.dental-header__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.dental-header__brand {
  min-width: 0;
}

.dental-title {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 750;
  letter-spacing: -0.025em;
  background: linear-gradient(120deg, var(--dc-text) 20%, var(--dc-mint-strong) 110%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.dental-subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--dc-text-muted);
}

.dental-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.dental-meta__chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--dc-border);
  border-radius: 999px;
  background: var(--dc-surface);
  box-shadow: var(--dc-shadow-sm);
  font-size: 0.8125rem;
  color: var(--dc-text);
}

.dental-meta__chip strong { font-weight: 650; }

.dental-meta__label {
  font-size: 0.6875rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--dc-text-muted);
}

.dental-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 0.95rem;
  border: 1px solid var(--dc-border);
  border-radius: var(--dc-radius-sm);
  background: var(--dc-surface);
  box-shadow: var(--dc-shadow-sm);
  color: var(--dc-text-soft);
  font-size: 0.8125rem;
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.18s, color 0.18s, box-shadow 0.18s, transform 0.18s;
  flex-shrink: 0;
}

.dental-back:hover {
  border-color: var(--dc-border-strong);
  color: var(--dc-mint-strong);
  box-shadow: var(--dc-shadow);
  transform: translateY(-1px);
  text-decoration: none;
}

.dental-back svg { flex-shrink: 0; }

/* Dentition switcher — segmented pill group */

.stage-switcher {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
  padding: 0.3rem;
  border: 1px solid var(--dc-border);
  border-radius: var(--dc-radius-md);
  background: var(--dc-surface);
  box-shadow: var(--dc-shadow-sm);
  flex-shrink: 0;
}

.stage-switcher__btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.05rem;
  padding: 0.5rem 0.95rem;
  border: 1px solid transparent;
  border-radius: var(--dc-radius-sm);
  background: transparent;
  cursor: pointer;
  transition: background 0.18s, box-shadow 0.18s, color 0.18s;
}

.stage-switcher__btn:hover {
  background: var(--dc-surface-2);
}

.stage-switcher__btn--active {
  background: linear-gradient(135deg, var(--dc-mint-soft), var(--dc-blue-soft));
  border-color: var(--dc-mint);
  box-shadow: var(--dc-glow), inset 0 0 0 1px rgba(0, 194, 168, 0.25);
}

.stage-switcher__name {
  font-size: 0.8125rem;
  font-weight: 650;
  color: var(--dc-text);
}

.stage-switcher__btn--active .stage-switcher__name {
  color: var(--dc-mint-strong);
  font-weight: 700;
}

.stage-switcher__btn--active .stage-switcher__meta {
  color: var(--dc-mint-strong);
  font-weight: 600;
}

.stage-switcher__meta {
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--dc-text-muted);
}

.stage-description {
  margin: 0 0 1rem;
  font-size: 0.8125rem;
  color: var(--dc-text-muted);
  flex-shrink: 0;
}

.stage-description--hint {
  color: var(--dc-amber);
  font-weight: 600;
}

/* Chart workspace: left edit rail | chart | right stage rail */

.dental-chart-workspace {
  display: flex;
  align-items: stretch;
  gap: 0.75rem;
  flex: 1 1 auto;
  min-height: calc(100dvh - 16rem);
  width: 100%;
  box-sizing: border-box;
}

.dental-chart-wrapper {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-x: auto;
  overflow-y: visible;
  padding-bottom: 0.5rem;
}

/* Left of chart — remove (top) / add (bottom), full chart height */

.chart-edit-overlay {
  position: relative;
  z-index: 2;
  flex: 0 0 5.5rem;
  width: 5.5rem;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0;
  border: 1px solid rgba(47, 124, 255, 0.35);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow:
    0 18px 50px rgba(47, 124, 255, 0.12),
    0 2px 8px rgba(28, 55, 90, 0.06);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  box-sizing: border-box;
  overflow: hidden;
}

.chart-edit-overlay__btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 0;
  padding: 0.75rem 0.45rem;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--dc-text-soft);
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, color 0.15s;
}

.chart-edit-overlay__btn + .chart-edit-overlay__btn {
  border-top: 1px solid var(--dc-border);
}

.chart-edit-overlay__btn:hover {
  background: rgba(255, 255, 255, 0.72);
}

.chart-edit-overlay__btn--active {
  box-shadow: inset 0 0 0 2px rgba(0, 194, 168, 0.35);
}

.chart-edit-overlay__btn--add.chart-edit-overlay__btn--active {
  background: rgba(0, 194, 168, 0.12);
  color: var(--dc-mint-strong);
  box-shadow: inset 0 0 0 2px rgba(0, 194, 168, 0.45);
}

.chart-edit-overlay__btn--remove:hover {
  background: rgba(244, 63, 94, 0.06);
}

.chart-edit-overlay__btn--remove.chart-edit-overlay__btn--active {
  background: rgba(244, 63, 94, 0.1);
  box-shadow: inset 0 0 0 2px rgba(244, 63, 94, 0.4);
  color: #e11d48;
}

.chart-edit-overlay__icon {
  font-size: 1.125rem;
  font-weight: 700;
  line-height: 1;
}

.chart-edit-overlay__label {
  font-size: 0.625rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.chart-edit-overlay__extra-types {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 0 0 auto;
  max-height: 42%;
  overflow: auto;
  padding: 0.55rem 0.5rem 0.65rem;
  border-top: 1px solid var(--dc-border);
  background: rgba(246, 249, 253, 0.72);
}

.chart-edit-overlay__extra-types[hidden] {
  display: none;
}

.chart-edit-overlay__extra-label {
  font-size: 0.625rem;
  font-weight: 650;
  color: var(--dc-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chart-edit-overlay__extra-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.chart-edit-overlay__type-btn {
  padding: 0.3rem 0.45rem;
  border: 1px solid var(--dc-border);
  border-radius: 8px;
  background: #f6f9fd;
  font-size: 0.625rem;
  font-weight: 650;
  color: var(--dc-text-soft);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.chart-edit-overlay__type-btn:hover {
  border-color: var(--dc-mint);
  background: rgba(0, 194, 168, 0.08);
  color: var(--dc-mint-strong);
}

.chart-edit-overlay__type-btn--active {
  border-color: var(--dc-mint);
  background: rgba(0, 194, 168, 0.14);
  color: var(--dc-mint-strong);
  box-shadow: 0 0 0 2px rgba(0, 194, 168, 0.14);
}

.dental-page:has(.dental-chart--readonly) .chart-edit-overlay {
  opacity: 0.45;
  pointer-events: none;
}

.dental-chart {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 500px;
  padding: 1.75rem clamp(1rem, 2.5vw, 2.5rem) 2rem;
  border: 1px solid rgba(0, 194, 168, 0.28);
  border-radius: var(--dc-radius);
  background:
    radial-gradient(ellipse 85% 55% at 50% 42%, rgba(0, 194, 168, 0.22), transparent 62%),
    radial-gradient(ellipse 55% 45% at 8% 18%, rgba(47, 124, 255, 0.14), transparent 58%),
    radial-gradient(ellipse 50% 40% at 95% 85%, rgba(47, 124, 255, 0.12), transparent 55%),
    linear-gradient(165deg, #d5e6ef 0%, #c7dce8 48%, #b9d0e0 100%);
  box-shadow:
    var(--dc-shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    inset 0 -1px 0 rgba(47, 124, 255, 0.06);
  overflow: visible;
  box-sizing: border-box;
  container-type: inline-size;
  container-name: dental-chart;
  /* Preferred crown height; JS may shrink below this so the arch still fits. */
  --dc-tooth-slot-height: clamp(5.75rem, 13.5cqw, 9.25rem);
}

/* subtle dotted "design tool" grid */
.dental-chart::before {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: calc(var(--dc-radius) - 8px);
  background-image: radial-gradient(rgba(2, 168, 144, 0.16) 1px, transparent 1px);
  background-size: 22px 22px;
  pointer-events: none;
  z-index: 0;
}

.dental-chart > * { position: relative; z-index: 1; }

.dental-chart-wrapper.dental-chart--paint-mode .dental-chart,
.dental-chart-wrapper.dental-chart--edit-mode .dental-chart {
  cursor: crosshair;
}

.dental-chart-wrapper.dental-chart--paint-mode .tooth,
.dental-chart-wrapper.dental-chart--edit-mode .tooth,
.dental-chart-wrapper.dental-chart--paint-mode .tooth-gap,
.dental-chart-wrapper.dental-chart--paint-mode .arch-midline-gap {
  cursor: crosshair;
}

/* Arch layout */

.dental-arch {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
}

.dental-arch--upper {
  padding-top: 5rem;
  padding-bottom: 1rem;
  align-items: flex-end;
}

.dental-arch--lower {
  padding-top: 1rem;
  padding-bottom: 5rem;
  align-items: flex-start;
}

/* Flatten halves into one flex row so the midline gap matches every other
   tooth-gap (no separate half formatting context stretching 11–21 / 41–31). */
.dental-arch__half {
  display: contents;
}

.dental-arch__half--right,
.dental-arch__half--left {
  flex-direction: row;
}

/* Occlusal plane */

.occlusal-plane {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0.5rem 0;
  height: 38px;
}

.occlusal-plane::before {
  content: "";
  position: absolute;
  left: 4%;
  right: 4%;
  top: 50%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--dc-border-strong) 30%, var(--dc-border-strong) 70%, transparent);
}

.occlusal-plane__label {
  position: relative;
  z-index: 1;
  padding: 0.28rem 0.95rem;
  font-size: 0.625rem;
  font-weight: 750;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--dc-mint-strong);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid var(--dc-border-strong);
  border-radius: 999px;
  box-shadow: var(--dc-shadow-sm);
}

/* Quadrant labels */

.quadrant-label {
  position: absolute;
  font-size: 0.625rem;
  font-weight: 650;
  color: #5a6d86;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
}

.quadrant-label--ur { top: 0.4rem; left: 0.9rem; }
.quadrant-label--ul { top: 0.4rem; right: 0.9rem; }
.quadrant-label--lr { bottom: 0.4rem; left: 0.9rem; }
.quadrant-label--ll { bottom: 0.4rem; right: 0.9rem; }

/* Tooth element */

.tooth {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 auto;
  /* Fallback equal slot; custom art overrides with --dc-tooth-art-width. */
  width: min(100px, calc((100cqw - 15 * var(--dc-ipr-contact-gap, 6px)) / 16));
  min-width: 1.25rem;
  max-width: 100px;
  position: relative;
  /* Above gap slots so tooth clicks and side IPR lines are not covered by gap IPR. */
  z-index: 3;
  cursor: pointer;
  transition: transform 0.18s ease, filter 0.18s ease;
}

.tooth:hover {
  transform: translateY(-3px) scale(1.04);
  filter: drop-shadow(0 8px 14px rgba(0, 194, 168, 0.25));
  z-index: 4;
}

/* Selection highlight hugs the visible tooth art. Custom PNGs set
   --dc-tooth-art-inset per tooth; built-in SVGs fall back to --dc-select-inset. */
.tooth--selected .tooth__icon::after {
  content: "";
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: var(--dc-tooth-art-inset, var(--dc-select-inset));
  right: var(--dc-tooth-art-inset, var(--dc-select-inset));
  border: 2px solid var(--dc-mint);
  border-radius: 14px;
  box-shadow: var(--dc-glow);
  pointer-events: none;
  z-index: 3;
}

.tooth--selected .tooth__number {
  color: var(--dc-mint-strong);
  font-weight: 750;
}

.tooth--custom-image.tooth--selected {
  z-index: 4;
}

.tooth--excluded {
  flex: 0 0 auto;
  opacity: 0.4;
  filter: grayscale(0.8);
  cursor: not-allowed;
}

.tooth--excluded:hover { transform: none; filter: grayscale(0.8); }

.tooth--excluded .tooth__number {
  text-decoration: line-through;
  color: var(--dc-text-muted);
}

.tooth--excluded .tooth__enamel { fill: #dfe6ef; }

.dental-arch--treatment-disabled .tooth--arch-disabled,
.dental-arch--treatment-disabled .tooth-gap--arch-disabled {
  opacity: 0.4;
  filter: grayscale(0.7);
  cursor: not-allowed;
}

.dental-arch--treatment-disabled .tooth--arch-disabled:hover,
.dental-arch--treatment-disabled .tooth-gap--arch-disabled:hover {
  transform: none;
}

/* Custom art: width = art aspect × shared height. Gaps stay identical because
   spacing comes only from .tooth-gap / .arch-midline-gap — never from pull. */
.tooth--custom-image:not(.tooth--excluded) {
  width: var(--dc-tooth-art-width, min(100px, calc((100cqw - 15 * var(--dc-ipr-contact-gap, 8px)) / 16)));
  max-width: none;
  margin-inline: 0;
  position: relative;
  z-index: 3;
}

/* Excluded-neighbor squeeze only. Do not let midline pull exceed the contact
   gap or centrals visually merge when a squeeze is applied. */
.tooth--pull-next {
  margin-right: calc(-1 * var(--dc-tooth-collapse-pull));
  position: relative;
  z-index: 3;
}

.tooth--pull-prev {
  margin-left: calc(-1 * var(--dc-tooth-collapse-pull));
  position: relative;
  z-index: 3;
}

.dental-arch__half--right .tooth--pull-midline,
.tooth[data-quadrant-side="right"].tooth--pull-midline {
  margin-right: calc(-1 * min(var(--dc-tooth-midline-pull), var(--dc-ipr-contact-gap, 8px)));
}

.dental-arch__half--left .tooth--pull-midline,
.tooth[data-quadrant-side="left"].tooth--pull-midline {
  margin-left: calc(-1 * min(var(--dc-tooth-midline-pull), var(--dc-ipr-contact-gap, 8px)));
}

.dental-chart-wrapper.dental-chart--add-mode .tooth--excluded {
  cursor: pointer;
  opacity: 0.55;
}

.dental-chart-wrapper.dental-chart--add-mode .tooth--excluded:hover {
  opacity: 0.8;
  transform: scale(1.04);
}

.dental-chart-wrapper.dental-chart--remove-mode .tooth:not(.tooth--excluded) {
  cursor: crosshair;
}

.tooth--extra .tooth__number {
  color: var(--dc-mint-strong);
  font-weight: 750;
}

.tooth--extra .tooth__icon {
  max-width: 100%;
  height: auto;
  aspect-ratio: 11 / 16;
  outline: 2px dashed var(--dc-mint);
  outline-offset: -8px;
  border-radius: 14px;
}

.dental-chart-wrapper.dental-chart--remove-extra-mode .tooth--extra { cursor: crosshair; }

.dental-chart-wrapper.dental-chart--remove-extra-mode .tooth--extra:hover {
  transform: scale(1.07);
  outline: 2px solid var(--dc-amber);
  outline-offset: 2px;
}

.tooth__number {
  font-size: 0.6875rem;
  font-size: clamp(0.5rem, 1.35cqi, 0.6875rem);
  font-weight: 650;
  color: var(--dc-text-muted);
  line-height: 1;
  margin: 5px 0;
  user-select: none;
  font-variant-numeric: tabular-nums;
  max-width: 100%;
  overflow: hidden;
  text-overflow: clip;
  text-align: center;
}

.tooth__number--upper { order: 0; }
.tooth__number--lower { order: 2; }

.tooth__icon {
  order: 1;
  position: relative;
  width: var(--dc-tooth-icon-width);
  max-width: 100%;
  margin-inline: auto;
  height: auto;
  aspect-ratio: 11 / 16;
}

.tooth__icon svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 3px 6px rgba(28, 55, 90, 0.18));
  overflow: visible;
}

.tooth__image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 4px 8px rgba(28, 55, 90, 0.22));
  pointer-events: none;
}

/* Custom tooth art: shared height, width from art aspect — fills the box.
   Keep overflow visible so mesial/distal IPR lines and Step/mm tags are not clipped. */
.tooth--custom-image .tooth__icon {
  width: 100%;
  max-width: 100%;
  height: var(--dc-tooth-slot-height);
  aspect-ratio: auto;
  overflow: visible;
  filter: none;
}

.tooth--custom-image .tooth__image {
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: fill;
  object-position: center center;
  /* Shadow on the image only — filtering the icon box clipped IPR labels. */
  filter: drop-shadow(0 2px 3px rgba(28, 55, 90, 0.16));
  pointer-events: none;
}

.tooth--upper.tooth--custom-image .tooth__image {
  object-position: center bottom;
}

.tooth--lower.tooth--custom-image .tooth__image {
  object-position: center top;
}

/* SVG tooth anatomy — pearl on light tray */

.tooth__enamel {
  fill: #fdfeff;
  stroke: #c2d0e2;
  stroke-width: 0.7;
  stroke-linejoin: round;
}

.tooth__enamel-shade {
  fill: #e7eef6;
  stroke: none;
  opacity: 0.9;
}

.tooth__gloss {
  fill: #ffffff;
  opacity: 0.75;
  stroke: none;
}

.tooth__cusp {
  fill: none;
  stroke: #aebccd;
  stroke-width: 0.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tooth__root {
  fill: #ecd9bf;
  stroke: #d6bd9a;
  stroke-width: 0.6;
  stroke-linejoin: round;
}

.tooth:hover .tooth__enamel { stroke: var(--dc-border-strong); }

.tooth--missing .tooth__number {
  color: var(--dc-blue);
  font-weight: 750;
}

.tooth--missing .tooth__enamel { fill: #dbe3ee; }
.tooth--missing .tooth__root { opacity: 0.5; }

.tooth__missing-x {
  stroke: var(--dc-blue);
  stroke-width: 2.5;
  stroke-linecap: round;
}

.arch-midline {
  width: var(--dc-ipr-contact-gap, 8px);
  flex-shrink: 0;
}

/* All dentition stages share the same tooth slot size (sized for 8 teeth/half
   so milky / without wisdom / with wisdom match, with no horizontal scroll). */
.dental-chart-wrapper.dental-chart--stage-with_wisdom .dental-chart,
.dental-chart-wrapper.dental-chart--stage-without_wisdom .dental-chart,
.dental-chart-wrapper.dental-chart--stage-milky .dental-chart {
  padding-left: clamp(0.5rem, 1.5vw, 1.25rem);
  padding-right: clamp(0.5rem, 1.5vw, 1.25rem);
  overflow: visible;
}

.dental-chart-wrapper.dental-chart--stage-with_wisdom .dental-arch__half,
.dental-chart-wrapper.dental-chart--stage-without_wisdom .dental-arch__half,
.dental-chart-wrapper.dental-chart--stage-milky .dental-arch__half {
  gap: 0;
}

.dental-chart-wrapper.dental-chart--stage-with_wisdom .arch-midline,
.dental-chart-wrapper.dental-chart--stage-without_wisdom .arch-midline,
.dental-chart-wrapper.dental-chart--stage-milky .arch-midline {
  width: var(--dc-ipr-contact-gap, 8px);
}

.dental-chart-wrapper.dental-chart--stage-with_wisdom .arch-midline-gap,
.dental-chart-wrapper.dental-chart--stage-without_wisdom .arch-midline-gap,
.dental-chart-wrapper.dental-chart--stage-milky .arch-midline-gap {
  width: var(--dc-ipr-contact-gap, 8px);
  min-width: var(--dc-ipr-contact-gap, 8px);
  max-width: var(--dc-ipr-contact-gap, 8px);
}

.dental-chart-wrapper.dental-chart--stage-with_wisdom .tooth,
.dental-chart-wrapper.dental-chart--stage-without_wisdom .tooth,
.dental-chart-wrapper.dental-chart--stage-milky .tooth {
  flex: 0 0 auto;
  width: min(100px, calc((100cqw - 15 * var(--dc-ipr-contact-gap, 6px)) / 16));
  max-width: 100px;
  min-width: 1.25rem;
}

.dental-chart-wrapper.dental-chart--stage-with_wisdom .tooth--custom-image:not(.tooth--excluded),
.dental-chart-wrapper.dental-chart--stage-without_wisdom .tooth--custom-image:not(.tooth--excluded),
.dental-chart-wrapper.dental-chart--stage-milky .tooth--custom-image:not(.tooth--excluded) {
  width: var(--dc-tooth-art-width, min(100px, calc((100cqw - 15 * var(--dc-ipr-contact-gap, 6px)) / 16)));
  max-width: none;
}

.dental-chart-wrapper.dental-chart--stage-with_wisdom .tooth__icon,
.dental-chart-wrapper.dental-chart--stage-with_wisdom .tooth--extra .tooth__icon,
.dental-chart-wrapper.dental-chart--stage-without_wisdom .tooth__icon,
.dental-chart-wrapper.dental-chart--stage-without_wisdom .tooth--extra .tooth__icon,
.dental-chart-wrapper.dental-chart--stage-milky .tooth__icon,
.dental-chart-wrapper.dental-chart--stage-milky .tooth--extra .tooth__icon {
  aspect-ratio: 10 / 16;
}

.dental-chart-wrapper.dental-chart--stage-with_wisdom .tooth--custom-image .tooth__icon,
.dental-chart-wrapper.dental-chart--stage-without_wisdom .tooth--custom-image .tooth__icon,
.dental-chart-wrapper.dental-chart--stage-milky .tooth--custom-image .tooth__icon {
  aspect-ratio: auto;
  height: var(--dc-tooth-slot-height);
}

.dental-chart-wrapper.dental-chart--stage-with_wisdom .tooth-gap,
.dental-chart-wrapper.dental-chart--stage-without_wisdom .tooth-gap,
.dental-chart-wrapper.dental-chart--stage-milky .tooth-gap {
  flex: 0 0 var(--dc-ipr-contact-gap, 5px);
  min-width: var(--dc-ipr-contact-gap, 5px);
  max-width: var(--dc-ipr-contact-gap, 5px);
}

@media (max-width: 1400px) {
  :root {
    --dc-ipr-contact-gap: 7px;
    --dc-tooth-collapse-pull: 10px;
    --dc-tooth-midline-pull: 10px;
  }
}

@media (max-width: 1200px) {
  :root {
    --dc-ipr-contact-gap: 6px;
    --dc-tooth-collapse-pull: 9px;
    --dc-tooth-midline-pull: 9px;
  }

  .dental-chart-workspace {
    flex-direction: column;
    min-height: 0;
    gap: 0.65rem;
  }

  .dental-chart-wrapper {
    flex: none;
    order: 1;
  }

  .chart-edit-overlay {
    flex: none;
    width: 100%;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    order: 2;
  }

  .chart-edit-overlay__btn {
    flex: 1 1 0;
    min-height: 3.5rem;
    padding: 0.55rem 0.45rem;
  }

  .chart-edit-overlay__btn + .chart-edit-overlay__btn {
    border-top: none;
    border-left: 1px solid var(--dc-border);
  }

  .chart-edit-overlay__extra-types {
    flex: 1 1 100%;
    max-height: 10rem;
  }
}

@media (max-width: 900px) {
  :root {
    --dc-ipr-contact-gap: 5px;
    --dc-tooth-collapse-pull: 8px;
    --dc-tooth-midline-pull: 8px;
  }
}

@media (max-width: 768px) {
  /* Small screens: allow page scroll so content is not clipped */
  html:has(.dental-page),
  body:has(.dental-page) {
    height: auto;
    overflow: auto;
  }

  body:has(.dental-page) .app-main {
    height: auto;
    overflow: visible;
  }

  .dental-page {
    width: 100%;
    padding: 1rem 0.75rem 1.5rem;
    overflow: visible;
    flex: none;
    min-height: 0;
  }

  .dental-chart-workspace {
    flex-direction: column;
    min-height: 0;
    gap: 0.65rem;
  }

  .dental-chart-wrapper {
    flex: none;
    order: 1;
  }

  .dental-chart { padding: 1.5rem 0.85rem 2rem; min-height: 420px; }

  .dental-arch {
    min-width: 0;
    width: 100%;
  }

  .dental-chart-wrapper.dental-chart--stage-with_wisdom .tooth,
  .dental-chart-wrapper.dental-chart--stage-without_wisdom .tooth,
  .dental-chart-wrapper.dental-chart--stage-milky .tooth,
  .tooth {
    flex: 0 0 auto;
    min-width: 1.2rem;
    max-width: 76px;
    width: min(76px, calc((100cqw - 15 * var(--dc-ipr-contact-gap, 5px)) / 16));
  }

  .dental-chart-wrapper.dental-chart--stage-with_wisdom .tooth--custom-image:not(.tooth--excluded),
  .dental-chart-wrapper.dental-chart--stage-without_wisdom .tooth--custom-image:not(.tooth--excluded),
  .dental-chart-wrapper.dental-chart--stage-milky .tooth--custom-image:not(.tooth--excluded),
  .tooth--custom-image:not(.tooth--excluded) {
    width: var(--dc-tooth-art-width, min(76px, calc((100cqw - 15 * var(--dc-ipr-contact-gap, 5px)) / 16)));
    max-width: none;
  }

  /* Keep custom PNG crowns on the JS-fitted slot height — do not force a fixed ratio. */
  .tooth__icon,
  .tooth--extra .tooth__icon {
    max-width: 100%;
  }

  .tooth--custom-image .tooth__icon {
    max-width: 100%;
    height: var(--dc-tooth-slot-height);
    aspect-ratio: auto;
  }

  .dental-title { font-size: 1.25rem; }
}
