* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #17181c;
  --panel: #1f2127;
  --panel2: #2a2d35;
  --line: #383c46;
  --text: #e8eaf0;
  --muted: #9aa0ae;
  --accent: #f97316;
  --accent2: #fdba74;
  --danger: #ef4444;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
}

#viewport { position: absolute; inset: 0; right: 300px; }
#viewport canvas { display: block; }

#panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 300px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  padding: 16px 14px 24px;
}

h1 { font-size: 18px; letter-spacing: .5px; margin-bottom: 4px; color: var(--accent); }
h1 .sub { font-size: 11px; color: var(--muted); font-weight: normal; letter-spacing: 0; }
.title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.title-row h1 { margin-bottom: 4px; }
.lang-toggle { flex: 0 0 auto; width: auto; padding: 4px 10px; font-size: 12px; font-weight: 600; margin-top: 2px; }

section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
h2 { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 8px; letter-spacing: .5px; }

button {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
button:hover { background: #343845; border-color: #4a4f5c; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; width: 100%; padding: 10px; }
button.primary:hover { background: #fb8b3c; }
button.danger { color: #fca5a5; }
button.danger:hover { background: #3b2325; border-color: var(--danger); }
button.small { width: 100%; margin-top: 6px; }
button.mode { flex: 1; }
button.mode.on, button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.btn-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.btn-grid button { padding: 8px 4px; }
.btn-row { display: flex; gap: 6px; margin-bottom: 6px; }
.btn-row button { flex: 1; white-space: nowrap; }
.mode-row { display: flex; gap: 6px; margin-bottom: 8px; }

select, input[type="text"] {
  width: 100%;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 12px;
}
.btn-row select, .btn-row input[type="text"] { flex: 1.4; min-width: 0; }

.slider-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.slider-row label { width: 14px; font-size: 12px; color: var(--muted); font-weight: 700; }
.slider-row span { width: 44px; font-size: 11px; text-align: right; color: var(--accent2); font-variant-numeric: tabular-nums; }
input[type="range"] { flex: 1; accent-color: var(--accent); }

#jointControls { margin-top: 8px; }
.hidden { display: none !important; }

.check { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 8px; cursor: pointer; }
.check input { accent-color: var(--accent); }

.mini { font-size: 10.5px; color: var(--muted); margin: 4px 0 6px; line-height: 1.5; }
.lbl { width: 34px; flex: 0 0 34px; font-size: 12px; color: var(--muted); align-self: center; }
.hint { margin-top: 16px; font-size: 11px; line-height: 1.8; color: var(--muted); }
.hint b { color: var(--accent2); font-weight: 700; }
.credits { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 10px; line-height: 1.6; color: var(--muted); }

#refWrap {
  position: absolute; left: 12px; bottom: 12px; z-index: 5;
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  background: var(--panel);
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}
#refWrap img { display: block; max-width: 180px; max-height: 240px; }
#refClose {
  position: absolute; top: 2px; right: 2px;
  padding: 1px 7px; font-size: 13px; border-radius: 6px;
  background: rgba(20,21,26,.85);
}

#toast {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: rgba(20,21,26,.92); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 18px; font-size: 13px;
  opacity: 0; pointer-events: none; transition: opacity .25s;
  z-index: 10;
}
#toast.show { opacity: 1; }

/* タッチ操作: キャンバス上のドラッグでページがスクロール/ズームしないように */
#viewport canvas { touch-action: none; }

/* 狭い画面(スマホ・タブレット縦): 3Dを上・操作パネルを下にスタック */
@media (max-width: 820px) {
  #viewport { inset: 0; right: 0; bottom: 48vh; }
  #panel {
    top: 52vh; left: 0; right: 0; bottom: 0; width: 100%;
    border-left: none; border-top: 1px solid var(--line);
    padding: 12px 14px calc(24px + env(safe-area-inset-bottom));
  }
  #refWrap { top: 12px; bottom: auto; }
  #refWrap img { max-width: 120px; max-height: 160px; }
  #toast { bottom: calc(48vh + 16px); }
}
