/* =============================================================================
   style.css — Gaya kustom di atas Tailwind CSS (via CDN)
   Tema warna: Primary #2563EB, Secondary #0F172A, Accent #38BDF8, BG #F8FAFC
============================================================================= */

:root {
  --color-primary: #2563EB;
  --color-secondary: #0F172A;
  --color-accent: #38BDF8;
  --color-bg: #F8FAFC;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Poppins', sans-serif;
  background-color: var(--color-bg);
  color: var(--color-secondary);
  transition: background-color 0.3s ease, color 0.3s ease;
}

body.dark {
  background-color: #0B1220;
  color: #E2E8F0;
}

body.dark .surface {
  background-color: #111827;
  border-color: #1F2937;
}

body.dark .surface-alt {
  background-color: #0B1220;
}

body.dark .navbar {
  background-color: rgba(15, 23, 42, 0.85);
  border-color: #1F2937;
}

.text-muted {
  color: #64748B;
}
body.dark .text-muted {
  color: #94A3B8;
}

body.dark input,
body.dark textarea,
body.dark select {
  background-color: #0B1220;
  border-color: #1F2937;
  color: #E2E8F0;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-thumb {
  background: var(--color-accent);
  border-radius: 999px;
}

/* ---------- Navbar ---------- */
.navbar {
  backdrop-filter: blur(10px);
  background-color: rgba(248, 250, 252, 0.85);
  border-bottom: 1px solid #E2E8F0;
}

.nav-link {
  position: relative;
  transition: color 0.2s ease;
}
.nav-link::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -4px;
  height: 2px;
  width: 0%;
  background: var(--color-accent);
  transition: width 0.25s ease;
}
.nav-link:hover::after,
.nav-link.active::after {
  width: 100%;
}

/* ---------- Hero ---------- */
.hero-gradient {
  background: radial-gradient(circle at 20% 20%, rgba(56, 189, 248, 0.18), transparent 40%),
              radial-gradient(circle at 80% 0%, rgba(37, 99, 235, 0.18), transparent 45%),
              linear-gradient(180deg, #F8FAFC 0%, #EFF6FF 100%);
}
body.dark .hero-gradient {
  background: radial-gradient(circle at 20% 20%, rgba(56, 189, 248, 0.12), transparent 40%),
              radial-gradient(circle at 80% 0%, rgba(37, 99, 235, 0.20), transparent 45%),
              linear-gradient(180deg, #0B1220 0%, #0F172A 100%);
}

/* ---------- Cards ---------- */
.algo-card {
  background: white;
  border: 1px solid #E2E8F0;
  border-radius: 1rem;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}
.algo-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 20px 40px -20px rgba(37, 99, 235, 0.35);
  border-color: var(--color-accent);
}
body.dark .algo-card {
  background: #111827;
  border-color: #1F2937;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-blue { background: #DBEAFE; color: #1D4ED8; }
.badge-sky { background: #E0F2FE; color: #0369A1; }
body.dark .badge-blue { background: rgba(37,99,235,0.2); color: #93C5FD; }
body.dark .badge-sky { background: rgba(56,189,248,0.15); color: #7DD3FC; }

/* ---------- Section ---------- */
.module-section {
  scroll-margin-top: 90px;
}

.surface {
  background: white;
  border: 1px solid #E2E8F0;
  border-radius: 1rem;
}
.surface-alt {
  background: #F1F5F9;
}

/* ---------- Step Card / Accordion ---------- */
.step-card {
  border: 1px solid #E2E8F0;
  border-radius: 0.75rem;
  overflow: hidden;
  background: white;
}
body.dark .step-card {
  background: #0B1220;
  border-color: #1F2937;
}

.step-header {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  gap: 0.75rem;
  user-select: none;
}
.step-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.35s ease, padding 0.35s ease;
  padding: 0 1rem;
  font-size: 0.85rem;
  line-height: 1.6;
}
.step-card.open .step-body {
  padding: 0 1rem 1rem 1rem;
}
.step-chevron {
  transition: transform 0.25s ease;
}
.step-card.open .step-chevron {
  transform: rotate(180deg);
}

.mono {
  font-family: 'Courier New', Consolas, monospace;
  word-break: break-all;
}

/* ---------- Matrix table ---------- */
.matrix-table td, .matrix-table th {
  border: 1px solid #CBD5E1;
  padding: 0.35rem 0.55rem;
  text-align: center;
  font-family: 'Courier New', monospace;
}
body.dark .matrix-table td, body.dark .matrix-table th {
  border-color: #334155;
}

/* ---------- Loading ---------- */
.spinner {
  border: 3px solid rgba(37,99,235,0.15);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  width: 22px;
  height: 22px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Toast ---------- */
#toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  background: var(--color-secondary);
  color: white;
  padding: 0.65rem 1rem;
  border-radius: 0.6rem;
  font-size: 0.85rem;
  box-shadow: 0 10px 25px -10px rgba(0,0,0,0.4);
  animation: toast-in 0.25s ease, toast-out 0.25s ease 2.5s forwards;
  border-left: 3px solid var(--color-accent);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px);} to {opacity:1; transform: translateY(0);} }
@keyframes toast-out { to { opacity: 0; transform: translateY(-6px);} }

/* ---------- Tooltip ---------- */
.tooltip {
  position: relative;
}
.tooltip::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-secondary);
  color: white;
  padding: 0.3rem 0.6rem;
  border-radius: 0.4rem;
  font-size: 0.7rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 20;
}
.tooltip:hover::before {
  opacity: 1;
}

/* ---------- Utility fade-in ---------- */
.fade-in {
  animation: fadeIn 0.5s ease both;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Round pill nav (within module) ---------- */
.pill-btn {
  border-radius: 999px;
  padding: 0.4rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid #E2E8F0;
  transition: all 0.2s ease;
}
.pill-btn.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}
body.dark .pill-btn {
  border-color: #1F2937;
}

textarea, input[type="text"] {
  font-family: 'Courier New', monospace;
}

/* =============================================================================
   SOLUSI: REPORT-STYLE LAYOUT
   Input -> Key Generation -> Initial Process -> Round 1..N -> Final -> Hasil
============================================================================= */

/* Ringkasan alur di bagian atas panel solusi */
.flow-overview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.85rem 1rem;
  margin-bottom: 1.25rem;
  background: #EFF6FF;
  border: 1px solid #DBEAFE;
  border-radius: 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-primary);
}
body.dark .flow-overview {
  background: rgba(37, 99, 235, 0.08);
  border-color: rgba(37, 99, 235, 0.25);
}
.flow-overview-item {
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: white;
  border: 1px solid #BFDBFE;
  white-space: nowrap;
}
body.dark .flow-overview-item {
  background: #0B1220;
  border-color: rgba(37, 99, 235, 0.3);
}
.flow-overview-arrow {
  color: var(--color-accent);
  flex-shrink: 0;
}

/* Stage Card: SATU accordion untuk Key Generation / Initial Process / Round N / Final */
.stage-card {
  border: 1px solid #E2E8F0;
  border-radius: 1rem;
  margin-bottom: 1rem;
  overflow: hidden;
  background: white;
}
body.dark .stage-card {
  background: #111827;
  border-color: #1F2937;
}
.stage-header {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  user-select: none;
}
.stage-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.35s ease;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}
.stage-card.open .stage-body {
  grid-template-rows: 1fr;
  padding-bottom: 1.25rem;
}
/* .stage-content adalah SATU-SATUNYA grid item di dalam .stage-body (dibungkus otomatis
   oleh buildStageCard). Ini penting: CSS Grid "0fr -> 1fr" hanya menganimasikan tinggi
   baris tunggal; bila body punya lebih dari satu child langsung (mis. beberapa div hasil
   gabungan string), child ke-2/ke-3 akan jatuh ke baris implisit yang TIDAK ikut
   collapse — itulah penyebab isi masih terlihat/terpotong saat accordion ditutup.
   min-height:0 + overflow:hidden pada satu wrapper ini membuat seluruh isi benar-benar
   collapse ke tinggi 0 saat tertutup, sementara elemen scroll-horizontal di dalamnya
   (round-flow-horizontal, tabel) tetap bisa scroll sendiri karena overflow itu terjadi
   di DALAM stage-content, bukan dibatasi olehnya secara horizontal. */
.stage-content {
  overflow: hidden;
  min-height: 0;
  min-width: 0;
}
.stage-card .step-chevron {
  transition: transform 0.25s ease;
  flex-shrink: 0;
}
.stage-card.open .step-chevron {
  transform: rotate(180deg);
}

/* Vertical timeline (solution-flow): garis alur menghubungkan tiap langkah */
.solution-flow {
  position: relative;
  padding-top: 0.25rem;
}
.flow-step {
  position: relative;
  display: flex;
  gap: 0.9rem;
  padding-bottom: 1.25rem;
}
.flow-step:last-child {
  padding-bottom: 0.5rem;
}
.flow-step::before {
  /* garis vertikal penghubung */
  content: "";
  position: absolute;
  left: 15px;
  top: 32px;
  bottom: -4px;
  width: 2px;
  background: repeating-linear-gradient(to bottom, var(--color-accent) 0 4px, transparent 4px 8px);
}
.flow-step:last-child::before {
  display: none;
}
.flow-number {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  z-index: 1;
}
.flow-content {
  flex: 1;
  min-width: 0;
  border: 1px solid #E2E8F0;
  border-radius: 0.65rem;
  padding: 0.75rem 1rem;
}
body.dark .flow-content {
  border-color: #1F2937;
}
.flow-title {
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.2rem;
  color: var(--color-secondary);
}
body.dark .flow-title {
  color: #E2E8F0;
}
.flow-note {
  font-size: 0.72rem;
  margin-bottom: 0.45rem;
  line-height: 1.5;
}
.flow-body {
  font-size: 0.8rem;
}

/* Tabel S-Box & Matrix di dalam flow-body */
.flow-body .matrix-table {
  border-collapse: collapse;
}
.flow-body table.matrix-table td,
.flow-body table.matrix-table th {
  font-size: 0.75rem;
  padding: 0.3rem 0.5rem;
}

/* =============================================================================
   STEPPER / TABS WIDGET (Key Expansion horizontal, Round Key tabs)
============================================================================= */
.stepper-widget {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.stepper-nav {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.4rem;
  scrollbar-width: thin;
}
.stepper-btn {
  flex-shrink: 0;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: 'Courier New', monospace;
  border: 1px solid #E2E8F0;
  background: white;
  color: var(--color-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.stepper-btn:hover {
  border-color: var(--color-accent);
}
.stepper-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
}
body.dark .stepper-btn {
  background: #0B1220;
  border-color: #1F2937;
  color: #E2E8F0;
}
.stepper-widget.tabs-variant .stepper-btn {
  border-radius: 0.5rem;
}
.stepper-panel {
  border: 1px solid #E2E8F0;
  border-radius: 0.65rem;
  padding: 0.9rem 1rem;
  background: #F8FAFC;
  min-height: 60px;
}
body.dark .stepper-panel {
  background: #0B1220;
  border-color: #1F2937;
}

/* =============================================================================
   HORIZONTAL ROUND FLOW (AES / S-AES): State Awal -> ... -> State Akhir
============================================================================= */
.round-flow-horizontal {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.35rem 0.1rem 0.9rem 0.1rem;
  scrollbar-width: thin;
}
.round-flow-card {
  flex-shrink: 0;
  width: 180px;
  border: 1px solid #E2E8F0;
  border-radius: 0.75rem;
  padding: 0.65rem;
  background: white;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
  display: flex;
  flex-direction: column;
}
body.dark .round-flow-card {
  background: #0B1220;
  border-color: #1F2937;
}
.round-flow-card-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 0.4rem;
  text-align: center;
}
.round-flow-card-matrix {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}
.round-flow-card-matrix table.matrix-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 auto;
}
.round-flow-card-matrix table.matrix-table td {
  font-size: 0.62rem;
  padding: 0.2rem 0.25rem;
  text-align: center;
}
.round-flow-card-note {
  font-size: 0.62rem;
  color: #64748B;
  margin-top: 0.4rem;
  line-height: 1.4;
  text-align: center;
}
body.dark .round-flow-card-note {
  color: #94A3B8;
}

/* Varian kartu berbasis teks (DES per-round, S-DES Key Generation & Round) */
.round-flow-card.text-card {
  width: 190px;
  justify-content: center;
}
.round-flow-card-body {
  font-size: 0.7rem;
  text-align: center;
  word-break: break-all;
  line-height: 1.5;
  color: var(--color-secondary);
}
body.dark .round-flow-card-body {
  color: #E2E8F0;
}

/* Tabel full-width (S-Box DES) di antara 2 baris horizontal */
.round-flow-fullwidth {
  width: 100%;
  margin: 0.75rem 0;
}
.round-flow-fullwidth .matrix-table {
  width: 100%;
}

.round-flow-arrow {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-accent);
  width: 20px;
}

/* =============================================================================
   DES KEY GENERATION TABLE
============================================================================= */
.des-key-table td, .des-key-table th {
  white-space: nowrap;
}
.detail-toggle-btn {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--color-primary);
  background: #EFF6FF;
  border: 1px solid #DBEAFE;
  border-radius: 0.4rem;
  padding: 0.2rem 0.55rem;
  cursor: pointer;
  white-space: nowrap;
}
.detail-toggle-btn:hover {
  background: #DBEAFE;
}
body.dark .detail-toggle-btn {
  background: rgba(37, 99, 235, 0.12);
  border-color: rgba(37, 99, 235, 0.3);
  color: #93C5FD;
}
tr.detail-row.hidden {
  display: none;
}

/* =============================================================================
   SOLUTION STEPPER NAVIGATION + PROGRESS (sticky, di atas panel solusi)
============================================================================= */
.solution-nav {
  position: sticky;
  top: 4.2rem;
  z-index: 10;
  display: inline-flex;
  max-width: 100%;
  align-items: center;
  gap: 0.5rem;
  background: rgba(248, 250, 252, 0.92);
  backdrop-filter: blur(6px);
  border: 1px solid #E2E8F0;
  border-radius: 999px;
  padding: 0.35rem 0.5rem;
  margin-bottom: 1.25rem;
}
body.dark .solution-nav {
  background: rgba(11, 18, 32, 0.92);
  border-color: #1F2937;
}
.solution-nav-scroll {
  display: flex;
  gap: 0.3rem;
  overflow-x: auto;
  scrollbar-width: thin;
  flex: 1;
  min-width: 0;
  max-width: 420px;
}
.solution-nav-btn {
  flex-shrink: 0;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 700;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.solution-nav-btn.upcoming {
  background: #F1F5F9;
  color: #94A3B8;
  border-color: #E2E8F0;
}
.solution-nav-btn.done {
  background: #DCFCE7;
  color: #16A34A;
  border-color: #BBF7D0;
}
.solution-nav-btn.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
  transform: scale(1.05);
}
body.dark .solution-nav-btn.upcoming {
  background: #111827;
  color: #64748B;
  border-color: #1F2937;
}
body.dark .solution-nav-btn.done {
  background: rgba(34, 197, 94, 0.12);
  color: #4ADE80;
  border-color: rgba(34, 197, 94, 0.3);
}
.solution-progress {
  flex-shrink: 0;
  font-size: 0.64rem;
  font-weight: 700;
  color: var(--color-primary);
  background: #EFF6FF;
  border: 1px solid #DBEAFE;
  border-radius: 999px;
  padding: 0.22rem 0.6rem;
  white-space: nowrap;
}
body.dark .solution-progress {
  background: rgba(37, 99, 235, 0.12);
  border-color: rgba(37, 99, 235, 0.3);
}

@media (max-width: 640px) {
  .round-flow-card { width: 138px; }
  .round-flow-card.text-card { width: 150px; }
  .solution-nav { top: 3.6rem; max-width: 100%; }
  .solution-nav-scroll { max-width: 220px; }
}

/* =============================================================================
   ROUND NAV WIDGET (navigasi internal Round di dalam SATU card, mis. "Feistel Round",
   "Round" pada AES/S-AES): tab R1..Rn + Prev/Next + panel isi.
============================================================================= */
.round-nav-widget {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.round-nav-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}
.round-nav-arrow {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #E2E8F0;
  background: white;
  color: var(--color-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
}
.round-nav-arrow:hover:not(:disabled) {
  border-color: var(--color-accent);
  color: var(--color-primary);
}
.round-nav-arrow:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
body.dark .round-nav-arrow {
  background: #0B1220;
  border-color: #1F2937;
  color: #E2E8F0;
}
.round-nav-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--color-primary);
  min-width: 110px;
  text-align: center;
}
.round-nav-tabs {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  scrollbar-width: thin;
  padding-bottom: 0.3rem;
  justify-content: flex-start;
}
.round-nav-tab {
  flex-shrink: 0;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  border: 1px solid #E2E8F0;
  background: #F1F5F9;
  color: #64748B;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}
.round-nav-tab:hover {
  border-color: var(--color-accent);
}
.round-nav-tab.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: white;
}
body.dark .round-nav-tab {
  background: #111827;
  border-color: #1F2937;
  color: #94A3B8;
}
.round-nav-panel {
  border-top: 1px dashed #E2E8F0;
  padding-top: 0.75rem;
}
body.dark .round-nav-panel {
  border-color: #1F2937;
}

/* =============================================================================
   RESPONSIVE / MOBILE SAFETY NET
   Tampilan desktop (>= lg) tidak diubah sama sekali — seluruh rule di bawah ini
   hanya aktif di breakpoint mobile/tablet (max-width queries) atau bersifat
   "safety net" yang tidak berdampak visual selama tidak ada elemen yang overflow.
============================================================================= */

/* Cegah horizontal scroll pada level halaman. Elemen yang memang butuh scroll
   horizontal (tabel, matrix, stepper) tetap bisa scroll karena masing-masing
   sudah punya overflow-x:auto sendiri di dalam container-nya — aturan ini hanya
   mencegah overflow tersebut "bocor" ke document/body. */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Judul & paragraf otomatis mengecil di layar sangat kecil agar tidak overflow.
   .module-section mencakup Home, DES, S-DES, AES, S-AES, dan About. */
@media (max-width: 480px) {
  .module-section h1 {
    font-size: 1.85rem;
    line-height: 1.25;
  }
  .module-section h2 {
    font-size: 1.4rem;
    line-height: 1.3;
  }
  .module-section h3 {
    font-size: 1rem;
  }
  .module-section p {
    overflow-wrap: break-word;
    word-break: break-word;
  }
}

/* Tombol Submit / Reset / Contoh Otomatis: tersusun vertikal (full-width) di
   layar sangat sempit, tetap wrap seperti biasa di layar yang lebih lebar. */
@media (max-width: 480px) {
  button[id$="-submit"],
  button[id$="-reset"],
  button[id$="-example"] {
    flex: 1 1 100%;
  }
}

/* Toast notification tidak boleh melebihi lebar viewport */
#toast-container {
  max-width: calc(100vw - 2.5rem);
}
.toast {
  max-width: 100%;
  overflow-wrap: break-word;
}

/* Pastikan card/accordion selalu memenuhi lebar container-nya (bukan lebar tetap) */
.surface,
.algo-card,
.stage-card {
  width: 100%;
}