* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background: #0f0f1a;
  color: #fff;
  min-height: 100vh;
  overscroll-behavior-y: none;
}

.lang-switcher {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 50;
  background: #1a1a2e;
  border: 1px solid #2a2a3a;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  color: #ccc;
  font-family: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  line-height: 1.2;
}
.lang-switcher:hover { border-color: #6c5ce7; }
.lang-switcher:focus { border-color: #6c5ce7; }

.page { padding: 16px; max-width: 100%; margin: 0 auto; }

.page-title {
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  margin: 0 0 4px;
  color: #fff;
  letter-spacing: 0.3px;
  line-height: 1.3;
}
.page-subtitle {
  font-size: 12px;
  color: #6c5ce7;
  text-align: center;
  margin: 0 0 14px;
  letter-spacing: 0.3px;
  font-weight: 500;
}

.main {
  width: 100%;
  height: 42vh;
  min-height: 220px;
  border-radius: 16px;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}

.uploader {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 2px dashed #3a3a5a;
  border-radius: 16px;
  background: #15152a;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  padding: 16px;
}
.uploader:hover, .uploader.dragover {
  border-color: #6c5ce7;
  background: rgba(108, 92, 231, 0.08);
}
.uploader-icon { font-size: 42px; color: #6c5ce7; margin-bottom: 10px; line-height: 1; }
.uploader-title { font-size: 15px; color: #ccc; margin-bottom: 4px; font-weight: 500; letter-spacing: 0.2px; }
.uploader-sub { font-size: 12px; color: #666; letter-spacing: 0.1px; }

.uploader-badge {
  margin-top: 14px;
  padding: 6px 12px;
  background: rgba(108, 92, 231, 0.12);
  border: 1px solid rgba(108, 92, 231, 0.3);
  border-radius: 20px;
  font-size: 11px;
  color: #a29bfe;
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.uploader-badge .lock { font-size: 12px; }

.cutout-area {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #ffffff;
  background-image:
    linear-gradient(45deg, #e8e8e8 25%, transparent 25%),
    linear-gradient(-45deg, #e8e8e8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e8e8e8 75%),
    linear-gradient(-45deg, transparent 75%, #e8e8e8 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  position: relative;
}
.cutout-area img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
.cutout-placeholder { color: #999; font-size: 14px; }

.ref-area {
  display: flex;
  justify-content: center;
  gap: 50px;
  align-items: center;
  margin-bottom: 8px;
}
.ref-area.hidden { display: none; }

.ref-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.ref-label { font-size: 11px; color: #888; letter-spacing: 0.2px; }
.ref-img, .ref-color, .ref-checker {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background: #2a2a3a;
  border: 1px solid #333;
  object-fit: cover;
}
.ref-checker {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #ddd 25%, transparent 25%),
    linear-gradient(-45deg, #ddd 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ddd 75%),
    linear-gradient(-45deg, transparent 75%, #ddd 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
}
.ref-thumb-wrap { position: relative; }
.ref-thumb-remove {
  position: absolute;
  top: -6px; right: -6px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #6c5ce7;
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  z-index: 2;
}

.status {
  font-size: 13px;
  color: #888;
  text-align: center;
  min-height: 18px;
  margin-bottom: 4px;
  white-space: pre-line;
  letter-spacing: 0.1px;
}

.progress {
  width: 100%;
  height: 4px;
  background: #222;
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
  opacity: 1;
  transition: opacity 0.4s ease;
}
.progress.hidden { opacity: 0; pointer-events: none; }
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6c5ce7, #a29bfe);
  transition: width 0.25s ease-out;
}

.actions { display: flex; gap: 10px; margin-bottom: 8px; }
.actions:last-of-type { margin-bottom: 0; }
.btn {
  flex: 1;
  padding: 13px 12px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.2px;
  cursor: pointer;
  transition: opacity 0.2s;
  -webkit-appearance: none;
}
.btn:disabled { background: #2a2a3a; color: #555; cursor: not-allowed; }
.btn-primary { background: #6c5ce7; color: #fff; }
.btn-secondary { background: #2a2a3a; color: #ddd; }
.btn:not(:disabled):active { opacity: 0.7; }

.bg-picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 99;
}
.bg-picker-overlay.show { opacity: 1; pointer-events: auto; }

.bg-picker {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1a1a2e;
  border-radius: 16px 16px 0 0;
  border-top: 1px solid #2a2a3a;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 100;
  box-shadow: 0 -8px 24px rgba(0,0,0,0.4);
}
.bg-picker.show { transform: translateY(0); }

.bg-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.bg-picker-title {
  font-size: 14px;
  font-weight: 600;
  color: #ccc;
  letter-spacing: 0.2px;
}
.bg-picker-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #2a2a3a;
  color: #aaa;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-appearance: none;
}
.bg-picker-close:active { opacity: 0.7; }

.bg-list {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  -webkit-overflow-scrolling: touch;
}
.bg-list::-webkit-scrollbar { display: none; }

.bg-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  position: relative;
}
.bg-swatch {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid #333;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #6c5ce7;
  background: #1a1a2e;
  overflow: hidden;
  position: relative;
}
.bg-item.active .bg-swatch { border-color: #6c5ce7; border-width: 3px; }
.bg-swatch.transparent {
  background: repeating-conic-gradient(#2a2a3a 0% 25%, #1f1f2e 0% 50%) 50% / 10px 10px;
}
.bg-swatch img { width: 100%; height: 100%; object-fit: cover; }
.bg-name { font-size: 11px; color: #888; letter-spacing: 0.2px; }
.bg-item.active .bg-name { color: #6c5ce7; }

.bg-remove {
  position: absolute;
  top: -4px;
  right: 4px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #6c5ce7;
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  z-index: 2;
}

.content {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #222;
  font-size: 14px;
  line-height: 1.7;
  color: #aaa;
}
.content h2 { font-size: 17px; color: #fff; margin: 18px 0 8px; font-weight: 600; letter-spacing: 0.2px; }
.content h3 { font-size: 15px; color: #ddd; margin: 16px 0 6px; font-weight: 600; letter-spacing: 0.2px; }
.content p { margin: 0 0 12px; }
.content ul { padding-left: 20px; margin: 0 0 12px; }
.content strong { color: #ddd; }

.ad-slot { width: 100%; margin-top: 20px; text-align: center; min-height: 50px; }

.debug-log {
  margin-top: 16px;
  padding: 10px;
  background: #1a1a2e;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 10px;
  color: #8f8;
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
  display: none;
}
.debug-log.show { display: block; }

@media (min-width: 768px) {
  .page { max-width: 720px; margin: 0 auto; padding: 24px; }
  .page-title { font-size: 26px; margin-bottom: 6px; }
  .page-subtitle { font-size: 13px; margin-bottom: 16px; }
  .main { height: 440px; min-height: 440px; margin-bottom: 12px; }
  .ref-area { gap: 100px; margin-bottom: 12px; }
  .ref-img, .ref-color, .ref-checker { width: 72px; height: 72px; }
  .bg-picker {
    left: 50%; right: auto;
    width: 720px;
    max-width: calc(100vw - 32px);
    transform: translate(-50%, 100%);
    border-radius: 16px 16px 0 0;
  }
  .bg-picker.show { transform: translate(-50%, 0); }
}