:root {
  color-scheme: dark;
  --ink: #f1eee4;
  --muted: #99968d;
  --dark: #000;
  --panel: #1c1d1a;
  --panel-deep: #151613;
  --line: rgba(241, 238, 228, 0.16);
  --yellow: #f2bd20;
  --yellow-soft: #ffd447;
  --red: #ca4431;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: #000;
  touch-action: manipulation;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--ink);
  background: #000;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.h5-shell {
  position: relative;
  width: 10rem;
  min-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: #000;
  box-shadow: 0 0 1.4rem rgba(0, 0, 0, 0.48);
}

.h5-shell::after {
  position: fixed;
  inset: 0;
  z-index: 9;
  pointer-events: none;
  opacity: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.7'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
  content: "";
}

.topbar {
  position: absolute;
  top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  left: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 1.46rem;
  padding: 0 0.46rem;
  border-bottom: 0;
  background: #000;
  backdrop-filter: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.21rem;
  color: var(--ink);
  font-size: 0.38rem;
  font-weight: 760;
  text-decoration: none;
}

.brand-mark {
  position: relative;
  display: block;
  width: 0.53rem;
  height: 0.45rem;
  border-radius: 48% 52% 46% 54%;
  background: var(--yellow);
  transform: rotate(-6deg);
}

.brand-mark::before,
.brand-mark::after {
  position: absolute;
  top: -0.18rem;
  width: 0.16rem;
  height: 0.29rem;
  border-radius: 0.13rem 0.13rem 0.04rem 0.04rem;
  background: var(--yellow);
  content: "";
}

.brand-mark::before {
  left: 0.1rem;
  transform: rotate(-12deg);
}

.brand-mark::after {
  right: 0.07rem;
  transform: rotate(18deg);
}

.lab-live {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  color: var(--yellow-soft);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.23rem;
}

.live-light {
  width: 0.14rem;
  height: 0.14rem;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 0.08rem rgba(202, 68, 49, 0.18);
  animation: live-pulse 1.8s ease-in-out infinite;
}

.playground {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 100dvh;
  padding-bottom: calc(
    0.28rem + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px))
  );
}

.character-pane {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
}

.stage {
  --scene-lift: 0.45rem;
  position: relative;
  width: 100%;
  height: 13.33rem;
  overflow: hidden;
  background: #000;
  isolation: isolate;
}

.stage::before {
  position: absolute;
  inset: -0.08rem;
  z-index: 0;
  background-image:
    linear-gradient(to bottom, #000 0, rgba(0, 0, 0, 0.9) 0.55rem, transparent 1.65rem),
    url("./assets/dudu-stage-background.png");
  background-position: center top, center top;
  background-size: 100% 1.65rem, cover;
  background-repeat: no-repeat;
  content: "";
  opacity: 0.82;
  pointer-events: none;
  transform: translate(0.62rem, -1.26rem) scale(1.14);
  transform-origin: center top;
}

.stage::after {
  position: absolute;
  inset: 0;
  z-index: 4;
  border-right: 1px solid rgba(242, 189, 32, 0.14);
  border-left: 1px solid rgba(242, 189, 32, 0.14);
  pointer-events: none;
  content: "";
}

.dudu-wordmark {
  display: none;
}

.stage-label {
  position: absolute;
  top: 2.72rem;
  left: 0.35rem;
  z-index: 3;
  display: grid;
  gap: 0.04rem;
  color: rgba(255, 212, 71, 0.72);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.16rem;
  line-height: 1.3;
}

.stage-label::after {
  width: 0.66rem;
  height: 0.09rem;
  margin-top: 0.13rem;
  background: repeating-linear-gradient(
    90deg,
    var(--yellow) 0,
    var(--yellow) 0.08rem,
    transparent 0.08rem,
    transparent 0.12rem
  );
  content: "";
}

.stage-index {
  position: absolute;
  top: 1.67rem;
  right: 0.4rem;
  z-index: 3;
  display: grid;
  justify-items: end;
  color: rgba(241, 238, 228, 0.62);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.17rem;
  line-height: 1.35;
}

.meter-rail {
  position: absolute;
  top: calc(5rem - var(--scene-lift));
  left: 0.31rem;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 0.46rem;
  height: 4.9rem;
  padding-left: 0.16rem;
  border-left: 1px solid rgba(242, 189, 32, 0.72);
  color: rgba(255, 212, 71, 0.75);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.16rem;
}

.meter-rail::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0.15rem;
  background: repeating-linear-gradient(
    180deg,
    transparent 0,
    transparent 0.23rem,
    rgba(242, 189, 32, 0.68) 0.23rem,
    rgba(242, 189, 32, 0.68) 0.25rem
  );
  content: "";
}

.scanner-ring {
  display: none;
}

.scanner-ring::before,
.scanner-ring::after {
  position: absolute;
  top: 50%;
  left: 50%;
  border: 1px solid rgba(242, 189, 32, 0.28);
  border-radius: 50%;
  content: "";
  transform: translate(-50%, -50%);
}

.scanner-ring::before {
  width: 6.8rem;
  height: 0.92rem;
}

.scanner-ring::after {
  width: 5.55rem;
  height: 0.54rem;
}

#duduCanvas {
  position: absolute;
  right: -1.5rem;
  bottom: 0.55rem;
  z-index: 2;
  display: block;
  width: 11.2rem;
  height: 13.0667rem;
  filter: saturate(1.04) contrast(1.02) drop-shadow(0 0.24rem 0.16rem rgba(0, 0, 0, 0.24));
  touch-action: none;
  transform: translateZ(0);
}

#duduCanvas.is-pullable {
  cursor: grab;
}

#duduCanvas.is-pulling {
  cursor: grabbing;
}

.canvas-state {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  background: #000;
  color: rgba(255, 212, 71, 0.78);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.22rem;
  transition: opacity 320ms ease, visibility 320ms ease;
}

.canvas-state.is-hidden {
  visibility: hidden;
  opacity: 0;
}

.canvas-state.is-error {
  padding: 0.5rem;
  color: var(--red);
  text-align: center;
}

.stage-readout {
  position: absolute;
  bottom: 2.72rem;
  left: 0.55rem;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.05rem;
  color: var(--ink);
  line-height: 0.72;
}

.weight-number {
  min-width: 1.35ch;
  font-family: Impact, "Arial Black", sans-serif;
  font-size: 2.5rem;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-shadow: 0.05rem 0.05rem 0 rgba(0, 0, 0, 0.28);
}

.weight-unit {
  margin: 0.12rem 0 0 0.12rem;
  color: var(--yellow-soft);
  font-family: "Arial Narrow", "PingFang SC", sans-serif;
  font-size: 0.58rem;
  font-weight: 800;
}

.meme-tag {
  position: absolute;
  right: 0.35rem;
  bottom: 2.55rem;
  z-index: 5;
  max-width: 6rem;
  padding: 0.15rem 0.22rem 0.17rem;
  color: #fff8e8;
  background: var(--red);
  box-shadow: 0.08rem 0.08rem 0 rgba(0, 0, 0, 0.32);
  font-size: 0.33rem;
  font-weight: 800;
  line-height: 1.2;
  transform: rotate(-1.2deg);
  transform-origin: center;
  transition: transform 240ms cubic-bezier(0.16, 1, 0.3, 1);
}

.meme-tag.is-bumping {
  transform: rotate(1deg) scale(1.06);
}

.control-pane {
  position: relative;
  z-index: 5;
  flex: 0 0 auto;
  min-height: 7.9rem;
  margin-top: -1.5rem;
  padding: 0.6rem 0.5rem 0.42rem;
  border: 0;
  background: url("./assets/bg.png") center top / 100% 100% no-repeat;
  clip-path: none;
  box-shadow: 0 -0.22rem 0.5rem rgba(0, 0, 0, 0.32);
}

.control-pane::before {
  display: none;
}

.panel-handle {
  display: none;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  margin-bottom: 0.23rem;
  color: var(--yellow-soft);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.3rem;
}

.eyebrow::before {
  width: 0.35rem;
  height: 0.04rem;
  background: var(--yellow);
  content: "";
}

.eyebrow span {
  color: rgba(241, 238, 228, 0.48);
}

.summary-row {
  min-width: 0;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 0.18rem;
}

.status-row h1 {
  margin: 0;
  color: var(--ink);
  font-size: 0.58rem;
  font-weight: 780;
  line-height: 1.18;
  letter-spacing: 0;
  text-wrap: balance;
}

.status-dot {
  flex: 0 0 auto;
  width: 0.15rem;
  height: 0.15rem;
  border-radius: 50%;
  background: var(--yellow);
  box-shadow: 0 0 0 0.08rem rgba(242, 189, 32, 0.12);
  transition: background-color 320ms ease, box-shadow 320ms ease;
}

.status-dot.is-warning {
  background: var(--red);
  box-shadow: 0 0 0 0.08rem rgba(202, 68, 49, 0.15);
}

.status-copy {
  min-height: 0.52rem;
  max-width: 8rem;
  margin: 0.14rem 0 0;
  color: var(--muted);
  font-size: 0.3rem;
  line-height: 1.55;
}

.slider-block {
  margin-top: 0.36rem;
  padding: 0.32rem 0 0.26rem;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.slider-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.3rem;
}

.slider-heading label {
  color: var(--yellow-soft);
  font-size: 0.3rem;
  font-weight: 700;
}

.slider-value {
  color: rgba(241, 238, 228, 0.38);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.3rem;
}

.range-wrap {
  position: relative;
  height: 0.55rem;
  padding: 0.18rem 0.15rem;
  border: 1px solid rgba(241, 238, 228, 0.28);
  background: var(--panel-deep);
  box-shadow: inset 0 0.08rem 0.16rem rgba(0, 0, 0, 0.46);
}

input[type="range"] {
  position: absolute;
  top: 0.21rem;
  left: 0.16rem;
  width: calc(100% - 0.32rem);
  height: 0.12rem;
  margin: 0;
  appearance: none;
  border-radius: 0.02rem;
  outline: none;
  background: linear-gradient(
    to right,
    var(--yellow) 0%,
    var(--yellow) var(--range-progress, 55%),
    #474844 var(--range-progress, 55%),
    #474844 100%
  );
  cursor: ew-resize;
}

input[type="range"]::-webkit-slider-thumb {
  width: 0.54rem;
  height: 0.54rem;
  appearance: none;
  border: 0.06rem solid #282925;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f2f0e6 0, #8e8e88 36%, #3b3c38 70%);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.48),
    0 0.09rem 0.13rem rgba(0, 0, 0, 0.48);
  transition: transform 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

input[type="range"]::-moz-range-thumb {
  width: 0.42rem;
  height: 0.42rem;
  border: 0.06rem solid #282925;
  border-radius: 50%;
  background: #b8b7af;
}

input[type="range"]:active::-webkit-slider-thumb {
  transform: scale(1.12);
}

input[type="range"]:focus-visible {
  box-shadow: 0 0 0 0.06rem rgba(242, 189, 32, 0.42);
}

.range-wrap output {
  position: absolute;
  top: -0.35rem;
  left: var(--range-progress, 55%);
  padding: 0.04rem 0.08rem;
  border: 1px solid rgba(242, 189, 32, 0.55);
  color: var(--yellow-soft);
  background: var(--panel-deep);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.3rem;
  transform: translateX(-50%);
  pointer-events: none;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 0.12rem;
  color: rgba(241, 238, 228, 0.46);
  font-size: 0.3rem;
}

.actions {
  display: grid;
  grid-template-columns: 1.08fr 0.92fr;
  gap: 0.15rem;
  margin-top: 0.28rem;
}

.actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.12rem;
  min-width: 0;
  min-height: 0.86rem;
  padding: 0 0.13rem;
  border: 1px solid rgba(241, 238, 228, 0.36);
  border-radius: 0.06rem;
  font-size: 0.34rem;
  font-weight: 740;
  white-space: nowrap;
  cursor: pointer;
  transition:
    transform 180ms cubic-bezier(0.16, 1, 0.3, 1),
    background-color 180ms ease,
    border-color 180ms ease;
}

.actions button > span:first-child {
  flex: 0 0 auto;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.34rem;
  line-height: 1;
}

.actions button:active {
  transform: translateY(1px) scale(0.98);
}

.actions button:focus-visible {
  outline: 0.05rem solid rgba(242, 189, 32, 0.56);
  outline-offset: 0.05rem;
}

.primary-action {
  border-color: var(--yellow) !important;
  color: #171711;
  background: var(--yellow);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.34);
}

.primary-action:hover {
  background: var(--yellow-soft);
}

.secondary-action {
  color: rgba(241, 238, 228, 0.76);
  background: #262723;
}

.secondary-action:hover {
  border-color: rgba(241, 238, 228, 0.62);
  background: #2e2f2a;
}

@keyframes live-pulse {
  0%,
  100% {
    opacity: 0.48;
    transform: scale(0.82);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 350px) {
  .stage {
    height: 13.33rem;
  }

  .status-row h1 {
    font-size: 0.54rem;
  }

  .actions button {
    font-size: 0.34rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
