/* The gallery of optimized parts: the grid of cards and the 3D viewer dialog. Colors and type come
   from site.css. The stage background uses the same two colors the viewer paints
   (src/browser/viewer/colors.ts THEME_BACKGROUND), so the still picture and the 3D view match. */

.model-note { max-width: 60em; margin: 0 0 28px; padding: 12px 16px; text-wrap: pretty; border: 1px solid var(--filament); border-radius: var(--radius); font-size: .92rem; color: var(--text-2); background: #fff8ef; }
.on-ink .model-note { background: rgba(235, 139, 41, 0.08); color: var(--ink-text-2); }
.on-ink .model-note strong { color: var(--ink-text); }

.model-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px; }
@media (max-width: 1000px) { .model-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) { .model-grid { grid-template-columns: 1fr; gap: 20px; } }

.model-card { display: flex; flex-direction: column; border: 1px solid var(--n-200); border-radius: var(--radius); overflow: hidden; background: var(--n-0); }
.on-ink .model-card { background: var(--navy-900); border-color: var(--ink-line); }
.model-open { position: relative; display: block; background: linear-gradient(#f4f6f9, #e3e7ed); }
.on-ink .model-open { background: linear-gradient(#0d1a2e, #05080d); }
.model-open img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; transition: transform .25s ease; }
.model-open:hover img, .model-open:focus-visible img { transform: scale(1.03); }
.model-open:focus-visible { outline-offset: -3px; }
.model-open-hint { position: absolute; right: 12px; bottom: 12px; padding: 5px 10px; border-radius: 999px; font: 500 .78rem/1.2 var(--font); color: var(--text); background: rgba(255, 255, 255, 0.86); border: 1px solid var(--n-300); }
.on-ink .model-open-hint { color: var(--ink-text); background: rgba(10, 20, 36, 0.78); border-color: rgba(141, 187, 242, 0.3); }
.model-card-body { display: flex; flex: 1; flex-direction: column; align-items: start; gap: 8px; padding: 18px 20px 20px; }
.model-card h2 { font-size: 1.15rem; margin: 0; }
.model-card p { margin: 0; font-size: .92rem; color: var(--text-2); }
.on-ink .model-card p { color: var(--ink-text-2); }
.model-flag { font: 500 .7rem/1 var(--mono); letter-spacing: .06em; text-transform: uppercase; color: #9a4f06; border: 1px solid var(--filament); border-radius: 4px; padding: 4px 6px; }
.on-ink .model-flag { color: var(--filament); }
.model-facts { display: grid; grid-template-columns: auto 1fr; gap: 2px 14px; margin: 4px 0 0; font-size: .84rem; }
.model-facts > div { display: contents; }
.model-facts dt { color: var(--muted); }
.model-facts dd { margin: 0; color: var(--text); font-family: var(--mono); font-size: .8rem; align-self: center; }
.on-ink .model-facts dt { color: var(--ink-muted); }
.on-ink .model-facts dd { color: var(--ink-text); }
.gallery-note { color: var(--text-2); font-size: .88rem; line-height: 1.55; margin: 28px 0 0; max-width: 60em; text-wrap: pretty; }
.on-ink .gallery-note { color: var(--ink-text-2); }

/* The viewer dialog */
.model-viewer { width: min(1180px, calc(100vw - 32px)); height: min(820px, calc(100vh - 32px)); height: min(820px, calc(100dvh - 32px)); max-width: none; max-height: none; padding: 0; border: 0; border-radius: var(--radius-lg); overflow: hidden; background: transparent; box-shadow: 0 30px 80px rgba(5, 8, 13, 0.45); }
.model-viewer::backdrop { background: #05080d; }
.model-viewer-frame { --mv-top: #f4f6f9; --mv-bottom: #e3e7ed; --mv-surface: var(--n-0); --mv-text: var(--text); --mv-text-2: var(--text-2); --mv-line: var(--n-200); --mv-button: var(--n-0); --mv-button-line: var(--n-300); --mv-pressed: var(--blue-600); --mv-pressed-line: var(--blue-600); --mv-pressed-text: #fff; --mv-legend-line: #8c98a8; --mv-legend-shadow: 0 2px 10px rgba(14, 26, 43, 0.18);
  display: flex; flex-direction: column; width: 100%; height: 100%; background: var(--mv-surface); color: var(--mv-text); }
.model-viewer-frame.mv-dark { --mv-surface: var(--navy-900); --mv-text: var(--ink-text); --mv-text-2: var(--ink-text-2); --mv-line: var(--ink-line); --mv-button: var(--navy-850); --mv-button-line: rgba(141, 187, 242, 0.3); --mv-pressed: var(--blue-400); --mv-pressed-line: var(--blue-400); --mv-pressed-text: var(--navy-950); --mv-legend-line: rgba(141, 187, 242, 0.34); --mv-legend-shadow: 0 2px 12px rgba(0, 0, 0, 0.5); }
.model-viewer-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--mv-line); }
.model-viewer-header h2 { margin: 0; font-size: 1.1rem; color: var(--mv-text); }
.model-viewer-stage { position: relative; flex: 1; min-height: 0; background: linear-gradient(var(--mv-top), var(--mv-bottom)); }
.model-viewer-still, .model-viewer-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.model-viewer-still { object-fit: contain; }
.model-viewer-canvas { display: block; opacity: 0; outline-offset: -3px; }
.model-viewer-canvas:focus:not(:focus-visible) { outline: none; }
.model-viewer-frame.is-live .model-viewer-canvas { opacity: 1; }
.model-viewer-frame.is-live .model-viewer-still { visibility: hidden; }
.model-viewer-status { position: absolute; left: 16px; top: 14px; margin: 0; max-width: calc(100% - 32px); font-size: .86rem; color: var(--mv-text-2); }
.model-viewer-status:empty { display: none; }
.model-viewer-frame.is-loading .model-viewer-status::after { content: " …"; }
.model-viewer-legend { position: absolute; left: 16px; bottom: 14px; width: min(300px, calc(100% - 32px)); padding: 10px 12px; border: 1px solid var(--mv-legend-line); border-radius: var(--radius); background: var(--mv-surface); color: var(--mv-text); box-shadow: var(--mv-legend-shadow); pointer-events: none; }
.model-viewer-legend[hidden] { display: none; }
.model-viewer-legend p { margin: 0; }
.mv-legend-title { font-size: .82rem; font-weight: 500; }
.mv-legend-bar { display: block; height: 12px; margin: 7px 0 4px; border-radius: 3px; }
.mv-legend-ticks { display: flex; justify-content: space-between; font: .74rem/1.2 var(--mono); color: var(--mv-text-2); }
.mv-legend-note { margin-top: 6px !important; font-size: .74rem; line-height: 1.35; color: var(--mv-text-2); }
.model-viewer-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 10px 16px; border-top: 1px solid var(--mv-line); }
.mv-group { display: flex; gap: 6px; }
.mv-button { font: 500 .86rem/1 var(--font); color: var(--mv-text); background: var(--mv-button); border: 1px solid var(--mv-button-line); border-radius: 8px; padding: 9px 12px; cursor: pointer; }
.mv-button:hover:not(:disabled) { border-color: var(--mv-pressed-line); }
.mv-button:disabled { opacity: .45; cursor: default; }
.mv-button[aria-pressed="true"] { background: var(--mv-pressed); border-color: var(--mv-pressed-line); color: var(--mv-pressed-text); }
.mv-modes .mv-button:first-child { border-radius: 8px 0 0 8px; }
.mv-modes .mv-button:not(:first-child):not(:last-child) { border-radius: 0; margin-left: -7px; }
.mv-modes .mv-button:last-child { border-radius: 0 8px 8px 0; margin-left: -7px; }
.mv-modes .mv-button[aria-pressed="true"] { position: relative; z-index: 1; }
.mv-help { margin: 0 0 0 auto; font-size: .78rem; color: var(--mv-text-2); }
.model-viewer-frame:not(.is-live) .mv-help { visibility: hidden; }
.model-viewer-frame.is-still .model-viewer-toolbar { display: none; }
.mv-help-touch { display: none; }
@media (pointer: coarse) { .mv-help-mouse { display: none; } .mv-help-touch { display: inline; } }
.model-viewer-frame.is-fullscreen { border-radius: 0; }

/* Phones: the dialog fills the window */
@media (max-width: 620px), (max-height: 520px) {
  .model-viewer { width: 100vw; height: 100vh; height: 100dvh; border-radius: 0; margin: 0; }
  .model-viewer-header { padding: 8px 12px; }
  .model-viewer-toolbar { padding: 8px 12px; gap: 8px; }
  .mv-help { margin-left: 0; flex-basis: 100%; }
  .model-viewer-legend { left: 10px; bottom: 10px; width: min(240px, calc(100% - 20px)); padding: 8px 10px; }
}
@media (max-height: 520px) {
  .model-viewer-header { padding: 4px 12px; }
  .model-viewer-header h2 { font-size: 1rem; }
  .model-viewer-toolbar { padding: 6px 12px; }
  .mv-button { padding: 7px 10px; }
  .mv-help { display: none; }
}
@media (prefers-reduced-motion: reduce) { .model-open img { transition: none; } .model-open:hover img { transform: none; } }
