:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-muted: #f3f5f8;
  --panel-strong: #e5e7eb;
  --border: rgba(15, 23, 42, 0.18);
  --border-strong: rgba(15, 23, 42, 0.28);
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.16);

  --text: #111827;
  --muted: #667085;

  --title: #111827;
  --title-text: #ffffff;

  --good-strong: #00aa00;
  --good-generous: #228b22;
  --warn: #ffd400;
  --bad: #d10000;
  --dyn: #87cefa;
  --none: #9a9a9a;

  --accent: #2563eb;
  --accent-weak: rgba(37, 99, 235, 0.12);

  --legacy-frame: #c8c8c8;
  --legacy-black: #000000;
  --legacy-cyan: #00ffff;
  --legacy-yellow: #ffff00;

  --chrome-header-h: 102px;
  --chrome-menu-h: 58px;
  --chrome-stack-h: 160px;
  --chrome-footer-h: 34px;
  --viewer-max-w: 1600px;
  --desktop-min-h: 1140px;
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, #f8fbff 0%, var(--bg) 42%, #e8edf4 100%);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  user-select: none;
  overflow: hidden;
}

.hidden { display: none !important; }

#legacy-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10020;
  padding: 8px 12px 6px;
  background: linear-gradient(180deg, rgba(10, 10, 10, 0.98), rgba(17, 24, 39, 0.96));
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
}

#legacy-header-table {
  width: min(var(--viewer-max-w), calc(100vw - 24px));
  margin: 0 auto;
  border-collapse: separate;
  border-spacing: 8px;
  background: var(--legacy-frame);
  border-radius: 16px;
  overflow: hidden;
}

#legacy-header-table td {
  padding: 12px 16px;
  background: var(--legacy-black);
}

.legacy-logo-cell {
  width: 170px;
  text-align: center;
  vertical-align: middle;
}

.legacy-logo-badge {
  width: 120px;
  margin: 0 auto;
  padding: 12px 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.legacy-logo-badge-image {
  width: 132px;
  min-height: 68px;
  padding: 10px 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.legacy-logo-badge-inline {
  overflow: hidden;
}

.legacy-logo-image {
  display: block;
  max-width: 100%;
  height: auto;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.25));
}

.legacy-logo-image-inline {
  width: 100%;
  max-height: 74px;
  object-fit: contain;
}


.legacy-logo-fallback {
  display: inline-block;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--legacy-yellow);
}

.legacy-logo-top,
.legacy-logo-bottom {
  display: block;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.legacy-logo-top {
  font-size: 17px;
  color: var(--legacy-cyan);
}

.legacy-logo-bottom {
  margin-top: 4px;
  font-size: 15px;
  color: var(--legacy-yellow);
}

.legacy-title-cell {
  text-align: center;
}

.legacy-tagline {
  color: var(--legacy-yellow);
  font-size: 14px;
  font-style: italic;
  margin-bottom: 4px;
}

.legacy-title-wrap {
  line-height: 1.05;
}

.legacy-title-word,
.legacy-title-colon {
  font-size: 32px;
  font-weight: 900;
  color: var(--legacy-cyan);
  letter-spacing: 0.02em;
}

.legacy-subtitle {
  margin-top: 4px;
  color: #dff8ff;
  font-size: 17px;
  font-weight: 700;
}

#menu-bar {
  position: fixed;
  top: var(--chrome-header-h);
  left: 0;
  right: 0;
  z-index: 10010;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
}

#menu-bar-inner {
  width: min(var(--viewer-max-w), calc(100vw - 24px));
  margin: 0 auto;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.menu-group {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.menu-note {
  flex: 1 0 100%;
  margin-top: -2px;
  padding: 0 2px 2px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
}

.menu-note strong {
  color: var(--text);
}

#menu-bar button,
.menu-dropdown > summary {
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  padding: 7px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #ffffff;
  cursor: pointer;
  transition: transform 0.02s ease-in-out, background 0.12s ease-in-out, border-color 0.12s ease-in-out, box-shadow 0.12s ease-in-out;
}

#menu-bar button:hover,
.menu-dropdown > summary:hover {
  background: var(--panel-muted);
  border-color: var(--border-strong);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

#menu-bar button:active,
.menu-dropdown > summary:active {
  transform: translateY(1px);
}

#menu-bar button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

body.help-open #btn-help {
  background: var(--accent-weak);
  border-color: rgba(37, 99, 235, 0.34);
}

#menu-bar label {
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.menu-dropdown {
  position: relative;
}

.menu-dropdown > summary {
  list-style: none;
  user-select: none;
  min-width: 116px;
  text-align: center;
}

.menu-dropdown > summary::-webkit-details-marker {
  display: none;
}

.menu-dropdown > summary::after {
  content: ' ▾';
  font-weight: 900;
}

.menu-dropdown[open] > summary {
  background: var(--panel-muted);
  border-color: var(--border-strong);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.menu-dropdown-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 240px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
  backdrop-filter: blur(10px);
  z-index: 10060;
}

.menu-dropdown-panel button {
  width: 100%;
  text-align: left;
}

.menu-dropdown-panel button + button {
  margin-top: 6px;
}

#desktop-shell {
  position: fixed;
  top: var(--chrome-stack-h);
  left: 50%;
  width: min(var(--viewer-max-w), calc(100vw - 24px));
  transform: translateX(-50%);
  bottom: var(--chrome-footer-h);
  overflow: auto;
  overscroll-behavior: contain;
  padding-bottom: 16px;
}

#desktop {
  position: relative;
  width: var(--viewer-max-w);
  min-width: 100%;
  min-height: var(--desktop-min-h);
  margin: 0 auto;
}

.window {
  position: absolute;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 10;
  overflow: hidden;
}

.window.hidden { display: none; }

.window-title {
  background: var(--title);
  color: var(--title-text);
  padding: 9px 10px;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: move;
}

.window-controls {
  display: flex;
  gap: 8px;
}

.win-btn {
  width: 30px;
  height: 22px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.10);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.win-btn:hover {
  background: rgba(255, 255, 255, 0.20);
}

.window-content {
  padding: 12px;
}

.window-content.scroll {
  max-height: 520px;
  overflow: auto;
}

#rama-panel {
  position: relative;
  width: 430px;
  height: 400px;
}

#rama-plot {
  position: absolute;
  top: 0;
  left: 0;
  width: 361px;
  height: 361px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(16, 24, 40, 0.16);
}

#rama-bg,
#rama-canvas {
  position: absolute;
  top: 0;
  left: 0;
}

#rama-canvas {
  width: 361px;
  height: 361px;
}

.axis-label {
  position: absolute;
  font-size: 11px;
  font-weight: 700;
  color: #111;
  background: rgba(255, 255, 255, 0.0);
  padding: 0;
  pointer-events: none;
}

#phi-label {
  left: 10px;
  top: 365px;
  width: 160px;
  height: 15px;
}

#psi-label {
  left: 365px;
  top: 10px;
  width: 90px;
  height: 30px;
}

#rama-buttons {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

#rama-buttons .spacer {
  display: block;
  visibility: hidden;
}

#rama-buttons button,
#viewer-actions button {
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  padding: 6px 6px;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
}

#rama-buttons button:hover,
#viewer-actions button:hover {
  background: var(--panel-muted);
}

#rama-buttons button.class-btn {
  min-height: 28px;
}

#status-bar {
  margin-top: 10px;
  border-top: 1px solid rgba(16, 24, 40, 0.12);
  padding-top: 8px;
  font-size: 12px;
}

#status-text {
  font-weight: 700;
  margin-bottom: 4px;
}

#status-hint {
  font-size: 11px;
  color: var(--muted);
}

#sequence-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
}

.seq-btn {
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 5px 4px;
  border: 1px solid rgba(16, 24, 40, 0.22);
  border-radius: 10px;
  cursor: pointer;
  background: #fff;
}

.seq-btn:hover {
  background: var(--panel-muted);
}

.seq-btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.seq-btn.selected {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.chart-block {
  margin-bottom: 12px;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(16, 24, 40, 0.08);
}

.chart-title {
  font-weight: 800;
  font-size: 12px;
  margin-bottom: 4px;
  text-align: center;
  white-space: pre-line;
}

.small-note {
  margin-top: 10px;
  font-size: 11px;
  color: var(--muted);
}

.tooltip {
  position: fixed;
  background: rgba(16, 24, 40, 0.92);
  color: #fff;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 12px;
  max-width: 360px;
  z-index: 11000;
  pointer-events: none;
  white-space: pre-line;
  box-shadow: 0 10px 24px rgba(16, 24, 40, 0.35);
}

.tooltip.hidden { display: none; }

#viewer-text {
  width: 100%;
  min-height: 360px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  padding: 10px;
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

#viewer-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.viewer-tab {
  font-size: 12px;
  font-weight: 700;
  padding: 7px 10px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
}

.viewer-tab:hover {
  background: var(--panel-muted);
}

.viewer-tab.active {
  background: var(--accent-weak);
  border-color: rgba(37, 99, 235, 0.35);
}

#viewer-actions {
  margin-top: 10px;
  display: flex;
  gap: 10px;
}

#about-dialog {
  max-width: 720px;
  border-radius: 14px;
  border: 1px solid var(--border);
}

#about-dialog .about-reference {
  margin-top: 12px;
  color: #d10000;
  font-size: 1rem;
  line-height: 1.55;
}

#about-dialog code,
#help-panel code {
  background: var(--panel-muted);
  padding: 0 4px;
  border-radius: 6px;
}

#help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.34);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  z-index: 10030;
}

#help-panel {
  position: fixed;
  top: calc(var(--chrome-stack-h) + 10px);
  right: 12px;
  bottom: calc(var(--chrome-footer-h) + 12px);
  width: min(560px, calc(100vw - 24px));
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 24px 54px rgba(0, 0, 0, 0.26);
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.22s ease, opacity 0.22s ease;
  z-index: 10040;
}

body.help-open #help-overlay {
  opacity: 1;
  pointer-events: auto;
}

body.help-open #help-panel {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.help-panel-header {
  padding: 18px 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  background: linear-gradient(135deg, rgba(2, 6, 23, 0.98), rgba(15, 23, 42, 0.96));
  color: #fff;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
}

.help-eyebrow {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #fde047;
  margin-bottom: 6px;
}

.help-panel-header h2 {
  margin: 0;
  font-size: 21px;
  line-height: 1.2;
}

.help-close-btn {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.help-close-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}

.help-panel-body {
  padding: 18px 20px 20px;
  overflow: auto;
}

.help-callout {
  padding: 14px 16px;
  background: linear-gradient(180deg, rgba(37, 99, 235, 0.08), rgba(37, 99, 235, 0.03));
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 16px;
  margin-bottom: 18px;
}

.help-callout p {
  margin: 0;
  line-height: 1.55;
}

.help-section {
  margin-bottom: 20px;
}

.help-section h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.help-section ol,
.help-section ul {
  margin: 0;
  padding-left: 20px;
  line-height: 1.6;
}

.help-section li + li {
  margin-top: 4px;
}

.help-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  font-size: 13px;
}

.help-table thead th {
  background: #111827;
  color: #fff;
  text-align: left;
  padding: 10px 12px;
  font-size: 12px;
}

.help-table tbody td {
  padding: 10px 12px;
  vertical-align: top;
  border-top: 1px solid rgba(15, 23, 42, 0.08);
  background: #fff;
}

.faq-item {
  padding: 12px 14px;
  border: 1px solid rgba(15, 23, 42, 0.10);
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.04);
}

.faq-item + .faq-item {
  margin-top: 10px;
}

.faq-item h4 {
  margin: 0 0 6px;
  font-size: 14px;
}

.faq-item p {
  margin: 0;
  color: var(--text);
  line-height: 1.55;
}

.help-footnote {
  padding: 14px 16px;
  border-radius: 16px;
  background: #f8fafc;
  border: 1px dashed rgba(15, 23, 42, 0.16);
}

.help-footnote p {
  margin: 0;
  font-size: 13px;
  line-height: 1.55;
  color: var(--muted);
}

@media (max-width: 1100px) {
  :root {
    --chrome-header-h: 118px;
    --chrome-menu-h: 76px;
  }

  .legacy-title-word,
  .legacy-title-colon {
    font-size: 28px;
  }

  .legacy-subtitle {
    font-size: 15px;
  }
}

@media (max-width: 760px) {
  :root {
    --chrome-header-h: 132px;
    --chrome-menu-h: 92px;
  }

  #legacy-header-table {
    width: min(var(--viewer-max-w), calc(100vw - 16px));
    border-spacing: 6px;
  }

  .legacy-logo-cell {
    width: 120px;
  }

  .legacy-logo-badge {
    width: 88px;
    padding: 10px 8px;
  }

  .legacy-logo-badge-image {
    width: 100px;
    min-height: 56px;
  }

  .legacy-logo-top {
    font-size: 13px;
  }

  .legacy-logo-bottom {
    font-size: 12px;
  }

  .legacy-tagline {
    font-size: 12px;
  }

  .legacy-title-word,
  .legacy-title-colon {
    font-size: 23px;
  }

  .legacy-subtitle {
    font-size: 13px;
  }

  #help-panel {
    top: calc(var(--chrome-stack-h) + 6px);
    right: 8px;
    bottom: calc(var(--chrome-footer-h) + 8px);
    width: calc(100vw - 16px);
  }
}


.resizable-window {
  resize: both;
  min-width: 540px;
  min-height: 320px;
  max-width: 100%;
  max-height: 100%;
}

#s2-window .window-content.scroll {
  height: calc(100% - 40px);
  max-height: none;
  overflow: auto;
}

#s2-window canvas {
  display: block;
  width: 100%;
}

#footer-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10015;
  padding: 6px 12px 8px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -8px 22px rgba(15, 23, 42, 0.05);
}

#footer-bar-inner {
  width: min(var(--viewer-max-w), calc(100vw - 24px));
  margin: 0 auto;
  text-align: center;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

#footer-bar a {
  color: var(--text);
  text-decoration: none;
}

#footer-bar a:hover {
  text-decoration: underline;
}
