:root {
  --sora: #1A9BE0;
  --sora-deep: #0E6FA8;
  --pin: #FF5A4E;
  --pin-deep: #D93A30;
  --hiyoko: #FFC21A;
  --mint: #3CCB9E;
  --kumo: #F2F7FB;
  --yoru: #1E3550;
  --muted: #6A819A;
  --border: #DCEBF6;
  --border-strong: #CFE0EE;
  --stage: #D9EEFB;
  --stage-glow: #F2FAFF;
  --panel-bg: #EEF4F9;
  --ink: var(--yoru);
  --accent: var(--pin);
  --accent-ink: #ffffff;
  --good: var(--sora);
  --warn: #C47A1A;
  --shadow: 0 10px 28px rgba(30, 53, 80, 0.08);
  --btn-shadow: 0 3px 0 var(--border-strong);
  --radius-card: 20px;
  --radius-pill: 99px;
  --font-ui: "M PLUS Rounded 1c", "Hiragino Sans", "Noto Sans JP", sans-serif;
  --font-display: "Fredoka", "M PLUS Rounded 1c", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background: var(--kumo);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

button, input { font: inherit; color: inherit; }

img, canvas {
  -webkit-user-drag: none;
  user-select: none;
  -webkit-user-select: none;
}

/* —— Header —— */
.top {
  display: flex;
  justify-content: flex-start;
  gap: 16px;
  align-items: center;
  padding: 12px 24px;
  border-bottom: 3px solid var(--border);
  background: #fff;
  flex: none;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.brand-logo {
  display: block;
  height: 34px;
  width: auto;
  max-width: min(596px, 92vw);
  object-fit: contain;
  object-position: left center;
}

/* —— Buttons —— */
.btn {
  appearance: none;
  border: 2px solid var(--border-strong);
  background: #fff;
  border-radius: var(--radius-pill);
  padding: 9px 16px;
  cursor: pointer;
  line-height: 1.2;
  font-weight: 700;
  color: var(--yoru);
  box-shadow: var(--btn-shadow);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.08s ease;
}

.btn:hover { background: var(--kumo); }

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--border-strong);
}

.btn:focus-visible,
.eyes button:focus-visible,
.view-presets button:focus-visible,
.proposal:focus-visible,
.mode-row button:focus-visible,
.side-toggle button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--sora);
  outline-offset: 2px;
}

.btn.primary {
  background: var(--pin);
  border-color: var(--pin);
  color: var(--accent-ink);
  box-shadow: 0 4px 0 var(--pin-deep);
  font-weight: 800;
}

.btn.primary:hover { background: #ff6d63; }

.btn.primary:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--pin-deep);
}

.btn-block {
  width: 100%;
  margin: 4px 0 10px;
  padding: 12px 18px;
  font-size: 15px;
}

body[data-busy="true"] .btn { opacity: 0.7; }

/* —— Layout —— */
.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  gap: 16px;
  padding: 16px;
}

.panel {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  overflow: auto;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 13px;
  letter-spacing: 0.04em;
  font-weight: 800;
}

.panel h2 span {
  display: inline-block;
  border-top: none;
  padding-top: 0;
}

.lead, .hint, .fine {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
}

.slider {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  margin-bottom: 10px;
}

.slider-name { font-size: 13px; font-weight: 700; }

.slider-val {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--sora);
  font-weight: 600;
}

.slider input {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--sora);
  -webkit-appearance: none;
  appearance: none;
  height: 10px;
  border-radius: 99px;
  background: var(--border);
  outline: none;
}

.slider input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--sora);
  box-shadow: 0 2px 0 var(--sora-deep);
  cursor: pointer;
}

.slider input::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--sora);
  box-shadow: 0 2px 0 var(--sora-deep);
  cursor: pointer;
}

.slider-note {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.slider.uncertain .slider-name::after {
  content: "低";
  margin-left: 6px;
  color: var(--warn);
  font-size: 10px;
  letter-spacing: 0.08em;
}

.eyes {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.body-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 8px;
}

.body-actions .btn {
  width: 100%;
  padding-left: 6px;
  padding-right: 6px;
  font-size: 12px;
  border-radius: 12px;
}

.pose-tools {
  grid-template-columns: 1fr 1fr 1fr;
  margin-top: 6px;
}

.pose-tools .btn {
  background: var(--panel-bg);
  border: none;
  box-shadow: none;
  border-radius: 10px;
  height: 36px;
  padding: 0 4px;
}

.pose-tools .btn:hover { background: #e3ebf3; }
.pose-tools .btn:active {
  transform: translateY(1px);
  box-shadow: none;
}

.standing-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.standing-actions .btn {
  width: 100%;
  text-align: center;
}

#btn-look,
.btn-look {
  width: 100%;
  margin: 0 0 8px;
  height: 44px;
  border-radius: 14px;
  border: 2px solid var(--hiyoko);
  background: #FFF8E0;
  color: var(--yoru);
  box-shadow: 0 3px 0 #E0A800;
  font-weight: 800;
}

#btn-look:hover,
.btn-look:hover { background: #fff3c4; }

.look-hint { margin-top: 0; }

.view-presets {
  display: flex;
  background: var(--panel-bg);
  border-radius: var(--radius-pill);
  padding: 4px;
  gap: 4px;
  margin: 0 0 14px;
}

.view-presets button {
  flex: 1;
  border: none;
  background: transparent;
  border-radius: var(--radius-pill);
  padding: 8px 0;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  color: var(--yoru);
}

.view-presets button[aria-pressed="true"] {
  background: #fff;
  color: var(--sora);
  box-shadow: 0 2px 0 var(--border-strong);
}

.angle-downloads {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 4px;
}

.angle-downloads .btn {
  width: 100%;
  text-align: center;
}

.angle-downloads .hint {
  margin: 0;
}

.eyes button {
  border: 2px solid var(--border);
  background: #fff;
  border-radius: 10px;
  padding: 7px 0;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 2px 0 var(--border);
}

.eyes button[aria-pressed="true"] {
  border-color: var(--sora);
  background: #E8F6FD;
  color: var(--sora);
  box-shadow: 0 2px 0 var(--sora);
}

/* —— Stage —— */
.stage-wrap {
  position: relative;
  min-height: 520px;
  border-radius: 24px;
  border: none;
  background: var(--stage);
  background-image: radial-gradient(circle at 50% 38%, var(--stage-glow) 0%, var(--stage) 62%);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.stage-wrap::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 42%;
  background-image: radial-gradient(#B5D9F0 2px, transparent 2.5px);
  background-size: 28px 28px;
  opacity: 0.55;
  pointer-events: none;
  z-index: 0;
}

#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  z-index: 1;
}

#view.hot { cursor: grab; }
#view.dragging { cursor: grabbing; }

.stage-note {
  position: absolute;
  left: 12px;
  bottom: 12px;
  right: 12px;
  margin: 0;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 3px 0 #BFDDF0;
  z-index: 2;
  max-width: calc(100% - 24px);
}

.preview-block { margin-bottom: 4px; }

#preview, .preview-empty {
  width: 100%;
  height: auto;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--panel-bg);
}

#preview {
  touch-action: none;
  cursor: default;
}

#preview.hot { cursor: grab; }
#preview.dragging { cursor: grabbing; }

#btn-refit {
  width: 100%;
  margin-top: 8px;
}

.preview-empty {
  display: grid;
  place-items: center;
  min-height: 120px;
  color: var(--muted);
  font-size: 12px;
}

#preview[hidden], .preview-empty[hidden] { display: none; }

.proposals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 8px;
}

.proposal {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: #fff;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--border);
}

.proposal.selected {
  border-color: var(--sora);
  box-shadow: 0 2px 0 var(--sora);
}

.proposal img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: var(--stage);
}

.proposal-name { font-size: 12px; font-weight: 700; }

.proposal-note {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
}

#proposal-note {
  min-height: 1.2em;
  margin: 0;
}

/* —— Accordion cards —— */
details.acc {
  margin: 0;
  border: none;
  padding: 18px;
  background: #fff;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
}

details.acc:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 18px;
}

details.acc > summary {
  list-style: none;
  cursor: pointer;
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
  border-top: none;
  padding-top: 0;
  color: var(--yoru);
}

details.acc > summary::-webkit-details-marker { display: none; }

details.acc > summary::before {
  content: "▸";
  display: inline-block;
  width: 1em;
  margin-right: 0;
  color: var(--muted);
  font-size: 12px;
  transition: transform 0.12s ease;
  order: 10;
  margin-left: auto;
}

details.acc[open] > summary::before {
  transform: rotate(90deg);
}

.acc-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.acc-dot--body { background: var(--pin); }
.acc-dot--pose { background: var(--sora); }
.acc-dot--yaw { background: var(--hiyoko); }
.acc-dot--save { background: var(--mint); }
.acc-dot--ref { background: var(--pin); }
.acc-dot--prop { background: var(--sora); }
.acc-dot--joint { background: var(--yoru); }

.acc-sub {
  margin: 12px 0 10px;
  font-size: 13px;
  letter-spacing: 0.04em;
  font-weight: 800;
}

.acc-sub span {
  display: inline-block;
  border-top: none;
  padding-top: 0;
}

/* —— Footer / status —— */
.status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 0 24px;
  height: 40px;
  background: #fff;
  border-top: 3px solid var(--border);
  color: var(--yoru);
  font-size: 12px;
  flex: none;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mint);
  flex: none;
}

.status {
  margin: 0;
  padding: 0;
  color: var(--yoru);
  font-size: 12px;
  min-height: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-ver {
  margin-left: auto;
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 600;
  color: #9AB0C4;
  letter-spacing: 1px;
  flex: none;
}

/* —— Camera knobs (CAMERA pill) —— */
.view-knobs {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  z-index: 2;
  background: #fff;
  border-radius: var(--radius-pill);
  padding: 6px;
  box-shadow: 0 3px 0 #BFDDF0;
}

.view-knob {
  padding: 0;
  display: grid;
  place-items: center;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--yoru);
  cursor: grab;
  box-shadow: none;
  touch-action: none;
  font-family: var(--font-display);
}

.cam-rotate {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: min(46vw, 200px);
  height: 36px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  background: transparent;
  cursor: grab;
}

.cam-arrow {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--panel-bg);
  font-size: 14px;
  font-weight: 700;
  color: var(--yoru);
  flex: none;
  pointer-events: none;
}

.cam-label {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.5px;
  padding: 0 6px;
  pointer-events: none;
}

.cam-fit {
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  background: var(--sora);
  color: #fff;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  flex: none;
  white-space: nowrap;
}

.cam-fit:hover { background: #2aa8e8; }

.cam-zoom,
.cam-persp {
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  background: var(--panel-bg);
  color: var(--yoru);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 700;
  cursor: grab;
  flex: none;
  white-space: nowrap;
}

.cam-zoom:hover,
.cam-persp:hover { background: #e3ebf3; }

.cam-persp[aria-pressed="true"] {
  background: var(--sora);
  color: #fff;
}

.cam-persp[aria-pressed="true"]:hover { background: #2aa8e8; }

.view-knob:hover .cam-arrow { background: #e3ebf3; }

.view-knob:active,
.view-knob.dragging {
  cursor: grabbing;
}

.view-knob.dragging .cam-arrow {
  background: #d5e4f0;
}

.stage-wrap:has(#view.dragging) .view-knobs {
  pointer-events: none;
  opacity: 0.35;
}


.body-preset {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 0 0 8px;
}

.body-preset .side-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  width: 52px;
  flex: 0 0 52px;
}

.body-preset button {
  border: 2px solid var(--border-strong);
  background: #fff;
  border-radius: 12px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: var(--yoru);
  box-shadow: 0 2px 0 var(--border-strong);
}

.body-preset button[aria-pressed="true"] {
  border-color: var(--sora);
  background: #E8F6FD;
  color: var(--sora);
  box-shadow: 0 2px 0 var(--sora);
}

.body-preset button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

.body-preset-credit {
  margin: 0 0 10px;
  font-size: 11px;
  line-height: 1.35;
}

.body-type {
  margin: 0 0 12px;
}

.body-type .side-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.mode-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.mode-row button {
  border: 2px solid var(--border-strong);
  background: #fff;
  border-radius: 12px;
  padding: 8px 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  color: var(--yoru);
  box-shadow: 0 3px 0 var(--border-strong);
}

.mode-row button[aria-pressed="true"] {
  border-color: var(--sora);
  background: #E8F6FD;
  color: var(--sora);
  box-shadow: 0 3px 0 var(--sora);
}

.mode-opts {
  display: grid;
  gap: 8px;
  margin-bottom: 6px;
}

.side-toggle {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 10px;
  align-items: center;
}

.side-toggle .side-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.side-toggle:has(button[data-side]) {
  /* label + pill group: JS injects label then two buttons */
}

/* Wrap L/R buttons visually as a pill track when possible */
.side-toggle > button {
  border: none;
  background: var(--panel-bg);
  border-radius: var(--radius-pill);
  padding: 6px 0;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  height: 32px;
}

.side-toggle > button[aria-pressed="true"] {
  background: #fff;
  color: var(--sora);
  box-shadow: 0 2px 0 var(--border-strong);
}

/* Better: when there are two side buttons after label, nest look via grid */
.side-toggle {
  grid-template-columns: 52px 1fr 1fr;
  background: transparent;
  padding: 0;
  gap: 6px;
}

.side-toggle .side-label {
  width: 52px;
}

.side-toggle button {
  background: var(--panel-bg);
}

@media (max-width: 980px) {
  body { height: auto; }
  .layout {
    grid-template-columns: 1fr;
  }
  .stage-wrap {
    order: -1;
    height: 68vh;
    min-height: 420px;
  }
  .top { align-items: flex-start; }
  .brand-logo { height: 28px; }
  .status-bar { height: auto; min-height: 40px; padding: 8px 16px; flex-wrap: wrap; }
  .status { white-space: normal; }
}

@media (max-width: 640px) {
  .proposals { grid-template-columns: 1fr; }
  .eyes { grid-template-columns: repeat(3, 1fr); }
  .pose-tools { grid-template-columns: 1fr 1fr 1fr; }
  .cam-rotate { width: min(52vw, 160px); }
  .cam-label { font-size: 11px; padding: 0 2px; }
}
