/* 3D models of things on shelves (web/js/item-model.js): View in 3D on an
   item's photos, the owner's 3D Model panel, the capture steps and the viewer. */

/* ---------------------------------------------------------- on the item's sheet */
.kit-sheet-3d {
  position: absolute; right: 12px; bottom: 12px; z-index: 3;
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 34px; padding: 0 13px;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent); border-radius: var(--radius-pill);
  font: inherit; font-size: 12.5px; font-weight: 650; color: #fff; cursor: pointer;
  background: rgba(8, 10, 14, .66);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .05), 0 6px 18px rgba(0, 0, 0, .35);
  transition: background var(--t-1) var(--ease-out), transform var(--t-1) var(--ease-out);
}
.kit-sheet-3d:hover { background: color-mix(in srgb, var(--accent) 30%, rgba(8, 10, 14, .7)); }
.kit-sheet-3d:active { transform: translateY(1px); }
.kit-sheet-3d:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.kit-sheet-3d .ico { display: grid; line-height: 0; color: var(--accent); }
/* Clear of the photo dots, when there are some. */
.kit-sheet-media:has(.kit-sheet-dots) .kit-sheet-3d { bottom: 40px; }
/* No photos, but a 3D capture: its first frame in their place. */
.kit-sheet-poster { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.kit-sheet-media.has-poster .kit-sheet-ph { display: none; }

/* ---------------------------------------------------------- on the shelf's tiles */
.kit-grid-3d {
  position: absolute; top: 8px; right: 8px; z-index: 1;
  display: inline-flex; align-items: center; height: 21px; padding: 0 8px; border-radius: var(--radius-pill);
  font-size: 10.5px; font-weight: 800; letter-spacing: .06em; color: #fff;
  background: rgba(8, 10, 14, .74); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 70%, transparent);
}
.cab-plate-chip.cab-plate-3d { --chip: var(--accent); }
.cab-plate-chip.cab-plate-3d + .cab-plate-part::before { content: "·"; padding: 0 .38em; }

/* ---------------------------------------------------------- the panel and the capture */
.modal.modal-model-panel { width: min(540px, 100%); }
.im-dialog .ico { display: inline-grid; line-height: 0; }
.im-dialog .btn .ico { margin-right: 2px; }
.im-panel, .im-capture { gap: 14px; }

.im-poster {
  position: relative; display: block; width: 100%; aspect-ratio: 4 / 3; padding: 0; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
  background: radial-gradient(90% 70% at 50% 35%, #1a1e27, #090b0f 80%);
}
.im-poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.im-poster-ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-3); }
.im-poster-go {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px;
  border-radius: var(--radius-pill); font-weight: 700; font-size: 14px; color: #fff;
  background: rgba(8, 10, 14, .7); border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.im-poster-go .ico { color: var(--accent); }
.im-poster:hover .im-poster-go { background: color-mix(in srgb, var(--accent) 30%, rgba(8, 10, 14, .75)); }
.im-poster:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.im-meta, .im-limit { margin: 0; color: var(--ink-2); font-size: var(--fs-sm); }
.im-note { margin: 0; color: var(--ink-3); font-size: 12.5px; line-height: 1.45; }
.im-failed {
  margin: 0; padding: 10px 12px; border-radius: var(--radius-sm); font-size: var(--fs-sm); line-height: 1.45;
  color: var(--ink); background: color-mix(in srgb, var(--danger, #f87171) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger, #f87171) 40%, transparent);
}
.im-empty { display: grid; justify-items: center; gap: 8px; padding: 18px 8px 6px; text-align: center; color: var(--ink-2); }
.im-empty .ico { color: var(--accent); }
.im-empty .ico svg { width: 40px; height: 40px; }
.im-empty p { margin: 0; max-width: 40ch; line-height: 1.5; }
.im-open {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-3);
}
.im-open strong { display: block; margin-bottom: 2px; }
.im-open p { margin: 0; color: var(--ink-2); font-size: var(--fs-sm); line-height: 1.45; }
.im-spin {
  flex: none; width: 18px; height: 18px; margin-top: 1px; border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent) 25%, transparent); border-top-color: var(--accent);
  animation: im-spin 0.9s linear infinite;
}
@keyframes im-spin { to { transform: rotate(360deg); } }
:root[data-motion="reduced"] .im-spin,
:root[data-motion="off"] .im-spin { animation: none; }
.im-dialog .modal-foot .im-delete { margin-right: auto; }

.im-tips { margin: 0; padding-left: 20px; display: grid; gap: 8px; color: var(--ink-2); font-size: var(--fs-sm); line-height: 1.5; }
.im-tips strong { color: var(--ink); }
/* As many side by side as there are (the camera one only where there is a camera). */
.im-choices { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 10px; }
.im-choice {
  display: grid; justify-items: center; gap: 4px; padding: 16px 10px; min-height: 104px;
  border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
  font: inherit; color: var(--ink); text-align: center; background: var(--bg-3);
  transition: border-color var(--t-1) var(--ease-out), background var(--t-1) var(--ease-out);
}
.im-choice .ico { color: var(--accent); margin-bottom: 2px; }
.im-choice strong { font-size: 14px; }
.im-choice small { color: var(--ink-3); font-size: 12px; }
.im-choice:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); background: color-mix(in srgb, var(--accent) 7%, var(--bg-3)); }
.im-choice:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.im-capture .sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* The camera, with a ring to keep the thing in the middle of. */
.im-camera-wrap {
  position: relative; overflow: hidden; aspect-ratio: 3 / 4; max-height: 56vh; margin: 0 auto; width: 100%;
  border-radius: var(--radius); background: #000;
}
.im-camera { width: 100%; height: 100%; object-fit: cover; display: block; }
.im-ring {
  position: absolute; left: 50%; top: 50%; width: 62%; aspect-ratio: 1; transform: translate(-50%, -50%);
  border: 2px dashed rgba(255, 255, 255, .45); border-radius: 50%; pointer-events: none;
}
.im-count {
  position: absolute; left: 10px; top: 10px; padding: 3px 10px; border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums; color: #fff; background: rgba(8, 10, 14, .62);
}
.im-camera-wrap.is-flash::after {
  content: ''; position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none;
  animation: im-flash 260ms ease-out;
}
@keyframes im-flash { from { opacity: .45; } }
:root[data-motion="off"] .im-camera-wrap.is-flash::after { animation: none; }
.im-hint { margin: 0; color: var(--ink-2); font-size: 12.5px; line-height: 1.45; text-align: center; }
.im-camera-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.im-camera-bar > :first-child { justify-self: start; }
.im-camera-bar > :last-child { justify-self: end; }
.im-shutter {
  width: 64px; height: 64px; border-radius: 50%; cursor: pointer; padding: 0;
  border: 4px solid #fff; background: color-mix(in srgb, var(--accent) 70%, #fff);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
}
.im-shutter:active { transform: scale(.94); }
.im-shutter:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.im-auto.is-on { color: var(--accent-ink); background: var(--accent-fill); border-color: var(--accent); }
.im-camera-foot { display: flex; justify-content: flex-end; }

.im-progress { display: grid; gap: 10px; padding: 18px 0 8px; }
.im-bar-text { margin: 0; color: var(--ink-2); font-size: var(--fs-sm); }
.im-bar { height: 8px; border-radius: var(--radius-pill); background: var(--bg-3); border: 1px solid var(--line); overflow: hidden; }
.im-bar-fill { display: block; height: 100%; width: 0; background: var(--accent); transition: width 160ms linear; }
.im-done { display: grid; justify-items: center; gap: 6px; padding: 16px 6px 4px; text-align: center; }
.im-done .ico { color: var(--accent); }
.im-done .ico svg { width: 42px; height: 42px; }
.im-done strong { font-size: 16px; }
.im-done p { margin: 0; color: var(--ink-2); font-size: var(--fs-sm); max-width: 42ch; line-height: 1.5; }
.im-capture .modal-foot.im-row { padding: 0; }

/* ---------------------------------------------------------- the viewer */
.modal.modal-model {
  width: min(1080px, 94vw); height: min(820px, 90vh); max-height: none;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal.modal-model > .im-viewer { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.im-viewer-head { padding: 16px 56px 10px 20px; }
.im-viewer-head h2 { margin: 0 0 3px; font-size: var(--fs-h2); letter-spacing: -0.02em; }
.im-viewer-head p { margin: 0; color: var(--ink-3); font-size: 12.5px; }
.im-stage {
  position: relative; flex: 1; min-height: 0; margin: 0 12px; overflow: hidden; touch-action: none;
  border-radius: var(--radius); border: 1px solid var(--line);
  background: radial-gradient(90% 75% at 50% 40%, #20242e, #07080b 85%);
  -webkit-user-select: none; user-select: none;
}
.im-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
.im-stage canvas:active { cursor: grabbing; }
.im-status { margin: 0; padding: 10px 20px 0; color: var(--ink-2); font-size: var(--fs-sm); }
.im-status.is-error { color: var(--danger, #f87171); }
.im-viewer-foot { display: flex; align-items: center; gap: 12px; padding: 10px 20px 14px; }
.im-viewer-foot > :first-child { flex: 1; min-width: 0; }
.im-viewer-foot .btn .ico { display: inline-grid; line-height: 0; margin-right: 4px; }

/* A phone: the viewer is the whole screen. */
@media (max-width: 640px) {
  .modal.modal-model { position: fixed; inset: 0; width: auto; height: auto; border-radius: 0; border: none; }
  .im-stage { margin: 0; border-radius: 0; border-left: none; border-right: none; }
  .im-viewer-head { padding: calc(12px + env(safe-area-inset-top, 0px)) 56px 8px 16px; }
  .im-viewer-foot { padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px)); }
  .im-camera-wrap { max-height: 48vh; }
}

/* A narrow screen: the ways to capture, one under another. */
@media (max-width: 520px) {
  .im-choices { grid-auto-flow: row; grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .im-choice {
    grid-template-columns: auto minmax(0, 1fr); justify-items: start; align-items: center;
    column-gap: 12px; row-gap: 1px; min-height: 0; padding: 12px 14px; text-align: left;
  }
  .im-choice .ico { grid-row: span 2; margin: 0; }
}

/* A narrow cabinet keeps its plates to the name and the value (cabinet.css); the 3D chip stays too. */
@container cab (max-width: 640px) {
  .cab-plate .cab-plate-part.cab-plate-3d { display: inline-block; flex: none; margin-left: .4em; }
  .cab-plate .cab-plate-part.cab-plate-3d::before { content: none; }
}
