/* ===================================================================
   POLE 3D Structural Viewer — Stylesheet
   Scientific cryo-session aesthetic with muted publication palette
   =================================================================== */

:root {
  --bg-0: #080b11;
  --bg-1: #0c1019;
  --bg-2: rgba(14, 20, 30, 0.75);
  --line: #1a2230;
  --line-2: #243040;
  --ink: #d0d8e0;
  --ink-dim: #7a8898;
  --ink-faint: #4a5868;
  --accent: #7abba8;
  --accent-dim: rgba(122, 187, 168, 0.15);
  --warn: #c45c5c;
  --warn-dim: rgba(196, 92, 92, 0.08);

  /* Domain colors — muted, publication-quality (Cell / NSMB style) */
  --c-ntd: #c4a47a;
  --c-exo: #b85c5c;
  --c-palm: #6b8e6b;
  --c-pdomain: #4a8a7a;
  --c-fingers: #5b7f99;
  --c-thumb: #8b7ba8;
  --c-inactpol: #7a6a8a;
  --c-ctd: #b8a04a;

  /* Molecular element colors */
  --c-dna-template: #8c9aa8;
  --c-dna-primer: #6a9e96;
  --c-mg: #7abb4e;

  /* AlphaFold pLDDT confidence colors */
  --plddt-very-high: #0053D6;   /* >90: very high confidence */
  --plddt-confident: #65CBF3;   /* 70–90: confident */
  --plddt-low: #FFDB13;         /* 50–70: low confidence */
  --plddt-very-low: #FF7D45;    /* <50: very low / disordered */
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-0);
  color: var(--ink);
  font-family: 'JetBrains Mono', ui-monospace, 'Cascadia Code', monospace;
  font-size: 13px;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse 70% 50% at 65% 35%, #0c1a2a 0%, transparent 55%),
    radial-gradient(ellipse 50% 40% at 25% 75%, #140e20 0%, transparent 60%),
    var(--bg-0);
}

/* Subtle vignette — no grid, cryo-session feel */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(
    ellipse 55% 50% at 50% 50%,
    transparent 45%,
    rgba(0, 0, 0, 0.3) 100%
  );
}

/* ---- Layout ---- */

#app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: 320px 1fr 300px;
  grid-template-rows: auto 1fr auto;
  gap: 0;
  z-index: 2;
}

/* ---- Header ---- */

header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(12, 16, 25, 0.88), rgba(12, 16, 25, 0.5));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 14px;
}

.brand .glyph {
  font-family: 'Fraunces', serif;
  font-weight: 300;
  font-size: 32px;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--ink);
  font-style: italic;
}

.brand .glyph em {
  color: var(--accent);
  font-style: italic;
  font-weight: 400;
}

.brand .sub {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink-dim);
  border-left: 1px solid var(--line-2);
  padding-left: 14px;
}

.brand .sub b {
  color: var(--ink);
  font-weight: 500;
}

.header-meta {
  display: flex;
  gap: 14px;
  align-items: center;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--ink-dim);
}

.header-meta .pill {
  border: 1px solid var(--line-2);
  padding: 4px 9px;
  border-radius: 2px;
  color: var(--ink);
  background: var(--bg-2);
}

.header-meta .pill b {
  color: var(--accent);
  font-weight: 500;
}

/* Sidebar toggle button (hidden on desktop) */
.sidebar-toggle {
  display: none;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  color: var(--ink);
  font-size: 18px;
  padding: 4px 10px;
  border-radius: 3px;
  cursor: pointer;
  line-height: 1;
}

/* Sidebar close button (hidden on desktop, visible on mobile) */
.sidebar-close {
  display: none;
  position: sticky;
  top: 0;
  z-index: 60;
  width: 100%;
  background: rgba(8, 11, 17, 0.95);
  border: none;
  border-bottom: 1px solid var(--line-2);
  color: var(--ink);
  font-size: 28px;
  padding: 10px 16px;
  cursor: pointer;
  text-align: right;
  line-height: 1;
}
.sidebar-close:active { color: var(--accent); }

/* Backdrop overlay behind open sidebars (mobile) */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
}

/* ---- Side panels ---- */

aside {
  background: linear-gradient(180deg, rgba(12, 16, 25, 0.7), rgba(8, 11, 17, 0.85));
  backdrop-filter: blur(8px);
  overflow-y: auto;
}

aside.left { border-right: 1px solid var(--line); }
aside.right { border-left: 1px solid var(--line); }

aside::-webkit-scrollbar { width: 5px; }
aside::-webkit-scrollbar-track { background: transparent; }
aside::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }

.panel {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.panel:last-child { border-bottom: none; }

.panel h3 {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--ink-dim);
  margin-bottom: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.panel h3::before {
  content: "";
  width: 4px;
  height: 4px;
  background: var(--accent);
  border-radius: 50%;
  flex-shrink: 0;
}

.panel h3 .num {
  margin-left: auto;
  color: var(--ink-faint);
  font-size: 9.5px;
  letter-spacing: 0.1em;
}

/* ---- Domain legend ---- */

.domain {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 9px;
  align-items: center;
  padding: 8px 7px;
  margin: 0 -7px;
  border-radius: 3px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  border: 1px solid transparent;
}

.domain:hover {
  background: rgba(255, 255, 255, 0.025);
  border-color: var(--line);
}

.domain.active {
  background: var(--accent-dim);
  border-color: rgba(122, 187, 168, 0.2);
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex-shrink: 0;
}

.domain .name {
  font-size: 12px;
  color: var(--ink);
  font-family: 'Fraunces', serif;
  font-weight: 400;
}

.domain .range {
  font-size: 10px;
  color: var(--ink-faint);
  letter-spacing: 0.05em;
}

.domain .desc {
  grid-column: 2 / -1;
  font-size: 10.5px;
  color: var(--ink-dim);
  line-height: 1.5;
  margin-top: 3px;
  display: none;
  font-family: 'JetBrains Mono', monospace;
}

.domain.active .desc { display: block; }

/* ---- Toggles ---- */

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 11px;
  color: var(--ink);
  cursor: pointer;
  border-bottom: 1px dashed var(--line);
  user-select: none;
}

.toggle:last-child { border-bottom: none; }

.toggle .label {
  display: flex;
  align-items: center;
  gap: 7px;
}

.toggle .label::before {
  content: "\203A";
  color: var(--ink-faint);
  font-size: 13px;
}

.switch {
  width: 32px;
  height: 16px;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  border-radius: 9px;
  position: relative;
  transition: all 0.2s;
  flex-shrink: 0;
}

.switch::after {
  content: "";
  width: 10px;
  height: 10px;
  background: var(--ink-faint);
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: all 0.2s;
}

.toggle.on .switch {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.toggle.on .switch::after {
  background: var(--accent);
  left: 18px;
  box-shadow: 0 0 6px var(--accent);
}

/* ---- Info cards ---- */

.info-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 12px 13px;
  border-radius: 3px;
  margin-bottom: 10px;
}

.info-card .k {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--ink-faint);
  margin-bottom: 3px;
}

.info-card .v {
  font-size: 13px;
  color: var(--ink);
  font-family: 'Fraunces', serif;
}

.info-card .v.mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11.5px;
  letter-spacing: 0.04em;
}

/* ---- Mutations ---- */

.mutation {
  padding: 9px 11px;
  background: var(--warn-dim);
  border: 1px solid rgba(196, 92, 92, 0.18);
  border-left: 2px solid var(--warn);
  margin-bottom: 7px;
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.2s;
}

.mutation:hover { background: rgba(196, 92, 92, 0.12); }

.mutation .head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 3px;
}

.mutation .name {
  font-family: 'Fraunces', serif;
  font-size: 13.5px;
  color: var(--warn);
  font-weight: 500;
}

.mutation .loc {
  font-size: 9px;
  color: var(--ink-faint);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.mutation .text {
  font-size: 10px;
  color: var(--ink-dim);
  line-height: 1.5;
}

/* ---- 3D viewport ---- */

main { position: relative; overflow: hidden; }

#canvas-container { position: absolute; inset: 0; }

canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* ---- Overlays ---- */

.overlay {
  position: absolute;
  pointer-events: none;
  z-index: 3;
}

.corner-tl {
  top: 12px;
  left: 12px;
  font-size: 9px;
  color: var(--ink-faint);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.corner-tl .live { color: var(--accent); }

.corner-tl .live::before {
  content: "\25CF";
  margin-right: 5px;
  color: var(--accent);
  animation: pulse 1.8s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

.corner-tr {
  top: 12px;
  right: 12px;
  font-size: 9px;
  color: var(--ink-faint);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-align: right;
}

.corner-br {
  bottom: 12px;
  right: 12px;
  display: flex;
  gap: 12px;
  font-size: 8.5px;
  color: var(--ink-faint);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.corner-bl {
  bottom: 12px;
  left: 12px;
  font-size: 8.5px;
  color: var(--ink-faint);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 7px;
}

.corner-bl .scale {
  display: inline-block;
  width: 50px;
  height: 1px;
  background: var(--ink-faint);
  position: relative;
}

.corner-bl .scale::before,
.corner-bl .scale::after {
  content: "";
  position: absolute;
  top: -3px;
  width: 1px;
  height: 7px;
  background: var(--ink-faint);
}

.corner-bl .scale::before { left: 0; }
.corner-bl .scale::after { right: 0; }

/* ---- Tooltip ---- */

#tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 10;
  background: rgba(8, 11, 17, 0.94);
  border: 1px solid var(--line-2);
  padding: 7px 11px;
  font-size: 10.5px;
  font-family: 'JetBrains Mono', monospace;
  color: var(--ink);
  border-radius: 2px;
  backdrop-filter: blur(10px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transition: opacity 0.12s;
  max-width: 220px;
}

#tooltip.show { opacity: 1; }

#tooltip .t-name {
  font-family: 'Fraunces', serif;
  font-size: 12.5px;
  color: var(--accent);
  margin-bottom: 2px;
}

#tooltip .t-detail {
  color: var(--ink-dim);
  font-size: 9.5px;
  line-height: 1.4;
}

/* ---- Footer ---- */

footer {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding: 7px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 9px;
  color: var(--ink-faint);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  background: rgba(12, 16, 25, 0.6);
  backdrop-filter: blur(12px);
}

footer .left { display: flex; gap: 16px; }
footer .ax { color: var(--ink-dim); }
footer .ax b { color: var(--ink); font-weight: 500; }

/* ---- Loading ---- */

#loading {
  position: fixed;
  inset: 0;
  background: var(--bg-0);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  transition: opacity 0.6s;
}

#loading.hide {
  opacity: 0;
  pointer-events: none;
}

#loading .helix {
  width: 48px;
  height: 48px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  border-top-color: transparent;
  border-bottom-color: transparent;
  animation: spin 1.4s linear infinite;
  margin-bottom: 16px;
}

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

#loading .text {
  font-size: 9.5px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

/* Loading progress bar */
.progress-bar {
  width: 200px;
  height: 2px;
  background: var(--line);
  border-radius: 1px;
  margin-top: 12px;
  overflow: hidden;
}

.progress-fill {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 0.4s ease;
  border-radius: 1px;
}

/* ---- Color mode / scheme selector ---- */

.color-mode-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.color-mode-selector button {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 4px 8px;
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.15s;
}

.color-mode-selector button:hover {
  color: var(--ink);
  border-color: var(--line-2);
}

.color-mode-selector button.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

/* ---- Tool buttons ---- */

.tool-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tool-btn {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
  background: var(--bg-2);
  border: 1px solid var(--line);
  padding: 6px 10px;
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.15s;
}

.tool-btn:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--line-2);
}

.tool-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

/* ---- FPS counter ---- */

.fps-counter {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: var(--accent);
  letter-spacing: 0.1em;
}

/* ---- Keyboard help overlay ---- */

.keyboard-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 11, 17, 0.85);
  backdrop-filter: blur(8px);
}

.keyboard-overlay-inner {
  background: rgba(14, 20, 30, 0.95);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  padding: 24px 32px;
  max-width: 420px;
  width: 90%;
}

.keyboard-overlay-inner h3 {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.22em;
  color: var(--ink-dim);
  margin-bottom: 16px;
  font-weight: 500;
}

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

.shortcut {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  color: var(--ink-dim);
}

.shortcut kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  padding: 2px 6px;
  border-radius: 3px;
  color: var(--accent);
  min-width: 22px;
  text-align: center;
}

/* ---- View mode switcher (mutation page) ---- */

.view-switcher {
  display: flex;
  gap: 2px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 2px;
}

.view-switcher button {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  background: transparent;
  border: none;
  padding: 5px 12px;
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.15s;
}

.view-switcher button:hover { color: var(--ink); }

.view-switcher button.active {
  background: var(--accent-dim);
  color: var(--accent);
}

/* ---- Sequence display (mutation page) ---- */

.sequence-display {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  line-height: 1.8;
  color: var(--ink-dim);
  word-break: break-all;
  padding: 10px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  border-radius: 2px;
}

.sequence-display .deleted { color: var(--warn); text-decoration: line-through; }
.sequence-display .frameshift { color: #b8a04a; background: rgba(184, 160, 74, 0.1); }
.sequence-display .stop { color: var(--warn); font-weight: 600; }
.sequence-display .normal { color: var(--accent); }

/* ---- NMD pathway diagram (mutation page) ---- */

.nmd-diagram {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 8px 0;
}

.nmd-step {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 3px;
  width: 100%;
}

.nmd-step.nmd-degraded {
  border-color: rgba(196, 92, 92, 0.3);
  background: rgba(196, 92, 92, 0.06);
}

.nmd-icon {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 3px 6px;
  border-radius: 2px;
  text-transform: uppercase;
  min-width: 36px;
  text-align: center;
  flex-shrink: 0;
}

.nmd-degraded .nmd-icon {
  color: var(--warn);
  background: var(--warn-dim);
}

.nmd-desc {
  font-size: 10px;
  color: var(--ink-dim);
  line-height: 1.4;
}

.nmd-arrow {
  color: var(--ink-faint);
  font-size: 12px;
  padding: 2px 0;
}

/* ---- Mobile sidebar tabs (hidden on desktop) ---- */

.mobile-sidebar-tabs {
  display: none;
}

/* ---- Responsive ---- */

@media (max-width: 1100px) {
  #app { grid-template-columns: 1fr; }

  .sidebar-toggle { display: block; }
  .sidebar-close { display: block; }
  .sidebar-backdrop.open { display: block; }

  .header-meta { display: none; }

  aside {
    display: none;
    position: fixed;
    top: 0;
    bottom: 0;
    width: 100%;
    z-index: 50;
    background: rgba(8, 11, 17, 0.96);
    backdrop-filter: blur(12px);
    transition: transform 0.3s ease;
  }

  .mobile-sidebar-tabs {
    display: flex;
    position: sticky;
    top: 49px;
    z-index: 59;
    width: 100%;
    background: rgba(8, 11, 17, 0.95);
    border-bottom: 1px solid var(--line-2);
  }

  .mobile-sidebar-tabs button {
    flex: 1;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--ink-faint);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.15s;
  }

  .mobile-sidebar-tabs button:hover {
    color: var(--ink-dim);
  }

  .mobile-sidebar-tabs button.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
  }

  aside.left {
    left: 0;
    border-right: 1px solid var(--line);
    transform: translateX(-100%);
  }

  aside.right {
    right: 0;
    border-left: 1px solid var(--line);
    transform: translateX(100%);
  }

  aside.open {
    display: block;
    transform: translateX(0);
  }
}

@media (max-width: 1400px) and (min-width: 1101px) {
  #app { grid-template-columns: 280px 1fr 260px; }
}

/* Touch-friendly spacing on mobile */
@media (pointer: coarse) {
  .toggle { padding: 12px 0; }
  .domain { padding: 12px 7px; }
  .tool-btn { padding: 10px 14px; font-size: 10px; }
  .color-mode-selector button { padding: 6px 10px; }
}
