* { box-sizing: border-box; }
[hidden] { display: none !important; }

:root, :root[data-theme="light"] {
  --bg: #ffffff;
  --panel: #f5f5f5;
  --panel-hover: #ebebeb;
  --line: #e0e0e0;
  --text: #1a1a1a;
  --muted: #666666;
  --accent: #5b9e3f;
  --ink: #111111;
  --ad: #f0f0f0;
  --ad-text: #999999;
  --card: #f9f9f9;
  --checker-a: #e8e8e8;
  --checker-b: #f5f5f5;
  --shadow: rgba(0,0,0,0.10);
  font-family: "Avenir Next", "Segoe UI", "Pretendard", sans-serif;
}

:root[data-theme="dark"] {
  --bg: #1e1e22;
  --panel: #28282e;
  --panel-hover: #323238;
  --line: #3c3c44;
  --text: #f0f0f0;
  --muted: #aaaaaa;
  --accent: #7ec85a;
  --ink: #f0f0f0;
  --ad: #222228;
  --ad-text: #888888;
  --card: #222228;
  --checker-a: #2e2e34;
  --checker-b: #28282e;
  --shadow: rgba(0,0,0,0.40);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #1e1e22;
    --panel: #28282e;
    --panel-hover: #323238;
    --line: #3c3c44;
    --text: #f0f0f0;
    --muted: #aaaaaa;
    --accent: #7ec85a;
    --ink: #f0f0f0;
    --ad: #222228;
    --ad-text: #888888;
    --card: #222228;
    --checker-a: #2e2e34;
    --checker-b: #28282e;
    --shadow: rgba(0,0,0,0.40);
  }
}

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

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

.app-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
  padding: 0 32px;
  border-bottom: none;
  background: var(--bg);
  position: static;
  top: 0;
  z-index: 10;
}

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

.brand-wordmark {
  display: flex;
  align-items: baseline;
  gap: 0.28em;
  color: var(--ink);
  font-family: "Avenir Next Condensed", "Avenir Next", "Segoe UI", "Pretendard", sans-serif;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -0.055em;
  line-height: 1;
  white-space: nowrap;
}

.brand-wordmark-main {
  font-style: italic;
  transform: rotate(-4deg);
  display: inline-block;
}

.brand-wordmark-rest {
  font-style: italic;
  font-weight: 700;
  letter-spacing: -0.04em;
  opacity: 0.92;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 18px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
.nav-links a:hover { color: var(--ink); }

.prefs { display: flex; gap: 8px; }

.pref-btn {
  min-width: 42px;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.pref-btn:hover { color: var(--ink); }

.page {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) 160px;
  align-items: start;
  min-height: calc(100vh - 64px);
}

.page-center { min-width: 0; }

.hero {
  max-width: 760px;
  padding: 56px 28px 28px;
  margin: 0 auto;
  text-align: center;
}

.eyebrow {
  margin: 0 0 14px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.hero h1 {
  margin: 0;
  font-size: 46px;
  line-height: 1.08;
  letter-spacing: -0.04em;
  font-weight: 800;
}

.lede {
  max-width: 560px;
  margin: 16px auto 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.5;
}

.hero-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 22px;
}

.btn-primary, #convert-photo, #make-sheet {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0 16px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #f4d35e;
  color: #1d1912;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  height: 42px;
  padding: 0 16px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
  font-weight: 700;
}

.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--line);
  background: var(--ad);
  color: var(--ad-text);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ad-banner { height: 90px; margin: 0 20px 24px; border-radius: 10px; }
.ad-sky { position: sticky; top: 110px; min-height: 600px; margin: 56px 12px 80px; border-radius: 8px; }
.ad-rail { margin: 8px; height: 180px; border-radius: 8px; }

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 18px;
  margin: 0 0 80px;
  padding: 0 20px;
}

.frame-rail, .stage {
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 4px 4px 0 var(--shadow);
}

.rail-head, .stage-copy { padding: 18px 18px 8px; }
.rail-head h2, .stage-copy h2 { margin: 0; font-size: 18px; font-weight: 800; }
.rail-head p, .stage-copy p { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }

.stage-head {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 18px 8px;
}
.stage-head .stage-copy { padding: 0; min-width: 0; }

.add-frame-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: calc(100% - 16px);
  margin: 0 8px 8px;
  min-height: 96px;
  padding: 16px 12px;
  border: 2px dashed var(--ink);
  border-radius: 10px;
  background: var(--card);
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}
.add-frame-plus { font-size: 28px; line-height: 1; }
.add-frame-label {
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
  color: var(--muted);
}
.add-frame-btn:hover, .add-frame-btn[aria-expanded="true"] { background: var(--panel); }

.custom-frame-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0 8px 12px;
  padding: 12px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--card);
}
.custom-hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.custom-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 700; }
.custom-field input { border: 2px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--panel); }
.custom-size { display: flex; align-items: center; gap: 6px; }
.custom-size input { width: 100%; }
.dropzone.compact { min-height: 64px; padding: 10px; margin: 0; }
#custom-create { border: 2px solid var(--ink); border-radius: 8px; padding: 8px; background: var(--accent); color: #fff; font-weight: 800; cursor: pointer; }
.kicker { margin: 0 0 8px !important; font-size: 11px !important; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent) !important; }

.frame-list { display: flex; flex-direction: column; padding: 8px 8px 16px; gap: 10px; max-height: calc(100vh - 240px); overflow: auto; }
.frame-group { margin: 8px 4px 0; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.frame-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

.frame-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  padding: 10px 6px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: var(--card);
  cursor: pointer;
}

.frame-card img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  image-rendering: pixelated;
  background: repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%) 0 0 / 12px 12px;
}

.frame-card strong { font-size: 12px; font-weight: 800; }
.frame-card:hover, .frame-card.selected { background: var(--panel); border-color: var(--ink); }

.frame-example-pair {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  margin: 0;
  width: 100%;
}
.frame-example-pair .frame-example-images {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.frame-example-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  margin: 0;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}

.frame-example-panel figcaption {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.frame-example {
  display: block;
  width: 256px;
  height: 256px;
  object-fit: contain;
  border-radius: 4px;
  background: var(--panel);
}

.frame-example.pixel { image-rendering: pixelated; }

/* 입력 사진 미리보기 크기 제한 */
#product-source {
  max-width: 100%;
  max-height: 320px;
  width: auto;
  height: auto;
  display: block;
  object-fit: contain;
  border-radius: 8px;
}

.dropzone {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 8px 18px;
  padding: 28px 20px;
  border: 2px dashed var(--ink);
  border-radius: 12px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
}

.dropzone strong { color: var(--text); font-size: 15px; font-weight: 800; }
.dropzone:hover, .dropzone.dragging { background: var(--panel-hover); }

.preview-img, .result-preview img {
  display: block;
  max-width: 100%;
  margin: 0 18px 12px;
  border-radius: 8px;
  image-rendering: pixelated;
  background: repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%) 0 0 / 16px 16px;
}

.actions { display: flex; align-items: center; gap: 10px; padding: 0 18px 20px; flex-wrap: wrap; }
#convert-photo:disabled { opacity: 0.5; cursor: wait; }
#edit-original {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0 16px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
}
#edit-original:hover { background: var(--panel-hover); }
#edit-original:disabled { opacity: 0.5; cursor: not-allowed; }
#product-status { margin: 0; color: var(--muted); font-size: 13px; }

.result { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 16px; padding: 0 18px 24px; align-items: start; }
.result-preview { min-width: 0; }
.result-meta p { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.result-links { display: flex; gap: 16px; font-size: 13px; font-weight: 700; }
.sheet-result { margin-top: 14px; }
.sheet-result img { max-width: 100%; image-rendering: pixelated; }
#make-sheet { margin-top: 12px; height: 36px; }
.hint { color: var(--muted); font-size: 12px; }
.pixel-canvas {
  display: block;
  width: 100%;
  height: auto;
  max-width: 100%;
  margin: 0 0 12px;
  border-radius: 8px;
  image-rendering: pixelated;
  cursor: crosshair;
  touch-action: none;
  user-select: none;
  background: repeating-conic-gradient(var(--checker-a) 0 25%, var(--checker-b) 0 50%) 0 0 / 16px 16px;
}
.pixel-canvas-wrap {
  position: relative;
  margin: 0 0 12px;
}
.pixel-canvas-wrap .pixel-canvas {
  margin: 0;
}
.lasso-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  border-radius: 8px;
}
.pixel-editor { margin: 0 0 14px; }
.pixel-editor h3 { margin: 0 0 6px; font-size: 14px; font-weight: 800; }
.pixel-tools { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.pixel-tools button {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--card);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.pixel-tools button.active, .pixel-tools button:hover { border-color: var(--ink); background: var(--panel); }
.pixel-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
  max-height: 220px;
  overflow: auto;
}
.palette-swatch {
  width: 22px;
  height: 22px;
  border: 2px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}
.palette-swatch.selected { border-color: var(--ink); }
.pixel-add-color {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.pixel-add-color input { width: 32px; height: 24px; padding: 0; border: 0; background: transparent; cursor: pointer; }

@media (max-width: 1100px) {
  .page { grid-template-columns: 1fr; }
  .ad-sky { display: none; }
}


/* ── Footer (Kenney.nl style) ── */
.site-footer {
  padding: 48px 24px;
  text-align: center;
  font-size: 12.8px;
  color: #9090a1;
}
.site-footer-copy {
  margin-bottom: 12px;
}
.site-footer-links {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0;
}
.site-footer-links a {
  color: #9090a1;
  text-decoration: none;
  margin-right: 7px;
}
.site-footer-links a:last-child { margin-right: 0; }
.site-footer-links a:hover { color: var(--ink); }

@media (max-width: 860px) {
  .hero h1 { font-size: 32px; }
  .workspace, .result { grid-template-columns: 1fr; }
  .stage-head { flex-wrap: wrap; }
  .frame-example-pair { justify-content: flex-start; }
  .frame-example { width: 128px; height: 128px; }
  .ad-banner { margin-left: 16px; margin-right: 16px; }
}

@media (max-width: 640px) {
  /* 네비 */
  .app-nav { flex-wrap: wrap; gap: 8px; padding: 10px 14px; }
  .nav-links .prefs { gap: 6px; flex-wrap: wrap; }
  .google-signin-btn span { display: none; } /* 아이콘만 */
  .google-signin-btn { padding: 0 8px; gap: 0; }
  .pref-btn { font-size: 11px; padding: 0 8px; height: 30px; }

  /* 광고 숨김 */
  .ad-banner { display: none; }
  .ad-rail { display: none; }

  /* 히어로 */
  .hero { padding: 32px 16px 20px; }
  .hero h1 { font-size: 26px; }

  /* 레일 */
  .rail-head, .stage-copy { padding: 14px 14px 6px; }
  .frame-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .frame-card { padding: 6px 4px; }
  .frame-card strong { font-size: 10px; }

  /* 예시 이미지 */
  .frame-example { width: 96px; height: 96px; }

  /* 드롭존 */
  .dropzone { padding: 20px 16px; margin: 8px 14px; }

  /* 액션 버튼 */
  .actions { padding: 0 14px 16px; gap: 8px; }
  #convert-photo, #edit-original { height: 38px; font-size: 13px; padding: 0 12px; }

  /* 결과 */
  .result { padding: 0 14px 16px; }
  .result-panel { padding: 10px 12px; }

  /* 픽셀 에디터 */
  .pixel-tools { gap: 4px; }
  .pixel-tools button { height: 28px; padding: 0 8px; font-size: 11px; }

  /* 푸터 */
  .site-footer { padding: 32px 16px; }
}

/* ── Auth / Credits ── */
.user-area { display: flex; align-items: center; gap: 6px; }

/* 크레딧 칩 */
.credit-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px 3px 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.15s;
}
.credit-chip:hover { border-color: var(--accent); }

/* 아이콘 버튼 (Sign out) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.icon-btn:hover { border-color: var(--line); color: var(--text); }

.google-signin-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 10px;
  height: 36px;
  background: #fff;
  color: #3c4043;
  border: 1px solid #dadce0;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  font-family: "Google Sans", Roboto, sans-serif;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s, box-shadow 0.1s;
}
.google-signin-btn:hover { background: #f8faff; box-shadow: 0 1px 3px rgba(60,64,67,.2); border-color: #c6c6c6; }
[data-theme="dark"] .google-signin-btn { background: #131314; color: #e3e3e3; border-color: #8e918f; }
[data-theme="dark"] .google-signin-btn:hover { background: #1e1e1e; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .google-signin-btn { background: #131314; color: #e3e3e3; border-color: #8e918f; }
  :root:not([data-theme]) .google-signin-btn:hover { background: #1e1e1e; }
}
.user-credits {
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}
.login-btn {
  background: #4285f4;
  color: #fff !important;
  border-color: #4285f4;
}
.login-btn:hover { background: #3367d6; border-color: #3367d6; }
