/*!
 * 3DLiteView 1.7
 * Copyright (c) 2026 Sergio Romero. All rights reserved. / Todos los derechos reservados.
 *
 * This software may not be copied, modified, distributed or reused, in whole
 * or in part, without the written permission of the author.
 * Este software no puede copiarse, modificarse, distribuirse ni reutilizarse,
 * total o parcialmente, sin el permiso por escrito del autor.
 *
 * Includes three.js in lib/ (MIT License). See THIRD-PARTY-NOTICES.txt.
 */

/* Formero HUD look (same family as the "360 Method" block of the website):
   near-black background with a faint grid, neon outlines with a soft glow,
   dark glass panels. Buttons keep their size, shape and position.
   Type: Roboto (bundled in fonts/, no internet needed). */
@font-face {
  font-family: "Roboto";
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url("fonts/Roboto-Regular.woff") format("woff");
}
@font-face {
  font-family: "Roboto";
  font-weight: 500;
  font-style: normal;
  font-display: swap;
  src: url("fonts/Roboto-Medium.woff") format("woff");
}
@font-face {
  font-family: "Roboto";
  font-weight: 700;
  font-style: normal;
  font-display: swap;
  src: url("fonts/Roboto-Bold.woff") format("woff");
}

:root {
  --bg-dark: #0b0b0c;
  --cyan: #2ed3c6;
  --cyan-glow: rgba(46, 211, 198, 0.4);
  --magenta: #ff2db4;
  --magenta-glow: rgba(255, 45, 180, 0.4);
  --amber: #ffb020;
  --amber-glow: rgba(255, 176, 32, 0.4);
  --steel: #f4f2ee;
  --steel-glow: rgba(244, 242, 238, 0.25);
  --text: #f4f2ee;
  --btn-fill: rgba(11, 11, 12, 0.75);
  --panel-fill: rgba(11, 11, 12, 0.72);
  --panel-line: rgba(46, 211, 198, 0.28);
  --btn-radius: 2px;
}

html {
  height: 100%;
  background-color: var(--bg-dark);
  background-image:
    radial-gradient(circle at 50% 50%, rgba(58, 63, 68, 0.4) 0%, rgba(11, 11, 12, 0.97) 76%),
    linear-gradient(rgba(44, 246, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(44, 246, 255, 0.035) 1px, transparent 1px);
  background-size: 100% 100%, 41.4px 41.4px, 41.4px 41.4px;
  background-attachment: fixed;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: "Roboto", Arial, sans-serif;
  color: var(--text);
}

/* Soft dark edges (like a screen). Sits above the 3D view, below every control. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  box-shadow: inset 0 0 110px rgba(0, 0, 0, 0.6);
}

canvas {
  display: block;
  cursor: grab; /* open hand: you can click and drag to move around */
}

canvas:active {
  cursor: grabbing; /* closed hand while dragging */
}

/* Buttons: dark fill, neon outline (drawn inside, so the size never changes)
   and a soft glow. --c / --g set each button's color. */
button {
  --c: var(--cyan);
  --g: var(--cyan-glow);
  --tint: color-mix(in srgb, var(--c) 20%, transparent);
  position: absolute;
  right: 10px;
  padding: 10px 15px;
  background-color: var(--btn-fill);
  background-image: none;
  border: none;
  cursor: pointer;
  font-family: "Roboto", Arial, sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  border-radius: var(--btn-radius);
  box-shadow: inset 0 0 0 1px var(--c), 0 0 5px var(--g);
  transition: background-color 0.25s ease, box-shadow 0.25s ease;
  width: 75px;
  height: 36px; /* same height for every button so the gaps stay equal */
  box-sizing: border-box;
}

button:hover {
  background-image: linear-gradient(var(--tint), var(--tint));
  box-shadow: inset 0 0 0 1px var(--c), 0 0 12px var(--c);
}

/* Active button state */
button.active {
  --tint: color-mix(in srgb, var(--c) 34%, transparent);
  background-image: linear-gradient(var(--tint), var(--tint));
  box-shadow: inset 0 0 0 1px var(--c), 0 0 10px var(--g);
}

/* Button positions */

#uploadBtn {
    top: 10px;
    left: 10px;
    width: 160px; /* long enough for "Analyzing 100%" on one line */
    white-space: nowrap;
    height: 40px;
}

/* While a file is read the button shows a progress fill (set by the script) */
#uploadBtn.loading {
    opacity: 1 !important;
    filter: none !important;
}

/* While analyzing: same color as the RESET button */
#uploadBtn.loading.analyzing {
    --c: var(--magenta);
    --g: var(--magenta-glow);
}

/* EXPORT: same size as UPLOAD, right next to it, amber like DELETE.
   Grayed out until a model is on screen. The four format buttons open in a
   small menu right under it. */
#exportBtn {
  --c: var(--amber);
  --g: var(--amber-glow);
  top: 10px;
  left: 174px; /* 4px gap, same as between the camera buttons */
  right: auto;
  width: 160px;
  height: 40px;
  white-space: nowrap;
}
#exportBtn.disabled,
#exportBtn.disabled:hover {
  background-image: none;
  box-shadow: inset 0 0 0 1px var(--c), 0 0 5px var(--g);
  opacity: 0.4;
  cursor: not-allowed;
}
#exportMenu {
  position: absolute;
  top: 54px;
  left: 174px; /* 4px gap, same as between the camera buttons */
  width: 160px;
  display: none;
  grid-template-columns: repeat(4, 1fr); /* one row of four small buttons */
  gap: 4px;
  z-index: 20;
}
#exportMenu.open {
  display: grid;
}
#exportMenu button {
  --c: var(--amber);
  --g: var(--amber-glow);
  position: static;
  right: auto;
  width: 100%;
  height: 26px;
  padding: 0;
  font-size: 11px;
}

#viewBtn {
  top: 10px;
}
#frontBtn {
  top: 10px;
  right: 326px; /* leftmost of the four */
}
#sideBtn {
  top: 10px;
  right: 247px;
}
#topBtn {
  top: 10px;
  right: 168px;
}
#isoBtn {
  top: 10px;
  right: 89px; /* between TOP and the view button */
}
#frontBtn,
#sideBtn,
#topBtn,
#isoBtn {
  padding-left: 4px; /* leave room for longer labels like R.SIDE */
  padding-right: 4px;
  white-space: nowrap;
}
/* Gentle "breathing" glow on UPLOAD while no model is loaded */
@keyframes uploadBreath {
  0%,
  100% {
    box-shadow: inset 0 0 0 1px var(--cyan), 0 0 3px rgba(46, 211, 198, 0.25);
    filter: brightness(0.82);
  }
  50% {
    box-shadow: inset 0 0 0 1px var(--cyan), 0 0 20px 5px rgba(46, 211, 198, 0.9);
    filter: brightness(1.18);
  }
}
#uploadBtn.breathing {
  animation: uploadBreath 2.8s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  #uploadBtn.breathing {
    animation: none; /* respect the system "reduce motion" setting */
  }
}

#matBtn {
  top: 50px;
}
#colorBtn {
  top: 90px;
}
#wireBtn {
  top: 130px;
}
#turnBtn {
  top: 170px;
}
#gizmoBtn {
  top: 210px;
}
#gridBtn {
  top: 250px;
}

#printBtn {
  top: 400px; /* under the light wheel */
  font-size: 14pt;
  /* Center the camera emoji exactly in the button */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0; /* the fixed height below sets the vertical space */
  height: 36px; /* same height as the other 75px buttons */
  line-height: 1; /* emoji glyphs carry extra line spacing otherwise */
  text-align: center;
}

#resetBtn {
  --c: var(--magenta);
  --g: var(--magenta-glow);
  top: 520px; /* 40px steps like the others */
}

/* DELETE: amber, under RESET (same 40px step) */
#deleteBtn {
  --c: var(--amber);
  --g: var(--amber-glow);
  top: 560px;
  padding-left: 4px; /* leave room for the 6-letter label */
  padding-right: 4px;
  white-space: nowrap;
}

/* INFO: shows / hides the model data box, under DELETE (same 40px step) */
#infoBtn {
  top: 480px;
}

/* Steel (neutral) outline for the view buttons (FRONT, R.SIDE, TOP, PERSP),
   INFO and the model-rotation arrows */
#frontBtn,
#sideBtn,
#topBtn,
#isoBtn,
#viewBtn,
#infoBtn,
.rotBtn {
  --c: var(--steel);
  --g: var(--steel-glow);
}

/* Arrow buttons that turn the model: a d-pad centered under the UPLOAD button
   (UPLOAD is 160px wide at left: 10px, so its center is 90px from the left),
   with a small orientation cube in the middle. It takes the place of the
   upload hint, which is hidden once a model is loaded. Hidden by the script
   until a model is loaded. 3 x 3 grid of 36px cells, 40px apart. */
.rotBtn {
  width: 36px;
  border-radius: 50%; /* round buttons */
  padding: 0;
  right: auto; /* positioned from the left side */
  display: none; /* the script shows them when a model is on screen */
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
}
#rotUpBtn {
  top: 74px;
  left: 72px;
}
#rotLeftBtn {
  top: 114px;
  left: 32px;
}
#rotRightBtn {
  top: 114px;
  left: 112px;
}
#rotDownBtn {
  top: 154px;
  left: 72px;
}
#orientCube {
  position: absolute;
  top: 114px;
  left: 72px;
  width: 36px;
  height: 36px;
  display: none; /* shown together with the arrows */
  background: var(--btn-fill);
  outline: 1px solid var(--steel); /* same ring as the arrow buttons */
  outline-offset: -1px;
  box-shadow: 0 0 5px var(--steel-glow);
  border-radius: 50%; /* round frame */
  cursor: help;
}
.rotBtn svg {
  display: block;
  pointer-events: none;
}

/* Text panels (captions, hint, info box): dark glass with a thin cyan line */
#viewLabel,
#rotateLabel,
#uploadHint,
#controlsInfo,
#infoDisplay {
  background: var(--panel-fill);
  border: 1px solid var(--panel-line);
  border-radius: 2px;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

/* Caption under the FRONT / R.SIDE / TOP / ISO buttons: same look as the other
   captions. It spans those four buttons (right: 89px to 401px) and stops
   short of the right-hand stack. */
#viewLabel {
  position: absolute;
  top: 52px; /* below the top row (10px + 36px) plus a 6px gap */
  right: 89px;
  width: 312px;
  box-sizing: border-box;
  color: var(--cyan);
  padding: 5px 10px;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
  user-select: none;
  /* only shown as the tooltip of the four view buttons (see script.js) */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0s linear 0.15s;
}

/* Light wheel: a dial under the CAMERA VIEWS caption. FRONT is at the top;
   the dot shows where the light comes from: around the ring = front,
   sides or back, toward the middle = higher up. */
#lightWheel {
  position: absolute;
  top: 305px; /* in the right-hand column, under GRID (room above for the FRONT mark) */
  right: 10px;
  width: 76px;
  height: 76px;
  box-sizing: border-box;
  border: 2px solid var(--steel);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(46, 211, 198, 0.16) 0%, rgba(11, 11, 12, 0.78) 70%);
  box-shadow: 0 0 5px var(--steel-glow);
  cursor: grab;
  touch-action: none; /* dragging must not scroll the page on touch screens */
  user-select: none;
}
#lightWheel::before {
  content: "FRONT";
  position: absolute;
  top: -15px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 8px;
  font-weight: 700;
  color: var(--cyan);
  pointer-events: none;
}
#lightWheel:active {
  cursor: grabbing;
}
#lightWheel:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}
#lightWheel .lightLabel {
  position: absolute;
  bottom: -15px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 9px;
  font-weight: 700;
  color: var(--cyan);
  pointer-events: none;
}
#lightKnob {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 6px 2px rgba(255, 176, 32, 0.8);
  pointer-events: none;
}

/* Caption under the arrows: same look as the upload hint */
#rotateLabel {
  position: absolute;
  top: 198px; /* below the lowest arrow (154px + 36px) plus an 8px gap */
  left: 10px;
  width: 160px;
  box-sizing: border-box;
  display: none; /* shown together with the arrows */
  color: var(--cyan);
  padding: 5px 10px;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
  user-select: none;
}

#infoDisplay {
  position: absolute;
  bottom: 10px;
  right: 10px; /* always at the far right of the screen */
  color: var(--text);
  padding: 10px;
  font-size: 14px;
  font-weight: 400;
  text-align: left;
}

/* Watertight status row (text color is set by JS: green / amber / red) */
#watertightDisplay {
  margin-top: 2px;
  cursor: help; /* the hover tooltip shows the full report */
  transition: color 0.3s ease;
}

/* Hint under the UPLOAD button: same width as the button, grows in height with its text */
#uploadHint {
  position: absolute;
  top: 58px; /* button top (10px) + height (40px) + 8px gap */
  left: 10px;
  width: 160px; /* same as #uploadBtn */
  box-sizing: border-box;
  color: var(--cyan);
  padding: 5px 10px;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.4;
  text-align: left;
  cursor: pointer;
  user-select: none;
}

#controlsInfo {
  position: absolute;
  bottom: 10px;
  left: 10px;
  color: var(--cyan);
  padding: 5px 10px;
  font-size: 10px;
  font-weight: 500;
}

#viewerInfo {
  font-size: 10px;
  font-weight: 500;
  color: var(--cyan);
  text-align: left;
  margin-top: 4px;
  margin-bottom: 1px;
}

/* Dimension values in color */
.z-value {
  color: #49abfc;
}
.x-value {
  color: #fc5e49;
}
.y-value {
  color: #98eb34;
}

/* Notice shown before the viewer starts. Same look as the website's
   "360 Method" block: HUD frame with corner brackets, glass blocks with a
   colored top bar, neon accents, soft screen lines. */
#disclaimer {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  padding: 10px;
  box-sizing: border-box;
  overflow: auto;
  background-color: var(--bg-dark);
  background-image:
    radial-gradient(circle at 50% 50%, rgba(58, 63, 68, 0.4) 0%, rgba(11, 11, 12, 0.97) 76%),
    linear-gradient(rgba(44, 246, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(44, 246, 255, 0.035) 1px, transparent 1px);
  background-size: 100% 100%, 41.4px 41.4px, 41.4px 41.4px;
}
/* faint screen lines and dark edges over the whole notice (not clickable) */
#disclaimer::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.16) 50%);
  background-size: 100% 4.6px;
  box-shadow: inset 0 0 103px rgba(0, 0, 0, 0.85);
}
.dl-card {
  --accent: var(--cyan);
  position: relative;
  z-index: 1;
  container-type: inline-size;
  width: 100%;
  max-width: 760px;
  margin: auto; /* centered; still scrolls from the top on short screens */
  box-sizing: border-box;
  padding: 22px 16px 20px;
  text-align: center;
  background: rgba(11, 11, 12, 0.72);
  border: 1px solid var(--panel-line);
  border-radius: 2px;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  box-shadow: 0 28px 57px -14px rgba(0, 0, 0, 0.5), 0 0 30px -12px rgba(46, 211, 198, 0.35);
}
.dl-corner {
  position: absolute;
  width: 20px;
  height: 20px;
  border: 0 solid var(--cyan);
  opacity: 0.85;
  pointer-events: none;
}
.dl-corner.tl { top: -1px; left: -1px; border-top-width: 2px; border-left-width: 2px; }
.dl-corner.tr { top: -1px; right: -1px; border-top-width: 2px; border-right-width: 2px; }
.dl-corner.bl { bottom: -1px; left: -1px; border-bottom-width: 2px; border-left-width: 2px; }
.dl-corner.br { bottom: -1px; right: -1px; border-bottom-width: 2px; border-right-width: 2px; }

/* top and bottom strips */
.dl-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 12px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: rgba(46, 211, 198, 0.85);
}
.dl-strip-top {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--panel-line);
}
.dl-strip-bottom {
  margin-top: 16px;
  padding-top: 10px;
  border-top: 1px solid var(--panel-line);
  font-size: 9.5px;
  color: rgba(46, 211, 198, 0.65);
}
.dl-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  vertical-align: middle;
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
  animation: dlPulse 1.6s ease-in-out infinite;
}
@keyframes dlPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.dl-head {
  margin: 16px 0 8px;
}
/* Formero wordmark with "3D LITEVIEW" under it, right-aligned */
.dl-lockup {
  container-type: inline-size;
  width: min(380px, 100%);
  margin: 0 auto;
}
.dl-logo {
  display: block;
  width: 100%;
  height: auto;
}
.dl-title {
  margin: 3cqw 0 0 auto;
  width: max-content;
  padding: 0;
  font-size: 7.2cqw;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.15em;
  color: var(--amber);
  text-shadow: none;
}
.dl-intro {
  text-wrap: balance;
  margin: 14px auto 0;
  max-width: 660px;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.35;
  color: #ffffff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}

/* The four points: glass blocks with a colored top bar */
.dl-blocks {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.dl-blocks > li {
  --accent: var(--cyan);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 12px 8px;
  text-align: center;
  background: rgba(0, 0, 0, 0.38);
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 0 30px -12px var(--accent);
}
.dl-blocks > li.c-magenta { --accent: var(--magenta); }
.dl-blocks > li.c-amber { --accent: var(--amber); }
.dl-blocks > li::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}
.dl-blocks > li::after {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--accent);
  opacity: 0.07;
  pointer-events: none;
}
.dl-num {
  position: relative;
  z-index: 1;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--accent);
}
.dl-txt {
  position: relative;
  z-index: 1;
  font-size: 13.5px;
  font-weight: 400;
  line-height: 1.4;
  color: #ffffff;
}
@container (min-width: 600px) {
  .dl-blocks {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
}

#disclaimerOk {
  position: static;
  display: block;
  width: auto;
  min-width: 190px;
  height: 42px;
  padding: 0 26px;
  margin: 20px auto 0;
  background-color: var(--amber);
  color: #0b0b0c;
  text-shadow: none;
  font-size: 15px;
  letter-spacing: 0.06em;
  box-shadow: 0 0 14px var(--amber-glow);
}
#disclaimerOk:hover {
  background-image: none;
  filter: brightness(1.1);
  box-shadow: 0 0 22px var(--amber);
}
#disclaimerOk:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 3px;
}

/* Soft entrance, one piece after another */
@keyframes dlRise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}
.dl-head, .dl-blocks > li, #disclaimerOk {
  animation: dlRise 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}
.dl-head { animation-delay: 0.05s; }
.dl-blocks > li:nth-child(1) { animation-delay: 0.2s; }
.dl-blocks > li:nth-child(2) { animation-delay: 0.3s; }
.dl-blocks > li:nth-child(3) { animation-delay: 0.4s; }
.dl-blocks > li:nth-child(4) { animation-delay: 0.5s; }
#disclaimerOk { animation-delay: 0.65s; }
@media (prefers-reduced-motion: reduce) {
  .dl-head, .dl-blocks > li, #disclaimerOk, .dl-dot { animation: none !important; }
}

.nw {
  white-space: nowrap;
}

/* Detail box that opens over a point on hover (tap on touch screens) */
.dl-blocks > li { cursor: default; outline: none; }
.dl-blocks > li:hover,
.dl-blocks > li:focus-within,
.dl-blocks > li.open { z-index: 10; }
.dl-more {
  position: absolute;
  z-index: 10;
  top: -6px;
  left: -8px;
  right: -8px;
  box-sizing: border-box;
  padding: 12px 14px 10px;
  text-align: left;
  background: #040c10; 
  border: 1px solid var(--accent);
  box-shadow: 0 0 26px -6px var(--accent), 0 14px 34px rgba(0, 0, 0, 0.6);
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s linear 0.15s;
  pointer-events: none;
}
.dl-more::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 3px;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
}
.dl-blocks > li:nth-child(n + 3) .dl-more { /* lower row grows upward */
  top: auto;
  bottom: -6px;
}
.dl-blocks > li:hover .dl-more,
.dl-blocks > li:focus-within .dl-more,
.dl-blocks > li.open .dl-more {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition-delay: 0s;
  pointer-events: auto;
}
.dl-more .dl-num { display: block; margin-bottom: 6px; text-align: left; }
.dl-bullets {
  list-style: none;
  margin: 0;
  padding: 0;
}
.dl-bullets li {
  position: relative;
  margin: 0 0 5px;
  padding-left: 14px;
  font-size: 12.5px;
  line-height: 1.38;
  color: #ffffff;
}
.dl-bullets li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 0.5em;
  width: 5px;
  height: 5px;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}
/* One-column layout (narrow screens): the detail opens inside the point itself */
@container (max-width: 599px) {
  .dl-more {
    position: static;
    display: none;
    margin-top: 6px;
    width: 100%;
    opacity: 1;
    visibility: visible;
    transform: none;
    box-shadow: none;
    background: rgba(0, 0, 0, 0.35);
    pointer-events: auto;
  }
  .dl-blocks > li:hover .dl-more,
  .dl-blocks > li:focus-within .dl-more,
  .dl-blocks > li.open .dl-more { display: block; }
}
@container (max-width: 599px) {
  .dl-more .dl-num { display: none; } /* the point's own title is already right above */
}

/* Cards show only their title; the full text opens on hover / focus / tap */
.dl-blocks > li { min-height: 0; padding: 13px 12px; justify-content: center; }
.dl-blocks > li > .dl-num { font-size: 12.5px; letter-spacing: 0.12em; text-align: center; }
.dl-blocks > li::after { content: ""; }
.dl-more .dl-txt { display: block; margin: 0 0 8px; font-size: 13px; line-height: 1.4; text-align: left; font-weight: 500; }
.dl-more .dl-num { font-size: 11px; }
@container (min-width: 600px) {
  .dl-blocks { gap: 12px; }
}
@container (max-width: 599px) {
  .dl-more .dl-num { display: none; }
}

/* INFO off: only the credit line stays visible */
#infoDisplay.info-collapsed > :not(#viewerInfo) { display: none !important; }
#infoDisplay.info-collapsed { padding: 5px 10px; }
#infoDisplay.info-collapsed #viewerInfo { margin: 0; }

/* Info box: same typeface style as the "Left Click = Rotate" box (Roboto
   Medium); text stays white, credit line cyan; sizes and spacing are unchanged */
#infoDisplay {
  font-weight: 500;
}
#infoDisplay #creditHex {
  display: inline-block;
  width: 8px;
  height: 9px;
  margin-left: 3px;
  vertical-align: -1px;
  background: var(--cyan);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}

/* ====================================================================
 * TUTORIAL (shown right after the disclaimer)
 * ==================================================================== */

/* Controls that are not part of the current lesson look switched off */
.tut-lock {
  opacity: 0.28 !important;
  filter: grayscale(0.7) !important;
  pointer-events: none !important;
}
body.tut-on #uploadHint { visibility: hidden; }

#tutOverlay {
  position: fixed;
  inset: 0;
  z-index: 1500;
  pointer-events: none;
}
.tut-ring {
  position: fixed;
  box-sizing: border-box;
  border: 2px solid var(--amber);
  box-shadow: 0 0 12px var(--amber), inset 0 0 10px rgba(255, 176, 32, 0.35);
  animation: tutPulse 1.1s ease-in-out infinite;
}
@keyframes tutPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(1.05); }
}
#tutArrow {
  position: fixed;
  width: 34px;
  height: 40px;
  display: none;
  filter: drop-shadow(0 0 6px rgba(255, 45, 180, 0.9));
  transition: opacity 0.2s ease;
}
#tutArrow.tut-away { opacity: 0; }
.tut-arrow-in { animation: tutBounce 0.75s ease-in-out infinite; }
@keyframes tutBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-9px); }
}

#tutorial {
  position: fixed;
  z-index: 1600;
  /* bottom-left corner, just above the "Left Click = Rotate" box */
  left: 10px;
  bottom: 40px;
  width: 285px;
  box-sizing: border-box;
  padding: 10px 12px 12px;
  background: rgba(4, 12, 16, 0.96);
  border: 1px solid var(--cyan);
  box-shadow: 0 0 22px -6px var(--cyan), 0 10px 28px rgba(0, 0, 0, 0.55);
  font-family: "Roboto", Arial, sans-serif;
  color: #ffffff;
  text-align: left;
}
#tutorial::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 0;
  height: 3px;
  background: var(--cyan);
  box-shadow: 0 0 12px var(--cyan);
}
#tutorial .tut-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
#tutorial .tut-step {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--cyan);
}
#tutorial .tut-title {
  margin: 0 0 5px;
  font-size: 15px;
  font-weight: 700;
  color: var(--amber);
}
#tutorial .tut-text {
  margin: 0 0 7px;
  font-size: 11.5px;
  font-weight: 400;
  line-height: 1.4;
  color: #ffffff;
}
#tutorial .tut-items {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
}
#tutorial .tut-items:empty { display: none; }
#tutorial .tut-items li {
  position: relative;
  padding-left: 20px;
  margin-bottom: 3px;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--steel);
}
#tutorial .tut-items li::before {
  content: "";
  position: absolute;
  left: 1px; top: 1px;
  width: 11px; height: 11px;
  box-sizing: border-box;
  border: 2px solid var(--cyan);
}
#tutorial .tut-items li.done { color: var(--cyan); }
#tutorial .tut-items li.done::before {
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
}
#tutorial .tut-bar {
  height: 3px;
  background: rgba(46, 211, 198, 0.18);
}
#tutorial .tut-bar i {
  display: block;
  height: 100%;
  background: var(--amber);
  box-shadow: 0 0 8px var(--amber);
  transition: width 0.4s ease;
}
#tutorial.tut-ok { border-color: var(--amber); }
#tutorial.tut-ok .tut-step::after { content: "  ✓ DONE"; color: var(--amber); }

/* The tutorial's own buttons: small, in the normal flow (not the big absolute ones) */
#tutorial button {
  white-space: nowrap;
  position: static;
  width: auto;
  height: auto;
  padding: 3px 7px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  --c: var(--steel);
  --g: var(--steel-glow);
}
#tutorial .tut-go {
  display: none;
  width: 100%;
  margin: 2px 0 8px;
  padding: 9px 12px;
  font-size: 13px;
  --c: var(--amber);
  --g: var(--amber-glow);
  background-color: var(--amber);
  color: #0b0b0c;
  text-shadow: none;
}
#tutorial.tut-final .tut-go { display: block; }
#tutorial.tut-final .tut-skip { display: none; }
@media (prefers-reduced-motion: reduce) {
  .tut-ring, .tut-arrow-in { animation: none; }
}

/* Mesh view: a very faint white glow around the lines (ghost effect) */
canvas.mesh-glow {
  filter: drop-shadow(0 0 2.5px rgba(255, 255, 255, 0.55));
  /* a filter makes the canvas its own layer: keep the controls above that layer */
  position: relative;
  z-index: 0;
}
/* ...and every control (that has no z-index of its own) stays above it */
:where(body > *:not(canvas)) {
  z-index: 1;
}

#viewLabel.show {
  opacity: 1;
  visibility: visible;
  transition-delay: 0s;
}

/* Very short windows (under 730px tall): the button column would run into the
   info box, so it steps left of the column. The frame (marco.html) keeps the
   app at 740px design height or more, so this only matters when index.html is
   opened directly in a small window. */
@media (max-height: 729px) {
  #infoDisplay { right: 95px; }
}

/* The closing "You are ready!" card sits in the middle of the screen */
#tutorial.tut-final {
  left: 50%;
  top: 50%;
  bottom: auto;
  width: min(340px, calc(100vw - 20px));
  transform: translate(-50%, -50%);
  padding: 16px 18px 16px;
  text-align: center;
}
#tutorial.tut-final .tut-top { justify-content: center; }
#tutorial.tut-final .tut-title { font-size: 20px; margin-bottom: 8px; }
#tutorial.tut-final .tut-text { font-size: 13px; margin-bottom: 14px; }

/* Tutorial: little mouse drawing (seen from above) next to the checklist */
#tutorial .tut-row { display: flex; align-items: center; gap: 10px; }
#tutorial .tut-row .tut-items { flex: 1; min-width: 0; }
#tutorial .tut-art { display: none; flex: none; }
#tutorial .tut-row.has-art .tut-art { display: block; }
.tut-art svg { display: block; overflow: visible; }
.tut-art .mb-body, .tut-art .mb-line, .tut-art .mb-wheel {
  fill: none;
  stroke: var(--cyan);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.tut-art .mb-wheel { fill: rgba(46, 211, 198, 0.18); }
.tut-art .mb { fill: rgba(46, 211, 198, 0.05); stroke: none; transition: fill 0.2s ease; }
/* the button to press: lit in magenta (same as the arrow), pulsing */
.tut-art .mb.next { fill: var(--magenta); animation: tutMouseGlow 0.9s ease-in-out infinite; }
.tut-art .mb.done { fill: rgba(46, 211, 198, 0.75); }
/* held down for real: bright amber */
.tut-art .mb.down { fill: var(--amber); animation: none; }
@keyframes tutMouseGlow {
  0%, 100% { opacity: 1; filter: drop-shadow(0 0 4px var(--magenta)); }
  50% { opacity: 0.45; filter: none; }
}
@media (prefers-reduced-motion: reduce) { .tut-art .mb.next { animation: none; } }

/* RULER: button under INFO, length label, and the one-line hint */
#rulerBtn {
  top: 440px;
}
body.ruler-on canvas { cursor: crosshair; }
#rulerLabel {
  position: fixed;
  z-index: 3;
  display: none;
  transform: translate(-50%, -50%);
  padding: 2px 7px;
  background: rgba(4, 12, 16, 0.94);
  border: 1px solid #98eb34;
  color: #ffffff;
  font-family: "Roboto", Arial, sans-serif;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 0 8px rgba(152, 235, 52, 0.35);
}
#rulerHint {
  position: absolute;
  z-index: 2;
  display: none;
  left: 207px;
  bottom: 10px;
  max-width: 262px;
  box-sizing: border-box;
  padding: 5px 10px;
  background: var(--panel-fill);
  border: 1px solid var(--panel-line);
  border-radius: 2px;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  color: #98eb34;
  font-size: 10px;
  font-weight: 500;
  line-height: 1.4;
  pointer-events: none;
}

/* The tutorial card already explains the ruler: hide the one-line hint meanwhile */
body.tut-on #rulerHint { display: none !important; }

/* COLOR: button under MAT and its wheel panel (opens to the left of the column) */
#colorPanel {
  position: absolute;
  top: 90px;
  right: 95px;
  z-index: 5;
  width: 164px;
  padding: 10px;
  box-sizing: border-box;
  background: rgba(11, 11, 12, 0.94);
  border-radius: var(--btn-radius);
  box-shadow: inset 0 0 0 1px var(--cyan), 0 0 10px var(--cyan-glow);
  font-family: "Roboto", Arial, sans-serif;
  color: #fff;
  user-select: none;
}
#colorPanel[hidden] { display: none; }
#colorWheel {
  display: block;
  width: 144px;
  height: 144px;
  border-radius: 50%;
  cursor: crosshair;
  touch-action: none;
}
#colorVal {
  display: block;
  width: 100%;
  margin: 10px 0 6px;
  accent-color: var(--cyan);
}
#colorRow { display: flex; gap: 6px; align-items: center; }
/* the small RESET: it sits in the row, not in the button column */
#colorRow #colorReset {
  position: static;
  width: 46px;
  height: 26px;
  padding: 0;
  flex: none;
  font-size: 10px;
  --c: var(--magenta);
  --g: var(--magenta-glow);
}
#colorHex {
  display: block;
  flex: 1;
  min-width: 0;
  box-sizing: border-box;
  padding: 4px 6px;
  text-align: center;
  font-family: "Roboto", Arial, sans-serif;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
  border: none;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px var(--steel);
  outline: none;
  text-transform: uppercase;
}
#colorHex:focus { box-shadow: inset 0 0 0 1px var(--cyan), 0 0 6px var(--cyan-glow); }
#colorHex.bad { box-shadow: inset 0 0 0 1px var(--magenta); }

/* SECRET GLITCH: tag beside TURN (shows only with MESH + TURN on) and the effect layer */
#glitchCanvas {
  position: fixed;
  left: 0;
  top: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 0;
}
#glitchTag {
  position: absolute;
  top: 170px; /* same row as TURN */
  right: 95px;
  height: 36px;
  line-height: 36px;
  padding: 0 4px;
  font-family: "Roboto", Arial, sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--cyan);
  cursor: pointer;
  user-select: none;
}
#glitchTag[hidden] { display: none; }
#glitchTag::before,
#glitchTag::after {
  content: attr(data-text);
  position: absolute;
  left: 4px;
  top: 0;
  width: 100%;
  overflow: hidden;
  pointer-events: none;
}
#glitchTag::before {
  color: #ff2bd6;
  text-shadow: -2px 0 #ff2bd6;
  animation: glitchTagA 1.6s steps(1, end) infinite;
}
#glitchTag::after {
  color: #ffffff;
  text-shadow: 2px 0 #00f0ff;
  animation: glitchTagB 1.3s steps(1, end) infinite;
}
@keyframes glitchTagA {
  0%   { clip-path: inset(0 0 100% 0); transform: translate(0); }
  8%   { clip-path: inset(10% 0 60% 0); transform: translate(-3px, 0); }
  14%  { clip-path: inset(70% 0 5% 0); transform: translate(3px, 0); }
  20%  { clip-path: inset(0 0 100% 0); transform: translate(0); }
  55%  { clip-path: inset(40% 0 35% 0); transform: translate(-2px, 1px); }
  60%  { clip-path: inset(0 0 100% 0); transform: translate(0); }
  100% { clip-path: inset(0 0 100% 0); }
}
@keyframes glitchTagB {
  0%   { clip-path: inset(0 0 100% 0); }
  30%  { clip-path: inset(55% 0 20% 0); transform: translate(3px, 0); }
  36%  { clip-path: inset(15% 0 70% 0); transform: translate(-3px, 0); }
  42%  { clip-path: inset(0 0 100% 0); transform: translate(0); }
  80%  { clip-path: inset(80% 0 0 0); transform: translate(2px, 0); }
  86%  { clip-path: inset(0 0 100% 0); }
  100% { clip-path: inset(0 0 100% 0); }
}
#glitchTag.on { color: #ff2bd6; text-shadow: 0 0 8px rgba(255, 43, 214, 0.8); }
#glitchTag.on::before, #glitchTag.on::after { animation-duration: 0.5s; }
@media (prefers-reduced-motion: reduce) {
  #glitchTag::before, #glitchTag::after { animation: none; }
}
