.viewer-page,
.viewer-page * {
  box-sizing: border-box;
}

.viewer-page {
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 5%, rgba(111, 54, 211, 0.18), transparent 28rem),
    radial-gradient(circle at 82% 25%, rgba(47, 110, 214, 0.12), transparent 31rem),
    #06070b;
  color: #f7f5ff;
}

.viewer-main {
  width: min(1840px, calc(100% - 28px));
  margin: 0 auto;
  padding: 106px 0 36px;
}

.viewer-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  margin-bottom: 18px;
  padding: 24px 28px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(28, 29, 43, 0.96), rgba(18, 19, 29, 0.94));
  box-shadow: 0 20px 58px rgba(0, 0, 0, 0.34);
}

.viewer-kicker {
  margin: 0 0 7px;
  color: #cdb7ff;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.viewer-hero h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 54px);
  line-height: 1;
  letter-spacing: -0.03em;
}

.viewer-hero p:not(.viewer-kicker) {
  max-width: 820px;
  margin: 12px 0 0;
  color: rgba(255, 255, 255, 0.72);
  font-size: 16px;
  line-height: 1.55;
}

.hero-actions,
.toolbar-actions,
.animation-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
}

button,
select,
input {
  font: inherit;
}

.primary-action,
.secondary-action,
.toolbar-actions button,
.animation-actions button {
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 0 15px;
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
  font-weight: 850;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.primary-action {
  border-color: rgba(160, 114, 255, 0.74);
  background: linear-gradient(135deg, #7040c6, #4f2a91);
  box-shadow: 0 10px 24px rgba(70, 33, 140, 0.3);
}

.primary-action:hover,
.secondary-action:hover,
.toolbar-actions button:hover,
.animation-actions button:hover {
  transform: translateY(-1px);
  border-color: rgba(194, 160, 255, 0.72);
  background-color: rgba(127, 77, 221, 0.22);
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none !important;
}

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

.viewer-workspace {
  display: grid;
  grid-template-columns: 260px minmax(440px, 1fr) 280px;
  gap: 14px;
  align-items: stretch;
}

.viewer-panel,
.viewport-card {
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 17px;
  background: rgba(19, 20, 30, 0.94);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.viewer-panel {
  padding: 15px;
}

.drop-zone {
  display: flex;
  min-height: 155px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 7px;
  padding: 18px;
  border: 1px dashed rgba(179, 143, 255, 0.48);
  border-radius: 13px;
  background: rgba(88, 47, 159, 0.12);
  text-align: center;
  cursor: pointer;
  outline: none;
}

.drop-zone:hover,
.drop-zone:focus-visible,
.drop-zone.drag-active {
  border-color: #c7a7ff;
  background: rgba(112, 64, 198, 0.22);
}

.drop-zone strong {
  font-size: 17px;
}

.drop-zone span {
  color: rgba(255, 255, 255, 0.63);
  font-size: 13px;
  line-height: 1.35;
}

.drop-zone small {
  color: #cdb7ff;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.panel-section {
  padding: 16px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.panel-section:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.panel-section h2 {
  margin: 0 0 12px;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.panel-section > label:not(.toggle-row) {
  display: block;
  margin-bottom: 7px;
  color: rgba(255, 255, 255, 0.65);
  font-size: 12px;
  font-weight: 800;
}

.panel-section select,
.panel-section input[type="range"] {
  width: 100%;
}

.panel-section select {
  min-height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 9px;
  padding: 0 10px;
  color: #fff;
  background: #202131;
}

.toggle-row,
.sliders label {
  display: flex !important;
  min-height: 34px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 !important;
  color: rgba(255, 255, 255, 0.82) !important;
  font-size: 13px !important;
  font-weight: 750 !important;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: #8759dd;
}

input[type="color"] {
  width: 42px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 7px;
  padding: 2px;
  background: transparent;
}

input[type="range"] {
  accent-color: #8b5ee0;
}

.sliders output,
.animation-panel output {
  color: #d6c2ff;
  font-variant-numeric: tabular-nums;
}

.viewport-card {
  display: flex;
  min-height: 710px;
  flex-direction: column;
}

.viewport-toolbar,
.viewport-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  background: rgba(23, 24, 35, 0.98);
}

.viewport-toolbar {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.viewport-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.5);
  font-size: 12px;
}

.toolbar-title {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.toolbar-title strong,
.toolbar-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar-title strong {
  font-size: 14px;
}

.toolbar-title span {
  max-width: 620px;
  color: rgba(255, 255, 255, 0.54);
  font-size: 11px;
}

.toolbar-actions button,
.animation-actions button {
  min-height: 36px;
  padding: 0 11px;
  font-size: 12px;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 590px;
  overflow: hidden;
  background: #10111a;
  touch-action: none;
}

#viewer-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
}

.viewport-empty,
.loading-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.viewport-empty {
  color: rgba(255, 255, 255, 0.62);
}

.viewport-empty strong {
  color: #fff;
  font-size: 18px;
}

.viewport-empty span {
  font-size: 12px;
}

.empty-mark {
  display: grid;
  width: 76px;
  height: 76px;
  place-items: center;
  border: 1px solid rgba(190, 156, 255, 0.55);
  border-radius: 22px;
  color: #d8c5ff;
  background: linear-gradient(145deg, rgba(125, 75, 222, 0.32), rgba(36, 38, 59, 0.5));
  box-shadow: inset 0 0 24px rgba(130, 82, 220, 0.18), 0 14px 30px rgba(0, 0, 0, 0.28);
  font-size: 23px;
  font-weight: 950;
  transform: rotate(-7deg);
}

.loading-layer {
  z-index: 4;
  background: rgba(7, 8, 13, 0.72);
  backdrop-filter: blur(5px);
}

.hidden {
  display: none !important;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: #b58cff;
  border-radius: 50%;
  animation: viewer-spin 0.8s linear infinite;
}

@keyframes viewer-spin {
  to { transform: rotate(360deg); }
}

.stat-list {
  display: grid;
  gap: 0;
  margin: 0;
}

.stat-list div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 7px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-list div:last-child {
  border-bottom: 0;
}

.stat-list dt {
  color: rgba(255, 255, 255, 0.5);
  font-size: 12px;
}

.stat-list dd {
  max-width: 60%;
  margin: 0;
  color: #eee7ff;
  text-align: right;
  font-size: 12px;
  font-weight: 850;
  overflow-wrap: anywhere;
  font-variant-numeric: tabular-nums;
}

.animation-actions {
  margin: 10px 0 12px;
}

.animation-actions button {
  flex: 1;
}

.support-note p {
  margin: 0;
  color: rgba(255, 255, 255, 0.55);
  font-size: 12px;
  line-height: 1.55;
}

.viewport-card:fullscreen,
.viewport-card:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  border: 0;
  border-radius: 0;
}

.viewport-card:fullscreen .canvas-wrap,
.viewport-card:-webkit-full-screen .canvas-wrap {
  min-height: 0;
}

.nav-dropdown-menu .nav-tool-link {
  margin-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

@media (max-width: 1240px) {
  .viewer-workspace {
    grid-template-columns: 235px minmax(420px, 1fr);
  }

  .inspector-panel {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1.3fr 1fr 1fr;
    gap: 20px;
  }

  .inspector-panel .panel-section {
    min-width: 0;
    padding: 0;
    border: 0;
  }
}

@media (max-width: 820px) {
  .viewer-main {
    width: calc(100% - 16px);
    padding-top: 82px;
  }

  .viewer-hero {
    align-items: stretch;
    flex-direction: column;
    padding: 20px;
  }

  .hero-actions > button {
    flex: 1 1 140px;
  }

  .viewer-workspace {
    display: flex;
    flex-direction: column;
  }

  .file-panel {
    order: 2;
  }

  .viewport-card {
    order: 1;
    min-height: 560px;
  }

  .inspector-panel {
    order: 3;
    display: block;
  }

  .inspector-panel .panel-section {
    padding: 16px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .canvas-wrap {
    min-height: 450px;
  }

  .viewport-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
  }

  .toolbar-actions button {
    padding: 0 6px;
    font-size: 11px;
  }
}

@media (max-width: 480px) {
  .viewer-hero p:not(.viewer-kicker) {
    font-size: 14px;
  }

  .viewport-card {
    min-height: 500px;
  }

  .canvas-wrap {
    min-height: 385px;
  }

  .viewport-footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .toolbar-actions {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 1.8s;
  }

  .primary-action,
  .secondary-action,
  .toolbar-actions button,
  .animation-actions button {
    transition: none;
  }
}


/* v191: JS-assisted dropdown open state, stable on mouse + touch. */
.site-header, .chess-header { overflow: visible !important; }
.nav-dropdown.is-open > .nav-dropdown-menu { display: block !important; opacity: 1 !important; visibility: visible !important; pointer-events: auto !important; }
.nav-dropdown.is-open > .nav-dropbtn { background: rgba(255,255,255,0.12) !important; color: #fff !important; }
.nav-tools-menu { min-width: 220px; }
@media (hover: none), (pointer: coarse), (max-width: 760px) {
  .nav-dropdown:hover > .nav-dropdown-menu { display: none; }
  .nav-dropdown.is-open > .nav-dropdown-menu { display: block !important; }
}
