:root {
  --bg: #f4f4f2;
  --panel: #ffffff;
  --ink: #1d1f22;
  --muted: #6b7078;
  --line: #dddcd8;
  --accent: #2f6fdb;
  --ok: #2e9e5b;
  --bad: #c9473b;
  --cell: 220px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a; --panel: #212326; --ink: #e8e8e6; --muted: #9a9ea6;
    --line: #34373b; --accent: #6d9cf0;
  }
}
* { box-sizing: border-box; }
/* the hidden attribute must win over component display rules (flex/grid overlays would block the 3D canvas) */
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 "Segoe UI", "Yu Gothic UI", "Meiryo", system-ui, sans-serif; }

.bar { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between;
  align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.title { display: flex; align-items: baseline; gap: 12px; }
h1 { font-size: 17px; margin: 0; letter-spacing: .02em; }
.count { color: var(--muted); }
.back { color: var(--accent); text-decoration: none; font-size: 13px; }
.plist { list-style: none; margin: 0; padding: 16px; display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.pcard { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  overflow: hidden; color: var(--ink); height: 100%; display: flex; flex-direction: column; }
.pcard:hover, .pitem.sel .pcard { border-color: var(--accent); }
.pcard .plink { display: block; }
.pcard .thumb { aspect-ratio: 4 / 3; background: #9aa0a8; display: block; width: 100%; object-fit: cover; }
.pcard .psel { position: absolute; left: 8px; top: 8px; width: 18px; height: 18px; z-index: 2;
  accent-color: var(--accent); cursor: pointer; }
.pcard .pinfo { padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.pcard .pname { font-weight: 700; overflow-wrap: anywhere; color: var(--ink); text-decoration: none; }
.pcard .pname:hover { color: var(--accent); }
.pcard .pmeta { color: var(--muted); font-size: 12px; }
.pcard .pid { overflow-wrap: anywhere; }
.pcard .pmemo { font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; border-left: 3px solid var(--line);
  padding-left: 6px; margin-top: 2px; }
.pcard .pactions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 8px; }
.running { color: var(--ok); }
.err { color: var(--bad); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px 0; }
.toolbar input[type=search], .toolbar select, dialog input, dialog textarea {
  font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 8px; }
.toolbar input[type=search] { flex: 1 1 220px; min-width: 0; }
.selall { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 4px; }
button.btn { font: inherit; cursor: pointer; }
button.btn:disabled { opacity: .45; cursor: default; }
.btn.sm { padding: 2px 8px; font-size: 12px; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.btn.danger.primary, #dlgok.danger { color: #fff; background: var(--bad); border-color: var(--bad); }
dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--ink);
  width: min(460px, calc(100vw - 32px)); padding: 16px 18px; }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog h2 { font-size: 16px; margin: 0 0 10px; }
dialog textarea { width: 100%; resize: vertical; }
dialog .fl { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; }
dialog .fl.chk { flex-direction: row; align-items: center; gap: 6px; }
.dlglist { max-height: 200px; overflow: auto; margin: 6px 0; padding-left: 20px; }
.dlgbtns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.path { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.btn { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink);
  text-decoration: none; background: var(--panel); }
.btn.on { border-color: var(--accent); color: var(--accent); }
.bridge { padding: 4px 10px; border-radius: 6px; font-size: 13px; color: var(--muted);
  border: 1px solid var(--line); }
.bridge.ok { color: var(--ok); border-color: var(--ok); }
.bridge.bad { color: var(--bad); border-color: var(--bad); }

.sheet { padding: 0 16px 40px; }
.row { display: grid; grid-template-columns: 150px repeat(var(--ncol, 4), minmax(0, 1fr));
  gap: 8px; align-items: stretch; padding: 8px 0; border-bottom: 1px solid var(--line); }
.row.head { position: sticky; top: var(--bar-h, 50px); z-index: 4; background: var(--bg); padding: 6px 0;
  color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .08em; }
@media (max-width: 720px) {
  .row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row .meta { grid-column: 1 / -1; }
  .row.head { display: none; }
}
.vh { text-align: center; }
.meta { font-size: 12px; }
.mid { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; margin-bottom: 4px; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 1px 8px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 600; }
.sub { color: var(--muted); margin-top: 4px; }
.warn { color: var(--bad); margin-top: 4px; font-weight: 600; }

.cell { position: relative; display: block; padding: 0; border: 2px solid transparent;
  border-radius: 6px; overflow: hidden; background: #9aa0a8; cursor: pointer; aspect-ratio: 4 / 3; }
.cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cell:hover { border-color: var(--accent); }
.cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sheet[style*="--ncol: 1"] .row, .sheet[style*="--ncol: 2"] .row { max-width: 900px; }
.cell .tag { position: absolute; left: 6px; top: 6px; font-size: 11px; padding: 1px 6px;
  border-radius: 4px; background: rgba(0,0,0,.45); color: #fff; letter-spacing: .06em; }
.cell.active { border-color: var(--ok); }
.cell.busy { opacity: .55; cursor: progress; }
.cell.missing { display: flex; align-items: center; justify-content: center; color: var(--bad);
  background: var(--panel); border: 1px dashed var(--line); cursor: default; }

.empty { color: var(--muted); padding: 24px 0; }
.pager { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 16px 24px; }

.toast { position: fixed; right: 16px; bottom: 16px; max-width: min(420px, calc(100vw - 32px));
  padding: 10px 14px; border-radius: 8px; background: var(--ink); color: var(--bg);
  opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--bad); color: #fff; }

/* ---- evaluation-metric map ---- */
dl.metrics { margin-top: 6px; padding-top: 4px; border-top: 1px dashed var(--line); }
.maptools label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.maptools select { min-width: 140px; }
.mapempty { padding: 24px 16px; color: var(--muted); max-width: 720px; }
.mapgrid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; padding: 12px 16px; align-items: start; }
@media (max-width: 900px) { .mapgrid { grid-template-columns: minmax(0, 1fr); } }
.plotbox { position: relative; margin: 0; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; min-width: 0; }
.plotbox svg { display: block; width: 100%; height: auto; touch-action: none; }
.plotbox .hint { color: var(--muted); font-size: 12px; padding: 4px 6px 0; }
#plot .grid line { stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
#plot .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
#plot .axislabel { fill: var(--muted); font-size: 12px; font-weight: 600; }
#plot .dot { fill: var(--accent); stroke: var(--panel); stroke-width: 2; transition: r .08s; }
#plot .dot.hov { stroke: var(--ink); stroke-width: 1.5; }
#plot .dot.sel { stroke: var(--ink); stroke-width: 2.5; }
.tip { position: absolute; z-index: 3; pointer-events: none; background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 12px; line-height: 1.5;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18); width: 220px; font-variant-numeric: tabular-nums; }
.tip img { display: block; width: 100%; border-radius: 4px; margin-bottom: 4px; background: #9aa0a8; }
.detail { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-size: 13px; }
.detail h2 { font-size: 16px; margin: 0 0 8px; }
.detail h3 { font-size: 12px; color: var(--muted); margin: 12px 0 4px; letter-spacing: .06em; }
.detail .dimgs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.detail figure { margin: 0; }
.detail figure img { width: 100%; display: block; border-radius: 4px; background: #9aa0a8; aspect-ratio: 4 / 3; object-fit: cover; }
.detail figcaption { font-size: 11px; color: var(--muted); }
.detail dl { grid-template-columns: auto 1fr; }
.detail .btn { margin-top: 12px; }
.muted { color: var(--muted); }
.tableview { margin: 0 16px 32px; }
.tableview summary { cursor: pointer; color: var(--accent); padding: 6px 0; }
.tableview table { border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; min-width: min(560px, 100%); }
.tableview th, .tableview td { border-bottom: 1px solid var(--line); padding: 4px 10px; text-align: right; }
.tableview th:first-child, .tableview td:first-child { text-align: left; }
.tableview button.th { background: none; border: 0; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; padding: 0; }

/* ---- 3D viewer ---- */
body.viewer-page { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
main.viewer { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 300px; }
@media (max-width: 800px) {
  body.viewer-page { height: auto; overflow: auto; }
  main.viewer { grid-template-columns: minmax(0, 1fr); }
  .stage { height: 70vh; }
}
.stage { position: relative; min-height: 0; overflow: hidden; }
.stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.vtools { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; flex-wrap: wrap; gap: 8px;
  pointer-events: none; }
.vgroup { pointer-events: auto; display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  background: color-mix(in srgb, var(--panel) 88%, transparent); border: 1px solid var(--line);
  border-radius: 8px; padding: 5px 8px; font-size: 12px; }
.vgroup label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.vstatus { position: absolute; left: 12px; bottom: 30px; font-size: 12px; color: var(--muted); }
.vhelp { position: absolute; left: 12px; bottom: 10px; font-size: 11px; color: var(--muted); }
.vempty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center; padding: 24px; color: var(--muted); }
.vempty p { margin: 4px 0; max-width: 460px; }
.vempty .btn { margin-top: 10px; }
main.viewer .detail { border-radius: 0; border-width: 0 0 0 1px; overflow: auto; }
.mid .btn.sm { vertical-align: middle; margin-left: 4px; }

/* ---- 3D column on the contact sheet ---- */
.cell3d { cursor: grab; background: var(--panel); border: 1px solid var(--line); }
.cell3d img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cell3d canvas.live3d { position: absolute; inset: 0; width: 100% !important; height: 100% !important; touch-action: none; }
.cell3d.live { border-color: var(--accent); cursor: grabbing; }
.cell3d .s3d { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px; pointer-events: none; }
.cell3d .open3d { position: absolute; right: 6px; top: 6px; z-index: 2; font-size: 12px; line-height: 1; padding: 3px 6px;
  border-radius: 4px; background: rgba(0,0,0,.45); color: #fff; text-decoration: none; }
.cell3d .open3d:hover { background: var(--accent); }
.cell3d .tag { z-index: 2; }
.mini3d { position: relative; aspect-ratio: 4 / 3; border: 1px solid var(--line); border-radius: 6px; overflow: hidden;
  background: var(--bg); margin-bottom: 8px; cursor: grab; }
.mini3d canvas { width: 100% !important; height: 100% !important; touch-action: none; }
.mini3d .s3d { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; pointer-events: none; }
.mini3d .open3d { position: absolute; right: 6px; top: 6px; font-size: 12px; padding: 3px 6px; border-radius: 4px;
  background: rgba(0,0,0,.45); color: #fff; text-decoration: none; }
.parts3d { display: flex; flex-wrap: wrap; gap: 6px; }

/* ==== contact sheet: model cards with a big "hero" view (feature) or equal columns (grid) ==== */
.sheetbar { row-gap: 8px; }
.sheetbar .title { min-width: 0; }
.sheetbar h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 48vw; }
.sheettools { flex-basis: 100%; padding: 0; gap: 10px; }
.spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: var(--panel); }
.seg > a, .seg > button { font: inherit; font-size: 13px; padding: 4px 11px; border: 0; background: none; color: var(--muted);
  text-decoration: none; cursor: pointer; }
.seg > * + * { border-left: 1px solid var(--line); }
.seg > .on { background: var(--accent); color: #fff; }
.field { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.field select { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 3px 6px; }
.field select:disabled { opacity: .5; }

.sheet.layout-feature, .sheet.layout-grid { padding: 14px 16px 40px; display: flex; flex-direction: column; gap: 14px; }
.mcard { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.mhead { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.mhead .mid { font-size: 20px; margin: 0; letter-spacing: .01em; font-variant-numeric: tabular-nums; }
.mhead .sub { margin: 0; font-size: 12px; }
.mhead .mactions { margin-left: auto; display: inline-flex; gap: 6px; }
.btn.sm.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.apply-btn.busy { opacity: .55; cursor: progress; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 28px; margin-top: 10px; font-size: 13px; }
.facts dl { display: grid; grid-template-columns: auto auto; gap: 2px 12px; margin: 0; align-content: start; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.facts .fh { grid-column: 1 / -1; font-size: 11px; font-weight: 700; letter-spacing: .08em; color: var(--muted);
  text-align: left; border-bottom: 1px solid var(--line); padding-bottom: 2px; margin-bottom: 2px; }
.facts dd.fh { display: none; }
.mcard .warn { margin-top: 6px; }
.mcard .cell { border-radius: 8px; }
.mcard .cell .tag { font-size: 11px; }
.cell3d .hint3d { position: absolute; right: 8px; bottom: 8px; z-index: 2; font-size: 11px; padding: 2px 7px; border-radius: 4px;
  background: rgba(0,0,0,.45); color: #fff; pointer-events: none; opacity: 0; transition: opacity .15s; }
.cell3d:hover .hint3d { opacity: 1; }
.cell3d.live .hint3d { opacity: 0; }

/* feature: hero (3/5) | side (2/5) with the small strip at the bottom */
.layout-feature .mcard { display: grid; grid-template-columns: minmax(0, min(56%, 560px)) minmax(0, 1fr); gap: 18px;
  align-items: stretch; }
.layout-feature .hero > .cell { aspect-ratio: 4 / 3; width: 100%; }
.layout-feature .hero .tag { font-size: 13px; padding: 2px 9px; left: 10px; top: 10px; }
.layout-feature .hero .cell3d { background: var(--bg); }
.layout-feature .mside { display: flex; flex-direction: column; min-width: 0; }
.layout-feature .strip { margin-top: auto; padding-top: 14px; display: grid; gap: 8px;
  grid-template-columns: repeat(min(var(--n, 3), 3), minmax(0, 1fr)); }
.layout-feature .strip .cell { aspect-ratio: 4 / 3; }
.layout-feature .strip .cell:not(.cell3d) { opacity: .92; }
.layout-feature .strip .cell:hover { opacity: 1; }
@media (max-width: 760px) {
  /* one column, still in order of importance: id/values -> big view -> small strip */
  .layout-feature .mcard { display: flex; flex-direction: column; gap: 12px; }
  .layout-feature .mside { display: contents; }
  .layout-feature .mhead { order: 1; }
  .layout-feature .facts { order: 2; margin-top: 0; }
  .layout-feature .mcard .warn { order: 3; }
  .layout-feature .hero { order: 4; }
  .layout-feature .strip { order: 5; margin-top: 0; padding-top: 0; }
}
@media (max-width: 760px) {
  .sheetbar { position: static; } /* the wrapped toolbar would cover a quarter of a phone screen */
}
@media (max-width: 460px) {
  .layout-feature .strip { gap: 6px; } /* stays 3 across: small thumbs keep the big view dominant */
  .mhead .mactions { margin-left: 0; width: 100%; }
  .sheetbar h1 { max-width: 60vw; }
}

/* grid: id + facts on the left, every view the same size on the right (the original contact-sheet rows) */
.layout-grid .mcard { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 14px; padding: 12px; }
.layout-grid .hero { display: none; }
.layout-grid .mside { display: contents; }
.layout-grid .mhead, .layout-grid .facts, .layout-grid .warn { grid-column: 1; }
.layout-grid .mhead .mactions { margin-left: 0; flex-wrap: wrap; }
.layout-grid .facts { flex-direction: column; gap: 8px; }
.layout-grid .strip { grid-column: 2; grid-row: 1 / span 4; display: grid; gap: 8px; align-self: start;
  grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr)); }
.layout-grid .strip .cell { aspect-ratio: 4 / 3; }
@media (max-width: 760px) {
  .layout-grid .mcard { grid-template-columns: minmax(0, 1fr); }
  .layout-grid .strip { grid-column: 1; grid-row: auto; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---- hover to enlarge (sheet.js) ---- */
.layout-feature .hero { position: relative; }
.hero-peek { position: absolute; inset: 0; z-index: 4; border-radius: 8px; overflow: hidden; background: #9aa0a8;
  border: 2px solid var(--accent); opacity: 0; transition: opacity .12s; pointer-events: none; }
.hero-peek.on { opacity: 1; }
.hero-peek img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hero-peek .tag { font-size: 13px; padding: 2px 9px; left: 10px; top: 10px; }
.peek-note { position: absolute; right: 10px; bottom: 10px; font-size: 12px; padding: 2px 8px; border-radius: 4px;
  background: rgba(0,0,0,.5); color: #fff; }
.peek-pop { position: fixed; z-index: 30; pointer-events: none; border-radius: 10px; overflow: hidden; background: #9aa0a8;
  border: 1px solid var(--line); box-shadow: 0 12px 40px rgba(0,0,0,.28); opacity: 0; transform: scale(.98);
  transition: opacity .12s, transform .12s; }
.peek-pop.on { opacity: 1; transform: none; }
.peek-pop img { width: 100%; height: 100%; object-fit: cover; display: block; }
.peek-pop .tag { font-size: 13px; padding: 2px 9px; left: 10px; top: 10px; }
.strip button.cell:hover, .strip button.cell:focus-visible { border-color: var(--accent); }
.hero-peek .tag, .peek-pop .tag { position: absolute; border-radius: 4px; background: rgba(0,0,0,.45); color: #fff;
  letter-spacing: .06em; }

/* ---- read-only export pages ---- */
.sharenav { margin-right: 6px; }
.readonly { font-size: 12px; padding: 3px 9px; border-radius: 6px; border: 1px dashed var(--line); color: var(--muted); }
.sitehome { font-size: 13px; color: var(--muted); text-decoration: none; margin-right: 10px; white-space: nowrap; }
.sitehome:hover { color: var(--accent); }
