/* Alfreya stacks: the shared look of the ear, bracelet and ring pages.
 *
 * Built on the house tokens in /shared/alfreya.css (porcelain paper, near-black
 * ink, Newsreader + Host Grotesk, hairlines instead of boxes, oxblood only for
 * live markers). Page-specific bits stay inline in each index.html.
 *
 * Layout (desktop):            Phones (≤900px):
 *   ┌──────── top ────────┐      top
 *   │ stage      │  side  │      stage  (flex 1)
 *   │────────────│        │      tray   (strip)
 *   │ tray       │        │      side   (slim bar that opens upward)
 *   └────────────┴────────┘
 */
:root { --tray-h: 272px; --side-w: 340px; --top-h: 64px; }

html, body { height: 100%; }
body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side-w);
  grid-template-rows: var(--top-h) minmax(0, 1fr) var(--tray-h);
  grid-template-areas: "top top" "stage side" "tray side";
  height: 100vh; height: 100dvh; overflow: hidden;
  font-size: 14px; line-height: 1.5;
}
button, input { font: inherit; color: inherit; }

/* ── the header: back to every product, the brand, which stack ── */
.top {
  grid-area: top; display: flex; align-items: center; gap: 18px;
  padding: 0 var(--gutter); background: var(--paper);
  border-bottom: 1px solid var(--line); min-width: 0; z-index: 5;
}
.top .back {
  display: inline-flex; align-items: center; gap: 10px; flex: none;
  min-height: 38px; padding: 0 16px 0 6px; border-radius: 999px;
  border: 1px solid var(--line-strong); color: var(--ink); text-decoration: none;
  font: 500 13.5px/1 var(--font-sans);
  transition: background-color .3s var(--spring), color .3s var(--spring), border-color .3s ease;
}
.top .back::before {
  content: ""; width: 28px; height: 28px; border-radius: 50%; flex: none;
  background: var(--paper-2) var(--arrow-dark) center / 14px no-repeat;
  transform: rotate(180deg); transition: transform .5s var(--spring), background-color .3s ease;
}
.top .back:hover { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.top .back:hover::before { background-color: rgba(243, 239, 232, .14); background-image: var(--arrow-light); transform: rotate(180deg) translateX(2px); }
.top .logo { min-width: 0; }
.top .logo img { height: 20px; }
.top .logo-tag { white-space: nowrap; }

/* ── the stage: the model photo on warm paper ── */
#stage {
  grid-area: stage; position: relative; display: flex; align-items: center; justify-content: center;
  padding: 64px 32px 22px; min-height: 0; background: var(--paper-2);
}
#view { position: relative; overflow: hidden; border-radius: 4px; flex: none;
  box-shadow: 0 0 0 1px var(--line), 0 24px 60px -32px rgba(23, 21, 19, .35); background: var(--bone); }
#view.droptarget { outline: 1.5px solid var(--ink); outline-offset: 6px; }
#editor { position: absolute; left: 0; top: 0; display: block; touch-action: none; }

/* top right of the stage: which side, size boxes */
.tools { position: absolute; top: 16px; right: 24px; display: flex; align-items: center; gap: 8px; }
.tools > * { border: 1px solid var(--line-strong); border-radius: 999px; color: var(--ink-2);
  font-size: 13px; background: rgba(251, 250, 247, .7); }
.seg { display: flex; padding: 2px; }
.seg button { border: 0; background: none; color: inherit; font-size: 13px; font-weight: 500;
  padding: 5px 13px; border-radius: 999px; cursor: pointer; transition: background-color .2s ease, color .2s ease; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.tools .tgl { padding: 7px 14px; cursor: pointer; font-weight: 500; transition: background-color .2s ease, color .2s ease; }
.tools .tgl:hover { border-color: var(--ink); color: var(--ink); }
.tools .tgl[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* the first-use hint over the photo */
#empty {
  position: absolute; left: 50%; bottom: 40px; transform: translateX(-50%); pointer-events: none;
  background: rgba(251, 250, 247, .92); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border: 1px solid var(--line); color: var(--ink); border-radius: 999px;
  padding: 9px 20px; font-size: 13.5px; white-space: nowrap; transition: opacity .3s;
  box-shadow: 0 6px 20px -10px rgba(23, 21, 19, .25);
}
#empty.gone { opacity: 0; }

/* ── the collection tray ── */
#tray { grid-area: tray; background: var(--bone); border-top: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; padding: 16px 0 0; }
.tray-head { display: flex; align-items: center; gap: 18px; padding: 0 28px 12px; }
.tray-head h2 { font: 400 22px/1 var(--font-display); letter-spacing: -0.01em; margin-right: 6px; }
.chips { display: flex; gap: 4px; }
.chips button { border: 1px solid transparent; background: none; padding: 6px 13px; border-radius: 999px; cursor: pointer;
  color: var(--muted); font-size: 13.5px; transition: background-color .2s ease, color .2s ease; }
.chips button:hover { color: var(--ink); border-color: var(--line); }
.chips button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chips small { font-size: 11px; opacity: .7; margin-left: 3px; }
#search { margin-left: auto; width: 210px; border: 1px solid var(--line-strong); background: #fff; border-radius: 999px;
  padding: 7px 15px; font-size: 13.5px; transition: border-color .2s ease, box-shadow .2s ease; }
#search::placeholder { color: var(--faint); }
#search:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(23, 21, 19, .08); }
#catalog { flex: 1; min-height: 0; display: grid; grid-auto-flow: column; grid-auto-columns: 128px; gap: 16px;
  overflow-x: auto; overflow-y: hidden; padding: 2px 28px 18px; scroll-padding-inline: 28px;
  scroll-snap-type: x proximity; align-content: start; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.ccard { position: relative; display: flex; flex-direction: column; gap: 6px; cursor: pointer; scroll-snap-align: start;
  background: none; border: 0; text-align: left; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.ccard .ph { aspect-ratio: 1; border-radius: 4px; overflow: hidden; background: #fff;
  box-shadow: 0 0 0 1px var(--line); transition: box-shadow .2s ease; }
.ccard .ph img { width: 100%; height: 100%; object-fit: contain; display: block; padding: 12%;
  transition: transform .6s var(--spring); }
.ccard:hover .ph, .ccard:focus-visible .ph { box-shadow: 0 0 0 1px var(--ink); }
.ccard:hover .ph img { transform: scale(1.04); }
.ccard b { font: 400 15px/1.2 var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ccard small { color: var(--muted); font-size: 12px; margin-top: -4px; }
.ccard:disabled { opacity: .45; cursor: default; }
#none { color: var(--muted); padding: 24px 0; }

/* ── your stack ── */
#side { grid-area: side; background: var(--paper); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 24px 24px 12px; display: flex; align-items: baseline; justify-content: space-between; }
.side-head h2 { font: 300 28px/1 var(--font-display); letter-spacing: -0.016em; }
#sheetToggle { display: none; align-items: center; gap: 8px; border: 0; background: none; cursor: pointer; padding: 6px 4px;
  font: 400 19px/1 var(--font-display); }
#sheetToggle .n { font: 500 12px/1 var(--font-sans); background: var(--ink); color: var(--paper); border-radius: 999px; padding: 3px 7px; }
#sheetToggle .chev { width: 9px; height: 9px; border-right: 1.5px solid var(--muted); border-bottom: 1.5px solid var(--muted);
  transform: rotate(-135deg) translate(-2px, -2px); transition: transform .2s; }
body.sheet-open #sheetToggle .chev { transform: rotate(45deg); }
#clearAll { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 13px;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
#clearAll:hover { color: var(--ink); }
.rows { flex: 1; overflow-y: auto; padding: 4px 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.intro { padding: 6px 8px; color: var(--muted); line-height: 1.6; border-top: 1px solid var(--line); padding-top: 14px; }
.intro p + p { margin-top: 10px; }
.prow { display: grid; grid-template-columns: 56px minmax(0, 1fr) auto; gap: 2px 12px; align-items: center;
  padding: 8px; border-radius: 4px; transition: background-color .15s; }
.prow .th { grid-row: 1 / 3; width: 56px; height: 56px; border-radius: 4px; object-fit: contain; padding: 6px; background: #fff;
  box-shadow: 0 0 0 1px var(--line); }
.prow .nm { font: 400 17px/1.2 var(--font-display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prow .sub { grid-column: 2; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.prow .x { grid-row: 1 / 3; grid-column: 3; width: 32px; height: 32px; border-radius: 50%; border: 0; background: none;
  color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1; }
.prow .x:hover { background: var(--paper-2); color: var(--ink); }
.side-foot { padding: 16px 24px 22px; border-top: 1px solid var(--line); }
#download { width: 100%; min-height: 50px; border: 0; border-radius: 999px; background: var(--ink); color: var(--paper);
  padding: 0 20px; font: 500 15px/1 var(--font-sans); letter-spacing: .005em; cursor: pointer;
  transition: transform .5s var(--spring), background-color .3s ease; }
#download:hover:not(:disabled) { background: #000; transform: translateY(-1px); }
#download:active:not(:disabled) { transform: scale(.98); }
#download:disabled { background: var(--paper-2); color: var(--faint); cursor: default; }
#status { margin-top: 10px; min-height: 18px; color: var(--muted); font-size: 12.5px; text-align: center; }

/* ── phones: app-like, no page scroll ── */
@media (max-width: 900px) {
  :root { --top-h: 56px; }
  body { display: flex; flex-direction: column; }
  .top { flex: none; height: var(--top-h); gap: 12px; padding: 0 12px; padding-top: env(safe-area-inset-top);
    height: calc(var(--top-h) + env(safe-area-inset-top)); }
  .top .back { min-height: 36px; font-size: 13px; padding-right: 13px; }
  .top .back::before { width: 26px; height: 26px; }
  .top .logo img { height: 17px; }
  #stage { flex: 1 1 auto; min-height: 0; padding: 52px 10px 10px; }
  .tools { top: 10px; right: 10px; left: 10px; justify-content: flex-end; gap: 6px; }
  .tools > *, .seg button { font-size: 12.5px; }
  .seg button { padding: 4px 10px; }
  .tools .tgl { padding: 6px 11px; }
  #empty { bottom: 16px; font-size: 13px; padding: 8px 16px; }
  #tray { flex: none; padding-top: 10px; }
  .tray-head { gap: 8px; padding: 0 12px 8px; }
  .tray-head h2 { display: none; }
  .chips { flex: 1; min-width: 0; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chips button { white-space: nowrap; padding: 7px 11px; }
  #search { margin-left: 0; width: 96px; flex: none; font-size: 16px; padding: 5px 12px; }
  #catalog { flex: none; height: 152px; grid-auto-columns: 92px; gap: 10px; padding: 2px 12px 10px; scroll-padding-inline: 12px; }
  .ccard b { font-size: 13.5px; }
  .ccard small { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #side { flex: none; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center;
    border-left: 0; border-top: 1px solid var(--line); }
  .side-head { grid-column: 1; grid-row: 1; padding: 8px 8px 8px 12px; justify-content: flex-start; gap: 14px; }
  .side-head h2 { display: none; }
  #sheetToggle { display: flex; }
  #clearAll { display: none; }
  body.sheet-open #clearAll:not([hidden]) { display: inline; }
  .side-foot { grid-column: 2; grid-row: 1; padding: 8px 12px 8px 0; border-top: 0; }
  #download { width: auto; min-height: 42px; padding: 0 18px; font-size: 14px; }
  #status { display: none; }
  .rows { grid-column: 1 / -1; grid-row: 2; display: none; max-height: 40vh; max-height: 40dvh;
    padding: 0 8px calc(8px + env(safe-area-inset-bottom)); }
  body.sheet-open .rows { display: flex; }
  body.sheet-open #tray { display: none; }            /* the open stack takes the strip's room, not the photo's */
  body:not(.sheet-open) #side { padding-bottom: env(safe-area-inset-bottom); }
  .intro { font-size: 13.5px; }
}
@media (max-width: 380px) {
  .top .logo-tag { display: none; }
}

/* ?embed=1 and refused sites (kept from the k-smet port) */
html.embed body { display: block; background: transparent; }
html.embed #stage { height: 100%; padding: 0; background: transparent; }
html.embed #view { border-radius: 0; box-shadow: none; }
html.embed .top, html.embed #tray, html.embed #side, html.embed .tools, html.embed #empty { display: none; }
#refused { display: none; max-width: 32ch; text-align: center; color: var(--muted); font-size: 14.5px; }
html.refused body { display: block; }
html.refused #stage { height: 100%; justify-content: center; }
html.refused #view, html.refused #tray, html.refused #side, html.refused .tools, html.refused #empty { display: none; }
html.refused #refused { display: block; }

/* ── loading: from the first paint until the model photo is on screen ── */
#loading {
  position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; text-align: center; padding: 24px;
  background: var(--paper-2); color: var(--ink); transition: opacity .4s ease;
}
#loading.gone { opacity: 0; pointer-events: none; }
#loading p { font: 300 24px/1.2 var(--font-display); letter-spacing: -0.01em; }
#loading small { color: var(--muted); font-size: 13px; max-width: 30ch; min-height: 1.5em; }
#loading.failed .spinner { display: none; }
#loading.failed p { color: var(--danger); }
body.loading .tools, body.loading #empty { visibility: hidden; }
body.loading #download { visibility: hidden; }
/* placeholder cards in the strip until the pieces arrive */
.ccard.sk { cursor: default; pointer-events: none; }
.ccard.sk .ph, .ccard.sk b, .ccard.sk small {
  background: linear-gradient(90deg, var(--paper-2) 0%, var(--bone) 50%, var(--paper-2) 100%) 0 0 / 200% 100%;
  animation: sk-shimmer 1.4s ease-in-out infinite; box-shadow: none;
}
.ccard.sk b { height: 14px; width: 80%; border-radius: 2px; }
.ccard.sk small { height: 10px; width: 45%; border-radius: 2px; margin-top: 0; }
@keyframes sk-shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@media (max-width: 900px) { #loading p { font-size: 20px; } }
