/* tyschem – dark glass theme matching designreference */

/* ── Reset & base ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: #050505;
  background-image:
    radial-gradient(1200px 600px at 50% -10%, rgba(96,165,250,0.03), transparent),
    radial-gradient(800px 400px at 80% 20%, rgba(250,204,21,0.02), transparent);
  color: #f1f5f9;
  font-family: 'Press Start 2P', monospace;
  font-size: .68rem;
  line-height: 1.9;
  -webkit-font-smoothing: none;
  font-smooth: never;
}

/* Scale the entire UI with the viewport so it stays legible at 100% zoom. */
html { font-size: clamp(22px, 1.2vw + 12px, 34px); }

a { color: #60a5fa; text-decoration: none; transition: color .15s; }
a:hover { color: #93c5fd; }

/* ── Layout ────────────────────────────────────────────────── */
#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.site-header {
  display: flex;
  align-items: center;
  gap: .9rem;
  padding: .55rem 1.25rem;
  background: rgba(0,0,0,.72);
  border-bottom: 1px solid rgba(255,255,255,.08);
  position: sticky; top: 0; z-index: 30;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.site-logo {
  font-size: .82rem;
  color: #93c5fd;
  letter-spacing: .02em;
  white-space: nowrap;
}
.site-nav { display: flex; gap: .35rem; align-items: center; position: relative; }
.nav-link {
  display: inline-block;
  font-size: .62rem;
  padding: .4rem .8rem;
  border-radius: .5rem;
  color: #94a3b8;
  border: 1px solid transparent;
  transition: all .15s;
  line-height: 1.5;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,.05); }
.nav-link.active { color: #bfdbfe; background: rgba(59,130,246,.15); border-color: rgba(96,165,250,.35); }
.nav-sub {
  position: absolute;
  top: calc(100% + .3rem);
  left: 0;
  display: flex;
  align-items: center;
  gap: .35rem;
  max-width: 18rem;
  padding: .22rem .6rem;
  border-radius: .45rem;
  background: rgba(59,130,246,.15);
  border: 1px solid rgba(96,165,250,.35);
  color: #bfdbfe;
  font-size: .55rem;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
}
.nav-sub svg { width: .8rem; height: .8rem; flex: 0 0 auto; }
.nav-sub #nav-sub-text { overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.site-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* ── Profile menu (account button + dropdown) ──────────────── */
.profile-menu { position: relative; }
.profile-trigger {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .28rem .7rem .28rem .35rem;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: .55rem;
  color: #fff;
  font-family: inherit;
  font-size: .58rem;
  line-height: 1.5;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.profile-trigger:hover { background: rgba(255,255,255,.1); }
.profile-trigger:focus-visible { outline: 2px solid rgba(96,165,250,.5); outline-offset: 2px; }
.avatar {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 9999px;
  background: rgba(37,99,235,.8);
  border: 1px solid rgba(147,197,253,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  text-transform: uppercase;
  flex-shrink: 0;
  font-size: .7rem;
  line-height: 1;
}
.profile-name {
  max-width: 7.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.profile-chevron {
  width: .8rem;
  height: .8rem;
  color: #94a3b8;
  transition: transform .15s;
}
.profile-trigger.open .profile-chevron { transform: rotate(180deg); }
.profile-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: .5rem;
  width: 13rem;
  background: rgba(17,24,39,.95);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: .75rem;
  box-shadow: 0 20px 45px rgba(0,0,0,.5);
  overflow: hidden;
  z-index: 10000;
  transform-origin: top right;
  animation: profileScaleIn .14s ease-out;
}
@keyframes profileScaleIn {
  from { opacity: 0; transform: scale(.95); }
  to   { opacity: 1; transform: scale(1); }
}
.profile-dropdown-head { padding: .7rem 1rem; border-bottom: 1px solid rgba(255,255,255,.1); }
.profile-dropdown-label { font-size: .48rem; color: #64748b; line-height: 1.6; }
.profile-dropdown-user {
  font-size: .6rem;
  color: #fff;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.7;
}
.profile-dropdown-body { padding: .3rem 0; }
.profile-logout {
  width: 100%;
  text-align: left;
  padding: .6rem 1rem;
  font-size: .55rem;
  font-family: inherit;
  line-height: 1.7;
  color: #f87171;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: .5rem;
  transition: background .15s;
}
.profile-logout:hover { background: rgba(239,68,68,.2); }
.profile-link {
  width: 100%;
  text-align: left;
  padding: .6rem 1rem;
  font-size: .55rem;
  line-height: 1.7;
  color: #cbd5e1;
  display: flex;
  align-items: center;
  gap: .5rem;
  transition: background .15s;
}
.profile-link:hover { background: rgba(255,255,255,.08); color: #fff; }

.view-container {
  max-width: 52rem;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1rem;
  flex: 1;
}
.view-container.view-wide { max-width: none; }
.site-footer {
  text-align: center;
  padding: 1.5rem;
  font-size: .52rem;
  color: #475569;
  line-height: 1.6;
}

/* ── Glass panel ───────────────────────────────────────────── */
.panel {
  background: rgba(0,0,0,.55);
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 1.25rem;
  padding: 1.75rem 2rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.04);
}
.panel-compact { padding: 1.25rem 1.5rem; }

/* ── Title / heading ───────────────────────────────────────── */
.page-title {
  font-size: 1.05rem;
  color: #93c5fd;
  letter-spacing: .02em;
  margin-bottom: 1.5rem;
  text-shadow: 0 2px 8px rgba(0,0,0,.6);
  line-height: 1.6;
}
.section-title {
  font-size: .78rem;
  color: #e2e8f0;
  margin-bottom: .75rem;
  line-height: 1.6;
}

/* ── Form elements ─────────────────────────────────────────── */
.label {
  display: block;
  font-size: .6rem;
  color: #cbd5e1;
  margin-bottom: .5rem;
  line-height: 1.6;
}
.input, .select, .textarea {
  width: 100%;
  padding: .7rem .9rem;
  border-radius: .55rem;
  background: rgba(0,0,0,.72);
  border: 1px solid rgba(255,255,255,.10);
  color: #fff;
  font-size: .62rem;
  font-family: inherit;
  line-height: 1.8;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.input::placeholder, .textarea::placeholder { color: #64748b; }
.input:focus, .select:focus, .textarea:focus {
  border-color: rgba(96,165,250,.45);
  box-shadow: 0 0 0 3px rgba(96,165,250,.12);
}
.textarea { resize: vertical; min-height: 6rem; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .75rem center;
  padding-right: 2rem;
  cursor: pointer;
}
.select option { background: #111827; color: #f1f5f9; }

.form-group { margin-bottom: 1.35rem; }
.form-hint { font-size: .52rem; color: #64748b; margin-top: .4rem; line-height: 1.8; }

/* ── Buttons ───────────────────────────────────────────────── */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .65rem 1.1rem;
  border-radius: .55rem;
  font-size: .62rem;
  font-family: inherit;
  line-height: 1.5;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
  text-decoration: none;
  white-space: nowrap;
}
.button:disabled { opacity: .45; cursor: not-allowed; }

.button-primary {
  background: rgba(59,130,246,.88);
  color: #fff;
  box-shadow: 0 4px 14px rgba(59,130,246,.25);
}
.button-primary:hover:not(:disabled) { background: #3b82f6; }
.button-secondary {
  background: rgba(255,255,255,.07);
  color: #cbd5e1;
  border-color: rgba(255,255,255,.12);
}
.button-secondary:hover:not(:disabled) { background: rgba(255,255,255,.12); color: #fff; }
.button-danger {
  background: rgba(220,38,38,.85);
  color: #fff;
}
.button-danger:hover:not(:disabled) { background: #dc2626; }

.button-sm { padding: .45rem .7rem; font-size: .55rem; border-radius: .45rem; }
.button-icon { padding: .55rem; font-size: .72rem; min-width: 2.2rem; }
.button-ghost { background: transparent; color: #94a3b8; }
.button-ghost:hover:not(:disabled) { background: rgba(255,255,255,.06); color: #fff; }

/* ── Browse layout (fixed controls rail) ───────────────────── */
.browse-layout { display: block; padding-right: 7rem; }
.browse-rail {
  position: fixed;
  top: 4.5rem;
  right: 1rem;
  width: 4.25rem;
  display: flex;
  flex-direction: column;
  gap: .45rem;
  padding: .55rem;
  border-radius: 1rem;
  background: rgba(0,0,0,.6);
  border: 1px solid rgba(255,255,255,.10);
  box-shadow: 0 10px 30px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.04);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 25;
}
.rail-btn {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: .45rem;
  border-radius: .55rem;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.12);
  color: #cbd5e1;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.rail-btn:hover:not(:disabled) { background: rgba(255,255,255,.12); color: #fff; }
.rail-btn:disabled { opacity: .35; cursor: not-allowed; }
.rail-btn:focus-visible { outline: 2px solid rgba(96,165,250,.5); outline-offset: 2px; }
.rail-btn svg { width: 1.15rem; height: 1.15rem; }
.rail-btn.active { color: #bfdbfe; border-color: rgba(96,165,250,.5); background: rgba(59,130,246,.15); }
.rail-btn-primary {
  color: #fff;
  border-color: rgba(96,165,250,.5);
  background: rgba(59,130,246,.55);
}
.rail-btn-primary:hover:not(:disabled) { background: #3b82f6; color: #fff; }
.rail-btn.uploading svg { animation: railPulse 1s ease-in-out infinite; }
@keyframes railPulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.rail-order-icon { transition: transform .18s; }
.rail-btn.asc .rail-order-icon { transform: rotate(180deg); }
.browse-rail-count {
  margin-top: auto;
  padding-top: .1rem;
  text-align: center;
  font-size: .5rem;
  color: #64748b;
  line-height: 1.4;
  word-break: break-all;
}

/* ── Schematic cards (square panels) ───────────────────────── */
.schematics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 14rem);
  justify-content: start;
  gap: 1rem;
}
.schematic-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: .65rem;
  aspect-ratio: 1 / 1;
  padding: .9rem;
  border-radius: .85rem;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.07);
  transition: all .15s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  overflow: hidden;
}
.schematic-card:hover {
  background: rgba(96,165,250,.07);
  border-color: rgba(96,165,250,.22);
  transform: translateY(-2px);
}
.card-head {
  display: flex;
  align-items: flex-start;
  gap: .7rem;
  min-height: 0;
}
.card-thumb {
  position: relative;
  width: 3.75rem;
  height: 3.75rem;
  flex-shrink: 0;
  border-radius: .6rem;
  border: 1px solid rgba(255,255,255,.08);
  background:
    radial-gradient(circle at 50% 38%, rgba(96,165,250,.12), rgba(0,0,0,.0) 70%),
    linear-gradient(180deg, #0a0e16, #05070c);
  overflow: hidden;
}
.card-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0;
  transition: opacity .45s ease;
  image-rendering: pixelated;
}
.card-thumb.thumb-ready .card-thumb-img { opacity: 1; }
.card-thumb-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .55rem;
  color: #475569;
}
.card-thumb-loading::after { content: "\2026"; animation: thumbPulse 1.2s ease-in-out infinite; }
.card-thumb.thumb-ready .card-thumb-loading { display: none; }
.card-thumb.thumb-error .card-thumb-loading::after { content: "\00d7"; animation: none; }
@keyframes thumbPulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
.card-title-wrap {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.card-name {
  color: #e2e8f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: .6rem;
  line-height: 1.6;
}
.card-desc {
  font-size: .5rem;
  color: #64748b;
  line-height: 1.7;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-meta {
  display: flex;
  align-items: center;
  gap: .4rem;
  flex-wrap: wrap;
  margin-top: auto;
  padding-top: .5rem;
  border-top: 1px solid rgba(255,255,255,.06);
  font-size: .5rem;
  color: #64748b;
  line-height: 1.6;
}
.card-size {
  background: rgba(255,255,255,.06);
  padding: .2rem .5rem;
  border-radius: .25rem;
}
.card-owner { color: #7c8ba1; }
.card-date { white-space: nowrap; }
.card-download { margin-left: auto; text-decoration: none; }

/* ── Stars & likes ─────────────────────────────────────────── */
.star-icon, .heart-icon {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: -0.12em;
  flex: 0 0 auto;
}
.card-rating {
  display: flex;
  align-items: center;
  gap: .3rem;
  font-size: .5rem;
  color: #facc15;
}
.card-rating .star-icon { stroke: currentColor; }
.card-rating .rating-count { color: #64748b; }
.card-rating .rating-empty { color: #475569; display: inline-flex; align-items: center; gap: .3rem; }
.card-rating .rating-empty .star-icon { stroke: #475569; }

.like-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  padding: .45rem;
  border-radius: .45rem;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.12);
  color: #cbd5e1;
  font-family: inherit;
  font-size: .55rem;
  line-height: 1.5;
  cursor: pointer;
  transition: color .15s, background .15s, border-color .15s;
}
.like-btn:hover:not(:disabled) { color: #fecaca; background: rgba(239,68,68,.38); border-color: rgba(248,113,113,.9); }
.like-btn:disabled { opacity: .5; cursor: default; }
.like-btn .heart-icon { width: 1.5em; height: 1.5em; fill: currentColor; }
.like-btn.liked { color: #ef4444; border-color: rgba(239,68,68,.35); background: rgba(239,68,68,.1); }
.like-btn.liked:hover:not(:disabled) { color: #f87171; background: rgba(239,68,68,.18); border-color: rgba(248,113,113,.55); }
.like-btn .like-count {
  position: absolute;
  top: -.3rem;
  right: -.3rem;
  min-width: .85rem;
  padding: 0 .18rem;
  font-size: .42rem;
  line-height: .85rem;
  text-align: center;
  border-radius: 9999px;
  background: rgba(15,23,42,.95);
  color: #cbd5e1;
  border: 1px solid rgba(148,163,184,.4);
}

/* Hearts bubbling out of a like button (and back when unliked). */
.heart-burst {
  position: fixed;
  z-index: 100;
  width: 0;
  height: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
}
.heart-bubble {
  position: absolute;
  left: 0;
  top: 0;
  width: 1rem;
  height: 1rem;
  color: #ef4444;
  opacity: 0;
  animation: heartRise 950ms ease-out forwards;
  animation-delay: var(--delay, 0ms);
}
.heart-bubble .heart-icon { width: 100%; height: 100%; fill: currentColor; }
.heart-bubble.down { color: #64748b; animation-name: heartFall; }
@keyframes heartRise {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.3); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, -60px))) scale(1.15) rotate(var(--rot, 0deg)); }
}
@keyframes heartFall {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(1.15); }
  18% { opacity: .9; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx, 0px)), calc(-50% + var(--dy, 60px))) scale(.3) rotate(var(--rot, 0deg)); }
}
.rail-btn.like-rail { flex-direction: column; gap: .15rem; color: #fca5a5; border-color: rgba(248,113,113,.7); background: rgba(239,68,68,.28); }
.rail-btn.like-rail .like-count { font-size: .45rem; line-height: 1; color: #94a3b8; }
.rail-btn.like-rail.liked { color: #ef4444; border-color: rgba(239,68,68,.35); background: rgba(239,68,68,.1); }
.rail-btn.like-rail.liked .heart-icon { fill: currentColor; }

.rating-widget {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
  margin: .75rem 0 1rem;
  padding: .6rem .75rem;
  border-radius: .55rem;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.07);
}
.rating-widget .stars { display: inline-flex; gap: .15rem; }
.rating-widget .star,
.rating-widget .star-btn {
  display: inline-flex;
  padding: 0;
  background: none;
  border: none;
  color: #475569;
  font-size: .85rem;
  line-height: 1;
}
.rating-widget .star-btn { cursor: pointer; transition: color .12s, transform .12s; }
.rating-widget .star-btn:hover:not(:disabled) { color: #fde047; transform: scale(1.12); }
.rating-widget .star-btn:disabled { cursor: default; }
.rating-widget .star.filled,
.rating-widget .star-btn.filled { color: #facc15; }
.rating-widget .star.filled .star-icon,
.rating-widget .star-btn.filled .star-icon { fill: currentColor; }
.rating-summary { font-size: .5rem; color: #94a3b8; }
.schematic-card:focus-visible {
  outline: 2px solid rgba(96,165,250,.5);
  outline-offset: 2px;
}

/* ── Detail view ───────────────────────────────────────────── */
.detail-layout {
  display: grid;
  grid-template-columns: minmax(15rem, 21rem) 1fr;
  gap: .85rem;
  align-items: stretch;
  height: calc(100vh - 6rem);
}
@media (min-width: 768px) {
  body.detail-view { overflow: hidden; }
  body.detail-view .site-header { padding-bottom: 1.6rem; }
  body.detail-view .site-footer { display: none; }
  body.detail-view #app { height: 100vh; min-height: 0; }
  body.detail-view .view-container {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }
  body.detail-view .detail-layout {
    flex: 1;
    height: auto;
    min-height: 0;
  }
}
.detail-info {
  overflow-y: auto;
  min-height: 0;
}
.detail-name {
  font-size: 1.1rem;
  margin-bottom: .7rem;
}
.detail-description {
  font-size: .56rem;
  color: #94a3b8;
  line-height: 1.9;
  margin-bottom: 1.4rem;
  white-space: pre-wrap;
}
.detail-stage {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  min-width: 0;
  min-height: 0;
}
.detail-rail {
  position: absolute;
  top: .75rem;
  right: .75rem;
  z-index: 5;
  width: 4.25rem;
  display: flex;
  flex-direction: column;
  gap: .45rem;
  padding: .55rem;
  border-radius: 1rem;
  background: rgba(0,0,0,.6);
  border: 1px solid rgba(255,255,255,.10);
  box-shadow: 0 10px 30px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.04);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.detail-rail .rail-btn { text-decoration: none; }
.rail-btn-danger { color: #fca5a5; }
.rail-btn-danger:hover:not(:disabled) {
  background: rgba(239,68,68,.2);
  color: #fecaca;
  border-color: rgba(239,68,68,.4);
}
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 1rem 1.25rem;
}
.meta-item { display: flex; flex-direction: column; gap: .3rem; }
.meta-label { font-size: .5rem; color: #64748b; text-transform: uppercase; letter-spacing: .04em; line-height: 1.6; }
.meta-value { font-size: .6rem; color: #e2e8f0; word-break: break-all; line-height: 1.8; }
.meta-advanced {
  margin-top: 1.25rem;
  padding-top: .9rem;
  border-top: 1px solid rgba(255,255,255,.07);
}
.meta-advanced > summary {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .5rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .04em;
  line-height: 1.6;
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: color .15s;
}
.meta-advanced > summary::-webkit-details-marker { display: none; }
.meta-advanced > summary::before {
  content: "\203A";
  font-size: .75rem;
  line-height: 1;
  transition: transform .15s;
}
.meta-advanced[open] > summary::before { transform: rotate(90deg); }
.meta-advanced > summary:hover { color: #93c5fd; }
.meta-advanced .meta-grid { margin-top: 1rem; }
.description-section {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid rgba(255,255,255,.07);
}
.description-text {
  font-size: .6rem;
  color: #94a3b8;
  line-height: 2;
  white-space: pre-wrap;
}

/* ── 3D viewer ─────────────────────────────────────────────── */
.viewer-panel {
  padding: 0;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}
.viewer-container {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 12rem;
  background: #05070c;
}
.viewer-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}
.viewer-canvas.grabbing { cursor: grabbing; }
.viewer-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .55rem;
  color: #475569;
}
.viewer-hint {
  padding: .6rem 1rem;
  font-size: .5rem;
  color: #64748b;
  text-align: center;
  border-top: 1px solid rgba(255,255,255,.06);
  line-height: 1.6;
}

/* ── Search / filter bar ───────────────────────────────────── */
.toolbar {
  display: flex;
  align-items: center;
  gap: .65rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.toolbar .input { flex: 1; min-width: 12rem; }
.toolbar .select { width: auto; min-width: 10rem; }

/* ── Upload page ───────────────────────────────────────────── */
.upload-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr);
  gap: 1rem;
  align-items: stretch;
}
.upload-field {
  display: flex;
  flex-direction: column;
  padding: 1rem 1.1rem;
  border-radius: .85rem;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.08);
}
.upload-field .form-group { margin-bottom: 0; }
.upload-field .textarea { min-height: 9.5rem; flex: 1; }
.upload-form { transition: border-color .2s, background .2s; }
.upload-form.drag-over {
  border-color: rgba(96,165,250,.5);
  background: rgba(96,165,250,.06);
}
.upload-file {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-top: 1rem;
  padding: .8rem 1rem;
  border-radius: .6rem;
  background: rgba(255,255,255,.03);
  border: 1px dashed rgba(255,255,255,.12);
  color: #64748b;
  font-size: .55rem;
  line-height: 1.8;
  cursor: pointer;
}
.upload-file.has-file {
  border-style: solid;
  border-color: rgba(74,222,128,.45);
  background: rgba(74,222,128,.04);
  color: #4ade80;
}
.upload-file-icon { font-size: .9rem; }
.upload-preview {
  display: flex;
  align-items: center;
  gap: .9rem;
  margin-top: 1rem;
  padding: .8rem 1rem;
  border-radius: .6rem;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.08);
}
.upload-preview[hidden] { display: none; }
.upload-preview-thumb {
  width: 6rem;
  height: 6rem;
}
.upload-preview-hint {
  font-size: .55rem;
  line-height: 1.8;
  color: #64748b;
}
.upload-preview-error { border-color: rgba(248,113,113,.3); }
.upload-preview-error .upload-preview-hint { color: #f87171; }
.upload-progress {
  margin-top: .5rem;
  height: 4px;
  border-radius: 2px;
  background: rgba(255,255,255,.08);
  overflow: hidden;
}
.upload-progress-bar {
  height: 100%;
  background: #3b82f6;
  border-radius: 2px;
  transition: width .2s;
}

/* ── Empty state ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: #475569;
}
.empty-icon { font-size: 2rem; margin-bottom: 1rem; opacity: .5; }
.empty-text { font-size: .6rem; line-height: 1.9; }
.empty-hint { font-size: .52rem; margin-top: .5rem; line-height: 1.9; }

/* ── Infinite scroll (virtual pagination) ──────────────────── */
.list-sentinel { height: 1px; }
.list-status {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  margin-top: 1.25rem;
  padding: .75rem 0;
  font-size: .55rem;
  color: #64748b;
  line-height: 1.6;
}
.list-status-error { color: #ef4444; }
.list-spinner {
  width: .85rem;
  height: .85rem;
  border-radius: 50%;
  border: 2px solid rgba(148,163,184,.3);
  border-top-color: #93c5fd;
  animation: listSpin .7s linear infinite;
}
@keyframes listSpin { to { transform: rotate(360deg); } }

/* ── Toast ─────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.toast {
  min-width: 18rem;
  max-width: 26rem;
  padding: .8rem 1rem;
  border-radius: .6rem;
  font-size: .55rem;
  line-height: 1.8;
  backdrop-filter: blur(8px);
  animation: toastIn .3s cubic-bezier(.16,1,.3,1);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.toast.success { background: rgba(20,83,45,.92); border: 1px solid rgba(74,222,128,.3); color: #bbf7d0; }
.toast.error { background: rgba(127,29,29,.92); border: 1px solid rgba(248,113,113,.3); color: #fecaca; }
.toast-exit { animation: toastOut .2s ease-in forwards; }
@keyframes toastIn { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:translateY(0); } }
@keyframes toastOut { from { opacity:1; } to { opacity:0; transform:translateX(100%); } }

/* ── Action popover (edit / delete) ────────────────────────── */
.action-popover {
  position: fixed;
  z-index: 60;
  width: min(26rem, calc(100vw - 2rem));
  background: rgba(0,0,0,.6);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: .75rem;
  padding: 1.5rem;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  opacity: 0;
  transform: scale(.8);
  transition: opacity .18s ease, transform .22s cubic-bezier(.16, 1, .3, 1);
  will-change: transform, opacity;
}
.action-popover.open { opacity: 1; transform: scale(1); }
.action-popover::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  background: rgba(0,0,0,.6);
  border: 1px solid rgba(255,255,255,.12);
  transform: rotate(45deg);
}
.action-popover[data-side="right"]::after {
  right: -7px;
  top: calc(var(--caret-y, 50%) - 6px);
  border-left: none;
  border-bottom: none;
}
.action-popover[data-side="left"]::after {
  left: -7px;
  top: calc(var(--caret-y, 50%) - 6px);
  border-right: none;
  border-top: none;
}
.action-popover .form-group:last-of-type { margin-bottom: 1.25rem; }
.action-popover-menu {
  width: min(15rem, calc(100vw - 2rem));
  padding: 1.1rem;
}
.action-popover-menu .input + .input { margin-top: .55rem; }
.popover-menu { display: flex; flex-direction: column; gap: .3rem; }
.popover-item {
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: .58rem;
  padding: .55rem .7rem;
  border-radius: .45rem;
  background: transparent;
  border: 1px solid transparent;
  color: #cbd5e1;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.popover-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.popover-item.active { background: rgba(59,130,246,.15); border-color: rgba(96,165,250,.35); color: #bfdbfe; }
.dialog-title { font-size: .78rem; color: #f1f5f9; margin-bottom: .8rem; line-height: 1.6; }
.dialog-message { font-size: .55rem; color: #94a3b8; margin-bottom: 1.5rem; line-height: 1.9; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .6rem; }

/* ── Auth views ────────────────────────────────────────────── */
.auth-view { max-width: 26rem; margin: 0 auto; }
.auth-desc {
  font-size: .55rem;
  color: #94a3b8;
  line-height: 1.9;
  margin: -.75rem 0 1.5rem;
}
.auth-error {
  margin-bottom: 1rem;
  padding: .65rem .9rem;
  border-radius: .55rem;
  font-size: .55rem;
  line-height: 1.8;
  background: rgba(127,29,29,.92);
  border: 1px solid rgba(248,113,113,.3);
  color: #fecaca;
}
.auth-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: .75rem;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

/* ── Profile page ──────────────────────────────────────────── */
.profile-layout {
  display: grid;
  grid-template-columns: minmax(16rem, 20rem) 1fr;
  gap: 1.25rem;
  align-items: stretch;
  height: calc(100vh - 6rem);
}
@media (min-width: 768px) {
  body.profile-page { overflow: hidden; }
  body.profile-page .site-header { padding-bottom: 1.6rem; }
  body.profile-page .site-footer { display: none; }
  body.profile-page #app { height: 100vh; min-height: 0; }
  body.profile-page .view-container {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
  }
  body.profile-page .profile-layout {
    flex: 1;
    height: auto;
    min-height: 0;
  }
}
.profile-side {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-height: 0;
}
.profile-schematics {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-height: 0;
  overflow-y: auto;
}
.profile-header {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1.1rem;
}
.profile-header-main { display: flex; align-items: center; gap: 1.1rem; min-width: 0; }
.profile-avatar {
  width: 4.25rem;
  height: 4.25rem;
  border-radius: 9999px;
  background: rgba(37,99,235,.8);
  border: 1px solid rgba(147,197,253,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 1.4rem;
  line-height: 1;
  flex-shrink: 0;
}
.profile-identity { min-width: 0; }
.profile-username { margin-bottom: .5rem; }
.profile-bio { font-size: .56rem; color: #94a3b8; line-height: 1.9; white-space: pre-wrap; }
.profile-joined { font-size: .5rem; color: #64748b; margin-top: .4rem; letter-spacing: .02em; }
.profile-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  gap: .9rem;
}
.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .4rem;
  padding: 1rem .75rem;
  border-radius: .85rem;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.08);
}
.stat-value { font-size: 1rem; color: #bfdbfe; line-height: 1.4; }
.stat-label {
  font-size: .48rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: .05em;
  line-height: 1.6;
}
.profile-section { display: flex; flex-direction: column; gap: .85rem; }
.profile-section-title {
  font-size: .68rem;
  color: #e2e8f0;
  font-weight: 400;
  line-height: 1.7;
}
.owner-link { color: #93c5fd; }
.owner-link:hover { color: #bfdbfe; text-decoration: underline; }

/* ── Animations ────────────────────────────────────────────── */
.fade-in { animation: fadeIn .4s ease-out; }
@keyframes fadeIn { from { opacity:0; transform:translateY(14px); } to { opacity:1; transform:translateY(0); } }
@media (prefers-reduced-motion: reduce) {
  .fade-in { animation: none; }
  * { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 767px) {
  .browse-layout { padding-right: 0; }
  .browse-rail {
    position: static;
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 1rem;
    padding: .55rem;
  }
  .browse-rail .rail-btn { width: 2.4rem; flex: 0 0 auto; }
  .browse-rail-count { margin: 0 0 0 auto; padding: 0; }

  .detail-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .detail-info { overflow: visible; }
  .detail-stage { height: 60vh; }
  .detail-rail {
    flex-direction: row;
    width: auto;
  }
  .detail-rail .rail-btn { width: 2.4rem; flex: 0 0 auto; }
  .profile-layout { grid-template-columns: 1fr; height: auto; }
  .profile-side, .profile-schematics { overflow: visible; }
  .nav-sub { display: none; }
}
@media (max-width: 640px) {
  .site-header { padding: .7rem 1rem; gap: 1rem; flex-wrap: wrap; }
  .site-logo { font-size: .7rem; }
  .profile-name { max-width: 5rem; }
  .view-container { padding: 1rem .85rem; }
  .panel { padding: 1.25rem 1rem; border-radius: 1rem; }
  .page-title { font-size: .85rem; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .meta-grid { grid-template-columns: 1fr; }
  .schematics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .upload-fields { grid-template-columns: 1fr; }
  .upload-fields .textarea { min-height: 6rem; }
  .profile-header { flex-direction: column; align-items: stretch; }
  .profile-avatar { width: 3.25rem; height: 3.25rem; font-size: 1.1rem; }
}

/* ── Admin: user management ─────────────────────────────────── */
.admin-view { max-width: 62rem; }
.admin-users { display: flex; flex-direction: column; gap: .25rem; }
.admin-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .8rem .25rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.admin-user-row:last-child { border-bottom: none; }
.admin-user-info { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.admin-user-name {
  font-size: .7rem;
  color: #e2e8f0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.admin-badge {
  font-size: .5rem;
  padding: .2rem .45rem;
  border-radius: .35rem;
  background: #4f46e5;
  color: #fff;
  letter-spacing: .04em;
}
.admin-badge-self { background: #334155; }
.admin-user-actions { display: flex; gap: .4rem; flex: 0 0 auto; }
@media (max-width: 640px) {
  .admin-user-row { flex-direction: column; align-items: stretch; }
  .admin-user-actions { flex-wrap: wrap; }
}

/* ── Projects ───────────────────────────────────────────────── */
.projects-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.projects-head .page-title { margin-bottom: 0; }
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}
.projects-more {
  display: flex;
  justify-content: center;
  margin-top: 1.25rem;
}
.project-card {
  display: flex;
  flex-direction: column;
  gap: .7rem;
  padding: 1.1rem;
  border-radius: .85rem;
  background: rgba(255,255,255,.03);
  border: 1px solid rgba(255,255,255,.07);
  transition: all .15s;
  color: inherit;
  text-decoration: none;
}
.project-card:hover {
  background: rgba(96,165,250,.07);
  border-color: rgba(96,165,250,.22);
  transform: translateY(-2px);
  color: inherit;
}
.project-card-head { display: flex; align-items: center; gap: .6rem; }
.project-card-icon { font-size: 1rem; }
.project-card-title { min-width: 0; }
.project-card-name { font-size: .72rem; color: #e2e8f0; line-height: 1.6; }
.project-card-owner { font-size: .52rem; color: #64748b; }
.project-card-desc {
  font-size: .55rem;
  color: #94a3b8;
  line-height: 1.7;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.project-card-meta {
  display: flex;
  justify-content: space-between;
  gap: .5rem;
  font-size: .5rem;
  color: #64748b;
  margin-top: auto;
}

.project-view { max-width: 72rem; }
@media (min-width: 768px) {
  body.project-page .site-header { padding-bottom: 1.6rem; }
}
.project-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.project-header-title { display: flex; align-items: center; gap: .75rem; }
.project-header-icon { font-size: 1.3rem; }
.project-header-title .page-title { margin-bottom: .25rem; }
.project-meta { font-size: .55rem; color: #94a3b8; }
.project-description { margin-top: .9rem; font-size: .6rem; color: #cbd5e1; line-height: 1.9; }
.project-header-actions { display: flex; gap: .4rem; flex: 0 0 auto; }
.project-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.project-section-title { font-size: .78rem; color: #e2e8f0; }

.detail-projects { display: flex; flex-wrap: wrap; gap: .4rem; margin: -.75rem 0 1rem; }
.project-chip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .3rem .55rem;
  border-radius: .45rem;
  background: rgba(59,130,246,.15);
  border: 1px solid rgba(96,165,250,.35);
  color: #bfdbfe;
  font-size: .55rem;
}
.project-chip:hover { background: rgba(59,130,246,.28); color: #dbeafe; }

.project-card-actions {
  position: absolute;
  top: .4rem;
  right: .4rem;
  display: flex;
  gap: .2rem;
  opacity: 0;
  transition: opacity .15s;
  z-index: 2;
}
.schematic-card:hover .project-card-actions,
.schematic-card:focus-within .project-card-actions { opacity: 1; }
.project-card-btn {
  width: 1.35rem;
  height: 1.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: .35rem;
  background: rgba(0,0,0,.75);
  border: 1px solid rgba(255,255,255,.15);
  color: #e2e8f0;
  cursor: pointer;
  font-size: .6rem;
  line-height: 1;
}
.project-card-btn:hover { background: rgba(59,130,246,.35); border-color: rgba(96,165,250,.5); }
.project-card-btn-danger:hover { background: rgba(239,68,68,.4); border-color: rgba(248,113,113,.5); }

.add-schem-list {
  max-height: 14rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  margin: .6rem 0;
  padding: .35rem;
  border-radius: .5rem;
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(255,255,255,.08);
}
.add-schem-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .35rem .45rem;
  border-radius: .4rem;
  font-size: .55rem;
  color: #cbd5e1;
  cursor: pointer;
}
.add-schem-item:hover { background: rgba(255,255,255,.05); }
.add-schem-item input { accent-color: #3b82f6; }
.upload-projects { max-height: 9rem; margin-top: .4rem; }

@media (max-width: 640px) {
  .projects-grid { grid-template-columns: 1fr; }
  .project-header { flex-direction: column; }
  .project-header-actions { align-self: flex-start; }
}

.mobile-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem;
  text-align: center;
  background: #0b1120;
  color: #e2e8f0;
}
.mobile-gate svg {
  width: 3rem;
  height: 3rem;
  stroke: #3b82f6;
}
.mobile-gate h1 {
  font-size: 1rem;
  letter-spacing: .05em;
}
.mobile-gate p {
  max-width: 22rem;
  font-size: .7rem;
  line-height: 1.6;
  color: #94a3b8;
}
body.mobile-only #app { display: none; }
