:root {
  color-scheme: dark;
  --bg: #0b0e14;
  --panel: #121722;
  --panel-2: #0e131c;
  --line: #223047;
  --text: #cfe0ff;
  --muted: #7f95c0;
  --accent: #4ea1ff;
  --accent-dim: #1d3a5c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  overflow: hidden;
}

#app { height: 100vh; height: 100dvh; }

/* ---- boot ---- */
.boot {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100vh; height: 100dvh; gap: 16px; color: var(--muted); font: 14px monospace;
}
.loading-progress { width: 64px; height: 64px; }
.loading-progress circle { fill: none; stroke: var(--accent-dim); stroke-width: 6; }
.loading-progress circle:last-child {
  stroke: var(--accent);
  stroke-dasharray: 251;
  stroke-dashoffset: calc(251 * (1 - var(--blazor-load-percentage, 0)));
  transition: stroke-dashoffset .2s;
  transform: rotate(-90deg); transform-origin: 50% 50%;
}

/* ---- layout ---- */
.ok-app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.ok-topbar {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #131a27, #0d121b);
  flex: 0 0 auto;
}
.ok-title { font-weight: 650; font-size: 15px; letter-spacing: .2px; }
.ok-sub { color: var(--muted); font-weight: 400; }
.ok-stats { color: var(--muted); font-size: 12.5px; }
.ok-current { color: var(--accent); }
.ok-share {
  flex: 0 0 auto; padding: 5px 9px; border: 1px solid var(--line); border-radius: 8px;
  background: #0a0e15; color: var(--muted); cursor: pointer; font-size: 13px; line-height: 1;
}
@media (hover: hover) { .ok-share:hover { color: var(--text); border-color: var(--accent); } }

.ok-body { display: flex; flex: 1 1 auto; min-height: 0; }

/* ---- sidebar ---- */
.ok-sidebar {
  width: 300px; flex: 0 0 300px; display: flex; flex-direction: column;
  border-right: 1px solid var(--line); background: var(--panel-2); min-height: 0;
}
.ok-search {
  margin: 10px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: #0a0e15; color: var(--text);
  font-size: 13px; outline: none;
}
.ok-search:focus { border-color: var(--accent); }
.ok-list { flex: 1 1 auto; overflow-y: auto; padding: 0 6px 12px; }

.ok-group { margin-bottom: 2px; }
.ok-group-head {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; background: transparent; border: 0; cursor: pointer;
  color: var(--text); font-size: 12.5px; text-transform: uppercase; letter-spacing: .4px;
  border-radius: 6px;
}
@media (hover: hover) { .ok-group-head:hover { background: #16202f; } }
.ok-caret { color: var(--muted); width: 12px; }
.ok-cat { flex: 1 1 auto; text-align: left; font-weight: 600; }
.ok-count { color: var(--muted); font-size: 11px; }

.ok-items { display: flex; flex-direction: column; padding: 2px 0 6px 8px; }
.ok-item {
  text-align: left; padding: 5px 10px; margin: 1px 0; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer; font-size: 13px;
}
@media (hover: hover) { .ok-item:hover { background: #16202f; color: var(--text); } }
.ok-active { background: var(--accent-dim); color: #eaf3ff; font-weight: 600; }

.ok-empty { padding: 16px; color: var(--muted); font-size: 13px; }

/* ---- viewport ---- */
.ok-viewport { position: relative; flex: 1 1 auto; min-width: 0; background: radial-gradient(circle at 50% 40%, #131b28, #080b11 70%); }
#ok-canvas { width: 100%; height: 100%; display: block; }
.ok-overlay {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  color: var(--muted); font: 13px monospace; pointer-events: none;
}
.ok-help {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  color: var(--muted); font-size: 11.5px; opacity: .7; pointer-events: none;
  text-align: center; max-width: 92%;
}

/* ---- sidebar filter (surfaces the animated/"Moving" catalog) ---- */
.ok-filter { display: flex; gap: 4px; margin: 0 10px 6px; }
.ok-fbtn {
  flex: 1 1 0; padding: 6px 4px; border: 1px solid var(--line); border-radius: 7px;
  background: #0a0e15; color: var(--muted); cursor: pointer; font-size: 11.5px; white-space: nowrap;
}
@media (hover: hover) { .ok-fbtn:hover { color: var(--text); border-color: var(--accent-dim); } }
.ok-fon { background: var(--accent-dim); color: #eaf3ff; border-color: var(--accent); font-weight: 600; }

/* ---- viewport controls (size / rotate / animation) ---- */
.ok-controls {
  position: absolute; top: 10px; left: 10px; right: 10px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: rgba(14, 19, 28, .82); backdrop-filter: blur(6px);
  font-size: 12.5px; color: var(--text); z-index: 5;
}
.ok-ctl { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.ok-ctl input[type=range] { width: 108px; accent-color: var(--accent); cursor: pointer; }
.ok-ctl input[type=checkbox] { accent-color: var(--accent); cursor: pointer; }
.ok-ctl-val { color: var(--text); font-variant-numeric: tabular-nums; min-width: 30px; }
.ok-ctl-check { cursor: pointer; }
.ok-ctl-btn {
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 7px;
  background: #0a0e15; color: var(--text); cursor: pointer; font-size: 12.5px;
}
@media (hover: hover) { .ok-ctl-btn:hover { border-color: var(--accent); } }
.ok-ctl-play { border-color: var(--accent-dim); font-weight: 600; }
.ok-ctl-sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 2px; }

/* ---- per-part parameter panel (parametric models) ---- */
.ok-params {
  position: absolute; top: 62px; left: 10px; width: 236px; max-height: calc(100% - 96px);
  overflow-y: auto; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: rgba(14, 19, 28, .88); backdrop-filter: blur(6px); z-index: 5;
}
.ok-params-title { font-size: 12px; font-weight: 650; color: var(--accent); margin-bottom: 8px; }
.ok-pctl { display: grid; grid-template-columns: 78px 1fr 34px; align-items: center; gap: 6px; margin: 6px 0; }
.ok-plabel { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ok-pctl input[type=range] { width: 100%; accent-color: var(--accent); cursor: pointer; }
.ok-pval { color: var(--text); font-size: 11.5px; font-variant-numeric: tabular-nums; text-align: right; }

/* ---- per-part customization panel (show/hide + recolor) — mirrors ok-params on the right ---- */
.ok-parts {
  position: absolute; top: 62px; right: 10px; width: 244px; max-height: calc(100% - 96px);
  overflow-y: auto; border: 1px solid var(--line); border-radius: 10px;
  background: rgba(14, 19, 28, .88); backdrop-filter: blur(6px); z-index: 5;
}
.ok-parts-head {
  display: flex; align-items: center; gap: 6px; width: 100%; padding: 10px 12px;
  border: 0; background: transparent; color: var(--accent); font-size: 12px; font-weight: 650;
  cursor: pointer; text-align: left;
}
.ok-parts-list { padding: 0 12px 4px; }
.ok-part { display: grid; grid-template-columns: 22px 36px 1fr; align-items: center; gap: 8px; margin: 5px 0; }
.ok-part input[type=checkbox] { accent-color: var(--accent); cursor: pointer; }
.ok-part-col {
  width: 36px; height: 22px; padding: 0; border: 1px solid var(--line); border-radius: 5px;
  background: none; cursor: pointer;
}
.ok-part-label { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ok-part-tris { color: var(--muted); opacity: .72; font-variant-numeric: tabular-nums; }
.ok-parts-actions { display: flex; gap: 6px; padding: 6px 12px 10px; flex-wrap: wrap; }
.ok-parts-actions .ok-ctl-btn { flex: 1 1 auto; }
.ok-parts-msg { padding: 0 12px 10px; color: var(--muted); font-size: 11px; }

/* ---- top nav ---- */
.ok-title { cursor: pointer; }
.ok-nav { display: flex; gap: 6px; }
.ok-navbtn {
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: #0a0e15; color: var(--muted); cursor: pointer; font-size: 12.5px;
}
@media (hover: hover) { .ok-navbtn:hover { color: var(--text); border-color: var(--accent-dim); } }
.ok-navon { background: var(--accent-dim); color: #eaf3ff; border-color: var(--accent); font-weight: 600; }

/* ---- splash ---- */
.ok-splash {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 40px 24px 60px;
  display: flex; flex-direction: column; align-items: center; gap: 34px;
  background: radial-gradient(circle at 50% 0%, #16203040, transparent 60%);
}
.ok-splash-hero { max-width: 780px; text-align: center; display: flex; flex-direction: column; gap: 18px; align-items: center; }
.ok-splash-title { font-size: 52px; font-weight: 800; letter-spacing: -1px; margin: 8px 0 0; line-height: 1.05; text-wrap: balance; }
.ok-splash-title span { color: var(--accent); }
.ok-splash-tag { color: var(--muted); font-size: 16px; line-height: 1.6; max-width: 640px; margin: 0; text-wrap: pretty; }
.ok-splash-actions { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.ok-cta {
  padding: 12px 26px; border-radius: 10px; border: 1px solid var(--accent);
  background: var(--accent); color: #04101f; font-size: 15px; font-weight: 650; cursor: pointer;
}
@media (hover: hover) { .ok-cta:hover { filter: brightness(1.08); } }
.ok-cta2 { background: transparent; color: var(--accent); }
@media (hover: hover) { .ok-cta2:hover { background: var(--accent-dim); color: #eaf3ff; } }
.ok-splash-stats { display: flex; gap: 30px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }
.ok-splash-stats div { display: flex; flex-direction: column; align-items: center; }
.ok-splash-stats b { font-size: 26px; color: var(--text); font-variant-numeric: tabular-nums; }
.ok-splash-stats span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.ok-splash-showcase {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px; width: 100%; max-width: 980px;
}
.ok-show-card {
  display: flex; flex-direction: column; gap: 6px; padding: 8px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text);
  transition: border-color .12s, transform .12s;
}
@media (hover: hover) { .ok-show-card:hover { border-color: var(--accent); transform: translateY(-2px); } }
.ok-show-card img { width: 100%; aspect-ratio: 1; border-radius: 8px; background: #0a0e15; object-fit: contain; }
.ok-show-card span { font-size: 12.5px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- splash footer / "how it works" note (a real, specific voice, not filler) ---- */
.ok-colophon {
  max-width: 640px; margin: 6px auto 0; text-align: center;
  color: var(--muted); font-size: 13px; line-height: 1.65; text-wrap: pretty;
}
.ok-colophon b { color: var(--text); font-weight: 600; }
.ok-colophon code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; color: var(--accent);
  background: #0a0e15; border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px;
}

/* ---- gallery ---- */
.ok-gallery { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.ok-gallery-bar {
  display: flex; align-items: center; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line);
  flex: 0 0 auto; flex-wrap: wrap;
}
.ok-gsearch { flex: 1 1 240px; margin: 0; }
.ok-pager { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.ok-pager button {
  padding: 6px 14px; border: 1px solid var(--line); border-radius: 8px; background: #0a0e15;
  color: var(--text); cursor: pointer; font-size: 13px;
}
@media (hover: hover) { .ok-pager button:hover:not(:disabled) { border-color: var(--accent); } }
.ok-pager button:disabled { opacity: .4; cursor: default; }
.ok-grid {
  flex: 1 1 auto; overflow-y: auto; padding: 16px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(116px, 1fr)); gap: 12px; align-content: start;
}
.ok-tile {
  display: flex; flex-direction: column; gap: 4px; padding: 6px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel); color: var(--muted);
  transition: border-color .1s, transform .1s;
}
@media (hover: hover) { .ok-tile:hover { border-color: var(--accent); color: var(--text); transform: translateY(-2px); } }
.ok-tile img { width: 100%; aspect-ratio: 1; border-radius: 6px; background: #0a0e15; object-fit: contain; }
.ok-tile-name { font-size: 11px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ok-thumb-ph {
  width: 100%; aspect-ratio: 1; border-radius: 6px; background: #0a0e15; display: flex;
  align-items: center; justify-content: center; color: var(--muted); font-size: 18px;
}

@media (max-width: 720px) {
  .ok-splash-title { font-size: 38px; }
  .ok-nav { gap: 3px; }
  .ok-navbtn { padding: 5px 8px; font-size: 11px; }
  .ok-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; padding: 10px; }
}

/* ---- blazor error ---- */
#blazor-error-ui {
  display: none; position: fixed; bottom: 0; left: 0; right: 0;
  background: #7a1f1f; color: #fff; padding: 10px 16px; font-size: 13px; z-index: 1000;
}
#blazor-error-ui .reload { color: #ffd; margin-left: 8px; }
#blazor-error-ui .dismiss { cursor: pointer; float: right; }

/* ---- mobile viewer rework: off-canvas drawer + bottom sheet (desktop defaults) ---- */
.ok-backdrop { display: none; }
.ok-sheet { display: contents; }         /* desktop: controls/params keep their own absolute positioning */
.ok-mobile-bar { display: none; }
.ok-gcat {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #0a0e15; color: var(--text); font-size: 13px; max-width: 240px; cursor: pointer;
}

@media (max-width: 720px) {
  /* compact topbar — drop the subtitle + stats so the title doesn't wrap to four lines */
  .ok-topbar { padding: 8px 10px; gap: 8px; align-items: center; }
  .ok-title { font-size: 15px; line-height: 1.15; }
  .ok-sub { display: none; }
  .ok-stats { display: none; }
  .ok-nav { flex: 0 0 auto; gap: 4px; }
  .ok-navbtn { padding: 7px 9px; font-size: 12px; }

  /* the model list becomes an off-canvas drawer over a full-width canvas */
  .ok-sidebar {
    position: absolute; top: 0; bottom: 0; left: 0; z-index: 30;
    width: 86%; max-width: 340px; flex-basis: auto;
    transform: translateX(-102%); transition: transform .22s ease;
    box-shadow: 3px 0 22px rgba(0, 0, 0, .55);
  }
  .ok-drawer-open .ok-sidebar { transform: translateX(0); }
  .ok-backdrop {
    display: block; position: absolute; inset: 0; z-index: 25;
    background: rgba(0, 0, 0, .55); opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  .ok-drawer-open .ok-backdrop { opacity: 1; pointer-events: auto; }
  .ok-viewport { width: 100%; }

  /* size / ratio / animation controls + parametric sliders → a slide-up bottom sheet */
  /* viewer is a vertical stack: model canvas (flexes) ABOVE the controls sheet, so
     opening the sheet shrinks the canvas and the model re-fits into the space left */
  .ok-viewport { display: flex; flex-direction: column; }
  #ok-canvas { flex: 1 1 auto; height: auto; min-height: 0; }
  .ok-sheet {
    display: block; position: static; flex: 0 0 auto; width: auto; z-index: 18;
    max-height: 0; overflow: hidden; padding: 0 14px;
    background: rgba(10, 14, 21, .98); border-top: 1px solid transparent;
    transition: max-height .24s ease, padding .24s ease, border-color .24s ease;
  }
  .ok-sheet-open { max-height: 52%; overflow-y: auto; padding: 12px 14px 16px; border-top-color: var(--line); }
  .ok-controls {
    position: static; background: transparent; border: 0; backdrop-filter: none;
    padding: 0; flex-direction: column; align-items: stretch; gap: 14px;
  }
  .ok-ctl { justify-content: space-between; }
  .ok-ctl input[type=range] { flex: 1 1 auto; width: auto; margin: 0 8px; }
  .ok-ctl-btn { padding: 9px 0; }
  .ok-ctl-sep { display: none; }
  .ok-params {
    position: static; width: auto; max-height: none; margin-top: 12px; backdrop-filter: none;
    border: 0; border-top: 1px solid var(--line); border-radius: 0; padding: 12px 0 0;
  }
  .ok-pctl { grid-template-columns: 78px 1fr 34px; }
  .ok-parts {
    position: static; width: auto; max-height: none; margin-top: 12px; backdrop-filter: none;
    border: 0; border-top: 1px solid var(--line); border-radius: 0;
  }
  .ok-parts-head { padding: 12px 0 4px; }
  .ok-parts-list { padding: 0; }
  .ok-parts-actions { padding: 6px 0 0; }
  .ok-parts-msg { padding: 6px 0 0; }

  /* bottom action bar — a real flex row at the base of the app column (always on-screen) */
  .ok-mobile-bar {
    display: flex; flex: 0 0 auto; z-index: 22;
    gap: 8px; padding: 7px 10px; padding-bottom: calc(7px + env(safe-area-inset-bottom, 0px));
    background: rgba(10, 14, 21, .98); border-top: 1px solid var(--line);
  }
  .ok-mbtn {
    flex: 1 1 0; padding: 10px 0; border: 1px solid var(--line); border-radius: 8px;
    background: #0a0e15; color: var(--text); font-size: 13.5px; cursor: pointer;
  }
  .ok-mbtn-on { background: var(--accent-dim); border-color: var(--accent); color: #eaf3ff; }
  .ok-help { display: none; }

  .ok-fbtn { font-size: 10.5px; padding: 6px 2px; }
  .ok-gallery-bar { gap: 8px; }
  .ok-gcat { max-width: none; flex: 1 1 140px; }
  .ok-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; padding: 10px; }
}

/* ---- design hardening (mobile-web guide: touch / a11y / motion) ---- */
#ok-canvas { touch-action: none; }
button, .ok-item, .ok-group-head, .ok-tile, .ok-show-card,
.ok-navbtn, .ok-fbtn, .ok-mbtn, .ok-pager button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* 16px inputs avoid iOS focus-zoom */
.ok-search, .ok-gsearch, .ok-gcat { font-size: 16px; }
/* press feedback so touch taps register visibly (<100ms) */
.ok-navbtn:active, .ok-fbtn:active, .ok-item:active, .ok-tile:active, .ok-show-card:active,
.ok-mbtn:active, .ok-ctl-btn:active, .ok-pager button:active, .ok-cta:active { filter: brightness(1.18); }
/* top notch/status-bar inset (viewport-fit=cover) */
.ok-topbar { padding-top: max(10px, env(safe-area-inset-top)); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (pointer: coarse) {
  /* >=44px min hit targets */
  .ok-navbtn { min-height: 44px; }
  .ok-fbtn { min-height: 42px; }
  .ok-item { padding-top: 10px; padding-bottom: 10px; }
  .ok-group-head { padding-top: 11px; padding-bottom: 11px; }
  .ok-pager button { min-height: 44px; }
  .ok-mbtn { min-height: 46px; }
  .ok-ctl input[type=range], .ok-pctl input[type=range] { height: 30px; }
}
