:root {
  color-scheme: light;
  --ink: #0b1220;
  --ink-soft: #1c2636;
  --muted: #5f6b7a;
  --muted-soft: #8a95a3;
  --bg: #f6f4f0;
  --surface: #ffffff;
  --surface-2: #f1efe9;
  --line: #e5e1d8;
  --line-strong: #d0c9bb;
  --accent: #0f7a5f;
  --accent-dark: #0a5c47;
  --accent-soft: rgba(15, 122, 95, 0.1);
  --highlight: #d97706;
  --danger: #b42318;
  --paypal: #0070e0;
  --font-display: "Noto Serif SC", "Songti SC", Georgia, serif;
  --font-body: Inter, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 0 rgba(11, 18, 32, 0.04), 0 8px 24px rgba(11, 18, 32, 0.05);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 70% 40% at 50% -8%, rgba(0, 112, 224, 0.06), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin-top: 0; }
h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(26px, 4vw, 34px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
}
h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}
.hidden { display: none !important; }

.page-shell {
  width: min(100% - 32px, 980px);
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}
.brand-block { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px;
  height: 44px;
  border: 1px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.brand-logo { width: 36px; height: 36px; }
.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chain-badge,
.support-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-weight: 650;
  font-size: 13px;
}
.paypal-badge {
  border-color: rgba(0, 112, 224, 0.2);
  background: rgba(0, 112, 224, 0.07);
  color: #003087;
}
.chain-badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--paypal);
  box-shadow: 0 0 0 3px rgba(0, 112, 224, 0.12);
}
.support-button:hover { border-color: var(--ink); text-decoration: none; }
.secondary-button.wide { width: 100%; background: #fff; }

.hero-line {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
}

.layout {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 16px;
  align-items: start;
}

.shop-panel,
.checkout {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}
.checkout { position: sticky; top: 16px; }

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.section-meta-chip {
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.checkout-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.checkout-secure {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(15, 122, 95, 0.2);
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.secure-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.product-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  padding: 0;
  text-align: left;
  overflow: hidden;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}
.product-card:hover:not(:disabled) {
  border-color: var(--line-strong);
  transform: translateY(-1px);
  box-shadow: 0 8px 18px rgba(11, 18, 32, 0.06);
}
.product-card.selected {
  border-color: var(--highlight);
  box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.12);
}
.product-card.selected::after {
  content: "";
  position: absolute;
  top: 10px;
  right: 10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--highlight) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 8.2L6.8 11 12 5' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/12px no-repeat;
  z-index: 2;
}
.product-card:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
.product-thumb {
  width: 100%;
  aspect-ratio: 16 / 10;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.product-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.thumb-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: #fff;
  background: linear-gradient(145deg, #0f7a5f, #0a5c47);
}
.thumb-fallback.pack {
  background: linear-gradient(145deg, #0070e0, #003087);
}
.thumb-qty {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 700;
  line-height: 1;
}
.thumb-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.9;
}
.product-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px 14px;
  flex: 1;
}
.product-title {
  font-weight: 750;
  font-size: 15px;
  line-height: 1.3;
}
.product-desc {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  min-height: 34px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-meta {
  margin-top: auto;
  padding-top: 8px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
}
.product-price {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
}
.product-price small {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
}
.product-stock {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.product-stock.ok { color: var(--accent-dark); }
.product-stock.out { color: var(--danger); }
.empty-state {
  grid-column: 1 / -1;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-2);
}

.selected-box,
.info-box,
.status-box,
.codes-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 12px 14px;
}
.selected-box { margin-bottom: 14px; }
.selected-main {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.selected-thumb {
  width: 64px;
  height: 42px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.selected-thumb img,
.selected-thumb .thumb-fallback {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.selected-thumb .thumb-qty { font-size: 16px; }
.selected-thumb .thumb-label { font-size: 8px; }
.selected-info strong {
  display: block;
  font-size: 14px;
  margin-bottom: 2px;
}
.selected-info span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}
.selected-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  padding: 3px 0;
  font-size: 13px;
}
.selected-row span { color: var(--muted); }
.price-strong { font-size: 16px; }

.pay-block { margin-bottom: 12px; }
.paypal-panel { position: relative; min-height: 52px; }
.paypal-buttons-wrap { min-height: 50px; }
.pay-busy {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 600;
}
.pay-busy p { margin: 0; }
.pay-spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid rgba(0, 112, 224, 0.15);
  border-top-color: #0070e0;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.status-box {
  min-height: 42px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 0;
}
.status-box.success {
  border-color: rgba(15, 122, 95, 0.25);
  color: var(--accent-dark);
  background: #f3faf7;
}
.status-box.error {
  border-color: rgba(180, 35, 24, 0.22);
  color: var(--danger);
  background: #fff7f6;
}

.codes-box { margin-top: 12px; }
.codes-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.status-tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border: 1px solid rgba(15, 122, 95, 0.25);
  border-radius: 999px;
  color: var(--accent-dark);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.codes-mono {
  margin: 0;
  padding: 12px;
  border-radius: 10px;
  background: #0b1220;
  color: #e8eef7;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
}
.codes-actions {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.support-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.site-footer {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}
.site-footer p { margin: 0; }

/* Admin keeps working */
body.admin { background: #f3f1ec; }
.admin-shell {
  width: min(100% - 32px, 1100px);
  margin: 0 auto;
  padding: 28px 0 48px;
}
.admin-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.admin-card h2 { margin-bottom: 6px; }
.admin-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-top: 12px;
}
.stat-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface-2);
}
.stat-card span { display: block; color: var(--muted); font-size: 12px; }
.stat-card strong { display: block; margin-top: 4px; font-size: 22px; }
.login-box { max-width: 420px; margin: 10vh auto 0; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field input, .field textarea, .field select,
table input, table textarea, table select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
  vertical-align: top;
  text-align: left;
}
th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.message { margin-top: 10px; font-size: 13px; color: var(--muted); }
.message.success { color: var(--accent-dark); }
.message.error { color: var(--danger); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.order-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  background: var(--surface-2);
}
.order-item code { font-family: var(--font-mono); font-size: 12px; }
.order-grid {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 4px 10px;
  font-size: 13px;
  margin-top: 8px;
}
.order-grid span { color: var(--muted); }
.order-status {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
}
.order-status.delivered {
  color: var(--accent-dark);
  border-color: rgba(15, 122, 95, 0.28);
}
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.product-image-admin {
  width: 72px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
}
.product-image-admin img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.image-picker { width: 100%; font-size: 11px; }
.section-hint { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--ink);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
}
.primary-button.wide { width: 100%; }

@media (max-width: 860px) {
  .layout,
  .admin-grid { grid-template-columns: 1fr; }
  .checkout { position: static; }
}
@media (max-width: 640px) {
  .page-shell { width: min(100% - 20px, 980px); padding-top: 16px; }
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
  .topbar-actions { width: 100%; }
  .product-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .product-title { font-size: 13px; }
  .product-price { font-size: 18px; }
  .codes-actions { grid-template-columns: 1fr; }
}
