
/* Off-white enamel background, with minimal UI chrome */
:root{
  --bg: #fbf8f3;
  --ink: #1a1a1a;
  --muted: #555;
  --panel: rgba(255,255,255,0.82);
  --panelSolid: #ffffff;
  --border: rgba(0,0,0,0.12);
  --shadow: 0 12px 40px rgba(0,0,0,0.16);
  --outline: #b8b8b8;
  --stateStroke: rgba(255,255,255,0.92);

  /* ColorBrewer RdYlBu vibe (red - yellow - blue) */
  --red: #d73027;
  --yel: #fee08b;
  --blu: #4575b4;
}

*{ box-sizing: border-box; }

html, body{
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
}

.topbar{
  position: relative;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px 10px 18px;
}

.titles h1{
  margin: 0;
  font-size: clamp(18px, 2.4vw, 30px);
  letter-spacing: -0.02em;
}
.subtitle{
  margin: 6px 0 0 0;
  color: var(--muted);
  font-size: clamp(12px, 1.5vw, 15px);
}

.topActions{
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn{
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.7);
  backdrop-filter: blur(6px);
  padding: 9px 12px;
  border-radius: 12px;
  color: var(--ink);
  cursor: pointer;
  font-weight: 650;
}
.btn:hover{ background: rgba(255,255,255,0.9); }
.btn:active{ transform: translateY(1px); }
.btnGhost{
  background: transparent;
}

.app{
  height: calc(100% - 78px);
  padding: 0 14px 14px 14px;
}

.mapWrap{
  position: relative;
  height: 100%;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.06);
}

.viz{
  width: 100%;
  height: 100%;
  display: block;
  background: var(--bg);
}

.loading{
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: rgba(0,0,0,0.55);
  z-index: 5;
  pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(255,255,255,0.0), rgba(255,255,255,0.7));
}

.legend{
  position: absolute;
  left: 14px;
  bottom: 14px;
  width: 260px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 30;
  overflow: hidden;
}
.legendToggle{
  width: 100%;
  border: 0;
  cursor: pointer;
  text-align: left;
  padding: 10px 12px;
  font-weight: 800;
  background: rgba(255,255,255,0.55);
  color: var(--ink);
}
.legendBody{
  padding: 10px 12px 12px 12px;
}
.legendRow{
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
  font-size: 13px;
  color: rgba(0,0,0,0.72);
}
.swatch{
  width: 18px;
  height: 18px;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.12);
}
.swatchRed{ background: var(--red); }
.swatchYel{ background: var(--yel); }
.swatchBlu{ background: var(--blu); }
.legendNote{
  margin-top: 10px;
  font-size: 12px;
  color: rgba(0,0,0,0.62);
}

.info{
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: min(360px, calc(100% - 28px));
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 30;
  overflow: hidden;
  display: none; /* shown after click */
}
.infoHeader{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.55);
}
.infoTitle{
  font-weight: 900;
  letter-spacing: -0.01em;
}
.infoClose{
  border: 0;
  background: transparent;
  font-size: 20px;
  cursor: pointer;
  opacity: 0.75;
}
.infoClose:hover{ opacity: 1; }
.infoBody{
  padding: 10px 12px 12px 12px;
  color: rgba(0,0,0,0.75);
  font-size: 13px;
  line-height: 1.35;
}
.infoBody .kv{
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  margin: 8px 0 10px 0;
}
.infoBody .k{
  color: rgba(0,0,0,0.55);
}
.infoBody .v{
  font-weight: 800;
}
.infoHint{ color: rgba(0,0,0,0.55); }

.modal{
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(0,0,0,0.35);
  z-index: 100;
  padding: 18px;
}
.modalCard{
  width: min(680px, 100%);
  background: var(--panelSolid);
  border-radius: 16px;
  border: 1px solid rgba(0,0,0,0.12);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modalHeader{
  display:flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px 14px;
  border-bottom: 1px solid rgba(0,0,0,0.08);
}
.modalHeader h2{
  margin: 0;
  font-size: 16px;
}
.modalBody{
  padding: 12px 14px 16px 14px;
  color: rgba(0,0,0,0.75);
  font-size: 13px;
}
.modalFineprint{
  margin-top: 10px;
  color: rgba(0,0,0,0.55);
}
.modal a{ color: inherit; text-decoration: underline; }

/* Rotate gate (portrait mobile) */
.rotateGate{
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: none;
  place-items: center;
  z-index: 999;
  padding: 18px;
}
.rotateCard{
  width: min(520px, 100%);
  border-radius: 18px;
  background: rgba(255,255,255,0.85);
  border: 1px solid rgba(0,0,0,0.10);
  box-shadow: var(--shadow);
  padding: 18px;
  text-align: center;
}
.rotateIcon{
  font-size: 46px;
  opacity: 0.65;
  margin-bottom: 6px;
}
.rotateCard h2{
  margin: 0 0 8px 0;
  font-size: 18px;
}
.rotateCard p{
  margin: 0;
  color: rgba(0,0,0,0.7);
}
.rotateHint{
  margin-top: 10px;
  font-size: 12px;
  color: rgba(0,0,0,0.55);
}

/* Improve tap targets on small screens */
@media (max-width: 720px){
  .legend{ width: 240px; }
  .topbar{ padding: 14px 14px 8px 14px; }
  .app{ height: calc(100% - 72px); padding: 0 10px 10px 10px; }
}

/* SVG styling */
.state{
  cursor: pointer;
}
.stateOutline{
  fill: none;
  stroke: rgba(255,255,255,0.9);
  stroke-width: 1.2px;
  pointer-events: none;
}
.tooth{
  pointer-events: auto;
  cursor: pointer;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,0.18));
}
.tooth .enamel{
  fill: #ffffff;
}
.tooth .enamelStroke{
  fill: none;
  stroke: var(--outline);
  stroke-width: 2.2;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.toothHot{
  filter: drop-shadow(0 6px 12px rgba(0,0,0,0.25));
}
