:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1f2a37;
  --sub: #6b7280;
  --line: #d9dde3;
  --accent: #2563eb;
  --accent-ink: #ffffff;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 16px; line-height: 1.6;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
.view { min-height: 100%; display: flex; flex-direction: column; }

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--ink); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
}
.bar h1 { font-size: 17px; margin: 0; flex: 1; text-align: center; font-weight: 600; }
.bar-btn {
  background: none; border: 0; color: #cfd8e3; font-size: 15px; padding: 8px 6px; min-width: 76px;
}
.bar-btn:first-child { text-align: left; }
.bar-btn:last-child { text-align: right; }
.bar-btn.strong { color: #fff; font-weight: 700; }

.pad { padding: 16px; max-width: 640px; width: 100%; margin: 0 auto; }
.lead { margin: 0 0 16px; color: var(--sub); font-size: 14px; }
.note { color: var(--sub); font-size: 13px; margin: 12px 0 0; }
.version { color: #9aa1ab; font-size: 12px; text-align: center; margin-top: 28px; }

.slots { display: grid; gap: 12px; }
.slot { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.slot-label { font-size: 13px; color: var(--sub); padding: 8px 12px 0; }
.slot-body { padding: 8px 12px 12px; min-height: 96px; display: flex; align-items: center; justify-content: center; }
.slot-body img { max-width: 100%; max-height: 46vh; border-radius: 4px; box-shadow: 0 1px 6px rgba(0,0,0,.18); display: block; }
.empty { color: #9aa1ab; font-size: 14px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font-size: 16px; padding: 13px 10px; border-radius: 10px; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: none; font-weight: 400; font-size: 14px; color: var(--sub); padding: 9px 10px; }
.btn.small { font-size: 13px; padding: 8px 12px; font-weight: 400; white-space: nowrap; }
.btn:active { opacity: .7; }

/* 四隅の調整 */
#view-adjust { height: 100%; background: #111; }
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; }
#photo { position: absolute; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#quad { fill: rgba(37, 99, 235, .14); stroke: #4f8cff; stroke-width: 2; stroke-linejoin: round; }
.handle {
  position: absolute; width: 52px; height: 52px; margin: -26px 0 0 -26px;
  border-radius: 50%; touch-action: none;
}
.handle::after {
  content: ""; position: absolute; inset: 14px; border-radius: 50%;
  background: rgba(255,255,255,.25); border: 3px solid #fff; box-shadow: 0 0 0 1.5px #2563eb, 0 1px 4px rgba(0,0,0,.5);
}
.handle.drag::after { inset: 19px; background: none; }
#loupe {
  position: absolute; top: 10px; left: 10px; width: 120px; height: 120px;
  border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 10px rgba(0,0,0,.6); pointer-events: none;
}
#loupe.right { left: auto; right: 10px; }
.foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  color: #d5dae1; font-size: 13px; background: #1b1f26;
  padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
}

/* 結果 */
.result-frame { background: #e3e6eb; border-radius: 12px; padding: 14px; display: flex; justify-content: center; }
#result { max-width: 100%; max-height: 56vh; box-shadow: 0 2px 10px rgba(0,0,0,.25); border-radius: 3px; }

#busy {
  position: fixed; inset: 0; background: rgba(17,17,17,.55); color: #fff; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; font-size: 14px;
}
.spinner { width: 34px; height: 34px; border: 3px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
