/* ============================================================
   CSS VARIABLES — macOS Bright Theme
   ============================================================ */
:root {
  --bg-primary: #f5f5f7;
  --bg-secondary: #ffffff;
  --bg-tertiary: #fafafa;
  --bg-glass: rgba(255,255,255,0.72);
  --bg-glass-hover: rgba(255,255,255,0.88);
  --border-light: rgba(0,0,0,0.06);
  --border-medium: rgba(0,0,0,0.1);
  --border-focus: rgba(0,122,255,0.5);
  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;
  --accent: #007aff;
  --accent-hover: #0063d1;
  --accent-light: rgba(0,122,255,0.08);
  --green: #34c759;
  --green-hover: #2aad4a;
  --orange: #ff9500;
  --red: #ff3b30;
  --red-bg: rgba(255,59,48,0.08);
  --yellow: #ffcc00;
  --purple: #af52de;
  --pink: #ff2d55;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.12), 0 4px 12px rgba(0,0,0,0.06);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.15), 0 8px 20px rgba(0,0,0,0.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition: 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
  --font: 'Inter', 'Noto Sans TC', 'Noto Sans SC', 'Noto Sans JP', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Helvetica Neue', sans-serif;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}
img { display: block; max-width: 100%; }
button, select, input { font-family: inherit; }
::selection { background: var(--accent); color: #fff; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============================================================
   LAYOUT SHELL
   ============================================================ */
.app-shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
}

/* ============================================================
   HEADER — macOS toolbar
   ============================================================ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  margin-bottom: 24px;
  position: sticky;
  top: 12px;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}
.app-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.app-logo-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  object-fit: cover;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  animation: logo-float 3s ease-in-out infinite;
}
@keyframes logo-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}
.app-logo h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.app-logo h1 span { color: var(--text-tertiary); font-weight: 500; font-size: 12px; margin-left: 6px; }

/* Language Switcher */
.lang-switcher {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(0,0,0,0.04);
  border-radius: 980px;
  padding: 3px;
}
.lang-btn {
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  border: none;
  border-radius: 980px;
  background: transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.lang-btn:hover { color: var(--text-primary); }
.lang-btn.active {
  background: var(--bg-secondary);
  color: var(--accent);
  box-shadow: var(--shadow-sm);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 980px;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1.3;
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: 0 2px 12px rgba(0,122,255,0.3); }
.btn-secondary { background: rgba(0,0,0,0.05); color: var(--text-primary); }
.btn-secondary:hover { background: rgba(0,0,0,0.09); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { background: var(--green-hover); box-shadow: 0 2px 12px rgba(52,199,89,0.3); }
.btn-yellow { background: var(--yellow); color: #1d1d1f; }
.btn-yellow:hover { box-shadow: 0 2px 12px rgba(255,204,0,0.4); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* ============================================================
   HERO SECTION
   ============================================================ */
.hero-section {
  text-align: center;
  padding: 40px 20px 48px;
  margin-bottom: 24px;
  background: linear-gradient(180deg, rgba(0,122,255,0.04) 0%, transparent 100%);
  border-radius: var(--radius-xl);
  position: relative;
  overflow: hidden;
}
.hero-section::before {
  content: '';
  position: absolute;
  top: -60%;
  left: 50%;
  transform: translateX(-50%);
  width: 600px;
  height: 600px;
  background: radial-gradient(circle, rgba(0,122,255,0.06) 0%, transparent 70%);
  pointer-events: none;
}
.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: linear-gradient(135deg, rgba(255,45,85,0.1), rgba(175,82,222,0.1));
  border: 1px solid rgba(255,45,85,0.15);
  border-radius: 980px;
  font-size: 12px;
  font-weight: 600;
  color: var(--pink);
  margin-bottom: 16px;
  animation: badge-glow 3s ease-in-out infinite;
}
@keyframes badge-glow {
  0%, 100% { box-shadow: 0 0 0 rgba(255,45,85,0); }
  50% { box-shadow: 0 0 20px rgba(255,45,85,0.1); }
}
.hero-title {
  font-size: 36px;
  font-weight: 900;
  letter-spacing: -1px;
  line-height: 1.2;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #1d1d1f 0%, #6e6e73 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero-subtitle {
  font-size: 16px;
  color: var(--text-secondary);
  max-width: 520px;
  margin: 0 auto 24px;
  line-height: 1.6;
}
.hero-features {
  display: flex;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
}
.hero-feature {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}
.hero-feature .hf-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.hero-feature .hf-icon.blue { background: rgba(0,122,255,0.1); }
.hero-feature .hf-icon.orange { background: rgba(255,149,0,0.1); }
.hero-feature .hf-icon.green { background: rgba(52,199,89,0.1); }
.hero-feature .hf-icon.purple { background: rgba(175,82,222,0.1); }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow var(--transition);
}
.card-body { padding: 24px; }
.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}
.card-title .icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}
.card-title .icon.blue { background: rgba(0,122,255,0.1); color: var(--accent); }
.card-title .icon.orange { background: rgba(255,149,0,0.1); color: var(--orange); }
.card-title .icon.green { background: rgba(52,199,89,0.1); color: var(--green); }
.card-title .icon.purple { background: rgba(175,82,222,0.1); color: var(--purple); }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.form-group { margin-bottom: 16px; }
.form-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.form-label svg { width: 15px; height: 15px; opacity: 0.6; }
.form-select {
  width: 100%;
  padding: 10px 36px 10px 14px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2386868b' d='M6 8.825L1.175 4 2.238 2.938 6 6.7l3.763-3.762L10.825 4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: pointer;
  transition: all var(--transition);
  outline: none;
}
.form-select:hover { border-color: rgba(0,0,0,0.18); }
.form-select:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(0,122,255,0.15); }

/* Resolution badge */
.resolution-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: linear-gradient(135deg, rgba(0,122,255,0.06), rgba(88,86,214,0.06));
  border: 1px solid rgba(0,122,255,0.12);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}
.resolution-badge::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse-dot 2s infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ============================================================
   UPLOAD ZONE
   ============================================================ */
.upload-zone {
  position: relative;
  aspect-ratio: 1/1;
  border: 2px dashed var(--border-medium);
  border-radius: var(--radius-lg);
  background: var(--bg-tertiary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  overflow: hidden;
  margin-bottom: 20px;
}
.upload-zone:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.upload-zone.has-image {
  border-style: solid;
  border-color: var(--border-light);
}
.upload-zone img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.upload-placeholder {
  text-align: center;
  color: var(--text-tertiary);
}
.upload-placeholder svg { margin: 0 auto 12px; opacity: 0.4; }
.upload-placeholder .main-text { font-size: 14px; font-weight: 600; color: var(--text-secondary); }
.upload-placeholder .sub-text { font-size: 12px; margin-top: 4px; }

/* ============================================================
   GENERATE BUTTON
   ============================================================ */
.btn-generate {
  width: 100%;
  padding: 14px 24px;
  font-size: 15px;
  font-weight: 700;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #007aff, #5856d6);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(0,122,255,0.25);
  margin-top: 20px;
  position: relative;
  overflow: hidden;
}
.btn-generate:hover:not(:disabled) {
  box-shadow: 0 6px 24px rgba(0,122,255,0.35);
  transform: translateY(-1px);
}
.btn-generate:active:not(:disabled) { transform: translateY(0); }
.btn-generate:disabled {
  background: rgba(0,0,0,0.08);
  color: var(--text-tertiary);
  box-shadow: none;
  cursor: not-allowed;
}
.btn-generate.loading {
  background: linear-gradient(135deg, #007aff, #5856d6);
  pointer-events: none;
}

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ============================================================
   ERROR MESSAGE
   ============================================================ */
.error-msg {
  margin-top: 12px;
  padding: 12px 14px;
  background: var(--red-bg);
  border: 1px solid rgba(255,59,48,0.15);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--red);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.4;
}
.error-msg svg { flex-shrink: 0; margin-top: 1px; }

/* ============================================================
   MAIN LAYOUT — 2-column
   ============================================================ */
.main-grid {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  align-items: start;
}

/* ============================================================
   RESULTS PANEL
   ============================================================ */
.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.results-header h2 {
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.results-count {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-tertiary);
  background: rgba(0,0,0,0.04);
  padding: 2px 10px;
  border-radius: 980px;
}
.results-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  border: 2px dashed var(--border-light);
  border-radius: var(--radius-lg);
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  text-align: center;
  padding: 40px;
}
.empty-state .emoji { font-size: 48px; margin-bottom: 16px; opacity: 0.5; }
.empty-state .title { font-size: 15px; font-weight: 600; color: var(--text-secondary); }
.empty-state .subtitle { font-size: 13px; margin-top: 4px; }
.empty-state.is-loading .emoji { animation: pulse-emoji 1.5s ease-in-out infinite; }
@keyframes pulse-emoji {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* ============================================================
   STICKER GRID
   ============================================================ */
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.sticker-cell {
  position: relative;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
  background: #fff;
  background-image:
    linear-gradient(45deg, #f0f0f0 25%, transparent 25%),
    linear-gradient(-45deg, #f0f0f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f0f0f0 75%),
    linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  overflow: hidden;
  transition: all var(--transition);
  animation: sticker-in 0.4s ease-out both;
}
.sticker-cell:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-3px);
  border-color: var(--accent);
}
@keyframes sticker-in {
  from { opacity: 0; transform: scale(0.9) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.sticker-cell .sticker-img-wrap {
  aspect-ratio: 344/256;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}
.sticker-cell .sticker-img-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 1px 3px rgba(0,0,0,0.1));
}
.sticker-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: var(--bg-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 2px 8px;
  border-radius: 980px;
  border: 1px solid var(--border-light);
}
.sticker-dl {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 30px;
  height: 30px;
  background: var(--bg-glass);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--border-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all var(--transition);
  color: var(--accent);
  text-decoration: none;
}
.sticker-cell:hover .sticker-dl { opacity: 1; }
.sticker-dl:hover { background: var(--accent); color: #fff; }
.sticker-dl svg { width: 14px; height: 14px; }

/* ============================================================
   SEO / FEATURES SECTION
   ============================================================ */
.seo-section {
  margin-top: 40px;
  padding: 48px 24px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}
.seo-section-title {
  text-align: center;
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}
.seo-section-subtitle {
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 36px;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}
.features-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}
.feature-card {
  padding: 24px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  transition: all var(--transition);
  text-align: center;
}
.feature-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}
.feature-card .fc-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  margin: 0 auto 14px;
}
.feature-card h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 6px;
}
.feature-card p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* How-to Section */
.howto-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  counter-reset: step;
}
.howto-step {
  position: relative;
  padding: 24px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-light);
  text-align: center;
}
.howto-step::before {
  counter-increment: step;
  content: counter(step);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #007aff, #5856d6);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  border-radius: 50%;
  margin: 0 auto 14px;
}
.howto-step h3 { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.howto-step p { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }

/* FOOTER */
.app-footer {
  text-align: center;
  padding: 32px 20px;
  margin-top: 40px;
  color: var(--text-tertiary);
  font-size: 12px;
}
.app-footer a { color: var(--text-secondary); }

/* ============================================================
   HIDDEN UTILITY
   ============================================================ */
.hidden { display: none !important; }
canvas.processing-canvas { display: none; }

/* ============================================================
   RESPONSIVE — Tablet
   ============================================================ */
@media (max-width: 960px) {
  .main-grid { grid-template-columns: 1fr; }
  .sticker-grid { grid-template-columns: repeat(3, 1fr); }
  .features-grid { grid-template-columns: repeat(2, 1fr); }
  .howto-steps { grid-template-columns: repeat(2, 1fr); }
  .app-header { position: relative; top: 0; }
  .hero-title { font-size: 28px; }
}

/* ============================================================
   RESPONSIVE — Phone
   ============================================================ */
@media (max-width: 640px) {
  .app-shell { padding: 12px; }
  .app-header {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius-lg);
  }
  .lang-switcher { order: 3; width: 100%; justify-content: center; }
  .card-body { padding: 16px; }
  .sticker-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .results-header { flex-direction: column; align-items: flex-start; }
  .results-actions { width: 100%; }
  .results-actions .btn { flex: 1; justify-content: center; font-size: 12px; padding: 8px 12px; }
  .btn-generate { font-size: 14px; padding: 12px 20px; }
  .hero-section { padding: 28px 16px 32px; }
  .hero-title { font-size: 24px; }
  .hero-subtitle { font-size: 14px; }
  .hero-features { gap: 12px; }
  .features-grid { grid-template-columns: 1fr; }
  .howto-steps { grid-template-columns: 1fr; }
  .seo-section { padding: 32px 16px; }
  .seo-section-title { font-size: 20px; }
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }
