:root{
  /* Colors & surfaces */
  --card:#fafafa;         /* product card background */
  --ink:#111827;
  --muted:#667085;

  /* Unified box styling */
  --box-border:#bbb;
  --box-border-hover:#888;
  --box-shadow:0 2px 6px rgba(0,0,0,.10);
  --box-shadow-hover:0 6px 14px rgba(0,0,0,.15);

  /* Theme accents */
  --border:#e5e7eb;
  --ring:#2563eb22;

  /* Layout */
  --maxw:1200px;
  --r:12px;
  --header-h:160px;   /* JS will set precise height */
  --footer-h:28px;    /* JS will set precise height */

  /* Controls & cards */
  --thumb-size:64px;
  --btn-h:25px;
  --btn-w:68px;
  --btn-fs:12px;
}

/* Base */
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  background:#fff;
  color:var(--ink);
  font-family:Inter,system-ui,-apple-system,"Segoe UI","Segoe UI Symbol",Roboto,Helvetica,Arial,sans-serif;
}

/* ===== Fixed header ===== */
.topbar{
  position:fixed; left:0; right:0; top:0; z-index:1000;
  background:#fff;
  box-shadow:none;
}
.container{max-width:var(--maxw); margin:0 auto; padding:6px 10px}

.site-header{display:flex; align-items:center; justify-content:center; padding:2px 0 4px}
.site-header h1{
  font-family:"Playfair Display",serif;
  font-size:clamp(18px,2.8vw,26px);
  line-height:1.05;
  margin:0;
}

/* ===== Controls: Search + chips ===== */
.controls{
  display:grid;
  grid-template-columns:1fr auto auto;
  gap:8px;
  align-items:center;
  padding:6px 0;
}
.search-wrap{position:relative; min-width:0}
.input{
  width:100%; height:40px; padding:8px 30px 8px 12px;
  font-size:14px;
  border-radius:10px;
  border:2px solid var(--box-border);
  background:#fff; color:#111; outline:none;
  box-shadow:0 1px 4px rgba(0,0,0,.08) inset, 0 1px 2px rgba(0,0,0,.06);
}
.input:focus{
  border-color:#2563eb;
  box-shadow:0 0 0 4px var(--ring), 0 2px 6px rgba(0,0,0,.15);
}
.clear-btn{
  position:absolute; right:6px; top:50%; transform:translateY(-50%);
  width:26px; height:26px; border-radius:999px;
  border:1px solid #d1d5db; background:#fff; color:#444;
  font-size:14px; line-height:24px; cursor:pointer;
  display:none; align-items:center; justify-content:center;
}
.clear-btn.show{display:flex}

/* ===== Chips (soft active + fixed arrow slot) ===== */
.chip{
  display:inline-grid;                /* two columns: label + icon */
  grid-template-columns:auto 1.2em;   /* reserve fixed icon space */
  align-items:center;
  column-gap:4px;

  height:34px;
  padding:0 16px;
  font-size:13px;
  border:1px solid #d1d5db;
  border-radius:9999px;
  background:#f9fafb;
  color:#374151;
  cursor:pointer;
  user-select:none;
  white-space:nowrap;
  box-shadow:0 1px 2px rgba(0,0,0,.05);
  transition:all .15s ease;
}
.chip:hover{
  border-color:#9ca3af;
  background:#f3f4f6;
}
.chip[aria-pressed="true"]{
  background:#e0e7ff;     /* soft indigo tint */
  color:#1e3a8a;          /* indigo text */
  border-color:#6366f1;   /* indigo border */
  box-shadow:0 2px 6px rgba(0,0,0,.12);
}
/* Always reserve icon space; show arrow by direction (ASCII-safe Unicode escapes) */
.chip::after{
  content:"";             /* empty by default, keeps width */
  display:inline-block;
  width:1.2em;            /* matches grid column */
  text-align:center;
  font-size:11px;
  line-height:1;
  opacity:0;              /* space reserved, not visible */
}
.chip[aria-pressed="true"][data-dir="asc"]::after{
  content:"\25B2";        /* ? */
  opacity:1;
}
.chip[aria-pressed="true"][data-dir="desc"]::after{
  content:"\25BC";        /* ? */
  opacity:1;
}
@media (max-width:420px){.chip{padding:0 12px}}

/* ===== Description row ===== */
.descrow{margin:4px 0}
.descbox{
  border:2px solid var(--box-border);
  border-radius:10px;
  background:#fff;
  padding:8px 10px;
  font-size:12.5px;
  line-height:1.25;
  box-shadow:0 1px 4px rgba(0,0,0,.08);
  display:-webkit-box;
  -webkit-line-clamp:2;
  -webkit-box-orient:vertical;
  overflow:hidden;
  height:calc(1.25em * 2);
}
.descbox strong{font-weight:700}

/* ===== Content ===== */
.stage{
  max-width:var(--maxw);
  margin:0 auto;
  padding:10px 10px calc(var(--footer-h) + 12px + env(safe-area-inset-bottom));
  padding-top:calc(var(--header-h) + 10px);
  background:#fff;
}

/* Grid & cards */
.grid{
  display:grid;
  gap:12px;
  grid-template-columns:repeat(auto-fill, minmax(150px,1fr));
  background:#fff;
}

/* Product cards */
.card{
  background:var(--card);
  border:2px solid var(--box-border);
  border-radius:var(--r);
  padding:10px;
  text-align:center;
  box-shadow:var(--box-shadow);
  transition:box-shadow .15s,border-color .15s,transform .15s;
  display:flex; flex-direction:column; justify-content:space-between; align-items:center;
  width:100%;
}
.card:hover{
  border-color:var(--box-border-hover);
  box-shadow:var(--box-shadow-hover);
}
.card h3{
  margin:0 0 4px;
  font-size:14px;
  line-height:1.2;
  font-weight:700;
  word-break:break-word;
}
.price{font-size:13px; color:#0f172a; margin-bottom:8px}

.card.active{
  border-color:#2563eb;
  box-shadow:0 0 0 3px var(--ring), var(--box-shadow-hover);
  transform:translateY(-1px);
}

/* Actions */
.actions{display:flex; align-items:center; justify-content:center; gap:6px; width:100%}
.actions .cta-col{display:flex; flex-direction:column; gap:6px; justify-content:center; align-items:center}

/* Highlight */
.hl{font-weight:700; text-decoration:underline; text-underline-offset:2px}

/* Thumbnail */
.thumb{
  width:var(--thumb-size); height:var(--thumb-size);
  border-radius:10px;
  background:#fff;
  box-shadow:inset 0 0 0 1px #eef1f5;
}
.thumb img{
  width:100%; height:100%;
  object-fit:contain;
  border-radius:8px;
  display:block;
}

/* Buttons */
.btn{
  height:var(--btn-h); min-width:var(--btn-w); padding:0 10px;
  font-size:var(--btn-fs); line-height:1;
  border-radius:10px; border:1px solid #d1d5dc;
  background:#fff; color:#111;
  display:inline-flex; align-items:center; justify-content:center;
  box-shadow:0 1px 2px rgba(0,0,0,.06);
  transition:transform .12s ease, box-shadow .12s ease, background .12s ease, border-color .12s ease;
  cursor: pointer;
}
.btn, .btn * { cursor: pointer; }  /* ensure hand cursor over text */
.btn{ -webkit-user-select: none; user-select: none; }

.btn:hover{background:#f8fafc; box-shadow:0 2px 6px rgba(0,0,0,.12); transform:translateY(-1px)}
.btn:active{transform:translateY(0); box-shadow:0 1px 2px rgba(0,0,0,.08)}
.btn:focus{outline:none; box-shadow:0 0 0 4px var(--ring), 0 1px 2px rgba(0,0,0,.06)}
.btn.primary{background:#fff; border-color:#cfd4dc; color:#111}
.btn.primary:hover{background:#f1f5f9; border-color:#c7ccd5}
.btn.block{width:var(--btn-w); height:var(--btn-h); padding:0}

/* Underline only the Desc button (no hover change) */
.btn[data-action="desc"]{
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: auto;
  text-decoration-color: currentColor;
  text-decoration-skip-ink: auto;
}
.btn[data-action="desc"]:hover{
  text-decoration: underline;
}

/* ===== Fixed footer ===== */
.bottombar{
  position:fixed; left:0; right:0; bottom:0; z-index:1000;
  background:#fff;
  box-shadow:none;
  font-size:11.5px;
  line-height:1;
  color:#6b7280;
  padding:6px 10px calc(6px + env(safe-area-inset-bottom));
}
.bottombar .container{
  max-width:var(--maxw);
  margin:0 auto;
  padding:0;
  display:flex;
  align-items:center; justify-content:center;
}
.footline{width:100%; text-align:center; white-space:nowrap; overflow:hidden; text-overflow:ellipsis}

/* ===== Overlay ===== */
.preview-frame-container{
  position:fixed; inset:0; z-index:10000;
  background:rgba(0,0,0,.8);
  display:none; justify-content:center; align-items:center;
}
.preview-frame-inner{
  width:100%; height:100%;
  border-radius:0; border:0;
  overflow:hidden; position:relative;
  background:#fff; pointer-events:auto;
}
.preview-frame-inner iframe{
  width:100%; height:100%;
  border:0;
  display:block;
  position:relative;
  z-index:1;
}
.close-btn{
  position:absolute;
  top:calc(10px + env(safe-area-inset-top));
  left:10px;
  background:#fff;
  border:1px solid #ddd;
  border-radius:50%;
  width:40px; height:40px;
  display:flex; align-items:center; justify-content:center;
  font-size:24px; font-weight:bold; color:#555;
  cursor:pointer;
  z-index:2;
  box-shadow:2px 2px 5px rgba(0,0,0,.2);
}

/* Hidden heading for accessibility */
.sr-only{
  position:absolute !important;
  width:1px; height:1px;
  padding:0; margin:-1px;
  overflow:hidden;
  clip:rect(0 0 0 0);
  white-space:nowrap;
  border:0;
}

/* Lock scroll when overlay open */
body.lock{overflow:hidden}
