:root{
  --w: 1418;
  --h: 908;
  --blue: #2d5bff;

  /* responsive UI sizing */
  --ui-gap: 10px;
  --ui-pad-x: 12px;
  --btn-size: clamp(26px, 3.2vw, 44px);
  --btn-font: clamp(12px, 1.6vw, 20px);
}

html, body{
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #fff;
  font-family: system-ui, -apple-system, sans-serif;
}

/* ---------- UI (centered, scrolls when needed) ---------- */
#ui{
  position: fixed;
  top: calc(env(safe-area-inset-top) + 12px);
  left: 0;
  right: 0;
  z-index: 10000;
  display: flex;
  justify-content: center;
  pointer-events: auto;
}

#ui .ui-inner{
  display: flex;
  gap: var(--ui-gap);
  padding: 0 var(--ui-pad-x);
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  justify-content: center;
}

#ui .ui-inner::-webkit-scrollbar{ display:none; }

/* On touch devices, start from left (more natural), still scrollable */
@media (hover: none) and (pointer: coarse){
  #ui .ui-inner{ justify-content: flex-start; }
}

.btn{
  width: var(--btn-size);
  height: var(--btn-size);
  font-size: var(--btn-font);
  border: 2px solid var(--blue);
  background: #000;
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex: 0 0 auto;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 520px){
  :root{
    --ui-gap: 8px;
    --ui-pad-x: 10px;
  }
  .btn{ border-width: 1px; }
}

.btn.on{ box-shadow: 0 0 0 2px var(--blue) inset; }

/* ---------- Stage ---------- */
.wrap{
  height: 100%;
  display: grid;
  place-items: center;
  padding-top: calc(env(safe-area-inset-top) + 12px + var(--btn-size) + 24px);
}

#stage{
  position: relative;
  width: min(1418px, calc(100vw - 40px));
  aspect-ratio: var(--w) / var(--h);
}

/* Layers */
.layer-img{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.layer-vid{
  position: absolute;
  transform-origin: center;
  pointer-events: none;
}

.hidden{ display:none !important; }

/* Z order */
#doodle{ z-index: 1; }
#lines{ z-index: 10; }
#math{ z-index: 11; }
#labels{ z-index: 12; }

#v55{ z-index: 20; }
#vipad{ z-index: 21; }
#v65{ z-index: 22; }

#speakers{ z-index: 100; }

img{ image-orientation: none; }

/* ---------- Instruction overlay ---------- */
.instruction{
  position: absolute;
  right: 50px;
  bottom: 50px;
  z-index: 200;
  background: rgba(0,0,0,0.5);
  color: rgba(255,255,255,0.95);
  padding: 16px 18px;
  border-radius: 2px;
  max-width: 360px;

  font-size: 14px;
  line-height: 1.25;
  letter-spacing: 0.2px;

  pointer-events: none;
  user-select: none;
}

@media (max-width: 520px){
  .instruction{
    left: 6%;
    right: 6%;
    bottom: 6%;
    max-width: none;
    font-size: 12px;
    padding: 12px 14px;
  }
}

.instruction-title{ font-weight: 600; margin-bottom: 10px; }
.instruction-body{ font-weight: 400; margin-bottom: 10px; }
.instruction-name{ font-weight: 500; }
.instruction-year{ opacity: 0.9; }
