/* ====================================================================
   1. SISTEM WARNA KOGNITIF & VARIABEL CSS (DEEP OBSIDIAN & NORDIC NEON)
   ==================================================================== */
:root {
  --bg-main: #0B1120;
  --bg-panel: #1E293B;
  --bg-panel-elevated: #263449;
  --bg-glass: rgba(30, 41, 59, 0.88);
  --border-subtle: #334155;
  --border-focus: #475569;
  --text-main: #F8FAFC;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;

  /* Warna Semantik Kognitif */
  --c-blue: #38BDF8;     /* Variabel Independen (X) / Matriks Desain X / Parameter Populasi */
  --c-blue-dim: rgba(56, 189, 248, 0.16);
  --c-purple: #C084FC;   /* Variabel Dependen (Y) / Vektor Observasi Y / Estimasi Model */
  --c-purple-dim: rgba(192, 132, 252, 0.16);
  --c-green: #34D399;    /* Asumsi Terpenuhi / Korelasi Positif Kuat / Hasil Signifikan Valid */
  --c-green-dim: rgba(52, 211, 153, 0.16);
  --c-red: #FB7185;      /* Outlier Terdeteksi / Pelanggaran Asumsi / False Positive p-Hacking */
  --c-red-dim: rgba(251, 113, 133, 0.16);
  --c-amber: #FBBF24;    /* Transformasi Matriks (X'X)⁻¹ / Peringatan Diagnostik */
  --c-amber-dim: rgba(251, 191, 36, 0.16);

  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  --font-math: 'Cambria Math', 'Latin Modern Math', Georgia, serif;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.45), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --transition-fast: 160ms cubic-bezier(0.4, 0, 0.2, 1);
  --nav-bottom-h: 68px;
}

/* ====================================================================
   2. RESET & MOBILE-FIRST BASE ARCHITECTURE (320px+)
   ==================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.6;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  background-color: var(--bg-main);
  background-image:
    radial-gradient(circle at 14% 16%, rgba(56, 189, 248, 0.06) 0%, transparent 35%),
    radial-gradient(circle at 86% 84%, rgba(192, 132, 252, 0.06) 0%, transparent 35%);
  padding-bottom: calc(var(--nav-bottom-h) + 28px);
}

img, svg, canvas, video {
  max-width: 100%;
  display: block;
  box-sizing: border-box;
}

h1 { font-size: clamp(1.32rem, 2.8vw, 2.05rem); font-weight: 800; letter-spacing: -0.025em; line-height: 1.25; }
h2 { font-size: clamp(1.12rem, 2.1vw, 1.5rem); font-weight: 700; letter-spacing: -0.015em; line-height: 1.3; }
h3 { font-size: clamp(0.96rem, 1.6vw, 1.18rem); font-weight: 600; line-height: 1.35; }
p, li { font-size: clamp(0.86rem, 1.3vw, 0.98rem); color: var(--text-secondary); }
small { font-size: clamp(0.74rem, 1.05vw, 0.84rem); }

/* Target Sentuh Minimal 44x44px */
button, .btn, select, input[type="number"], input[type="text"], .compass-opt-btn {
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
}

button, .btn, select, input[type="number"], input[type="text"] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-panel-elevated);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: clamp(0.8rem, 1.15vw, 0.88rem);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  user-select: none;
}

textarea, input[type="number"], input[type="text"] {
  cursor: text;
  font-family: var(--font-mono);
}

button:hover, .btn:hover, select:hover {
  border-color: var(--c-blue);
  background: rgba(56, 189, 248, 0.12);
}

.btn-primary {
  background: linear-gradient(135deg, #0284C7, #2563EB);
  border-color: var(--c-blue);
  color: #fff;
}
.btn-primary:hover {
  background: linear-gradient(135deg, #0369A1, #1D4ED8);
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.35);
}

.btn-emerald {
  background: rgba(52, 211, 153, 0.16);
  border-color: var(--c-green);
  color: var(--c-green);
}
.btn-emerald:hover {
  background: rgba(52, 211, 153, 0.28);
  border-color: var(--c-green);
}

.btn-coral {
  background: rgba(251, 113, 133, 0.16);
  border-color: var(--c-red);
  color: var(--c-red);
}

.btn-purple {
  background: rgba(192, 132, 252, 0.16);
  border-color: var(--c-purple);
  color: var(--c-purple);
}

.btn-amber {
  background: rgba(251, 191, 36, 0.16);
  border-color: var(--c-amber);
  color: var(--c-amber);
}

/* ====================================================================
   3. FLUID GRID, CARDS & SEMANTIC BADGES
   ==================================================================== */
.app-container {
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: 12px;
}

.grid-fluid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 310px), 1fr));
  gap: 16px;
}

.grid-2col {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

.grid-3col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: 16px;
}

.card {
  background: var(--bg-panel);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-card);
  margin-bottom: 24px;
  overflow: hidden;
}

.section-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.section-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 4px 10px;
  border-radius: 999px;
  width: fit-content;
}

.sem-blue { color: var(--c-blue); background: var(--c-blue-dim); border: 1px solid rgba(56, 189, 248, 0.35); }
.sem-purple { color: var(--c-purple); background: var(--c-purple-dim); border: 1px solid rgba(192, 132, 252, 0.35); }
.sem-green { color: var(--c-green); background: var(--c-green-dim); border: 1px solid rgba(52, 211, 153, 0.35); }
.sem-red { color: var(--c-red); background: var(--c-red-dim); border: 1px solid rgba(251, 113, 133, 0.35); }
.sem-amber { color: var(--c-amber); background: var(--c-amber-dim); border: 1px solid rgba(251, 191, 36, 0.35); }

.text-blue { color: var(--c-blue) !important; }
.text-purple { color: var(--c-purple) !important; }
.text-green { color: var(--c-green) !important; }
.text-red { color: var(--c-red) !important; }
.text-amber { color: var(--c-amber) !important; }

/* ====================================================================
   4. HEADER & NAVIGASI 6 FILE KONSISTEN
   ==================================================================== */
.top-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 10px 12px;
}

.header-inner {
  max-width: 1480px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--c-blue), var(--c-purple));
  display: grid;
  place-items: center;
  font-weight: 900;
  font-family: var(--font-math);
  font-size: 1.35rem;
  color: #0B1120;
  box-shadow: 0 0 15px rgba(56, 189, 248, 0.4);
  flex-shrink: 0;
}

.desktop-nav {
  display: none;
  max-width: 1480px;
  margin: 8px auto 0;
  padding-top: 8px;
  border-top: 1px solid rgba(51, 65, 85, 0.6);
  gap: 6px;
  overflow-x: auto;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.84rem;
  font-weight: 600;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.nav-link:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
  border-color: var(--border-subtle);
}

.nav-link.active {
  color: var(--c-blue);
  background: var(--c-blue-dim);
  border-color: rgba(56, 189, 248, 0.4);
}

.nav-badge {
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.7);
  color: var(--text-main);
}

.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-bottom-h);
  background: rgba(11, 17, 32, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  z-index: 120;
  padding: 4px;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.65rem;
  font-weight: 600;
  border-radius: 8px;
  padding: 4px 2px;
  text-align: center;
  line-height: 1.1;
}

.mobile-nav-item svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
}

.mobile-nav-item.active {
  color: var(--c-blue);
  background: var(--c-blue-dim);
}

/* ====================================================================
   5. KOMPONEN BYOD SANDBOX, CODE SYNC, DECISION COMPASS & MATRIX OLS
   ==================================================================== */
.paste-textarea {
  width: 100%;
  min-height: 135px;
  background: #070C17;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 10px 12px;
  font-size: 0.8rem;
  line-height: 1.45;
  resize: vertical;
}

.paste-textarea:focus {
  outline: none;
  border-color: var(--c-blue);
}

.table-scroll-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: #070C17;
  max-height: 280px;
  overflow-y: auto;
}

table.stat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.79rem;
  text-align: left;
  font-family: var(--font-mono);
}

table.stat-table th, table.stat-table td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.5);
  white-space: nowrap;
}

table.stat-table th {
  position: sticky;
  top: 0;
  background: #131D31;
  color: var(--c-blue);
  font-weight: 700;
  z-index: 2;
}

tr.outlier-row {
  background: rgba(251, 113, 133, 0.22) !important;
  color: #FECDD3;
}

.canvas-box {
  width: 100%;
  height: 290px;
  background: #070B14;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  position: relative;
  overflow: hidden;
}

.canvas-box canvas {
  width: 100%;
  height: 100%;
}

.code-block-wrap {
  background: #060A12;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.code-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(30, 41, 59, 0.85);
  border-bottom: 1px solid var(--border-subtle);
  gap: 6px;
  flex-wrap: wrap;
}

pre.code-pre {
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.77rem;
  line-height: 1.5;
  color: #E2E8F0;
  overflow-x: auto;
  max-height: 360px;
  overflow-y: auto;
  white-space: pre;
}

/* Decision Compass Wizard */
.compass-step-box {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
}

.compass-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.compass-opt-btn {
  font-size: 0.78rem;
  padding: 6px 10px;
  min-height: 40px;
}

.compass-opt-btn.active {
  background: var(--c-blue-dim);
  border-color: var(--c-blue);
  color: var(--c-blue);
}

/* p-Hacking Grid 20 Variables */
.phack-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 105px), 1fr));
  gap: 6px;
  margin: 10px 0;
}

.phack-cell {
  padding: 8px 6px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-subtle);
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.phack-cell.sig-false {
  background: rgba(251, 113, 133, 0.25);
  border-color: var(--c-red);
  color: #fff;
  font-weight: 700;
}

/* Matrix Algebra Brackets Visualizer */
.matrix-flow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
}

.matrix-bracket-box {
  background: #070C17;
  border-left: 3px solid var(--c-amber);
  border-right: 3px solid var(--c-amber);
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.matrix-bracket-box table td {
  padding: 3px 6px;
  text-align: right;
}

/* Toast Notification */
#toastNotification {
  position: fixed;
  bottom: 84px;
  right: 16px;
  z-index: 999;
  background: #0F172A;
  border: 1px solid var(--c-green);
  color: var(--text-main);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: all 0.25s ease;
}
#toastNotification.show {
  opacity: 1;
  transform: translateY(0);
}

/* ====================================================================
   6. PROGRESSIVE MEDIA QUERIES (TABLET, LAPTOP, ULTRA-WIDE)
   ==================================================================== */
@media (min-width: 768px) {
  .app-container {
    padding: 20px;
  }
  .card {
    padding: 22px;
  }
  .section-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

@media (min-width: 1024px) {
  body {
    padding-bottom: 40px;
  }
  .desktop-nav {
    display: flex;
  }
  .mobile-bottom-nav {
    display: none;
  }
  .grid-2col {
    grid-template-columns: 1fr 1fr;
  }
  #toastNotification {
    bottom: 24px;
  }
}

@media (min-width: 1440px) {
  .app-container {
    padding: 28px 32px;
  }
  .canvas-box {
    height: 315px;
  }
}
