:root{
  --bg:#0f172a;
  --panel:#1e293b;
  --text:#f1f5f9;
  --muted:#94a3b8;
  --accent:#38bdf8;
  --success:#4ade80;
  --danger:#fb7185;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color:var(--text);
  display:flex;
  flex-direction:column;
  overflow-y:auto;
  -webkit-overflow-scrolling: touch;
}

.app{
  flex:1;
  display:grid;
  grid-template-rows: 60px 1fr 86px;
  max-width:1100px;
  margin:0 auto;
  width:100%;
  gap:1px;
}

header{
  display:flex; align-items:center; justify-content:space-between;
  padding:0 20px;
  border-bottom:1px solid rgba(255,255,255,0.1);
}
h1{font-size:16px; font-weight:600; letter-spacing:0.5px; margin:0;}

.headerRight{
  display:flex;
  align-items:center;
  gap:12px;
}

.badge{
  font-size:11px; text-transform:uppercase; letter-spacing:1px;
  background:rgba(255,255,255,0.1); padding:4px 8px; border-radius:6px;
  color:var(--muted);
}

/* Language dropdown */
.langWrap{
  display:flex;
  align-items:center;
  gap:8px;
  padding:6px 10px;
  border-radius:10px;
  border:1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font-size:12px;
  user-select:none;
}
.langLabel{ color: var(--muted); }
.langSelect{
  background: rgba(255,255,255,0.85);
  border:1px solid rgba(0,0,0,0.15);
  color: #0f172a;
  border-radius:8px;
  padding:6px 8px;
  font-size:12px;
  outline:none;
}
.langSelect:focus{
  border-color: rgba(56,189,248,0.65);
  box-shadow: 0 0 0 3px rgba(56,189,248,0.15);
}
.langSelect option{
  color:#0f172a;
}

.stage{
  position:relative;
  background: radial-gradient(circle at 50% 30%, #25334d 0%, var(--bg) 70%);
  display:flex; align-items:center; justify-content:center;
  overflow:hidden;
}

.controls{
  display:flex; align-items:center; gap:18px;
  padding:0 18px;
  background: var(--panel);
  border-top:1px solid rgba(255,255,255,0.1);
}

.status-box{
  flex:1;
  display:flex; align-items:center; gap:12px;
  font-size:14px;
  color:var(--muted);
  position:relative;
  min-width:260px;
}

/* Growing glow (green or red) */
.pulse{
  position:absolute;
  left:-4px;
  top:50%;
  width:46px;
  height:46px;
  border-radius:999px;
  transform: translateY(-50%) scale(0.6);
  opacity:0;
  pointer-events:none;
  filter: blur(0.2px);
}
.pulse.ok{ background: radial-gradient(circle, rgba(74,222,128,.50) 0%, rgba(74,222,128,.14) 45%, rgba(74,222,128,0) 70%); }
.pulse.bad{ background: radial-gradient(circle, rgba(251,113,133,.55) 0%, rgba(251,113,133,.16) 45%, rgba(251,113,133,0) 70%); }

@keyframes growPulse {
  0% { transform: translateY(-50%) scale(0.55); opacity:0; }
  18%{ opacity:1; }
  70%{ opacity:0.55; }
  100%{ transform: translateY(-50%) scale(1.55); opacity:0; }
}
.pulse.play{ animation: growPulse 650ms ease-out 1; }

.indicator{
  width:12px; height:12px; border-radius:50%;
  background:#ef4444;
  box-shadow: 0 0 10px rgba(239,68,68,0.4);
  transition: background 0.25s, box-shadow 0.25s;
  flex:0 0 auto;
}
.indicator.ok{
  background:var(--success);
  box-shadow: 0 0 16px rgba(74,222,128,0.65);
}
.indicator.bad{
  background:var(--danger);
  box-shadow: 0 0 16px rgba(251,113,133,0.65);
}

.rightControls{
  display:flex; align-items:center; gap:12px;
  flex:0 0 auto;
}

.toggleWrap{
  display:flex; align-items:center; gap:10px;
  padding:8px 12px;
  border-radius:10px;
  border:1px solid rgba(255,255,255,0.10);
  background: rgba(255,255,255,0.04);
  color:var(--muted);
  font-size:13px;
  user-select:none;
}
.toggleWrap strong{ color:var(--text); font-weight:600; }
.toggle{
  position:relative;
  width:46px; height:26px;
  background: rgba(255,255,255,0.08);
  border:1px solid rgba(255,255,255,0.12);
  border-radius:999px;
  cursor:pointer;
  flex:0 0 auto;
}
.knob{
  position:absolute; top:3px; left:3px;
  width:20px; height:20px; border-radius:999px;
  background: rgba(255,255,255,0.82);
  transition: transform 180ms ease, background 180ms ease;
}
.toggle[data-mode="wrong"] .knob{ transform: translateX(20px); background: rgba(255,255,255,0.86); }
.toggle.disabled{ opacity:0.4; pointer-events:none; }

button{
  background:rgba(255,255,255,0.05);
  border:1px solid rgba(255,255,255,0.1);
  color:var(--text);
  padding:10px 14px;
  border-radius:10px;
  cursor:pointer;
  font-size:13px;
  font-weight:600;
  transition:all 0.2s;
  white-space:nowrap;
}
button:hover{background:rgba(255,255,255,0.1);}
button:active{transform:translateY(1px);}

svg{width:100%; height:100%; max-height:520px;}
.cursor-grab { cursor: grab; }
.cursor-grabbing { cursor: grabbing; }

text { font-family: system-ui, -apple-system, sans-serif; user-select: none; pointer-events: none; }
.shear-line { stroke: var(--success); stroke-dasharray: 4 4; opacity:0.55; }
.shear-label { fill: var(--success); font-size: 10px; opacity:0.7; }

/* Make Key mode: optional cutaway view (hide lock internals + shear line/label) */
#svg.internals-hidden #pinsContainer { display: none; }
#svg.internals-hidden .shear-line,
#svg.internals-hidden .shear-label { display: none; }

/* Soft glow on plug when aligned/misaligned at full insertion */
.plugGlowOk { filter: drop-shadow(0 0 10px rgba(74,222,128,0.55)); }
.plugGlowBad{ filter: drop-shadow(0 0 10px rgba(251,113,133,0.55)); }

/* --- Maker panel (left side, positioned above key via JS) --- */
.maker {
  position:absolute;
  left:16px;
  right:auto;
  top:16px; /* JS will adjust */
  width:420px; max-width:90vw;
  background: rgba(30,41,59,0.96);
  border:1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  padding:14px;
  display:none;
  z-index:5;
}
.maker.open{ display:block; }
.maker h3{ margin:0 0 6px 0; font-size:14px; letter-spacing:0.2px; }
.maker .sub{ color:var(--muted); font-size:12px; margin-bottom:10px; line-height:1.35; }

.makerGrid{
  display:grid;
  grid-template-columns: repeat(5, 1fr);
  gap:10px;
  margin-top:8px;
  align-items:end;
}
.toothCol{
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.07);
  border-radius:12px;
  padding:10px 10px 12px;
  text-align:center;
}
.pinLabel{ font-size:12px; color:var(--muted); margin-bottom:8px; }

.depthTag{ font-size:11px; color:var(--muted); margin-top:6px; display:block; }

input[type="range"]{
  width:100%;
  appearance:none;
  height:6px; border-radius:999px;
  background: linear-gradient(90deg, rgba(148,163,184,0.25), rgba(148,163,184,0.12));
  outline:none;
}
input[type="range"]::-webkit-slider-thumb{
  appearance:none;
  width:18px; height:18px; border-radius:50%;
  background:#e2e8f0; border:1px solid rgba(0,0,0,0.25);
  box-shadow: 0 1px 0 rgba(255,255,255,0.6) inset;
  cursor:pointer;
}
.makerActions{
  display:flex; align-items:center; justify-content:space-between;
  gap:10px; margin-top:12px;
}
.makerLeft{
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}

.assist{
  display:flex; align-items:center; gap:8px;
  font-size:12px; color:var(--muted);
  background: rgba(255,255,255,0.03);
  border:1px solid rgba(255,255,255,0.08);
  padding:8px 10px; border-radius:10px;
}

@media (max-width: 520px){
  .maker{
    left:50%;
    transform:translateX(-50%);
    width:min(420px, 92vw);
  }
  .headerRight{ gap:8px; }
  .langWrap{ padding:6px 8px; }
}

/* iPad / touch: prevent page scroll/zoom from interfering with dragging */
#keyGroup, .stage, svg {
  touch-action: pan-y;
}
#keyGroup, .stage, svg {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
