* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  background: #000;
  color: white;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  overflow: hidden;
}

.app {
  width: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #000;
}

.view-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* カメラ全体エリア */

/* カメラ映像 */
#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ガイド画像 */
#guide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  opacity: 0.5;
  transform-origin: center center;
  transition: transform 120ms linear, opacity 120ms linear;
}

#guide[hidden] {
  display: none;
}

/* 上のステータス */
.top-bar {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: 8px;
  right: 8px;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  font-size: 15px;
  pointer-events: none;
}

.top-bar > * {
  pointer-events: auto;
}

.status {
  flex: 1 1 auto;
  min-width: 0;
  max-width: calc(100% - 110px);
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(8px);
  font-size: 12px;
  line-height: 1.3;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* 下の操作パネル */
.capture-panel {
  position: relative;
  min-height: 100%;
}

.camera-container {
  position: relative;
  width: 100%;
  min-height: 0;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(10px, env(safe-area-inset-top)) 8px 8px;
}

.camera-stage {
  position: relative;
  width: min(100%, calc(100vw - 16px));
  max-width: 460px;
  max-height: none;
  min-height: 260px;
  aspect-ratio: 3 / 4;
  background: #000;
  overflow: hidden;
  border-radius: 16px;
}

.camera-stage .button-area.camera-overlay {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 999px;
  backdrop-filter: blur(10px);
  z-index: 10;
}

.controls {
  position: relative;
  padding: 16px 20px calc(24px + env(safe-area-inset-bottom));
  background: rgba(20, 20, 20, 0.96);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.support-panel {
  width: 100%;
  max-width: 420px;
  min-height: 38px;
  margin: 0 auto 10px;
  padding: 8px 10px;
  border: 1px solid rgba(125, 211, 252, 0.35);
  border-radius: 10px;
  background: rgba(8, 47, 73, 0.52);
  color: #e0f2fe;
}

.support-label {
  margin-bottom: 2px;
  color: rgba(186, 230, 253, 0.8);
  font-size: 11px;
  font-weight: 700;
}

.support-message {
  font-size: 13px;
  line-height: 1.35;
}

.experiment-status {
  width: 100%;
  max-width: 420px;
  margin: 0 auto 10px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  text-align: center;
}

.guide-control[hidden] {
  display: none;
}

.slider-area {
  display: block;
  width: 100%;
  max-width: 420px;
  margin: 0 auto 12px;
  font-size: 14px;
}

.slider-area input {
  width: 100%;
  margin-top: 8px;
}

.button-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin-bottom: 12px;
}

.capture-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.85);
  background: white;
}

.photo-count {
  min-width: 48px;
  color: rgba(255, 255, 255, 0.75);
}

.action-buttons {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
}

.action-btn {
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  color: white;
  font-size: 15px;
  font-weight: 600;
}

.action-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.send-btn {
  background: #2563eb;
}

.clear-btn {
  background: #6b7280;
}

.danger-btn {
  background: #dc2626;
}

.error-panel {
  width: 100%;
  max-width: 420px;
  margin: 12px auto 0;
  padding: 10px 12px;
  border: 1px solid rgba(248, 113, 113, 0.55);
  border-radius: 10px;
  background: rgba(127, 29, 29, 0.72);
  color: #fee2e2;
  font-size: 13px;
  line-height: 1.45;
}

.gallery-panel {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.94);
  padding-top: env(safe-area-inset-top);
}

.gallery-content {
  flex: 1;
  overflow-y: auto;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}

.gallery-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.gallery-title {
  font-size: 18px;
  font-weight: 700;
}

.gallery-summary {
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 14px;
}

.thumbnail-container {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  width: 100%;
  padding: 16px;
  background: transparent;
}

.thumbnail-container[hidden] {
  display: none;
}

.gallery-title-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.gallery-title {
  font-size: 18px;
  font-weight: 700;
}

.gallery-summary {
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 14px;
}

.gallery-empty {
  padding: 24px 16px;
  text-align: center;
  color: rgba(255, 255, 255, 0.65);
  font-size: 15px;
}


.secondary-btn {
  background: rgba(255, 255, 255, 0.07);
}

#viewGalleryBtn {
  width: 100%;
  margin-top: 12px;
}

.action-btn.disabled,
.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.photo-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.92);
}

.photo-preview-overlay[hidden] {
  display: none;
}

.preview-close {
  position: absolute;
  top: max(14px, env(safe-area-inset-top) + 14px);
  right: 14px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(0, 0, 0, 0.72);
  color: white;
  font-size: 24px;
  line-height: 36px;
}

.photo-preview-overlay img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 18px;
  box-shadow: 0 0 45px rgba(0, 0, 0, 0.55);
}

.thumbnail {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  background: #222;
}

.thumbnail.selected {
  outline: 3px solid rgba(37, 99, 235, 0.85);
}

.thumbnail img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumbnail-delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  font-size: 20px;
  line-height: 28px;
}

@media (max-width: 420px) {
  .thumbnail-container {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }

  .action-buttons {
    flex-direction: column;
  }

  .action-buttons .action-btn {
    width: 100%;
  }

  .button-area {
    gap: 12px;
    flex-direction: column;
  }
}

#canvas {
  display: none;
}
