/* Shared styles for every toolbox page. Edit colors / sizes in :root. */
:root {
  --maroon: #6B1A2C;
  --gold: #C9A84C;
  --ink: #14110f;
  --title-h: clamp(56px, 8.5dvh, 84px);
  --btn-min: 132px;           /* smallest the button area may get */
  --ar: 0.75;                 /* photo width / height, set by box.js */
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ink);
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}
body { overflow: hidden; }

/* ---- Page: title / photo / buttons, one screen, no scroll ---- */
.page {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 100%;
  grid-template-rows: var(--title-h) auto 1fr;
}

.top {
  display: flex;
  align-items: center;
  background: var(--maroon);
  border-bottom: 4px solid var(--gold);
  min-width: 0;
}
.back {
  flex: 0 0 var(--title-h);
  height: 100%;
  display: grid;
  place-items: center;
  color: #fff;
  text-decoration: none;
  font-size: 40px;
  font-weight: 700;
  line-height: 1;
}
.top h1 {
  margin: 0;
  padding-right: 12px;
  font-size: clamp(20px, 6.2vw, 34px);
  line-height: 1.1;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Photo stage: sized to the photo's aspect ratio, never cropped ---- */
.stage {
  position: relative;
  justify-self: center;
  aspect-ratio: var(--ar);
  width: min(100vw, calc((100vh - var(--title-h) - var(--btn-min)) * var(--ar)));
  width: min(100vw, calc((100dvh - var(--title-h) - var(--btn-min)) * var(--ar)));
  container-type: inline-size;   /* lets children size text in cqw */
  overflow: hidden;
  background: #222;
  user-select: none;
  -webkit-user-select: none;
}
.photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
}
.shade {
  position: absolute;
  inset: 0;
  background: rgba(70, 70, 70, .5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s;
}
.stage.all .shade { opacity: 1; }

/* ---- Compartments: invisible tap zones laid over the photo ---- */
.zone {
  position: absolute;
  margin: 0;
  padding: 1cqw;
  border: 0;
  border-radius: 1.2cqw;
  background: transparent;
  color: #fff;
  font: inherit;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .8cqw;
  overflow: hidden;
}
.zone:focus-visible { outline: .9cqw solid var(--gold); outline-offset: -.9cqw; }

.stage.all .zone {
  outline: .6cqw dotted rgba(255, 255, 255, .95);
  outline-offset: -.6cqw;
}
.zone.active,
.stage.all .zone.active {
  outline: 1.1cqw solid var(--gold);
  outline-offset: -1.1cqw;
  background: rgba(201, 168, 76, .2);
}

/* "See All" chips: part name + quantity */
.li {
  display: none;
  flex-direction: column;
  align-items: center;
  max-width: 100%;
  padding: .9cqw 1.3cqw;
  border-radius: 1.2cqw;
  background: rgba(15, 15, 15, .86);
  text-align: center;
  line-height: 1.12;
}
.stage.all .li { display: flex; }
/* wide, short zones (e.g. the ball-valve strip): name and qty side by side */
.zone.row .li { flex-direction: row; align-items: baseline; gap: 1.8cqw; }
.li-name {
  font-size: max(11px, 3.3cqw);
  font-weight: 700;
  overflow: hidden;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.li-qty {
  font-size: max(13px, 4.8cqw);
  font-weight: 800;
  color: var(--gold);
}
/* ⋯ marks a zone whose label is clipped; tap it for the full text */
.stage.all .zone.clip::after {
  content: "\22EF";
  position: absolute;
  right: 1cqw;
  bottom: -.5cqw;
  font-size: 6cqw;
  font-weight: 900;
  line-height: 1;
  color: var(--gold);
  text-shadow: 0 0 .6cqw #000;
}

/* ---- Single-compartment popup ---- */
.pop {
  position: absolute;
  left: 4%;
  right: 4%;
  z-index: 5;
  max-height: 46%;
  overflow: auto;
  padding: 3.5cqw 4cqw;
  border: .9cqw solid var(--gold);
  border-radius: 3cqw;
  background: #fff;
  color: #111;
  box-shadow: 0 1.5cqw 6cqw rgba(0, 0, 0, .5);
}
.pop.at-top { top: 3%; }
.pop.at-bottom { bottom: 3%; }
.pop h2 {
  margin: 0 0 1.5cqw;
  font-size: max(13px, 3.8cqw);
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--maroon);
}
.pop ul { list-style: none; margin: 0; padding: 0; }
.pop li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 3cqw;
  padding: 2cqw 0;
  border-top: 1px solid #ddd;
  font-size: max(18px, 6cqw);
  font-weight: 700;
  line-height: 1.15;
}
.pop li:first-child { border-top: 0; }
.pop .q {
  font-size: max(22px, 8cqw);
  font-weight: 900;
  color: var(--maroon);
  white-space: nowrap;
}

/* ---- Bottom buttons ---- */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
  gap: 3vw;
  min-height: var(--btn-min);
  padding: 3vw 3vw calc(3vw + env(safe-area-inset-bottom));
  background: var(--ink);
}
.act {
  appearance: none;
  -webkit-appearance: none;
  min-height: 56px;
  margin: 0;
  padding: 8px;
  border: 0;
  border-radius: min(4vw, 24px);
  font: inherit;
  font-size: clamp(24px, 7.4vw, 44px);
  font-weight: 900;
  line-height: 1.05;
  text-align: center;
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
}
.act-all { background: #2f2f2f; border: 3px solid #fff; }
.act-all[aria-pressed="true"] { background: var(--gold); border-color: var(--gold); color: #111; }
.act-list { background: var(--maroon); border: 3px solid var(--maroon); }
.act:active { filter: brightness(1.25); }
.act:focus-visible { outline: 4px solid var(--gold); outline-offset: 2px; }

/* ---- Show List modal ---- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, .6);
}
.sheet {
  width: min(100%, 640px);
  height: 84vh;
  height: 84dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: min(5vw, 28px) min(5vw, 28px) 0 0;
  background: #fff;
  color: #111;
}
.sheet-head {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 14px 18px;
  background: var(--maroon);
  color: #fff;
}
.sheet-head h2 { margin: 0; font-size: clamp(22px, 6vw, 30px); font-weight: 800; }
.sheet-head .count { font-size: clamp(16px, 4.4vw, 20px); font-weight: 600; opacity: .85; }
.plist {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.plist li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  min-height: 52px;
  padding: 8px 18px;
  border-bottom: 1px solid #e3e3e3;
  font-size: clamp(19px, 5.4vw, 26px);
  font-weight: 700;
  line-height: 1.15;
}
.plist li:nth-child(even) { background: #f6f3ee; }
.plist .pq {
  flex: 0 0 auto;
  font-size: 1.25em;
  font-weight: 900;
  color: var(--maroon);
  white-space: nowrap;
}
.sheet-close {
  flex: 0 0 auto;
  appearance: none;
  -webkit-appearance: none;
  min-height: 64px;
  margin: 0;
  border: 0;
  background: var(--gold);
  color: #111;
  font: inherit;
  font-size: clamp(24px, 7vw, 34px);
  font-weight: 900;
  cursor: pointer;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet-close:active { filter: brightness(1.15); }

/* ---- Landscape phones: photo on the left, buttons stacked on the right ---- */
@media (orientation: landscape) and (max-height: 560px) {
  .page { grid-template-columns: auto 1fr; grid-template-rows: var(--title-h) 1fr; }
  .top { grid-column: 1 / -1; }
  .stage {
    justify-self: start;
    width: calc((100vh - var(--title-h)) * var(--ar));
    width: calc((100dvh - var(--title-h)) * var(--ar));
  }
  .actions {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
    min-height: 0;
    padding: 12px 16px;
    gap: 12px;
  }
  .act { font-size: clamp(22px, 5vw, 40px); }
  .sheet { height: 92dvh; }
}
