* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: #1c1c1e;
  color: #f2f2f7;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #38383a;
}
.app-header h1 { font-size: 18px; margin: 0; }
.cv-status { font-size: 12px; color: #8e8e93; }
.cv-status.ready { color: #30d158; }

.screen {
  display: none;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  height: calc(100% - 49px);
  overflow-y: auto;
}
.screen.active { display: flex; }

.top-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 360px;
  margin-top: 40px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 20px;
  border-radius: 12px;
  border: none;
  font-size: 16px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: #0a84ff; color: #fff; }
.btn-primary:disabled { background: #3a3a3c; color: #8e8e93; }
.btn-secondary { background: #2c2c2e; color: #f2f2f7; }
.btn-text { background: transparent; color: #0a84ff; }

/* バッチ状態（トップ画面） */
.batch-status {
  width: 100%;
  max-width: 360px;
  margin-top: 24px;
  padding: 16px;
  background: #2c2c2e;
  border-radius: 12px;
  text-align: center;
}
.batch-status p { margin: 0 0 12px; font-size: 14px; color: #c7c7cc; }
.batch-status .btn { width: 100%; }

/* カメラ画面 */
#camera-video {
  width: 100%;
  max-width: 480px;
  flex: 1;
  object-fit: cover;
  border-radius: 12px;
  background: #000;
}
.camera-thumbs {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 480px;
  overflow-x: auto;
  padding: 10px 0;
}
.camera-thumbs img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #48484a;
  flex-shrink: 0;
}
.camera-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 12px 0;
  width: 100%;
}
.btn-shutter {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid #8e8e93;
  padding: 0;
}
.camera-bottom-actions {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 480px;
}
.camera-bottom-actions .btn { flex: 1; }

/* 検出・補正画面 */
.page-progress {
  font-size: 13px;
  color: #8e8e93;
  margin: 0 0 4px;
}
.adjust-canvas-wrap, .preview-canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 480px;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
#canvas-adjust, #canvas-result {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}
#corner-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}
#corner-overlay .corner-hitarea {
  fill: transparent;
  cursor: grab;
}
#corner-overlay .corner-handle {
  fill: rgba(10, 132, 255, 0.85);
  stroke: #fff;
  stroke-width: 2;
  pointer-events: none;
}
#corner-overlay .corner-poly {
  fill: rgba(10, 132, 255, 0.2);
  stroke: #0a84ff;
  stroke-width: 2;
  pointer-events: none;
}

/* ドラッグ中ルーペ */
.loupe {
  position: absolute;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
  pointer-events: none;
  z-index: 10;
}

.hint {
  font-size: 13px;
  color: #8e8e93;
  margin: 8px 0;
  text-align: center;
}

.adjust-controls, .preview-controls {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 480px;
  padding: 12px 0;
}
.adjust-controls .btn, .preview-controls .btn { flex: 1; }

/* ギャラリー画面 */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  width: 100%;
  max-width: 480px;
  flex: 1;
  align-content: start;
  padding-top: 8px;
}
.gallery-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  background: #2c2c2e;
  aspect-ratio: 3/4;
  cursor: pointer;
}
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-item .gallery-item-index {
  position: absolute;
  top: 4px; left: 4px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 6px;
}
.gallery-controls {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 480px;
  padding: 12px 0;
}
.gallery-controls .btn { flex: 1; }

/* フィルター選択 */
.filter-choices {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 480px;
  padding: 12px 0 0;
}
.filter-btn {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid #48484a;
  background: #2c2c2e;
  color: #f2f2f7;
  font-size: 14px;
  cursor: pointer;
}
.filter-btn.active {
  background: #0a84ff;
  border-color: #0a84ff;
  font-weight: 600;
}
