/* js-3d-modeling preview — dark studio, one accent, system fonts. */

:root {
  --bg: #0b0d10;
  --surface: #12151a;
  --surface-2: #181c22;
  --surface-3: #1f242c;
  --line: #262c35;
  --line-strong: #353d49;
  --text: #e7e9ec;
  --text-dim: #a0a7b2;
  --text-faint: #6d7480;
  --accent: #ff7a1a;
  --accent-ink: #1a0d02;
  --accent-soft: rgba(255, 122, 26, 0.14);
  --danger: #ff6b5e;
  --ok: #5fd39a;

  --rail: 64px;
  --panel: 328px;
  --radius: 8px;
  --radius-sm: 6px;

  --font-ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

a {
  color: inherit;
}

small {
  font-size: inherit;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------------------------------------------------ layout */

.app {
  display: grid;
  grid-template-columns: var(--rail) var(--panel) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.app[data-panel="closed"] {
  grid-template-columns: var(--rail) 0 minmax(0, 1fr);
}

.app[data-panel="closed"] .panel {
  display: none;
}

/* Explicit tracks: hiding the panel must not let the stage slide into its column. */
.rail {
  grid-column: 1;
}

.panel {
  grid-column: 2;
}

.stage {
  grid-column: 3;
}

/* -------------------------------------------------------------------- rail */

.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 14px 0;
  background: var(--bg);
  border-right: 1px solid var(--line);
  z-index: 3;
}

.rail__brand {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  color: var(--accent);
  border-radius: var(--radius);
}

.rail__brand svg {
  width: 26px;
  height: 26px;
}

.rail__tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
}

.rail__tab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 100%;
  padding: 10px 0 9px;
  background: none;
  border: 0;
  color: var(--text-faint);
  font-size: 10.5px;
  line-height: 1.2;
  letter-spacing: 0.02em;
  transition: color 0.15s;
}

.rail__tab svg {
  width: 21px;
  height: 21px;
}

.rail__tab span {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.rail__tab small {
  color: inherit;
  opacity: 0.75;
}

.rail__tab::before {
  content: "";
  position: absolute;
  left: 0;
  top: 9px;
  bottom: 9px;
  width: 2px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
  opacity: 0;
  transition: opacity 0.15s;
}

@media (hover: hover) {
  .rail__tab:hover {
    color: var(--text-dim);
  }
}

.rail__tab[aria-selected="true"] {
  color: var(--text);
}

.rail__tab[aria-selected="true"]::before {
  opacity: 1;
}

/* ------------------------------------------------------------------- panel */

.panel {
  position: relative;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 2;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.panel__close {
  display: none;
}

.panel__section {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px 20px 28px;
}

.panel__head h2 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.panel__head h2 small,
.field__label small,
.doc summary small {
  margin-left: 6px;
  color: var(--text-faint);
  font-weight: 400;
}

.panel__head p {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
}

code {
  padding: 1px 5px;
  background: var(--surface-3);
  border-radius: 4px;
  font: 12px/1.4 var(--font-mono);
  color: var(--text);
}

/* -------------------------------------------------------------- model list */

.model-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.model-card {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 12px;
  align-items: center;
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.15s, background 0.15s;
}

@media (hover: hover) {
  .model-card:hover {
    border-color: var(--line-strong);
  }
}

.model-card[aria-checked="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.model-card__tag {
  grid-row: span 2;
  min-width: 46px;
  padding: 4px 6px;
  text-align: center;
  font: 600 11px/1.3 var(--font-mono);
  letter-spacing: 0.04em;
  color: var(--text-dim);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
}

.model-card[aria-checked="true"] .model-card__tag {
  color: var(--accent);
  border-color: var(--accent);
}

.model-card__name {
  font-weight: 600;
  font-size: 14px;
}

.model-card__name small {
  margin-left: 8px;
  color: var(--text-dim);
  font-weight: 400;
}

.model-card__summary {
  color: var(--text-faint);
  font-size: 12px;
}

/* ------------------------------------------------------------------ fields */

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.field__label small {
  letter-spacing: 0.02em;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.segmented button {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 44px;
  justify-content: center;
  padding: 5px 4px;
  background: none;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.25;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}

.segmented button small {
  font-size: 11px;
  color: var(--text-faint);
}

@media (hover: hover) {
  .segmented button:hover {
    color: var(--text);
  }
}

.segmented button[aria-checked="true"] {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line-strong);
}

.segmented button[aria-checked="true"] small {
  color: var(--accent);
}

.switches {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 8px 12px 8px 14px;
  background: var(--surface-2);
  border: 0;
  border-top: 1px solid var(--line);
  text-align: left;
}

.switch:first-child {
  border-top: 0;
}

.switch__text small {
  margin-left: 6px;
  color: var(--text-faint);
}

.switch__knob {
  position: relative;
  flex: none;
  width: 34px;
  height: 20px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  transition: background 0.15s, border-color 0.15s;
}

.switch__knob::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform 0.15s, background 0.15s;
}

.switch[aria-checked="true"] .switch__knob {
  background: var(--accent);
  border-color: var(--accent);
}

.switch[aria-checked="true"] .switch__knob::after {
  transform: translateX(14px);
  background: var(--accent-ink);
}

.actions {
  display: flex;
  gap: 8px;
}

.button {
  flex: 1;
  min-height: 40px;
  padding: 8px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
}

.button small {
  display: inline-block;
  margin-left: 4px;
  white-space: nowrap;
  color: var(--text-faint);
  font-weight: 400;
}

@media (hover: hover) {
  .button:hover {
    background: var(--surface-3);
  }
}

.button--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.button--primary small {
  color: inherit;
  opacity: 0.7;
}

@media (hover: hover) {
  .button--primary:hover {
    background: #ff8b36;
  }
}

.button[disabled] {
  opacity: 0.55;
  cursor: progress;
}

/* ----------------------------------------------------------- module loader */

.loader {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.code-input,
.text-input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  /* 16px keeps iOS Safari from zooming the page on focus. */
  font: 16px/1.45 var(--font-mono);
}

.code-input {
  min-height: 200px;
  resize: vertical;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

@media (min-width: 761px) {
  .code-input,
  .text-input {
    font-size: 12px;
  }
}

.code-input:focus,
.text-input:focus {
  outline: none;
  border-color: var(--accent);
}

.hint {
  margin: 0;
  color: var(--text-faint);
  font-size: 12px;
}

.notice {
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 12.5px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.notice strong {
  display: block;
  margin-bottom: 2px;
  font-weight: 600;
}

.notice--error {
  background: rgba(255, 107, 94, 0.1);
  border: 1px solid rgba(255, 107, 94, 0.45);
  color: #ffb4ac;
}

.notice--ok {
  background: rgba(95, 211, 154, 0.08);
  border: 1px solid rgba(95, 211, 154, 0.35);
  color: #a6e8c6;
}

.doc {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.doc summary {
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.doc p {
  margin: 0;
  padding: 0 12px 12px;
  color: var(--text-dim);
  font-size: 12.5px;
}

.doc__code {
  margin: 0 12px 12px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font: 11.5px/1.5 var(--font-mono);
  color: var(--text-dim);
  overflow-x: auto;
  tab-size: 2;
}

/* ------------------------------------------------------------------- about */

.keys {
  display: flex;
  flex-direction: column;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.keys > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 12px;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.keys > div:first-child {
  border-top: 0;
}

.keys dt small {
  margin-left: 6px;
  color: var(--text-faint);
}

.keys dd {
  margin: 0;
  color: var(--text-dim);
}

.prose {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
}

.links {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
}

.links a {
  color: var(--accent);
  text-decoration: none;
}

@media (hover: hover) {
  .links a:hover {
    text-decoration: underline;
  }
}

.links small {
  margin-left: 6px;
  color: var(--text-faint);
}

/* ------------------------------------------------------------------- stage */

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #101318;
}

/* Checkerboard shows through the canvas only when the background is transparent. */
.stage[data-background="grid"] {
  background-color: #14171c;
  background-image: linear-gradient(45deg, #1b1f26 25%, transparent 25%, transparent 75%, #1b1f26 75%),
    linear-gradient(45deg, #1b1f26 25%, transparent 25%, transparent 75%, #1b1f26 75%);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
}

.stage__canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  outline-offset: -2px;
  cursor: grab;
}

.stage__canvas:active {
  cursor: grabbing;
}

/* Model-name plate: the signature element. */
.plate {
  position: absolute;
  left: 28px;
  bottom: 26px;
  max-width: min(460px, calc(100% - 110px));
  pointer-events: none;
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.55);
}

.plate__meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.plate__tag {
  padding: 3px 8px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--accent);
  font: 600 11px/1.3 var(--font-mono);
  letter-spacing: 0.08em;
  text-shadow: none;
}

.plate__index {
  color: var(--text-faint);
  font: 11px/1.3 var(--font-mono);
  letter-spacing: 0.1em;
}

.plate__name {
  margin: 0;
  font-size: clamp(24px, 3.2vw, 38px);
  font-weight: 650;
  line-height: 1.08;
  letter-spacing: -0.022em;
}

.plate__zh {
  margin-top: 6px;
  color: var(--text-dim);
  font-size: clamp(14px, 1.5vw, 17px);
  letter-spacing: 0.14em;
}

.plate__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 22px;
  margin: 16px 0 0;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  position: relative;
}

.plate__stats::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 0;
  width: 44px;
  height: 1px;
  background: var(--accent);
}

.plate__stats dt {
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.plate__stats dt small {
  margin-left: 4px;
  font-weight: 400;
  letter-spacing: 0.04em;
}

.plate__stats dd {
  margin: 1px 0 0;
  font: 500 15px/1.3 var(--font-mono);
  font-variant-numeric: tabular-nums;
}

body[data-state="loading"] .plate__name,
body[data-state="loading"] .plate__zh {
  opacity: 0.55;
}

/* Quick controls */
.dock {
  position: absolute;
  right: 18px;
  bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
  background: rgba(18, 21, 26, 0.82);
  border: 1px solid var(--line);
  border-radius: 12px;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.dock__button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  background: none;
  border: 0;
  border-radius: var(--radius);
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}

.dock__button svg {
  width: 20px;
  height: 20px;
}

@media (hover: hover) {
  .dock__button:hover {
    background: var(--surface-3);
    color: var(--text);
  }
}

.dock__button[aria-pressed="true"] {
  color: var(--accent);
  background: var(--accent-soft);
}

.dock__rule {
  height: 1px;
  margin: 3px 6px;
  background: var(--line);
}

.toast {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(520px, calc(100% - 32px));
  padding: 9px 14px;
  background: rgba(18, 21, 26, 0.94);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
  overflow-wrap: anywhere;
}

.toast[data-kind="error"] {
  border-color: rgba(255, 107, 94, 0.6);
  color: #ffb4ac;
}

.fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
  z-index: 5;
}

.fallback__box {
  max-width: 420px;
  padding: 22px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.fallback__box h2 {
  margin: 0 0 8px;
  font-size: 17px;
}

.fallback__box p {
  margin: 0 0 6px;
  color: var(--text-dim);
  font-size: 13px;
}

/* ------------------------------------------------------------------ mobile */

@media (max-width: 760px) {
  :root {
    --rail-h: calc(58px + var(--safe-bottom));
  }

  /* Stage on top, the panel as a sheet under it, tab bar at the bottom.
     The sheet is in flow, so the stage shrinks and the model stays in view. */
  .app,
  .app[data-panel="closed"] {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto var(--rail-h);
  }

  .stage {
    grid-row: 1;
    grid-column: 1;
  }

  .rail {
    grid-row: 3;
    grid-column: 1;
    flex-direction: row;
    gap: 0;
    padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .rail__brand {
    display: none;
  }

  .rail__tabs {
    flex-direction: row;
    gap: 0;
    height: 100%;
  }

  .rail__tab {
    flex: 1;
    justify-content: center;
    gap: 3px;
    padding: 6px 0;
  }

  .rail__tab span {
    flex-direction: row;
    gap: 4px;
  }

  .rail__tab::before {
    left: 22%;
    right: 22%;
    top: 0;
    bottom: auto;
    width: auto;
    height: 2px;
    border-radius: 0 0 2px 2px;
  }

  .panel {
    grid-row: 2;
    grid-column: 1;
    max-height: min(54vh, calc(100vh - var(--rail-h) - 250px));
    max-height: min(54dvh, calc(100dvh - var(--rail-h) - 250px));
    border-right: 0;
    border-top: 1px solid var(--line-strong);
  }

  /* With the sheet open the stage is short: keep only the name on the plate. */
  .app:not([data-panel="closed"]) .plate__zh,
  .app:not([data-panel="closed"]) .plate__stats {
    display: none;
  }

  .app:not([data-panel="closed"]) .plate__name {
    font-size: 20px;
  }

  .panel__close {
    position: absolute;
    top: 12px;
    right: 12px;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 50%;
    color: var(--text-dim);
    z-index: 1;
  }

  .panel__close svg {
    width: 16px;
    height: 16px;
  }

  .panel__section {
    gap: 16px;
    padding: 18px 16px 22px;
  }

  .panel__head {
    padding-right: 44px;
  }

  .plate {
    left: 16px;
    bottom: 14px;
    max-width: calc(100% - 84px);
  }

  .plate__meta {
    margin-bottom: 7px;
  }

  .plate__zh {
    margin-top: 4px;
  }

  .plate__stats {
    gap: 4px 16px;
    margin-top: 11px;
    padding-top: 9px;
  }

  .plate__stats dd {
    font-size: 13px;
  }

  .plate__stats dt small {
    display: none;
  }

  .dock {
    right: 10px;
    bottom: auto;
    top: 12px;
  }

  .toast {
    top: 12px;
    left: 12px;
    right: 64px;
    transform: none;
    max-width: none;
  }
}

@media (max-height: 480px) and (min-width: 761px) {
  .plate__stats {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
