/* ===================================================
   スタンプカメラ - スタイルシート
   =================================================== */

/* --- CSS Custom Properties --- */
:root {
  --color-bg: #0a0a12;
  --color-surface: rgba(255, 255, 255, 0.06);
  --color-surface-hover: rgba(255, 255, 255, 0.12);
  --color-border: rgba(255, 255, 255, 0.1);
  --color-text: #f1f1f4;
  --color-text-muted: rgba(255, 255, 255, 0.5);
  --color-accent-start: #a78bfa;
  --color-accent-end: #f472b6;
  --color-danger: #ef4444;
  --font-main:
    "Noto Sans JP", "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --z-video: 1;
  --z-stamp-stage: 2;
  --z-flash: 5;
  --z-top-bar: 10;
  --z-bottom-ui: 10;
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-main);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* --- Screen System --- */
.screen {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  display: none;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

/* ===================================================
   初期画面 (Home Screen)
   =================================================== */
.home-bg {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  background: #ffffff url("../images/all_bg.png") center top no-repeat;
  background-size: 100% auto;
  z-index: 0;
}

#home-screen {
  justify-content: center;
  align-items: center;
}

.home-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 48px;
  padding: 24px;
}

.home-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

/* カメラ起動ボタン */
.btn-start-camera {
  display: flex;
  align-items: center;
  gap: 12px;
  border: none;
  background: none;
}

.btn-start-camera:disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* flex gap 非対応環境向けフォールバック */
@supports not (gap: 1px) {
  .home-content > * + * {
    margin-top: 48px;
  }
  .home-logo > * + * {
    margin-top: 12px;
  }
  .btn-start-camera > * + * {
    margin-left: 12px;
  }
}

.btn-start-icon {
  display: flex;
  align-items: center;
}

/* ===================================================
   撮影画面 (Camera Screen)
   =================================================== */
#camera-screen {
  background: #000;
}

/* --- 上部バー --- */
.camera-top-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  padding-top: max(12px, constant(safe-area-inset-top));
  padding-top: max(12px, env(safe-area-inset-top));
  z-index: var(--z-top-bar);
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0.5), transparent);
}

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-icon:active {
  background: rgba(255, 255, 255, 0.2);
}

/* --- カメラプレビュー（画面全体いっぱいに表示） --- */
#camera-preview-container {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  overflow: hidden;
  background: #000;
}

#camera-video {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: var(--z-video);
}

#stamp-stage {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  z-index: var(--z-stamp-stage);
  touch-action: none;
}

/* フラッシュエフェクト */
#flash-overlay {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: var(--z-flash);
  transition: opacity 0.1s ease;
}

#flash-overlay.flash-active {
  opacity: 1;
  transition: opacity 0s;
}

/* --- スタンプアイテム --- */
.stamp-item {
  position: absolute;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transform-origin: center center;
}

.stamp-item img {
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
  max-width: none;
}

.stamp-item.selected {
  z-index: 100;
}

.stamp-selection-ring {
  display: none;
  position: absolute;
  top: -6px;
  right: -6px;
  bottom: -6px;
  left: -6px;
  inset: -6px;
  border: 2px dashed rgba(255, 255, 255, 0.85);
  border-radius: 6px;
  box-shadow: 0 0 8px rgba(167, 139, 250, 0.5);
  pointer-events: none;
}

.stamp-item.selected .stamp-selection-ring {
  display: block;
  animation: ring-dash 1s linear infinite;
}

@keyframes ring-dash {
  to {
    stroke-dashoffset: -16;
  }
}

/* --- 下部UI（フォールドタブ + 折りたためるコンテンツ） --- */
#bottom-ui {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-bottom-ui);
}

#bottom-ui-content {
  display: flex;
  flex-direction: column;
  max-height: 640px;
  overflow: hidden;
  transition:
    max-height 0.25s ease,
    opacity 0.2s ease;
}

#camera-screen.ui-hidden #bottom-ui-content {
  max-height: 0;
  opacity: 0;
  pointer-events: none;
}

/* 折りたたみ時はタブ以外のヒット領域を無効化し、下の映像・撮影ボタンへの
   タップを妨げないようにする */
#camera-screen.ui-hidden #bottom-ui {
  pointer-events: none;
}

/* --- UI開閉タブ（右上に付いた取っ手。UIが閉じると画面下端まで追従する） --- */
#ui-fold-tab {
  position: absolute;
  top: -30px;
  right: 16px;
  width: 48px;
  height: 30px;
  border: 1px solid var(--color-border);
  border-bottom: none;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  background: rgba(10, 10, 18, 0.95);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: auto;
}

#ui-fold-tab svg {
  transition: transform 0.25s ease;
}

#camera-screen.ui-hidden #ui-fold-tab svg {
  transform: rotate(180deg);
}

/* --- 折りたたみ時に表示するフローティング撮影ボタン ---
   （.btn-captureクラスの position:relative より優先させるため
   IDセレクタで指定する） --- */
#capture-btn-floating {
  display: none;
  position: absolute;
  left: 50%;
  bottom: max(24px, constant(safe-area-inset-bottom));
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  /* 折りたたみ時に #bottom-ui と重なっても確実に手前でタップを受けられるように */
  z-index: 20;
}

#camera-screen.ui-hidden #capture-btn-floating {
  display: flex;
}

/* --- スタンプコントロール --- */
#stamp-controls {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition:
    opacity 0.2s,
    transform 0.2s;
}

@supports not (gap: 1px) {
  #stamp-controls > * + * {
    margin-left: 8px;
  }
}

#stamp-controls.hidden {
  display: none;
}

.btn-control {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: #fff;
  cursor: pointer;
  transition:
    background 0.15s,
    transform 0.15s;
}

.btn-control:active {
  background: var(--color-surface-hover);
  transform: scale(0.92);
}

.btn-control-danger {
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--color-danger);
}

.btn-control-danger:active {
  background: rgba(239, 68, 68, 0.15);
}

/* --- スタンプサムネイルパネル --- */
#stamp-panel {
  height: 140px;
  min-height: 140px;
  overflow-y: auto;
  overflow-x: hidden;
  background: rgba(10, 10, 18, 0.95);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--color-border);
  -webkit-overflow-scrolling: touch;
}

#stamp-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px;
}

.stamp-thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  cursor: pointer;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    border-color 0.2s,
    transform 0.15s;
}

/* aspect-ratio 非対応環境向けフォールバック（padding-topトリックで正方形を確保） */
@supports not (aspect-ratio: 1 / 1) {
  .stamp-thumb {
    height: 0;
    padding-top: 100%;
  }
  .stamp-thumb img {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
  }
}

.stamp-thumb:active {
  transform: scale(0.93);
  border-color: var(--color-accent-start);
}

.stamp-thumb img {
  width: 70%;
  height: 70%;
  object-fit: contain;
  pointer-events: none;
}

.stamp-thumb.disabled {
  opacity: 0.35;
  pointer-events: none;
}

/* --- 撮影バー --- */
#capture-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  padding-bottom: max(12px, constant(safe-area-inset-bottom));
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: rgba(10, 10, 18, 0.95);
  border-top: 1px solid var(--color-border);
}

.stamp-count {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  width: 60px;
}

#stamp-count-current {
  color: var(--color-text);
  font-weight: 700;
}

.capture-spacer {
  width: 60px;
}

/* 撮影ボタン */
.btn-capture {
  position: relative;
  width: 68px;
  height: 68px;
  border: none;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s;
}

.btn-capture:active {
  transform: scale(0.9);
}

.btn-capture-ring {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0;
  border-radius: 50%;
  border: 3px solid #fff;
  transition: border-color 0.2s;
}

.btn-capture-inner {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #fff;
  transition:
    background 0.15s,
    transform 0.15s;
}

.btn-capture:active .btn-capture-inner {
  background: #ccc;
  transform: scale(0.9);
}

/* ===================================================
   ユーティリティ
   =================================================== */
.hidden {
  display: none !important;
}

/* --- スクロールバー(WebKit) --- */
#stamp-panel::-webkit-scrollbar {
  width: 4px;
}

#stamp-panel::-webkit-scrollbar-track {
  background: transparent;
}

#stamp-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
}

/* --- トースト通知 --- */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 24px;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  z-index: 999;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.3s,
    transform 0.3s;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* --- セーフエリア対応 --- */
@supports (padding: max(0px)) {
  .camera-top-bar {
    padding-top: max(12px, constant(safe-area-inset-top));
    padding-top: max(12px, env(safe-area-inset-top));
  }
  #capture-bar {
    padding-bottom: max(12px, constant(safe-area-inset-bottom));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

#footer {
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 0;
  padding: 0 0 1rem;
}

body.camera-active #footer {
  display: none;
}
#footer-links {
  width: 100%;
  max-width: 500px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2rem;
}
#footer-links a {
  width: 48%;
  max-width: 200px;
  display: block;
}

#footer small {
  width: 100%;
  text-align: center;
  color: #1a1a1a;
  font-size: 0.8rem;
  display: block;
}

/* ===================================================
   非対応環境の案内パネル
   =================================================== */
.unsupported-notice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  max-width: 320px;
  padding: 20px;
  border-radius: var(--radius-lg);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  text-align: center;
  font-size: 13px;
  line-height: 1.7;
}

.unsupported-notice p {
  white-space: pre-line;
}

.unsupported-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.btn-outline {
  padding: 10px 20px;
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: var(--radius-full);
  background: transparent;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.btn-outline:active {
  background: rgba(255, 255, 255, 0.15);
}

@supports not (gap: 1px) {
  .unsupported-notice > * + * {
    margin-top: 16px;
  }
  .unsupported-actions > * + * {
    margin-top: 8px;
  }
}

/* ===================================================
   PC表示対応（スマホ幅カラムに制限して中央寄せ）
   =================================================== */
@media (min-width: 600px) {
  /* all_bg.png を画面いっぱいに拡大してぼかし、外側の背景にする */
  body::before {
    content: "";
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    inset: 0;
    background: #fff url("../images/all_bg.png") center center no-repeat;
    background-size: cover;
    filter: blur(24px);
    /* ぼかしで生じる縁の透けを画面外へ逃がす */
    transform: scale(1.1);
    z-index: -1;
  }

  /* 表示エリアをスマホ幅のカラムに制限して中央寄せ */
  .screen,
  #footer {
    left: 0;
    right: 0;
    width: 430px;
    margin-left: auto;
    margin-right: auto;
  }

  .screen {
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.45);
  }
}
