html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: #eaf3ff;
}

.v3d-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(circle at 18% 18%, rgba(122, 221, 255, 0.24), transparent 30%),
    radial-gradient(circle at 80% 20%, rgba(164, 142, 255, 0.22), transparent 28%),
    linear-gradient(180deg, #eff8ff 0%, #eaf1ff 56%, #f7f4ff 100%);
}

.v3d-container::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(96, 132, 190, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(96, 132, 190, 0.07) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: radial-gradient(circle at 50% 38%, rgba(0, 0, 0, 0.42), transparent 68%);
  pointer-events: none;
}

.v3d-container canvas {
  touch-action: none;
}

#lesson-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.ui-hidden #lesson-overlay {
  display: none;
}

.op-panel {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: min(760px, calc(100vw - 24px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) 136px;
  grid-template-rows: auto auto;
  gap: 8px 12px;
  align-items: stretch;
  min-height: 254px;
  padding: 12px;
  border: 1px solid rgba(89, 112, 172, 0.14);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.84);
  backdrop-filter: blur(12px);
  box-shadow: 0 18px 42px rgba(71, 89, 145, 0.14);
  pointer-events: auto;
}

.ui-restore {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid rgba(89, 112, 172, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
  color: #3b2f73;
  font-size: 14px;
  font-weight: 900;
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 24px rgba(71, 89, 145, 0.14);
  cursor: pointer;
  pointer-events: auto;
}

.ui-restore {
  bottom: 14px;
  border-radius: 999px;
  display: none;
}

.panel-hidden .op-panel {
  display: none;
}

.panel-hidden .ui-restore {
  display: block;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 6px;
  grid-column: 1 / 2;
}

.stat-row div {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 34px;
  border: 1px solid rgba(89, 112, 172, 0.1);
  border-radius: 12px;
  background: rgba(245, 249, 255, 0.76);
}

.stat-hide-btn {
  min-width: 76px;
  min-height: 34px;
  border: 1px solid rgba(141, 114, 232, 0.25);
  border-radius: 12px;
  background: rgba(141, 114, 232, 0.12);
  color: #3b2f73;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.stat-row span {
  display: block;
  font-size: 20px;
  line-height: 1;
  font-weight: 900;
  color: #3b2f73;
}

.stat-row small {
  font-size: 12px;
  font-weight: 900;
  color: #667085;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  grid-column: 1 / 2;
  grid-row: 2 / 3;
}

.range-field {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: center;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid rgba(31, 42, 68, 0.08);
  border-radius: 14px;
  background: rgba(250, 250, 255, 0.88);
}

.range-field span,
.range-field strong {
  font-size: 16px;
  font-weight: 900;
  color: #1f2a44;
  text-align: center;
}

.range-field input {
  width: 100%;
  accent-color: #8d72e8;
}

.formula-box {
  min-height: 40px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 6px 12px;
  border: 1px solid rgba(141, 114, 232, 0.18);
  border-radius: 14px;
  background: rgba(248, 246, 255, 0.9);
}

.formula-box strong {
  font-size: 16px;
  line-height: 1.15;
  color: #38286e;
  font-weight: 900;
}

.formula-box span {
  font-size: 13px;
  line-height: 1.25;
  color: #695f88;
  font-weight: 800;
}

.formula-box.is-complete {
  border-color: rgba(55, 190, 120, 0.35);
  background: rgba(238, 255, 246, 0.92);
}

.button-stack {
  display: grid;
  grid-template-rows: repeat(5, 1fr);
  align-content: stretch;
  gap: 8px;
  grid-column: 2 / 3;
  grid-row: 1 / 3;
  align-self: stretch;
}

.fill-btn {
  min-height: 0;
  border: 1px solid rgba(141, 114, 232, 0.38);
  border-radius: 14px;
  background: rgba(141, 114, 232, 0.18);
  color: #2f235f;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
}

.aux-btn {
  min-height: 0;
  border-color: rgba(78, 143, 188, 0.24);
  background: rgba(92, 202, 232, 0.12);
  font-size: 13px;
}

.fill-btn:disabled {
  cursor: default;
  opacity: 0.58;
}

.fullscreen-button {
  z-index: 4;
}

@media (max-width: 620px) {
  .op-panel {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    width: calc(100vw - 18px);
    padding: 8px;
    gap: 8px;
  }

  .ui-restore {
    bottom: 10px;
  }

  .stat-row div {
    min-height: 44px;
  }

  .button-stack {
    grid-column: auto;
    grid-row: auto;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: none;
  }

  .stat-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat-hide-btn {
    grid-column: span 2;
  }

  .stat-row,
  .control-grid {
    grid-column: auto;
    grid-row: auto;
  }

  .stat-row span {
    font-size: 18px;
  }

  .range-field {
    min-height: 40px;
  }

  .formula-box {
    min-height: 42px;
  }

  .formula-box strong {
    font-size: 16px;
  }

  .formula-box span {
    font-size: 12px;
  }
}
