:root {
  --bg: #f9f6f0;
  --surface: rgba(255, 252, 246, 0.88);
  --surface-solid: #fffcf6;
  --text: #3d352e;
  --text-muted: #84786c;
  --border: rgba(85, 68, 52, 0.14);
  --shadow: 0 10px 30px rgba(60, 44, 28, 0.12);
  --accent: #b87344;
  --ring: #3d352e;
  --btn-bg: rgba(255, 252, 246, 0.84);
  --btn-hover: rgba(255, 252, 246, 0.98);
}

html[data-theme="dark"] {
  --bg: #101722;
  --surface: rgba(22, 31, 46, 0.88);
  --surface-solid: #161f2e;
  --text: #e6ecf5;
  --text-muted: #8fa1ba;
  --border: rgba(160, 188, 226, 0.18);
  --shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
  --accent: #7da6e0;
  --ring: #dbe7fa;
  --btn-bg: rgba(22, 31, 46, 0.78);
  --btn-hover: rgba(34, 48, 70, 0.95);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 18px 16px 28px;
  transition: background-color 0.55s ease, color 0.4s ease;
  user-select: none;
}

.app {
  width: 100%;
  max-width: 980px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* Stage */
.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #cbbba6;
  outline: none;
  touch-action: none;
}

.stage[data-over="true"] {
  cursor: none;
}

.stage:fullscreen {
  border-radius: 0;
  aspect-ratio: auto;
  width: 100vw;
  height: 100vh;
}

#scene {
  width: 100%;
  height: 100%;
  display: block;
}

#hand-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
}

/* Top Controls inside Stage */
.stage-top-left {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
  cursor: default;
}

.stage-top-right-group {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 12;
  cursor: default;
}

.lang-wrap {
  position: relative;
}

.lang-btn {
  height: 38px;
  padding: 0 12px;
  font-size: 12px;
  gap: 5px;
}

.lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 128px;
  padding: 5px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 20;
}

.lang-option {
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: background 0.15s ease;
}

.lang-option:hover {
  background: rgba(128, 128, 128, 0.12);
}

.lang-option.active {
  background: var(--text);
  color: var(--bg);
}

.lang-option-code {
  font-size: 10px;
  opacity: 0.65;
  text-transform: uppercase;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.08);
  transition: transform 0.15s ease, background 0.2s ease;
}

.pill-btn:hover {
  background: var(--btn-hover);
  transform: translateY(-1px);
}

.pill-btn:active {
  transform: scale(0.97);
}

.custom-mode-bar {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.08);
}

.seg-btn {
  height: 28px;
  padding: 0 11px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.seg-btn.active {
  background: var(--text);
  color: var(--bg);
}

.icon-mini-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s ease;
}

.icon-mini-btn:hover {
  background: rgba(128, 128, 128, 0.15);
}

.circle-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.08);
  transition: transform 0.15s ease, background 0.2s ease;
}

.circle-icon-btn:hover {
  background: var(--btn-hover);
  transform: scale(1.05);
}

html[data-theme="light"] .icon-sun { display: none; }
html[data-theme="dark"] .icon-moon { display: none; }

/* Floating Custom Tweak Panel */
.floating-panel {
  position: absolute;
  top: 58px;
  left: 14px;
  width: 304px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  z-index: 12;
  cursor: default;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.custom-preview-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.custom-preview-row img {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
}

.panel-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.close-x {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.close-x:hover {
  background: rgba(128, 128, 128, 0.14);
  color: var(--text);
}

.palette-dots {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.palette-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.palette-tag {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 4px;
}

/* Drop Overlay */
.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 16, 12, 0.42);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 20;
}

.drop-overlay.visible {
  opacity: 1;
}

.drop-card {
  padding: 24px 36px;
  border-radius: 16px;
  border: 2px dashed rgba(255, 255, 255, 0.75);
  background: rgba(255, 252, 246, 0.16);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 500;
}

/* Hint Toast */
.hint-toast {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(24, 20, 16, 0.54);
  color: rgba(255, 252, 246, 0.94);
  font-size: 12px;
  letter-spacing: 0.02em;
  pointer-events: none;
  transition: opacity 0.5s ease;
  white-space: nowrap;
}

.hint-toast.fade-out {
  opacity: 0;
}

/* Bottom Controls */
.controls-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  position: relative;
}

.swatch-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 11px;
  padding: 2px 4px;
}

.swatch-btn {
  position: relative;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid transparent;
  padding: 2px;
  background: transparent;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.2s ease;
}

.swatch-btn:hover {
  transform: scale(1.1);
}

.swatch-btn.active {
  border-color: var(--ring);
}

.swatch-inner {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, 0.28), 0 2px 6px rgba(0, 0, 0, 0.1);
  background-size: cover;
  background-position: center;
}

.swatch-btn.active::after {
  content: "✓";
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ring);
  color: var(--bg);
  font-size: 10px;
  font-weight: 700;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--bg);
}

.swatch-upload .swatch-inner {
  background: var(--surface-solid);
  border: 1.5px dashed var(--text-muted);
  color: var(--text-muted);
  box-shadow: none;
}

/* Utility Row */
.utility-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}

.cat-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.utility-btns {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.tool-btn:hover {
  background: rgba(128, 128, 128, 0.12);
  color: var(--text);
}

.tool-btn[aria-checked="true"],
.tool-btn[aria-expanded="true"] {
  background: var(--surface-solid);
  border-color: var(--border);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.tool-btn[aria-checked="false"] .icon-sound-on { display: none; }
.tool-btn[aria-checked="true"] .icon-sound-off { display: none; }

/* Proportions Panel */
.proportions-panel {
  width: 100%;
  max-width: 340px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.slider-row {
  display: grid;
  grid-template-columns: 106px 1fr 38px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
}

.slider-row input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.slider-val {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 11px;
}

.hidden {
  display: none !important;
}

@media (max-width: 640px) {
  .stage {
    aspect-ratio: 4 / 3;
    border-radius: 14px;
  }
  .swatch-btn {
    width: 38px;
    height: 38px;
  }
  .hint-toast {
    font-size: 11px;
    padding: 5px 10px;
  }
}
