:root {
  color-scheme: light;
  --paper: #fbf5ec;
  --ink: #413024;
  --mark: #413024;
  --muted: #756456;
  --edge: #d9cfc1;
  --focus: #925b36;
  --hover: #eee5d9;
  --cloth: #ddcbb2;
  --control: rgba(251, 245, 236, 0.84);
  --panel: rgba(251, 245, 236, 0.96);
  --shadow: rgba(65, 48, 36, 0.14);
  --size: clamp(38px, 3.3vw, 48px);
}

html[data-weather="rainy"] {
  --paper: #ebeff3;
  --ink: #353d45;
  --mark: #353d45;
  --muted: #646e78;
  --edge: #cdd4dc;
  --focus: #5a7694;
  --hover: #dde3ea;
  --cloth: #cbd3dc;
  --control: rgba(237, 241, 245, 0.86);
  --panel: rgba(241, 244, 248, 0.96);
  --shadow: rgba(38, 48, 60, 0.16);
}

html[data-theme="dark"] {
  color-scheme: dark;
  --paper: #101722;
  --ink: #dfebf3;
  --mark: #425c75;
  --muted: #a0afbf;
  --edge: #526276;
  --focus: #b4d9fa;
  --hover: #293546;
  --cloth: #303e50;
  --control: rgba(18, 29, 43, 0.84);
  --panel: rgba(20, 31, 46, 0.96);
  --shadow: rgba(3, 8, 18, 0.45);
}

html[data-theme="dark"][data-weather="rainy"] {
  --paper: #0b1018;
  --cloth: #232f3e;
  --control: rgba(13, 21, 32, 0.86);
  --panel: rgba(15, 24, 36, 0.96);
  --shadow: rgba(2, 5, 12, 0.58);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "Outfit", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  transition: background-color 0.55s ease, color 0.45s ease;
  -webkit-font-smoothing: antialiased;
}

html:lang(zh-TW) body {
  font-family: "Outfit", "PingFang TC", "Heiti TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
}

html:lang(ja) body {
  font-family: "Outfit", "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, -apple-system, sans-serif;
}

html:lang(ko) body {
  font-family: "Outfit", "Apple SD Gothic Neo", "Malgun Gothic", "NanumBarunGothic", system-ui, -apple-system, sans-serif;
}

.symbols {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

main {
  max-width: 1920px;
  margin: 0 auto;
  min-height: 100svh;
  padding: clamp(8px, 0.8vw, 14px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 0.9vw, 12px);
}

#viewer {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 1vw, 14px);
}

#viewer:fullscreen,
#viewer.is-full {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  padding: 12px;
  background: var(--paper);
  justify-content: center;
}

.stage-wrap {
  position: relative;
  width: min(100%, calc((100svh - 176px) * 1.62246));
}

#stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1517 / 935;
  max-height: calc(100svh - 176px);
  background: var(--cloth);
  border-radius: clamp(12px, 1.32vw, 25px);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  box-shadow: 0 12px 34px -18px var(--shadow);
  outline: none;
}

#viewer:fullscreen .stage-wrap,
#viewer.is-full .stage-wrap {
  width: min(100%, calc((100dvh - 144px) * 1.62246));
}

#viewer:fullscreen #stage,
#viewer.is-full #stage {
  max-height: calc(100dvh - 144px);
  width: 100%;
}

#stage:focus-visible {
  box-shadow: 0 0 0 3px var(--focus), 0 12px 34px -18px var(--shadow);
}

#stage[data-pressed="true"] {
  cursor: none;
}

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

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.icon-svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.85;
  stroke-linecap: round;
  stroke-linejoin: round;
  display: block;
}

.retry-btn {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 5;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--edge);
  font-size: 0.85rem;
}

button[hidden],
[hidden] {
  display: none !important;
}

/* Two-row bottom control deck */
.toolbar {
  width: min(100%, max(1420px, calc((100svh - 176px) * 1.62246)));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
  user-select: none;
  -webkit-user-select: none;
}

.choices {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: clamp(6px, 0.6vw, 10px);
}

.swatch {
  position: relative;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  background-color: var(--cloth);
  background-size: cover;
  background-position: center;
  border: 1px solid var(--edge);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
  flex: 0 0 auto;
}

.swatch:hover {
  transform: translateY(-2px) scale(1.04);
}

.swatch[aria-pressed="true"] {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px var(--paper), 0 0 0 4px var(--ink);
}

.swatch[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background-color: var(--mark);
  border: 2px solid var(--paper);
  background-repeat: no-repeat;
  background-position: center;
  background-size: 11px 11px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23fbf5ec' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3.2 8.4l3.1 3.1 6.5-6.8'/%3E%3C/svg%3E");
}

.controls-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
}

.control-pill {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: var(--control);
  border: 1px solid var(--edge);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.pill-btn {
  height: 34px;
  padding: 0 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 0.81rem;
  font-weight: 500;
  white-space: nowrap;
  color: var(--muted);
  transition: background-color 0.18s ease, color 0.18s ease, transform 0.14s ease;
}

.pill-btn:hover {
  color: var(--ink);
  background: var(--hover);
}

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

.pill-btn[aria-pressed="true"],
.pill-btn[aria-checked="true"] {
  background: var(--ink);
  color: var(--paper);
}

.pill-icon {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.hand-icon {
  width: auto;
  height: auto;
  flex: 0 0 auto;
}

/* Inline body proportions capsule */
.proportions-bar {
  padding: 3px 10px;
  gap: 8px;
}

.pill-divider {
  width: 1px;
  height: 18px;
  background: var(--edge);
  flex: 0 0 auto;
}

.slider-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.slider-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  user-select: none;
}

.slider-glyph {
  color: var(--ink);
  opacity: 0.85;
  display: block;
  flex: 0 0 auto;
}

.slider-wrap {
  position: relative;
  width: clamp(56px, 4.6vw, 82px);
  height: 22px;
  display: flex;
  align-items: center;
}

/* Center tick mark indicating default 100% (value = 5) */
.slider-wrap::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 1.5px;
  height: 4px;
  background: var(--muted);
  transform: translateX(-50%);
  pointer-events: none;
  border-radius: 1px;
}

.slider-wrap input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 5px;
  margin: 0;
  border-radius: 999px;
  background: var(--edge);
  cursor: pointer;
}

.slider-wrap input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--paper);
  box-shadow: 0 1px 4px var(--shadow);
  cursor: pointer;
  transition: transform 0.12s ease;
}

.slider-wrap input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.14);
}

.slider-wrap input[type="range"]::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--paper);
  box-shadow: 0 1px 4px var(--shadow);
  cursor: pointer;
}

.profile {
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  letter-spacing: 0.01em;
  max-width: 1380px;
  padding: 0 8px;
}

/* Language switcher capsule & upward popover */
.lang-switch {
  position: relative;
  z-index: 20;
}

.lang-btn {
  gap: 4px;
  padding: 0 10px;
}

.lang-btn[aria-expanded="true"] {
  background: var(--hover);
  color: var(--ink);
}

.lang-caret {
  width: 13px;
  height: 13px;
  opacity: 0.72;
  transition: transform 0.18s ease;
}

.lang-btn[aria-expanded="true"] .lang-caret {
  transform: rotate(180deg);
}

.lang-menu {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(2, minmax(112px, 1fr));
  gap: 4px;
  padding: 6px;
  border-radius: 16px;
  background: var(--paper);
  border: 1px solid var(--edge);
  box-shadow: 0 12px 30px -10px var(--shadow);
}

.lang-option {
  height: 34px;
  padding: 0 10px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.lang-option:hover {
  background: var(--hover);
  color: var(--ink);
}

.lang-option[aria-selected="true"] {
  background: var(--ink);
  color: var(--paper);
}

.lang-check {
  width: 14px;
  height: 14px;
  opacity: 0;
  flex: 0 0 auto;
}

.lang-option[aria-selected="true"] .lang-check {
  opacity: 1;
}

@media (max-width: 720px) {
  .stage-wrap {
    width: 100%;
  }

  #stage {
    max-height: none;
    aspect-ratio: 1.12 / 1;
  }

  .toolbar {
    width: 100%;
  }
}

@media (max-width: 525px) {
  :root {
    --size: 42px;
  }

  #stage {
    aspect-ratio: 1.05 / 1;
  }

  .choices {
    max-width: 312px;
    justify-content: center;
    gap: 8px;
  }

  .pill-btn {
    padding: 0 9px;
    font-size: 0.8rem;
  }

  .proportions-bar {
    padding: 3px 11px;
    gap: 9px;
  }

  .slider-wrap {
    width: 68px;
  }
}
