:root {
  /* Theme A: Minimal White × Indigo (default / free) */
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --surface2: #F3F4F6;
  --border: #E5E7EB;
  --accent: #4F46E5;
  --accent2: #ff6584;
  --accent-tint: rgba(79, 70, 229, 0.1);
  --text: #111827;
  --text-muted: #9CA3AF;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 12px;
  --radius-sm: 8px;
}

/* Theme B: Cream × Terracotta (premium) */
[data-theme="B"] {
  --bg: #FFFBF7;
  --surface: #FFFFFF;
  --surface2: #FFF7ED;
  --border: #FED7AA;
  --accent: #C2410C;
  --accent2: #FB923C;
  --accent-tint: rgba(194, 65, 12, 0.1);
  --text: #1C1917;
  --text-muted: #A8A29E;
}

/* Theme C: Deep Navy × Teal (premium) */
[data-theme="C"] {
  --bg: #F0F4F8;
  --surface: #FFFFFF;
  --surface2: #E2E8F0;
  --border: #CBD5E1;
  --accent: #0D9488;
  --accent2: #0F172A;
  --accent-tint: rgba(13, 148, 136, 0.1);
  --text: #0F172A;
  --text-muted: #94A3B8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Header */
.app-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.app-header .subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Auth */
.auth-area {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

#user-info {
  display: flex;
  align-items: center;
  gap: 6px;
}

.user-name {
  font-size: 12px;
  color: var(--text-muted);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--surface2);
  color: var(--text-muted);
}

.user-badge.premium {
  background: linear-gradient(135deg, #a78bfa, #ec4899);
  color: #fff;
}

.auth-btn {
  font-size: 12px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s;
}

.auth-btn:hover {
  background: var(--surface2);
}

.auth-btn-out {
  color: var(--text-muted);
  border-color: transparent;
}

.lang-toggle-wrap {
  display: flex;
  background: var(--surface2);
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
  margin-top: 3px;
}

.lang-btn {
  padding: 4px 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  touch-action: manipulation;
  letter-spacing: 0.5px;
}

.lang-btn.active {
  background: var(--accent);
  color: white;
}

/* Status bar */
#status-bar {
  padding: 8px 20px;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

#status-bar.loading { color: var(--accent); }
#status-bar.success { color: var(--success); }
#status-bar.error   { color: var(--accent2); }
#status-bar.warning { color: var(--warning); }

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Main content */
main {
  flex: 1;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 600px;
  width: 100%;
  margin: 0 auto;
}

/* Section */
.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* File input zones */
.file-inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.file-zone {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  position: relative;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  overflow: hidden;
  touch-action: manipulation;
}

.file-zone:active {
  background: var(--surface2);
  border-color: var(--accent);
}

.file-zone.has-file {
  border-style: solid;
  border-color: var(--accent);
}

.file-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  font-size: 0;
}

.file-zone-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--accent);
  margin-bottom: 6px;
  pointer-events: none;
  /* has-file時は写真の上にバッジ表示 */
  z-index: 2;
}

.file-zone.has-file .file-zone-label {
  position: absolute;
  top: 8px;
  left: 8px;
  margin-bottom: 0;
  background: rgba(255,255,255,0.92);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10px;
}

.file-zone-icon {
  font-size: 28px;
  margin-bottom: 6px;
  pointer-events: none;
}

.file-zone-hint {
  font-size: 11px;
  color: var(--text-muted);
  pointer-events: none;
}

.file-zone-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: calc(var(--radius) - 2px);
  display: none;
}

.file-zone.has-file .file-zone-preview { display: block; }
.file-zone.has-file .file-zone-icon,
.file-zone.has-file .file-zone-hint { display: none; }

.file-zone-overlay {
  display: none;
}

.file-zone-name {
  display: none;
}

/* Media type toggle */
.type-toggle {
  display: flex;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}

.type-toggle button {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  transition: all 0.2s;
  touch-action: manipulation;
}

.type-toggle button.active {
  background: var(--accent);
  color: white;
}

/* Aspect ratio toggle */
.ar-toggle {
  display: flex;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}

.ar-btn {
  flex: 1;
  padding: 7px 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  transition: all 0.2s;
  touch-action: manipulation;
  white-space: nowrap;
}

.ar-btn.active {
  background: var(--accent);
  color: white;
}

/* Background color picker */
.bg-color-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.bg-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  flex-shrink: 0;
  touch-action: manipulation;
  position: relative;
}

.bg-swatch:active { transform: scale(0.9); }

.bg-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
  transform: scale(1.1);
}

/* Custom color picker swatch */
.bg-swatch-custom {
  background: conic-gradient(
    #ff0000, #ff8000, #ffff00, #00ff00,
    #00ffff, #0000ff, #ff00ff, #ff0000
  );
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.bg-swatch-custom input[type="color"] {
  opacity: 0;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  border: none;
  padding: 0;
}

/* Compare mode toggle */
.compare-toggle {
  display: flex;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}

.compare-btn {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  transition: all 0.2s;
  touch-action: manipulation;
}

.compare-btn.active {
  background: var(--accent);
  color: white;
}

/* Layout toggle */
.layout-toggle {
  display: flex;
  gap: 8px;
}

.layout-btn {
  flex: 1;
  padding: 10px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  touch-action: manipulation;
}

.layout-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-tint);
}

.layout-icon {
  display: flex;
  gap: 2px;
  align-items: center;
}

.layout-icon span {
  background: currentColor;
  border-radius: 2px;
}

.h-icon span:nth-child(1),
.h-icon span:nth-child(2) {
  width: 10px;
  height: 16px;
}

.v-icon span:nth-child(1),
.v-icon span:nth-child(2) {
  width: 18px;
  height: 7px;
  display: block;
}

.v-icon {
  flex-direction: column;
}

/* Action button */
.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  touch-action: manipulation;
}

.btn-primary:active { transform: scale(0.98); opacity: 0.9; }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-secondary {
  width: 100%;
  padding: 12px;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  touch-action: manipulation;
}

.btn-secondary:active { background: var(--surface2); }
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }

/* Preview area */
#preview-section {
  display: none;
}

#preview-section.visible { display: block; }

#composite-canvas {
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  background: var(--surface);
  display: block;
}

/* Export section */
#export-section {
  display: none;
}

#export-section.visible { display: flex; flex-direction: column; gap: 10px; }

/* Progress bar */
#progress-wrap {
  display: none;
  flex-direction: column;
  gap: 6px;
}

#progress-wrap.visible { display: flex; }

#progress-bar-bg {
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}

#progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0%;
  transition: width 0.1s;
}

#progress-text {
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
}

/* Detected bounding box info */
.bbox-info {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.bbox-badge {
  flex: 1;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 11px;
}

.bbox-badge .badge-label {
  color: var(--text-muted);
  margin-bottom: 2px;
}

.bbox-badge .badge-value {
  font-weight: 600;
  color: var(--success);
}

.bbox-badge .badge-value.fallback {
  color: var(--warning);
}

/* Manual adjustment panel */
#adjust-section {
  display: none;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px;
}

#adjust-section.visible { display: block; }

.adjust-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.btn-reset {
  padding: 4px 12px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text-muted);
  font-size: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  touch-action: manipulation;
}

.btn-reset:active { background: var(--border); }

.adjust-tabs {
  display: flex;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}

.adjust-tab {
  flex: 1;
  padding: 5px 16px;
  font-size: 12px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  transition: all 0.15s;
  touch-action: manipulation;
}

.adjust-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
}

.adjust-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.adjust-label {
  font-size: 11px;
  color: var(--text-muted);
  width: 22px;
  flex-shrink: 0;
}

.adjust-row input[type="range"] {
  flex: 1;
  height: 4px;
  accent-color: var(--accent);
  cursor: pointer;
  min-width: 0;
}

.adjust-value {
  font-size: 10px;
  color: var(--text-muted);
  width: 36px;
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* Theme selector */
.theme-row {
  display: flex;
  gap: 10px;
}

.theme-swatch {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
  touch-action: manipulation;
  flex-direction: column;
  gap: 2px;
}

.theme-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.theme-swatch:active { transform: scale(0.95); }

.theme-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: block;
  flex-shrink: 0;
}

.theme-lock {
  font-size: 10px;
  line-height: 1;
  color: var(--text-muted);
}

.theme-label {
  position: absolute;
  bottom: 3px;
  font-size: 8px;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* ── Accordion settings ─────────────────────────────────────────────────── */

.accordion-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  touch-action: manipulation;
  transition: border-radius 0.2s;
}

.accordion-trigger.open {
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom-color: transparent;
}

.acc-left {
  display: flex;
  align-items: center;
  gap: 7px;
}

.acc-gear { font-size: 15px; }

.acc-chevron {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.accordion-trigger.open .acc-chevron {
  transform: rotate(180deg);
}

.accordion-body {
  display: none;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

.accordion-body.open { display: block; }

/* ── Settings block ─────────────────────────────────────────────────────── */

/* 行1: レイアウト + 比較モード */
.settings-row-cols {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.settings-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.settings-sublabel {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.settings-hint {
  font-size: 10px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
  opacity: 0.7;
}

/* 行2: アスペクト比 */
.settings-row-ar {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 8px;
}

/* 行3: 背景色 + ラベル + フレーム */
.settings-row-inline {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bg-swatches-inline {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.bg-swatches-inline .bg-swatch {
  width: 22px;
  height: 22px;
}

.mini-controls {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

.mini-ctrl-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.mini-ctrl-label {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
  width: 34px;
  flex-shrink: 0;
}

/* Segment control */
.seg-ctrl {
  display: flex;
  background: var(--surface2);
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
  flex: 1;
}

.seg-btn {
  flex: 1;
  padding: 7px 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  touch-action: manipulation;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  white-space: nowrap;
}

.seg-btn.active {
  background: var(--accent);
  color: white;
}

/* XS variant for ラベル/フレーム toggles */
.seg-ctrl-xs {
  flex: 1;
}

.seg-ctrl-xs .seg-btn {
  padding: 3px 4px;
  font-size: 10px;
}

/* テーマ footer area */
.theme-footer-area {
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.theme-footer-area .theme-row {
  justify-content: center;
}

/* FPS selector for video */
.fps-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.fps-row label {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.fps-row select {
  flex: 1;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
