:root {
  color-scheme: dark;
  --bg: #0b0b0c;
  --surface: #151517;
  --line: #26262b;
  --text: #f5f5f6;
  --muted: #8b8b92;
  --accent: #ffd23a;
  --radius: 18px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: "Pretendard Variable", Pretendard, -apple-system,
    "Apple SD Gothic Neo", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

.app-shell {
  width: 100%;
  max-width: 440px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 56px 22px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 26px;
}

.brand {
  display: flex;
  align-items: center;
}

.brand-handle,
.result-insta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
}

.brand-handle {
  font-size: 16px;
}

.brand-handle:hover,
.result-insta:hover {
  color: var(--accent);
}

.ig-icon {
  flex-shrink: 0;
}

.hero-copy h1 {
  margin-top: 16px;
  margin-bottom: 16px;
  font-size: 44px;
  font-weight: 950;
  line-height: 1.14;
  letter-spacing: -0.03em;
}

.hero-copy p {
  color: var(--muted);
  font-size: 17px;
  line-height: 1.62;
}

.upload-panel {
  margin-top: 22px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.upload-card {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #101012;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.upload-card.ready {
  border-color: rgba(255, 210, 58, 0.56);
}

.preview-shell {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 14px;
  background: #0a0a0b;
  display: grid;
  place-items: center;
}

.preview-shell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.upload-card.ready .preview-shell img {
  display: block;
}

.preview-empty {
  color: rgba(255, 255, 255, 0.28);
  font-size: 46px;
  font-weight: 950;
}

.upload-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.upload-meta strong {
  font-size: 14px;
}

.upload-meta span {
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mini-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.mini-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  padding: 9px 8px;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.mini-button:active,
.primary-button:active {
  transform: scale(0.985);
}

.mini-button:hover {
  border-color: #3a3a42;
}

.primary-button {
  width: 100%;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #111;
  padding: 15px 18px;
  font: inherit;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.primary-button:hover {
  opacity: 0.92;
}

.primary-button:disabled {
  opacity: 0.36;
  cursor: not-allowed;
}

.hint,
.share-fallback {
  color: var(--muted);
  font-size: 11.5px;
  text-align: center;
}

.workspace,
.scan-view,
.result-view {
  display: flex;
  flex-direction: column;
}

.scan-view,
.result-view {
  align-items: center;
  gap: 16px;
}

.scan-card {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #101012;
}

.scan-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: saturate(0.95) contrast(1.05);
}

.scan-grid {
  position: absolute;
  inset: 0;
  background-image: linear-gradient(rgba(255, 210, 58, 0.13) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 210, 58, 0.13) 1px, transparent 1px);
  background-size: 34px 34px;
  opacity: 0.38;
}

.scan-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--accent);
  box-shadow: 0 0 22px rgba(255, 210, 58, 0.92),
    0 0 80px rgba(255, 210, 58, 0.34);
  animation: scan 1.55s ease-in-out infinite;
}

.scan-corners::before,
.scan-corners::after {
  content: "";
  position: absolute;
  width: 34px;
  height: 34px;
  border-color: var(--accent);
  border-style: solid;
}

.scan-corners::before {
  left: 18px;
  top: 18px;
  border-width: 3px 0 0 3px;
}

.scan-corners::after {
  right: 18px;
  bottom: 18px;
  border-width: 0 3px 3px 0;
}

@keyframes scan {
  0% { top: 0; opacity: 0; }
  10% { opacity: 1; }
  90% { opacity: 1; }
  100% { top: 100%; opacity: 0; }
}

.scan-title {
  margin-top: 4px;
  font-size: 18px;
  font-weight: 900;
}

.scan-copy {
  margin-top: -10px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

#resultCanvas {
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  display: block;
}

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

.ai-button {
  box-shadow: 0 0 28px rgba(255, 210, 58, 0.16);
}

.result-insta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 20px;
}

.debug-stats {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.debug-stats div {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.debug-stats dt {
  color: var(--muted);
  font-size: 11px;
}

.debug-stats dd {
  margin-top: 2px;
  font-size: 13px;
  font-weight: 800;
}

.file-input,
.scratch-canvas {
  position: fixed;
  left: -9999px;
  top: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.hidden {
  display: none !important;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  padding: 22px;
  background: rgba(0, 0, 0, 0.72);
  display: grid;
  place-items: center;
  backdrop-filter: blur(10px);
}

.modal-card {
  position: relative;
  width: min(100%, 520px);
  max-height: calc(100vh - 44px);
  overflow: auto;
  padding: 30px 24px 24px;
  border: 1px solid rgba(255, 210, 58, 0.28);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(25, 25, 27, 0.96), rgba(13, 13, 14, 0.98));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.5);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
}

.modal-kicker {
  margin-bottom: 10px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.modal-card h2 {
  margin-bottom: 12px;
  font-size: 28px;
  line-height: 1.22;
  font-weight: 950;
  letter-spacing: -0.02em;
}

.modal-card p {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.7;
}

.modal-spinner {
  width: 48px;
  height: 48px;
  margin: 22px auto 4px;
  border: 4px solid rgba(255, 255, 255, 0.14);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.9s linear infinite;
  box-shadow: 0 0 28px rgba(255, 210, 58, 0.22);
}

.modal-result-image {
  display: block;
  width: 100%;
  max-height: min(58vh, 620px);
  margin-top: 20px;
  border: 1px solid rgba(255, 210, 58, 0.22);
  border-radius: 22px;
  object-fit: contain;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.42);
}

.modal-error {
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid rgba(248, 113, 113, 0.28);
  border-radius: 16px;
  background: rgba(248, 113, 113, 0.1);
  color: #fecaca !important;
  font-weight: 700;
}

.modal-link {
  display: block;
  margin-top: 20px;
  padding: 14px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: #111;
  text-align: center;
  text-decoration: none;
  font-size: 14px;
  font-weight: 900;
}

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

@media (max-width: 380px) {
  .app-shell {
    padding-left: 18px;
    padding-right: 18px;
  }

  .hero-copy h1 {
    font-size: 39px;
  }
}

/* AI 합성 결과 이미지 — 화면 벗어남 방지 */
.modal-result-image {
  display: block;
  width: 100%;
  max-width: 320px;
  height: auto;
  margin: 16px auto 0;
  border-radius: 16px;
  border: 1px solid var(--line);
}
.modal-backdrop .modal,
.modal-card,
.modal {
  max-height: 88vh;
  overflow-y: auto;
}
