/*
 * Model Monkey Lighting & Depth System
 *
 * Surfaces use an absolute 0-255 depth coordinate. The procedural engine
 * calculates each cast from caster depth minus receiver depth. Current UI
 * static assignments stop at 200; transient button hover can reach 222, so
 * levels 223-255 remain available for expansion.
 */

:root {
  --mm-lighting-duration: 1.4s;
  --mm-lighting-easing: cubic-bezier(0.37, 0, 0.63, 1);
  --mm-hover-duration: 0.46s;
  --mm-hover-easing: cubic-bezier(0.22, 0.61, 0.36, 1);
  --mm-light-gradient-angle: 20deg;
  --mm-light-gradient-shadow-opacity: 0.012;
  --mm-light-gradient-highlight-opacity: 0.045;
  --mm-light-gradient-shadow: rgb(0 0 0 / var(--mm-light-gradient-shadow-opacity));
  --mm-light-gradient-highlight: rgb(255 255 255 / var(--mm-light-gradient-highlight-opacity));
  --mm-light-gradient: linear-gradient(
    var(--mm-light-gradient-angle),
    var(--mm-light-gradient-shadow) 0%,
    transparent 48%,
    var(--mm-light-gradient-highlight) 100%
  );
}

/* All coloured controls share one face opacity, including hover states. */
.side-tab#tab-btn-intro { background: var(--tab-intro); }
.side-tab#tab-btn-token { background: var(--tab-token); }
.side-tab#tab-btn-text { background: var(--tab-text); }
.side-tab#tab-btn-image { background: var(--tab-image); }
.side-tab#tab-btn-four { background: var(--tab-four); }
.side-tab#tab-btn-model { background: var(--tab-model); }
.side-tab#tab-btn-info { background: var(--tab-info); }
.side-tab#tab-btn-dev {
  background: rgb(225 82 145 / var(--mm-coloured-control-opacity));
  color: #101010;
}

body[data-theme="dark"] .side-tab#tab-btn-dev {
  color: #ffffff;
}

.mm-light-controller {
  position: absolute;
  z-index: 3;
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  padding: 0;
  border: 2px solid #000;
  border-radius: 50%;
  background: #fff;
  color: #000;
  box-shadow: var(--mm-depth-shadow, none);
  transform: translate(-50%, -50%);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.mm-light-controller:active,
.mm-light-controller.dragging {
  cursor: grabbing;
}

.mm-light-controller::after {
  content: attr(data-position);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 7px);
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  font-size: 11px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  opacity: 0;
  transform: translateX(-50%);
  pointer-events: none;
}

.mm-light-controller:hover::after,
.mm-light-controller:focus-visible::after,
.mm-light-controller.dragging::after {
  opacity: 1;
}

.dev-lighting-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.dev-panel-info-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.dev-panel-info-row > p {
  flex: 1 1 auto;
  min-width: 0;
}

.dev-reset-toggle {
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.dev-reset-toggle-track {
  position: relative;
  display: block;
  width: 46px;
  height: 28px;
  border: 1px solid var(--toggle-border);
  border-radius: 999px;
  background: var(--toggle-bg);
}

.dev-reset-toggle-thumb {
  position: absolute;
  left: 3px;
  top: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--toggle-thumb);
  transition: left 0.24s var(--mm-hover-easing);
}

.dev-reset-toggle.is-resetting .dev-reset-toggle-thumb {
  left: 21px;
}

.dev-reset-toggle:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--text) 45%, transparent);
  outline-offset: 3px;
  border-radius: 999px;
}

.dev-tool-card {
  padding: 16px;
}

.dev-tool-card > .inner-card-title {
  margin: 0 0 14px;
  text-align: center;
  font-size: 22px;
  line-height: 1.3;
  font-weight: 500;
}

.dev-joystick-card {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.mm-light-joystick-pad {
  position: relative;
  width: min(100%, 240px);
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: 50%;
  background-color: var(--surface-soft);
  background-image: var(--mm-light-gradient);
  overflow: visible;
  touch-action: none;
}

.mm-light-joystick-axis {
  position: absolute;
  z-index: 0;
  background: color-mix(in srgb, var(--text) 14%, transparent);
  pointer-events: none;
}

.mm-light-joystick-axis-horizontal {
  left: 8%;
  right: 8%;
  top: 50%;
  height: 1px;
}

.mm-light-joystick-axis-vertical {
  top: 8%;
  bottom: 8%;
  left: 50%;
  width: 1px;
}

.mm-light-joystick-centre {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 1;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.dev-light-angle-copy {
  margin: 12px 0 0;
  color: var(--text);
  font-size: 18px;
}

.dev-tool-note {
  margin: 8px 0 12px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.4;
  text-align: center;
}

.dev-setting-list {
  display: grid;
  gap: 8px;
}

.dev-setting-row {
  min-height: 42px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.dev-setting-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.dev-setting-label {
  color: var(--text);
  font-size: 15px;
  line-height: 1.25;
}

.dev-setting-controls {
  display: grid;
  grid-template-columns: 34px minmax(58px, auto) 34px;
  align-items: center;
  gap: 6px;
}

.dev-setting-step {
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
}

.dev-setting-value {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.dev-level-card,
.dev-save-card {
  grid-column: 1 / -1;
}

.dev-setting-list-levels {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 20px;
}

.dev-save-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px 16px;
}

.dev-save-card > .inner-card-title,
.dev-save-status {
  grid-column: 1;
}

.dev-admin-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 15px;
}

.dev-save-card #dev-admin-token {
  width: 100%;
}

.dev-save-status {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  text-align: center;
}

.dev-save-status[data-status="success"] { color: var(--status-success); }
.dev-save-status[data-status="error"] { color: var(--status-error); }

.soft-card,
.paypal-card {
  --inner-card-title-surface: var(--surface);
  --inner-card-title-contrast: var(--text);
  --mm-light-gradient-surface: var(--surface);
}

.info-block-intro {
  --inner-card-title-surface: var(--tab-intro-card);
  --inner-card-title-contrast: var(--tab-intro-text);
  --mm-light-gradient-surface: var(--tab-intro-card);
}

.info-block-token {
  --inner-card-title-surface: var(--tab-token-card);
  --inner-card-title-contrast: var(--tab-token-text);
  --mm-light-gradient-surface: var(--tab-token-card);
}

.info-block-text {
  --inner-card-title-surface: var(--tab-text-card);
  --inner-card-title-contrast: var(--tab-text-text);
  --mm-light-gradient-surface: var(--tab-text-card);
}

.info-block-image {
  --inner-card-title-surface: var(--tab-image-card);
  --inner-card-title-contrast: var(--tab-image-text);
  --mm-light-gradient-surface: var(--tab-image-card);
}

.info-block-four {
  --inner-card-title-surface: var(--tab-four-card);
  --inner-card-title-contrast: var(--tab-four-text);
  --mm-light-gradient-surface: var(--tab-four-card);
}

.info-block-model {
  --inner-card-title-surface: var(--tab-model-card);
  --inner-card-title-contrast: var(--tab-model-text);
  --mm-light-gradient-surface: var(--tab-model-card);
}

body[data-theme] {
  background-color: var(--bg);
}

body[data-theme] .panel-host {
  background-color: var(--panel);
}

body[data-theme] .soft-card,
body[data-theme] .paypal-card {
  background-color: var(--mm-light-gradient-surface, var(--surface));
}

body[data-theme] .global-status {
  background-color: var(--status-bg);
}

body[data-theme] .intro-video-placeholder,
body[data-theme] #token-input,
body[data-theme] textarea,
body[data-theme] #paypal-quantity,
body[data-theme] .custom-dropzone,
body[data-theme] .mm-light-joystick-pad {
  background-color: var(--surface-soft);
}

body[data-theme] .viewer-shell {
  background-color: var(--viewer-bg);
}

body[data-theme="light"] .intro-video-placeholder,
body[data-theme="light"] .custom-dropzone,
body[data-theme="light"] .viewer-shell {
  background-color: #ffffff;
  background-image: none;
}

body[data-theme="dark"] .intro-video-placeholder,
body[data-theme="dark"] .custom-dropzone,
body[data-theme="dark"] .viewer-shell {
  background-color: #000000;
  background-image: none;
}

body[data-theme] .intro-video-placeholder,
body[data-theme] .custom-dropzone,
body[data-theme] .viewer-shell {
  border: 1px solid rgb(128 128 128 / 0.62);
}

/*
 * One fixed gradient spans the viewport. Each physical surface clips the
 * portion beneath it, so the light does not restart at every card edge.
 * CSS keeps the projection aligned while the page scrolls or resizes.
 */
body[data-theme],
body[data-theme] .panel-host,
body[data-theme] .soft-card,
body[data-theme] .paypal-card,
body[data-theme] .global-status,
body[data-theme] #token-input,
body[data-theme] textarea,
body[data-theme] #paypal-quantity,
body[data-theme] .mm-light-joystick-pad,
body[data-theme] .primary-action,
body[data-theme] .secondary-action,
body[data-theme] .paypal-step-button {
  background-image: var(--mm-light-gradient);
  background-repeat: no-repeat;
  background-position: 0 0;
  background-size: 100vw 100vh;
  background-attachment: fixed;
}

/*
 * Mobile WebKit does not reliably paint fixed backgrounds on nested surfaces.
 * The depth engine supplies each surface's offset into one viewport-sized
 * gradient instead, preserving the same lighting map without fixed attachment.
 */
@media (max-width: 960px) {
  body[data-theme],
  body[data-theme] .panel-host,
  body[data-theme] .soft-card,
  body[data-theme] .paypal-card,
  body[data-theme] .global-status,
  body[data-theme] #token-input,
  body[data-theme] textarea,
  body[data-theme] #paypal-quantity,
  body[data-theme] .mm-light-joystick-pad,
  body[data-theme] .primary-action,
  body[data-theme] .secondary-action,
  body[data-theme] .paypal-step-button {
    background-attachment: scroll;
    background-position:
      var(--mm-gradient-viewport-x, 0px)
      var(--mm-gradient-viewport-y, 0px);
    background-size:
      var(--mm-gradient-viewport-width, 100vw)
      var(--mm-gradient-viewport-height, 100vh);
  }
}

body[data-theme] .inner-card-title {
  color: rgba(210, 210, 216, 0.96);
}

body[data-theme="dark"] .inner-card-title {
  color: rgba(112, 112, 118, 0.96);
}

body[data-theme] .metric-label.inner-card-title,
body[data-theme] .upload-title.inner-card-title,
body[data-theme] .paypal-card > .inner-card-title {
  font-size: 22px;
}

body[data-theme] .paypal-card > .inner-card-title {
  font-weight: 500;
  letter-spacing: normal;
  line-height: 1.3;
}

body[data-theme] .info-block > .inner-card-title {
  font-size: 26px;
}

body[data-theme] .paypal-card,
body[data-theme] .paypal-card * {
  font-family: "Roboto", Arial, sans-serif;
  font-style: normal;
  font-weight: 300;
  letter-spacing: -0.03em;
}

body[data-theme] .paypal-card .paypal-quantity-wrap > label {
  font-size: 22px;
}

/* Every external cast below is generated by the depth engine. */
.panel-host,
.global-status,
.loading-status-bar,
body[data-theme] .side-tab.active,
body[data-theme] .side-tab.active:hover {
  box-shadow: var(--mm-depth-shadow, none);
}

.soft-card,
.paypal-card {
  box-shadow: var(--mm-depth-shadow, none);
}

.paypal-step-button,
.primary-action,
.secondary-action {
  box-shadow: var(--mm-depth-shadow, none);
}

/* Disabled state mutes the face, not the physical shadow or depth. */
.primary-action:disabled,
.secondary-action:disabled {
  opacity: 1;
  color: var(--muted);
}

.primary-token-tab:disabled {
  background-color: color-mix(in srgb, var(--tab-token) 55%, var(--panel));
}

.primary-text-tab:disabled {
  background-color: color-mix(in srgb, var(--tab-text) 55%, var(--panel));
}

.primary-image-tab:disabled {
  background-color: color-mix(in srgb, var(--tab-image) 55%, var(--panel));
}

.primary-four-tab:disabled {
  background-color: color-mix(in srgb, var(--tab-four) 55%, var(--panel));
}

.primary-model-tab:disabled {
  background-color: color-mix(in srgb, var(--tab-model) 55%, var(--panel));
}

.secondary-action:disabled {
  background-color: color-mix(in srgb, var(--secondary-bg) 58%, var(--panel));
}

.theme-toggle-track,
.theme-toggle-track[data-mm-depth="0"],
.theme-toggle-thumb,
.paypal-button-container {
  box-shadow: var(--mm-depth-shadow, none);
}

body[data-theme] .side-tab:not(.active) {
  box-shadow: var(--mm-depth-shadow, none);
}

body[data-theme] .side-tab:not(.active):hover {
  box-shadow: var(--mm-depth-shadow, none);
}

/*
 * The real open tab is above the card and therefore casts its 129->128
 * contact shadow directly. This receiver-clipped layer supplies its stronger
 * 129->0 cast only outside the card, where the receiver is the background.
 */
body[data-theme] .side-tab.active,
body[data-theme] .side-tab.active:hover {
  z-index: 3;
}

.panel-host {
  isolation: isolate;
}

.panel-host::before {
  content: "";
  position: absolute;
  left: var(--mm-tab-cast-left, 0px);
  top: var(--mm-tab-cast-top, 0px);
  z-index: 0;
  width: var(--mm-tab-cast-width, 0px);
  height: var(--mm-tab-cast-height, 0px);
  border-radius: var(--mm-tab-cast-radius, 0px);
  background: transparent;
  box-shadow: var(--mm-tab-background-shadow, none);
  clip-path: inset(
    var(--mm-background-clip-top, 0)
    var(--mm-background-clip-right, 0)
    var(--mm-background-clip-bottom, 0)
    var(--mm-background-clip-left, 0)
  );
  pointer-events: none;
}

/*
 * The open tab's shadow silhouette is projected onto the background receiver.
 * Because this layer sits beneath the translucent tab, the same procedural
 * cast is visible through the tab face rather than being painted inside it.
 */
.panel-host::after {
  content: "";
  position: absolute;
  left: var(--mm-tab-projection-left, 0px);
  top: var(--mm-tab-projection-top, 0px);
  z-index: 0;
  width: var(--mm-tab-cast-width, 0px);
  height: var(--mm-tab-cast-height, 0px);
  border-radius: var(--mm-tab-cast-radius, 0px);
  background: var(--mm-tab-projection-colour, transparent);
  filter: blur(var(--mm-tab-projection-blur, 0px));
  clip-path: inset(
    var(--mm-projection-clip-top, 0)
    var(--mm-projection-clip-right, 0)
    var(--mm-projection-clip-bottom, 0)
    var(--mm-projection-clip-left, 0)
  );
  pointer-events: none;
}

.panel-host > .panel {
  position: relative;
  z-index: 1;
}

@media (hover: hover) and (pointer: fine) {
  body[data-theme] .side-tab:not(.active),
  body[data-theme] .primary-action,
  body[data-theme] .secondary-action,
  body[data-theme] .paypal-step-button {
    transition:
      transform var(--mm-hover-duration) var(--mm-hover-easing),
      filter var(--mm-hover-duration) var(--mm-hover-easing);
  }

  body[data-theme] .side-tab:not(.active):hover,
  body[data-theme] .primary-action:not(:disabled):hover,
  body[data-theme] .secondary-action:not(:disabled):hover,
  body[data-theme] .paypal-step-button:not(:disabled):hover {
    transform: translateY(-2px);
  }

  body[data-theme] .primary-action:active,
  body[data-theme] .secondary-action:active,
  body[data-theme] .paypal-step-button:active,
  body[data-theme] .primary-action:disabled:hover,
  body[data-theme] .secondary-action:disabled:hover,
  body[data-theme] .paypal-step-button:disabled:hover {
    transform: translateY(0);
  }
}

body.mm-lighting-transition,
body.mm-lighting-transition *,
body.mm-lighting-transition *::before,
body.mm-lighting-transition *::after {
  transition-property:
    background-color,
    color,
    border-color,
    outline-color,
    text-decoration-color,
    fill,
    stroke;
  transition-duration: var(--mm-lighting-duration);
  transition-timing-function: var(--mm-lighting-easing);
}

body.mm-lighting-transition .primary-action,
body.mm-lighting-transition .secondary-action {
  transition-property:
    transform,
    opacity,
    background-color,
    color,
    border-color,
    outline-color,
    text-decoration-color,
    fill,
    stroke;
  transition-duration:
    var(--mm-hover-duration),
    0.16s,
    var(--mm-lighting-duration),
    var(--mm-lighting-duration),
    var(--mm-lighting-duration),
    var(--mm-lighting-duration),
    var(--mm-lighting-duration),
    var(--mm-lighting-duration),
    var(--mm-lighting-duration);
  transition-timing-function:
    var(--mm-hover-easing),
    ease,
    var(--mm-lighting-easing),
    var(--mm-lighting-easing),
    var(--mm-lighting-easing),
    var(--mm-lighting-easing),
    var(--mm-lighting-easing),
    var(--mm-lighting-easing),
    var(--mm-lighting-easing);
}

body.mm-lighting-transition .theme-toggle-thumb {
  transition-property: left, background-color, color, border-color, outline-color;
  transition-duration:
    var(--mm-lighting-duration),
    var(--mm-lighting-duration),
    var(--mm-lighting-duration),
    var(--mm-lighting-duration),
    var(--mm-lighting-duration);
  transition-timing-function:
    var(--mm-lighting-easing),
    var(--mm-lighting-easing),
    var(--mm-lighting-easing),
    var(--mm-lighting-easing),
    var(--mm-lighting-easing);
}

body.mm-lighting-transition .panel-host::after {
  transition: none;
}

body.mm-lighting-transition .mm-light-controller {
  transition: none;
}

@media (prefers-reduced-motion: reduce) {
  body.mm-lighting-transition,
  body.mm-lighting-transition *,
  body.mm-lighting-transition *::before,
  body.mm-lighting-transition *::after {
    transition-duration: 0s !important;
    transition-delay: 0s !important;
  }
}

@media (max-width: 800px) {
  .dev-lighting-grid,
  .dev-setting-list-levels {
    grid-template-columns: 1fr;
  }

  .dev-level-card,
  .dev-save-card {
    grid-column: 1;
  }

}
