:root {
  --brand: #1447e6;
  --brand-dark: #0a2472;
  --brand-soft: #e8edfc;
  --accent: #ffd400;
  --accent-deep: #c98a00;
  --sale: #ef1f5f;
  --sale-dark: #b8154a;
  --ink: #0b1220;
  --bg: #eef1f8;
  --card-bg: #ffffff;
  --muted: #667085;
  --border: #e1e6f0;
  --shadow: rgba(20, 30, 70, 0.1);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --brand: #6688ff;
  --brand-dark: #0d1b3d;
  --brand-soft: #16224a;
  --accent: #ffd400;
  --accent-deep: #ffe066;
  --sale: #ff4d7d;
  --sale-dark: #d81a54;
  --ink: #edf0f9;
  --bg: #080c18;
  --card-bg: #121a30;
  --muted: #8a97b8;
  --border: #232d4d;
  --shadow: rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #6688ff;
    --brand-dark: #0d1b3d;
    --brand-soft: #16224a;
    --accent: #ffd400;
    --accent-deep: #ffe066;
    --sale: #ff4d7d;
    --sale-dark: #d81a54;
    --ink: #edf0f9;
    --bg: #080c18;
    --card-bg: #121a30;
    --muted: #8a97b8;
    --border: #232d4d;
    --shadow: rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

::selection {
  background: var(--accent);
  color: var(--brand-dark);
}

body {
  margin: 0;
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--ink);
  transition: background 0.2s ease, color 0.2s ease;
}

a { color: inherit; }

button, input, select {
  font-family: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

header {
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
  color: white;
  padding: 22px 20px 26px;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1100px;
  margin: 0 auto;
}

header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}

header h1 .wordmark-en {
  font-weight: 500;
  opacity: 0.75;
  font-size: 14px;
}

header h1 .logo {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  vertical-align: middle;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

header p {
  margin: 10px 0 0;
  max-width: 1100px;
  margin-left: auto;
  margin-right: auto;
  opacity: 0.85;
  font-size: 13px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.install-btn {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: white;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.install-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.theme-toggle {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: white;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.22);
  transform: translateY(-1px);
}

nav.tabs {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  position: sticky;
  top: 0;
  z-index: 10;
}

nav.tabs button {
  border: none;
  background: none;
  color: var(--muted);
  padding: 14px 14px 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

nav.tabs button:hover {
  color: var(--ink);
}

nav.tabs button.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

nav.tabs button .count {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px;
}

.category-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 12px;
  margin-bottom: 4px;
}

.category-row button {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--ink);
  padding: 6px 14px;
  border-radius: 16px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.category-row button.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}

.grid-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.grid-toolbar-label {
  font-size: 12px;
  color: var(--muted);
}

.sort-select {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--ink);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  margin-left: auto;
}

.filter-chips, .suggest-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.chip.active {
  border-color: var(--brand);
  background: var(--brand-soft);
  color: var(--brand);
}

.load-more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

.load-more-btn {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--ink);
  padding: 10px 24px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.load-more-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
}

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

.panel-header-label {
  font-size: 13px;
  color: var(--muted);
}

.clear-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  padding: 4px;
}

.clear-btn:hover {
  color: var(--sale);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.card {
  background: var(--card-bg);
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.15s, box-shadow 0.15s;
  animation: cardIn 0.25s ease both;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 24px var(--shadow);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
}

.card-img-wrap {
  position: relative;
  background: var(--border);
}

.card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
}

.ribbon {
  position: absolute;
  top: 12px;
  left: -6px;
  background: var(--sale);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: -0.02em;
  padding: 4px 12px 4px 14px;
  transform: skewX(-10deg);
  box-shadow: 2px 3px 6px rgba(0, 0, 0, 0.3);
}

.ribbon::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -5px;
  border-width: 0 5px 5px 0;
  border-style: solid;
  border-color: transparent var(--sale-dark) transparent transparent;
}

.card-tools {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
}

.wish-btn, .share-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 15px;
  line-height: 30px;
  text-align: center;
  padding: 0;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.wish-btn.active {
  color: var(--sale);
}

.share-btn:hover, .wish-btn:hover {
  transform: translateY(-1px);
}

.card-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.card-category {
  font-size: 11px;
  color: var(--brand);
  font-weight: 600;
}

.card-name {
  font-size: 13px;
  line-height: 1.4;
  height: 36px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card-name mark {
  background: var(--accent);
  color: var(--brand-dark);
  padding: 0 2px;
  border-radius: 2px;
}

.card-price {
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.prev-price {
  text-decoration: line-through;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  margin-right: 6px;
}

.badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand);
}

.badge.rocket {
  background: color-mix(in srgb, var(--brand) 12%, transparent);
  color: var(--brand);
}

.card-actions {
  display: flex;
  gap: 6px;
  margin-top: auto;
}

.card-actions a, .card-actions button {
  flex: 1;
  text-align: center;
  padding: 8px 6px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
}

.card-actions a.buy {
  background: var(--brand);
  color: white;
  border-color: var(--brand);
}

.state-msg {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
  font-size: 14px;
  grid-column: 1 / -1;
}

.tool-box {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  max-width: 640px;
}

.tool-box h2 {
  margin-top: 0;
  font-size: 18px;
}

.tool-box input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 10px;
  background: var(--bg);
  color: var(--ink);
}

.tool-box button.primary {
  background: var(--brand);
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
}

.tool-box button.primary:hover {
  background: var(--brand-dark);
}

/* ---------------- 스켈레톤 로딩 ---------------- */
.skeleton-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.skeleton-card .sk-img {
  aspect-ratio: 1 / 1;
}

.skeleton-card .sk-line {
  height: 12px;
  margin: 12px;
  border-radius: 6px;
}

.skeleton-card .sk-line.short {
  width: 50%;
}

.sk-img, .sk-line {
  background: linear-gradient(90deg, var(--border) 25%, var(--bg) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .sk-img, .sk-line {
    animation: none;
    background: var(--border);
  }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--card-bg);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.modal h3 {
  margin-top: 0;
  font-size: 16px;
}

.lowest-badge {
  display: inline-block;
  background: var(--sale);
  color: white;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
  margin-bottom: 10px;
}

.modal-stats {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.modal-stat {
  flex: 1;
  background: var(--bg);
  border-radius: 10px;
  padding: 8px;
  text-align: center;
}

.modal-stat span {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 2px;
}

.modal-stat strong {
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.modal-buy {
  display: block;
  margin-top: 12px;
  text-align: center;
  background: var(--brand);
  color: white;
  padding: 10px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
}

.modal-buy:hover {
  background: var(--brand-dark);
}

.modal .close-btn {
  float: right;
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
}

.chart-wrap {
  height: 260px;
  margin-top: 12px;
}

footer {
  text-align: center;
  padding: 24px 20px 40px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

/* ---------------- 토스트 ---------------- */
.toast-container {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  background: var(--ink);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* ---------------- 맨 위로 ---------------- */
.back-to-top {
  position: fixed;
  right: 20px;
  bottom: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--brand);
  color: white;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.back-to-top.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
  .toast, .back-to-top {
    transition: none;
  }
}
