
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --line: #dde2e8;
  --text: #1f2833;
  --muted: #66707a;
  --accent: #1459c7;
  --accent-2: #0f4aa4;
  --shadow: 0 12px 30px rgba(31, 40, 51, 0.08);
  --radius: 18px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #f8f9fb 0%, var(--bg) 100%);
}
a { color: inherit; }
button, input { font: inherit; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand-title { font-size: 1.15rem; font-weight: 700; }
.brand-subtitle { color: var(--muted); font-size: 0.95rem; }
.shop-link, .shop-link-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border-radius: 999px;
  text-decoration: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}
.shop-link:hover, .shop-link-inline:hover { background: var(--accent-2); }
.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 1.2fr) minmax(340px, 440px);
  gap: 18px;
  padding: 18px;
}
.viewer-card, .controls-card {
  background: var(--card);
  border: 1px solid rgba(0,0,0,0.04);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.viewer-card {
  position: relative;
  min-height: calc(100vh - 110px);
  overflow: hidden;
}
.controls-card {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: calc(100vh - 110px);
  overflow: auto;
}
#viewer { width: 100%; height: 100%; display: block; min-height: calc(100vh - 110px); }
.loading-box {
  position: absolute;
  inset: 18px 18px auto 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 14px;
  background: rgba(255,255,255,0.94);
  border: 1px solid var(--line);
}
.loading-box.hidden { display: none; }
.loading-box.error { border-color: #d84d4d; }
.spinner {
  width: 26px; height: 26px; border: 3px solid #dce4f3; border-top-color: var(--accent);
  border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.viewer-tools {
  position: absolute; right: 16px; bottom: 46px; display: flex; gap: 10px; flex-wrap: wrap;
}
.viewer-tools button, .group-btn, .color-btn, .secondary, .wide, .catalog-card button, #applyCustomColor {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}
.viewer-tools button:hover, .group-btn:hover, .color-btn:hover, .secondary:hover, .catalog-card button:hover, #applyCustomColor:hover {
  border-color: #b8c4d4;
}
.viewer-help {
  position: absolute; left: 16px; bottom: 16px; font-size: 0.86rem; color: var(--muted);
  background: rgba(255,255,255,0.8); padding: 8px 12px; border-radius: 999px;
}
section h1, section h2 { margin: 0 0 10px; }
.lead { margin: 0; color: var(--muted); line-height: 1.45; }
.group-buttons, .palette {
  display: flex; flex-wrap: wrap; gap: 10px;
}
.group-btn.active {
  border-color: var(--accent); background: #eaf1fd; color: var(--accent-2); font-weight: 700;
}
.color-btn {
  display: inline-flex; align-items: center; gap: 8px;
}
.swatch { width: 20px; height: 20px; border-radius: 999px; border: 1px solid rgba(0,0,0,0.15); flex: 0 0 auto; }
.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}
.catalog-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: #fff;
  display: flex;
  flex-direction: column;
  min-height: 250px;
}
.catalog-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(20,89,199,0.10); }
.catalog-thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  background: linear-gradient(180deg, #f6f8fc 0%, #e8edf5 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.catalog-thumb img {
  width: 100%; height: 100%; object-fit: contain; background: #fff; padding: 6px; opacity: 1;
}
.catalog-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: #fff;
  padding: 10px;
  text-align: center;
}
.catalog-color-badge {
  position: absolute;
  right: 10px; top: 10px;
  width: 22px; height: 22px; border-radius: 999px;
  border: 2px solid rgba(255,255,255,0.85);
  box-shadow: 0 3px 8px rgba(0,0,0,0.15);
}
.catalog-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.catalog-title { font-size: 0.92rem; font-weight: 700; line-height: 1.35; }
.catalog-meta, .small-note, .muted, .legal-note, .notice { color: var(--muted); font-size: 0.9rem; line-height: 1.4; }
.catalog-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.catalog-actions a {
  text-decoration: none; text-align: center; border-radius: 10px; padding: 9px 10px; border: 1px solid var(--line);
}
.catalog-actions a:hover { border-color: #b8c4d4; }
.custom-color-row { display: flex; gap: 10px; align-items: center; }
#customColor { width: 54px; height: 42px; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.wide { width: 100%; }
.status-section, .info-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fcfcfd;
}
.info-card.hidden, .notice.hidden { display: none; }
.info-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.span-2 { grid-column: 1 / -1; }
.status-row {
  display: flex; justify-content: space-between; gap: 12px; padding: 6px 0;
}
.legal-note { margin: 0; }
@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 1fr; }
  .viewer-card, #viewer { min-height: 58vh; }
  .controls-card { max-height: none; }
}
@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .catalog-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .custom-color-row { flex-direction: column; align-items: stretch; }
  .viewer-tools { left: 16px; right: 16px; bottom: 56px; }
}
