/* =========================================
   Global Layout & Theme
========================================= */
* {
  box-sizing: border-box;
}

:root {
  --bg: #02030a;
  --card-bg: rgba(10, 12, 24, 0.95);
  --accent: #ffffff;
  --accent-soft: rgba(255, 255, 255, 0.18);
  --text-main: #ffffff;
  --text-muted: rgba(255, 255, 255, 0.7);
  --text-soft: rgba(255, 255, 255, 0.45);
  --panel-bg: rgba(5, 8, 20, 0.97);
  --live-green: #42ff9e;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #202840 0, #03030a 45%, #000 100%);
  color: var(--text-main);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Mono", monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  transition: background 0.3s ease-out;
}

body.neon {
  background: radial-gradient(circle at top, #5a00a0 0, #050014 45%, #000 100%);
}

body.neon .card,
body.neon .history-card {
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.12),
    0 0 30px rgba(123, 97, 255, 0.7),
    0 30px 80px rgba(0, 0, 0, 0.9);
}

body::before {
  content: "";
  position: absolute;
  inset: -50px;
  background-image:
    linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: 0.6;
  pointer-events: none;
}

/* =========================================
   Layout & Header
========================================= */
.layout {
  position: relative;
  width: 100%;
  max-width: 960px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  z-index: 1;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2px;
  padding: 2px 2px 8px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-soft);
}

.top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.top-link,
.top-button {
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: transparent;
  color: var(--text-main);
  font-size: 11px;
  padding: 4px 10px;
  text-decoration: none;
  cursor: pointer;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.top-button {
  background: rgba(255, 255, 255, 0.04);
}

.top-button:hover,
.top-link:hover {
  background: rgba(255, 255, 255, 0.08);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* =========================================
   Card & Modules
========================================= */
.card {
  position: relative;
  border-radius: 24px;
  padding: 22px 20px 18px;
  background: rgba(10, 12, 24, 0.95);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 30px 80px rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(16px);
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.card-title {
  font-size: 12px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.card-subtitle {
  font-size: 11px;
  color: var(--text-soft);
  margin-bottom: 10px;
}

.module-version {
  margin-top: 8px;
  font-size: 9px;
  color: rgba(255,255,255,0.4);
  text-align: right;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Live indicator */

.live-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-soft);
}

.live-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--live-green);
  box-shadow: 0 0 10px rgba(66,255,158,0.9);
  animation: livePulse 1s infinite alternate;
}

@keyframes livePulse {
  0%   { transform: scale(0.9); opacity: 0.7; }
  100% { transform: scale(1.15); opacity: 1; }
}

/* =========================================
   Prime focus (Index-Seite & Stats)
========================================= */

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

.prime-current-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-soft);
}

.prime-current-value {
  font-family: "SF Mono", ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 24px;
  line-height: 1.3;
  color: var(--text-main);
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(4,6,16,0.9);
  padding: 10px 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.prime-current-value:hover {
  white-space: normal;
  word-break: break-all;
}

.prime-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 10px;
}

.meta-item {
  display: flex;
  flex-direction: column;
  font-size: 11px;
}

.meta-label {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-soft);
  margin-bottom: 2px;
}

.meta-value {
  font-family: "SF Mono", ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 13px;
  color: var(--text-main);
}

.clickable {
  cursor: pointer;
  text-decoration: underline dotted rgba(255,255,255,0.2);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.live-note {
  font-size: 10px;
  color: var(--text-soft);
  margin-top: 6px;
}

/* =========================================
   Gap Bars (Index + Histogram-Style)
========================================= */
.gap-bars-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.gap-bars-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-soft);
}

.gap-bars-meta {
  font-size: 10px;
  color: var(--text-soft);
}

.gap-bars-container {
  margin-top: 6px;
  max-height: 200px;
  overflow-y: auto;
  padding-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.12);
}

.gap-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 11px;
  font-family: "SF Mono", ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.gap-label {
  flex: 0 0 70px;
  color: var(--text-soft);
  white-space: nowrap;
}

.gap-bar-wrapper {
  flex: 1;
  height: 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.05);
  overflow: hidden;
}

.gap-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.15s ease-out;
}

.gap-bar-fill.small {
  background: linear-gradient(90deg, #21f6ff, #0ab3c9);
  box-shadow: 0 0 8px rgba(33,246,255,0.8);
}

.gap-bar-fill.medium {
  background: linear-gradient(90deg, #ffdd63, #ff9e4f);
  box-shadow: 0 0 8px rgba(255,182,72,0.8);
}

.gap-bar-fill.large {
  background: linear-gradient(90deg, #ff5aa5, #c135ff);
  box-shadow: 0 0 9px rgba(255,90,165,0.9);
}

.gap-value {
  flex: 0 0 46px;
  text-align: right;
  font-size: 10px;
  color: var(--text-soft);
  white-space: nowrap;
}

/* Text-Farben für Gaps */

.gap-low-text  { color: #21f6ff; }
.gap-mid-text  { color: #ffb847; }
.gap-high-text { color: #ff5aa5; }

/* =========================================
   History (4x4)
========================================= */
.history-card {
  border-radius: 24px;
  padding: 18px 16px 14px;
  background: rgba(4, 6, 14, 0.95);
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.06),
    0 18px 40px rgba(0,0,0,0.75);
  backdrop-filter: blur(12px);
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.history-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--text-soft);
}

.history-count {
  font-size: 11px;
  color: var(--text-soft);
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
  font-size: 11px;
  font-family: "SF Mono", ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 6px;
}

.history-item {
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(10,12,24,0.9);
  padding: 4px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 46px;
}

.history-meta {
  font-size: 10px;
  opacity: 0.85;
}

.history-index {
  color: var(--text-muted);
}

.history-gap {
  font-size: 10px;
}

.history-value {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-main);
}

.history-value:hover {
  white-space: normal;
  word-break: break-all;
}

/* =========================================
   Scrollbars
========================================= */
.scrollable {
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.7) rgba(0,0,0,0.5);
}

.scrollable::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.scrollable::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.5);
}

.scrollable::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.75);
  border-radius: 4px;
}

/* =========================================
   Overlays (Max Gap + Alle Primes)
========================================= */
.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.overlay.visible {
  display: flex;
}

.overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.7);
}

.overlay-panel {
  position: relative;
  z-index: 1;
  width: 90%;
  max-width: 580px;
  max-height: 80vh;
  background: rgba(6, 8, 20, 0.98);
  border-radius: 18px;
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.16),
    0 26px 70px rgba(0,0,0,0.9);
  padding: 14px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.overlay-title {
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.overlay-subtitle {
  font-size: 11px;
  color: var(--text-soft);
}

.overlay-close-btn {
  border: 1px solid rgba(255,255,255,0.4);
  background: transparent;
  color: var(--text-main);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}

.overlay-close-btn:hover {
  background: rgba(255,255,255,0.1);
}

.overlay-body {
  flex: 1;
  min-height: 60px;
  max-height: 60vh;
  overflow-y: auto;
  font-size: 11px;
  font-family: "SF Mono", ui-monospace, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.pairs-list {
  margin: 0;
  padding-left: 12px;
}

.pairs-list li {
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.overlay-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
  margin-bottom: 4px;
}

.overlay-select {
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(10,12,24,0.9);
  color: var(--text-main);
  font-size: 11px;
}

.overlay-btn {
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.35);
  background: rgba(255,255,255,0.04);
  color: var(--text-main);
  font-size: 11px;
  padding: 3px 10px;
  cursor: pointer;
}

.overlay-btn:hover {
  background: rgba(255,255,255,0.12);
}

.primes-list {
  margin: 0;
  padding-left: 12px;
}

.primes-list li {
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =========================================
   Footer
========================================= */
footer {
  position: fixed;
  bottom: 8px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 10px;
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.08em;
  font-family: system-ui, -apple-system, "SF Mono", monospace;
  pointer-events: none;
}

footer a {
  color: rgba(255,255,255,0.6);
  text-decoration: none;
  pointer-events: auto;
}

/* =========================================
   Responsive
========================================= */
@media (max-width: 640px) {
  .prime-meta-grid {
    grid-template-columns: repeat(2, minmax(0,1fr));
  }

  .history-grid {
    grid-template-columns: repeat(2, minmax(0,1fr));
  }
}