/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', sans-serif;
  color: #fff;
  -webkit-tap-highlight-color: transparent;
}

button { cursor: pointer; font-family: inherit; touch-action: manipulation; }

[hidden] { display: none !important; }

#toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.75);
  color: #fff;
  padding: 9px 20px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  white-space: nowrap;
}
#toast.show { opacity: 1; }

/* ===== カメラ画面 ===== */
#camera-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

#camera-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#guide-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#camera-top {
  position: relative;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: linear-gradient(to bottom, rgba(0,0,0,0.55), transparent);
}

#camera-title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.cam-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  color: #fff;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

.cam-btn.active {
  background: rgba(255,255,255,0.45);
}

#camera-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px;
  padding-bottom: max(32px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0,0,0,0.55), transparent);
}

.cam-side { width: 60px; }

#shutter-btn {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: #fff;
  border: 5px solid rgba(255,255,255,0.5);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.3);
  transition: transform 0.1s;
}

#shutter-btn:active { transform: scale(0.92); }

/* ===== 補正中画面 ===== */
#processing-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

#processing-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#processing-overlay {
  position: relative;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: rgba(0,0,0,0.6);
  padding: 28px 36px;
  border-radius: 16px;
  backdrop-filter: blur(8px);
}

#processing-overlay p { font-size: 15px; }

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(255,255,255,0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 結果画面 ===== */
#result-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #000;
}

#compare-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.compare-canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

#after-wrap {
  position: absolute;
  top: 0;
  left: 0;
  width: 50%;
  height: 100%;
  overflow: hidden;
}

#compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: ew-resize;
  z-index: 20;
  touch-action: none;
}

#compare-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  background: #fff;
  transform: translateX(-50%);
  box-shadow: 0 0 6px rgba(0,0,0,0.5);
}

#compare-knob {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #fff;
  color: #000;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
  font-weight: bold;
  letter-spacing: -2px;
}

#compare-label-before,
#compare-label-after {
  position: absolute;
  top: 14px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(0,0,0,0.5);
  padding: 3px 10px;
  border-radius: 10px;
  pointer-events: none;
  z-index: 10;
}
#compare-label-before { right: calc(50% + 12px); }
#compare-label-after  { left:  calc(50% + 12px); }

/* 結果画面 下部 */
#result-bottom {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  background: rgba(0,0,0,0.8);
}

#retake-btn {
  flex: 1;
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 12px;
  background: transparent;
  color: #fff;
  font-size: 15px;
}

#save-btn {
  flex: 2;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: #fff;
  color: #000;
  font-size: 15px;
  font-weight: 700;
}

#save-btn:active { opacity: 0.85; }