:root {
  --bg: #1d1b26;
  --surface: #282535;
  --surface-2: #322e42;
  --text: #f3f1f8;
  --muted: #a9a4bb;
  --accent: #ff5c8a;
  --accent-2: #7cc4ff;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

main { padding: 8px 16px max(24px, env(safe-area-inset-bottom)); max-width: 1200px; margin: 0 auto; }

.screen { display: none; }
.screen.active { display: block; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- camera（フルスクリーン） ---------- */
body.cam-mode { overflow: hidden; background: #000; overscroll-behavior: none; }
/* ビューポート全体＝ビューファインダー＝撮影フレーム。操作系はその上に重ねる */
.camera-screen.active {
  position: fixed; inset: 0; z-index: 1;
  display: block;
  background: #000;
}
.cam-stage {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.viewfinder { position: absolute; inset: 0; background: #000; overflow: hidden; }
.viewfinder[hidden] { display: none; }
.viewfinder video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover; /* 画面全体を覆う中央クロップ。撮影時も同じ範囲を切り出す */
}
.viewfinder video.mirror { transform: scaleX(-1); }
/* 撮影結果（世界の向き）の座標系。中心で回転させ、右下 = 写真の右下 */
.vf-world {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  transition: transform .25s ease;
  pointer-events: none;
}
.live-sticker { position: absolute; right: 0; bottom: 0; display: block; max-width: none; pointer-events: none; user-select: none; }
.live-sticker[hidden] { display: none; }
.vf-message {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: .9rem; text-align: center; padding: 16px;
}
.vf-message:empty { display: none; }

.motion-chip {
  position: absolute; z-index: 3; top: var(--edge-t); left: 0; right: 0; margin: 0 auto; width: max-content; /* 既定は上部中央（右上は切替ボタン用） */
  border: 0; border-radius: 999px; padding: 6px 12px;
  background: rgba(0, 0, 0, .55); color: #fff; font: inherit; font-size: .75rem; cursor: pointer;
}
.motion-chip[hidden] { display: none; }
.motion-chip[data-slot="tl"] { right: auto; margin: 0; }
.motion-chip[data-slot="tr"] { left: auto; margin: 0; }

.cam-fallback {
  display: flex; flex-direction: column; gap: 10px;
  width: min(320px, 86vw); text-align: center;
}
.cam-fallback[hidden] { display: none; }
.cam-fallback p { color: var(--muted); font-size: .85rem; margin: 0 0 6px; }

/* 操作レイヤー: 画面全体に重ね、各ボタンを角／下部中央の「スロット」に置く。
 * どのスロットを使うかは app.js の placeControls() がステッカーの画面上の矩形と重ならないように決める。 */
.camera-screen {
  --edge-t: max(12px, calc(env(safe-area-inset-top) + 8px));
  --edge-r: max(16px, env(safe-area-inset-right));
  --edge-b: max(18px, env(safe-area-inset-bottom));
  --edge-l: max(16px, env(safe-area-inset-left));
}
.cam-bar {
  position: absolute; inset: 0; z-index: 2;
  pointer-events: none; /* 背景は素通し。ボタンだけ反応させる */
}
.cam-bar > * { pointer-events: auto; position: absolute; }
/* 角スロット（52px ボタンは下段でシャッター 74px と中心をそろえる: +11px） */
[data-slot="tl"] { top: var(--edge-t); left: var(--edge-l); }
[data-slot="tr"] { top: var(--edge-t); right: var(--edge-r); }
.round-btn[data-slot="bl"] { bottom: calc(var(--edge-b) + 11px); left: var(--edge-l); }
.round-btn[data-slot="br"] { bottom: calc(var(--edge-b) + 11px); right: var(--edge-r); }
/* 下部中央。--dx/--dy はステッカー回避のずらし量（transform と独立した translate を使い :active の縮小と両立） */
.shutter[data-slot="bc"] { bottom: var(--edge-b); left: calc(50% - 37px); translate: var(--dx, 0px) var(--dy, 0px); }
/* 傾きチップ用: 上部中央 */
[data-slot="tc"] { top: var(--edge-t); left: 0; right: 0; margin: 0 auto; width: max-content; }
.round-btn, .shutter { filter: drop-shadow(0 1px 4px rgba(0, 0, 0, .5)); }
.round-btn {
  width: 52px; height: 52px; border-radius: 12px;
  display: grid; place-items: center;
  border: 2px solid rgba(255, 255, 255, .8); background: rgba(255, 255, 255, .12); color: #fff;
  cursor: pointer; transition: transform .25s ease;
}
#btn-cam-flip { border-radius: 50%; border-width: 0; background: rgba(255, 255, 255, .16); }
.round-btn[hidden] { visibility: hidden; display: grid; }
.shutter {
  width: 74px; height: 74px; border-radius: 50%;
  border: 5px solid #fff; background: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 92, 138, .35);
  cursor: pointer;
}
.shutter:disabled { opacity: .35; cursor: not-allowed; }
.shutter:not(:disabled):active { transform: scale(.94); }

/* ---------- editor ---------- */
#screen-editor { padding-top: max(8px, env(safe-area-inset-top)); }
.editor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 860px) {
  .editor { grid-template-columns: 1fr; }
}
.preview-wrap {
  position: sticky; top: 8px;
  background: repeating-conic-gradient(#2e2a3d 0 25%, #252232 0 50%) 0 0 / 20px 20px;
  border-radius: var(--radius);
  padding: 10px;
  text-align: center;
}
@media (max-width: 860px) { .preview-wrap { position: static; } }
#preview {
  display: block; margin: 0 auto;
  max-width: 100%; max-height: 72vh; width: auto; height: auto;
  border-radius: 6px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .45);
}
.preview-meta { color: var(--muted); font-size: .75rem; margin: 8px 0 0; }

.panel { display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 14px 16px; }
.card h3 { margin: 0 0 10px; font-size: .95rem; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
.stats div { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.stats dt { color: var(--muted); font-size: .72rem; }
.stats dd { margin: 0; font-weight: 700; font-size: .95rem; font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: .7rem; margin: 10px 0 0; }

.control { margin-bottom: 12px; }
.control label { display: flex; justify-content: space-between; font-size: .88rem; margin-bottom: 4px; }
.control output { color: var(--accent-2); font-variant-numeric: tabular-nums; }
.range-ends { display: flex; justify-content: space-between; color: var(--muted); font-size: .7rem; }
input[type="range"] { width: 100%; accent-color: var(--accent); height: 28px; }

.auto-note { color: var(--muted); font-size: .75rem; margin: 10px 0 0; white-space: pre-line; }
.auto-note:empty { display: none; }

.actions { display: flex; flex-direction: column; gap: 10px; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 12px 18px;
  font: inherit; font-weight: 700; cursor: pointer; color: var(--text);
  min-height: 44px;
}
.btn.wide { width: 100%; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.secondary { background: #3b5674; color: #fff; }
.btn.ghost { background: transparent; border: 1px solid #4a4460; }
.btn:disabled { opacity: .5; cursor: progress; }
.btn:focus-visible, .round-btn:focus-visible, .shutter:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }

.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: #000c; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .85rem;
  z-index: 10; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
