:root {
  --bg: #0a1020;
  --bg-2: #101827;
  --panel: rgba(14, 23, 42, 0.78);
  --panel-solid: #111c31;
  --text: #f8fafc;
  --muted: #a8b3c7;
  --border: rgba(226, 232, 240, 0.14);
  --primary: #00e5ff;
  --secondary: #ff4ecd;
  --warning: #ffd166;
  --success: #7cf7a8;
  --danger: #ff6b81;
  --shadow: 0 26px 80px rgba(0, 0, 0, 0.42);
}

html[data-bs-theme="light"] {
  --bg: #f3f7ff;
  --bg-2: #ffffff;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-solid: #ffffff;
  --text: #111827;
  --muted: #64748b;
  --border: rgba(15, 23, 42, 0.12);
  --shadow: 0 22px 70px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 10%, rgba(0, 229, 255, 0.16), transparent 25rem),
    radial-gradient(circle at 90% 8%, rgba(255, 78, 205, 0.16), transparent 24rem),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  overflow-x: hidden;
}

.bg-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .55;
  background-image:
    linear-gradient(rgba(255, 255, 255, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .035) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(to bottom, black, transparent 78%);
}

.topbar {
  background: rgba(10, 16, 32, .76);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
}

html[data-bs-theme="light"] .topbar {
  background: rgba(255, 255, 255, .72);
}

.brand {
  color: var(--text) !important;
  font-weight: 900;
  letter-spacing: -.04em;
}

.brand-logo {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #07111f;
  font-size: .85rem;
  box-shadow: 0 16px 36px rgba(0, 229, 255, .16);
}

.status-chip {
  align-items: center;
  gap: .45rem;
  padding: .55rem .8rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, .04);
  font-size: .82rem;
}

.status-chip i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 0 5px rgba(124, 247, 168, .12);
}

.theme-toggle {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.hero-shell {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 36px;
  padding: clamp(1.2rem, 3vw, 2rem);
  background:
    linear-gradient(135deg, rgba(0, 229, 255, .12), transparent 36%),
    linear-gradient(315deg, rgba(255, 78, 205, .13), transparent 36%),
    var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.hero-shell::after {
  content: "";
  position: absolute;
  width: 18rem;
  height: 18rem;
  right: -7rem;
  top: -7rem;
  border-radius: 50%;
  background: rgba(0, 229, 255, .16);
  filter: blur(12px);
}

.hero-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: clamp(1rem, 4vw, 3rem);
  align-items: center;
}

.mini-label {
  display: inline-flex;
  padding: .5rem .75rem;
  border-radius: 999px;
  border: 1px solid rgba(0, 229, 255, .26);
  color: var(--primary);
  background: rgba(0, 229, 255, .08);
  font-weight: 800;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.hero-content h1 {
  margin: .9rem 0 .6rem;
  font-size: clamp(3.2rem, 9vw, 6.8rem);
  line-height: .88;
  font-weight: 950;
  letter-spacing: -.08em;
  background: linear-gradient(135deg, var(--text), var(--primary), var(--secondary));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-subtitle {
  max-width: 48rem;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.25rem);
  line-height: 1.8;
}

.hero-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-top: 1.5rem;
}

.btn-main,
.btn-ghost,
.btn-run,
.copy-btn,
.clear-btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  text-decoration: none;
  border: 0;
  border-radius: 16px;
  font-weight: 900;
  transition: .2s ease;
}

.btn-main,
.btn-run {
  padding: .9rem 1.15rem;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #06101d;
  box-shadow: 0 16px 40px rgba(0, 229, 255, .18);
}

.btn-ghost,
.clear-btn {
  padding: .9rem 1.15rem;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .045);
  color: var(--text);
}

.btn-main:hover,
.btn-run:hover,
.btn-ghost:hover,
.copy-btn:hover,
.clear-btn:hover {
  transform: translateY(-2px);
}

.dashboard-card {
  border: 1px solid var(--border);
  border-radius: 28px;
  padding: 1.1rem;
  background: rgba(3, 7, 18, .44);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08);
}

html[data-bs-theme="light"] .dashboard-card {
  background: rgba(255, 255, 255, .52);
}

.dashboard-top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 1rem;
}

.dashboard-top small {
  display: block;
  color: var(--muted);
}

.dashboard-top strong {
  font-size: 1.1rem;
}

.live-dot {
  color: var(--success);
  font-size: .82rem;
  font-weight: 800;
}

.cipher-flow {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: .75rem;
  align-items: center;
}

.flow-box {
  min-height: 8rem;
  display: grid;
  align-content: center;
  gap: .55rem;
  padding: 1rem;
  border-radius: 22px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .04);
}

.flow-box small {
  color: var(--muted);
  font-weight: 900;
  letter-spacing: .12em;
}

.flow-box b {
  word-break: break-word;
}

.flow-box.active {
  border-color: rgba(255, 78, 205, .42);
  background: rgba(255, 78, 205, .08);
}

.flow-arrow {
  color: var(--primary);
  font-size: 1.4rem;
  font-weight: 900;
}

.formula-strip {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: .9rem;
}

.formula-strip span {
  padding: .45rem .6rem;
  border-radius: 999px;
  background: rgba(0, 229, 255, .08);
  border: 1px solid rgba(0, 229, 255, .16);
  color: var(--primary);
  font-size: .8rem;
  font-weight: 800;
}

.feature-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-top: 1rem;
}

.feature-row article,
.app-card {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.feature-row article {
  padding: 1rem;
}

.feature-row span {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 13px;
  background: rgba(0, 229, 255, .1);
  color: var(--primary);
  font-weight: 900;
}

.feature-row h3 {
  margin: .9rem 0 .35rem;
  font-size: 1.05rem;
  font-weight: 900;
}

.feature-row p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.app-card {
  padding: clamp(1rem, 2.4vw, 1.45rem);
}

.form-sticky {
  top: 5.7rem;
}

.card-heading,
.history-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.2rem;
}

.card-heading {
  justify-content: flex-start;
}

.heading-icon {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(0, 229, 255, .18), rgba(255, 78, 205, .16));
  color: var(--primary);
  font-weight: 900;
}

.card-heading h2,
.history-head h2 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 950;
  letter-spacing: -.035em;
}

.card-heading p,
.history-head p {
  margin: .15rem 0 0;
  color: var(--muted);
}

.form-label {
  font-weight: 800;
  color: var(--text);
}

.field,
.form-control,
.form-select {
  border-radius: 16px;
  border: 1px solid var(--border);
  background-color: rgba(255, 255, 255, .045);
  color: var(--text);
}

.form-select option {
  color: #111827;
}

.field:focus,
.form-control:focus,
.form-select:focus {
  border-color: rgba(0, 229, 255, .72);
  box-shadow: 0 0 0 .25rem rgba(0, 229, 255, .12);
  background-color: rgba(255, 255, 255, .06);
  color: var(--text);
}

.form-text,
.text-secondary {
  color: var(--muted) !important;
}

.algorithm-note {
  padding: .75rem;
  border-radius: 16px;
  border: 1px dashed var(--border);
  color: var(--muted);
  background: rgba(255, 255, 255, .035);
  line-height: 1.6;
}

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .45rem;
  padding: .35rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, .045);
  border: 1px solid var(--border);
}

.mode-tabs input {
  display: none;
}

.mode-tabs label {
  padding: .78rem;
  border-radius: 14px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
  font-weight: 900;
}

.mode-tabs input:checked+label {
  color: #06101d;
  background: linear-gradient(135deg, var(--primary), var(--warning));
}

.key-group {
  display: none;
  margin-top: 1rem;
}

.key-group.active {
  display: block;
  animation: fadeUp .25s ease both;
}

.btn-run {
  min-height: 52px;
}

.output-card {
  min-height: 43rem;
}

.result-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem;
  border-radius: 24px;
  background: linear-gradient(135deg, rgba(0, 229, 255, .1), rgba(255, 78, 205, .08));
  border: 1px solid rgba(0, 229, 255, .22);
}

.result-panel small {
  color: var(--muted);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.result-text {
  margin-top: .35rem;
  font-size: clamp(1.45rem, 3vw, 2.2rem);
  font-weight: 950;
  word-break: break-word;
  letter-spacing: .02em;
}

.copy-btn {
  padding: .68rem .9rem;
  background: #fff;
  color: #06101d;
}

.visual-block h3 {
  font-size: .86rem;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: .1em;
  margin-bottom: .8rem;
  font-weight: 950;
}

.matrix-grid,
.playfair-grid {
  display: grid;
  gap: .48rem;
  width: max-content;
  max-width: 100%;
  padding: .8rem;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .035);
}

.matrix-grid.size-2 {
  grid-template-columns: repeat(2, 48px);
}

.matrix-grid.size-3 {
  grid-template-columns: repeat(3, 48px);
}

.playfair-grid {
  grid-template-columns: repeat(5, 48px);
}

.matrix-grid span,
.playfair-grid span {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: rgba(0, 229, 255, .09);
  border: 1px solid rgba(0, 229, 255, .18);
  color: var(--text);
  font-weight: 950;
}

.custom-accordion .accordion-item,
.custom-accordion .accordion-button {
  background: rgba(255, 255, 255, .035);
  color: var(--text);
  border-color: var(--border);
}

.custom-accordion .accordion-item {
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: .7rem;
}

.custom-accordion .accordion-button:focus {
  box-shadow: none;
}

.timeline {
  display: grid;
  gap: .75rem;
}

.timeline-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: .85rem;
  padding: .85rem;
  border-radius: 18px;
  background: rgba(255, 255, 255, .035);
  border: 1px solid var(--border);
}

.timeline-item span {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  color: #06101d;
  background: var(--primary);
  font-weight: 950;
  font-size: .82rem;
}

.timeline-item p {
  margin: 0;
  line-height: 1.7;
}

.empty-result {
  min-height: 32rem;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
}

.empty-result span {
  width: 82px;
  height: 82px;
  display: grid;
  place-items: center;
  border-radius: 28px;
  background: rgba(0, 229, 255, .08);
  color: var(--primary);
  font-size: 2.6rem;
  margin-bottom: 1rem;
}

.empty-result h3 {
  font-weight: 950;
}

.empty-result p {
  color: var(--muted);
  max-width: 28rem;
}

.history-head {
  align-items: center;
}

.clear-btn {
  padding: .72rem .95rem;
}

.history-table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--text);
  --bs-table-border-color: var(--border);
  --bs-table-hover-bg: rgba(0, 229, 255, .05);
  color: var(--text);
}

.history-table thead th {
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .78rem;
}

.empty-table,
.footer-text {
  color: var(--muted);
}

.reveal {
  opacity: 0;
  transform: translateY(14px);
  animation: fadeUp .55s ease forwards;
}

@keyframes fadeUp {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 992px) {

  .hero-grid,
  .feature-row {
    grid-template-columns: 1fr;
  }

  .form-sticky {
    position: static !important;
  }
}

@media (max-width: 576px) {

  .hero-shell,
  .app-card,
  .feature-row article {
    border-radius: 22px;
  }

  .hero-content h1 {
    font-size: 3.25rem;
  }

  .cipher-flow {
    grid-template-columns: 1fr;
  }

  .flow-arrow {
    transform: rotate(90deg);
    text-align: center;
  }

  .result-panel,
  .history-head {
    align-items: stretch;
    flex-direction: column;
  }

  .playfair-grid {
    grid-template-columns: repeat(5, 38px);
  }

  .playfair-grid span,
  .matrix-grid span {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }

  .matrix-grid.size-2 {
    grid-template-columns: repeat(2, 38px);
  }

  .matrix-grid.size-3 {
    grid-template-columns: repeat(3, 38px);
  }
}