:root {
  --bg: #fbf6ee;
  --surface: #ffffff;
  --scene-bg: #fffaf2;
  --text: #2b2622;
  --muted: #5e544b;
  --border: #cdbfae;
  --accent: #8a3b12;
  --accent-text: #ffffff;
  --focus: #1c5fb8;
  --error: #b3261e;
  --ground: #7d6e60;
  --guide: #8a7a6a;
  --eye: #5b3f7a;
  --fig-a: #d4673a;
  --fig-b: #3f8aa6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1f1b18;
    --surface: #2a2521;
    --scene-bg: #26211d;
    --text: #f1e9df;
    --muted: #bdb1a5;
    --border: #5a4f45;
    --accent: #f0c9a5;
    --accent-text: #2b1a0c;
    --focus: #8fb9f2;
    --error: #ff9a92;
    --ground: #a39384;
    --guide: #a39384;
    --eye: #c9a9ea;
    --fig-a: #f0925f;
    --fig-b: #6fb9d6;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", sans-serif;
  overflow-x: hidden;
}
.site-header, main, .site-footer { max-width: 960px; margin: 0 auto; padding: 0 16px; }
.site-header { padding-top: 20px; }
h1 { margin: 0; font-size: 1.6rem; }
h2 { font-size: 1.15rem; margin: 0 0 8px; }
.subtitle { margin: 4px 0 16px; color: var(--muted); }
main { display: grid; gap: 16px; padding-bottom: 8px; }
section { min-width: 0; }

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

.cards { display: grid; gap: 12px; grid-template-columns: 1fr; }
fieldset { border: 1px solid var(--border); border-radius: 12px; margin: 0; padding: 8px 14px 14px; min-width: 0; background: var(--surface); }
legend { font-weight: 600; padding: 0 6px; }
.badge { display: inline-block; min-width: 1.6em; text-align: center; border-radius: 6px; padding: 0 6px; color: #1b1411; font-weight: 700; }
.badge-a { background: var(--fig-a); }
.badge-b { background: var(--fig-b); }
.field { display: grid; gap: 2px; margin-top: 8px; min-width: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label { font-size: 0.9rem; color: var(--muted); }
input[type="text"], input[type="number"] {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-height: 44px;
}
input[aria-invalid="true"] { border-color: var(--error); }
.error { color: var(--error); margin: 6px 0 0; min-height: 1.2em; font-size: 0.9rem; }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; }
.inline-group { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; padding: 4px 12px 6px; }
.inline-group legend { font-size: 0.85rem; color: var(--muted); font-weight: 400; }
.choice { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 1rem; min-height: 44px; }
.choice input { width: 20px; height: 20px; }

button {
  font: inherit; font-weight: 600; cursor: pointer; min-height: 44px; padding: 8px 16px;
  color: var(--accent-text); background: var(--accent); border: 2px solid var(--accent); border-radius: 10px;
}
button:hover { filter: brightness(1.08); }
button.secondary { color: var(--text); background: transparent; border-color: var(--border); }

.scene {
  overflow-x: auto; overflow-y: hidden; background: var(--scene-bg);
  border: 1px solid var(--border); border-radius: 12px; max-width: 100%;
}
.scene svg { display: block; margin: 0 auto; }
.numbers { margin-top: 10px; padding: 10px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); }
.numbers .headline { font-size: 1.2rem; font-weight: 700; margin: 0; overflow-wrap: anywhere; }
.numbers .detail { margin: 2px 0 0; color: var(--muted); overflow-wrap: anywhere; }

.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.status { margin: 0; color: var(--muted); font-size: 0.9rem; flex-basis: 100%; min-height: 1.2em; }
.link-fallback { flex-basis: 100%; display: grid; gap: 4px; }
.link-fallback[hidden] { display: none; }

.mylist-save { display: flex; flex-wrap: wrap; gap: 10px; }
.mylist-items { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.mylist-items li {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
.mylist-items .entry-name { flex: 1 1 140px; min-width: 0; overflow-wrap: anywhere; }
.mylist-items button { min-height: 40px; padding: 4px 12px; }

.site-footer { padding-top: 20px; padding-bottom: 28px; color: var(--muted); font-size: 0.9rem; }

@media (min-width: 720px) {
  .cards { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

.limb-mode { margin-top: 10px; border-radius: 10px; }
input:disabled { opacity: 1; color: var(--muted); background: transparent; border-style: dashed; cursor: not-allowed; }

.scene-picker { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-bottom: 10px; }
.scene-picker label[for] { color: var(--text); font-weight: 600; }
select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; min-height: 44px; max-width: 100%;
}
.scene-options { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: center; }
.scene-options .inline-group { padding: 2px 12px 4px; }
.numbers .note { margin: 6px 0 0; color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }
[hidden] { display: none !important; }

.scene-options input.option-number { width: 6em; min-height: 44px; }
.scene-options select.option-select { min-height: 44px; font-size: 1rem; max-width: 100%; }

/* heads (proportion) control */
.heads-row { display: grid; grid-template-columns: 1fr 5.5rem; gap: 10px; align-items: center; }
.heads-range { width: 100%; min-width: 0; }
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.preset-row .preset { padding: 4px 10px; min-height: 36px; }
.preset-row .preset[aria-pressed="true"] { outline: 2px solid var(--fig-a); outline-offset: 1px; }
.caption { margin: 4px 0 0; font-size: 0.85rem; color: var(--muted); }
.heads-field .error { min-height: 0; margin-top: 2px; }

/* 3D scene */
.threed { display: grid; gap: 8px; padding: 8px; }
.threed-tools { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.threed-tools button { min-height: 40px; padding: 4px 14px; }
.threed-stage { min-width: 0; }
.threed-stage canvas { display: block; width: 100%; height: clamp(300px, min(60vh, 110vw), 520px); touch-action: none; cursor: grab; border-radius: 8px; }
.threed-stage canvas:active { cursor: grabbing; }
.threed-stage canvas:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.threed-hint { margin: 0; font-size: 0.85rem; color: var(--muted); }
.threed-clock { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.threed-note { margin: 0; padding: 6px 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); font-size: 0.9rem; }
.threed-stage { position: relative; }
.threed-crosshair { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; pointer-events: none; }
.threed-crosshair::before, .threed-crosshair::after { content: ""; position: absolute; background: var(--text); opacity: 0.75; }
.threed-crosshair::before { left: 10px; top: 0; width: 2px; height: 22px; }
.threed-crosshair::after { left: 0; top: 10px; width: 22px; height: 2px; }
.threed-tools button[aria-pressed="true"] { outline: 2px solid var(--focus); outline-offset: 1px; }
