:root {
  --bg: #000;
  --fg: #0fffc1;
  /* neon green-ish */
  --muted: #9aa0a6;
  --circle-size: 36px;
  --gap: 10px;
}

* {
  box-sizing: border-box
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
}

.app,
main,
body,
html {
  background: var(--bg);
  color: white;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 24px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.top h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0.5px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-direction: column;
}

.controls label {
  font-size: 14px;
  color: var(--muted);
}

.controls input {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 8px 12px;
  border-radius: 8px;
  color: white;
  outline: none;
  width: 220px;
  font-size: 16px;
}

.controls input:focus {
  box-shadow: 0 0 8px rgba(0, 255, 170, 0.06), 0 0 24px rgba(0, 255, 170, 0.06);
}

.mode-select {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 6px;
}

.mode-select select {
  background: rgba(228, 213, 213, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: rgb(0, 102, 46);
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
}

.mode-select label {
  font-size: 13px;
  color: var(--muted);
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 20px;
}

.info {
  display: flex;
  flex-direction: column;
  align-items: center;

  .modifier-tip {
    color: var(--muted);
    font-size: 13px;
    display: flex;
    gap: 8px;
    align-items: center;
  }

  .modifier-tip .keys {
    display: inline-block;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 6px;
    padding: 2px 6px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    font-weight: 700;
    color: var(--fg);
    text-wrap: nowrap;
  }

  .modifier-tip strong {
    color: var(--muted);
    font-size: 12px;
    margin-right: 6px;
  }

  margin-bottom: 18px;
}

.info .value {
  font-size: 22px;
  font-weight: 700;
}

.info .small {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
}

#bitField-wrap {
  width: 100%;
  max-width: 1400px;
  padding: 18px;
  position: relative;
}

.bitField {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
  justify-content: center;
  align-items: center;
  transition: all 200ms ease;
}

.byte {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: linear-gradient(0deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(4px);
  min-width: fit-content;
}

.byte .row {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.bit {
  width: var(--circle-size);
  height: var(--circle-size);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.5);
  /* animation duration is adjustable using --bit-transition (ms) set by JS */
  transition: all var(--bit-transition, 350ms) cubic-bezier(.2, .9, .23, 1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.bit.on {
  background: radial-gradient(circle at 35% 35%, #00ff99 8%, #00ff99 18%, #00ff66 46%);
  border-color: rgba(0, 255, 120, 0.9);
  box-shadow: 0 0 12px rgba(0, 255, 120, 0.45), 0 0 28px rgba(0, 255, 120, 0.15), inset 0 -3px 6px rgba(0, 0, 0, 0.4);
  transform: scale(1.06);
}

.bit.off {
  border: dashed 1px #fff;
  opacity: 0.45;
}

.byte-title {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin-top: 2px;
}

/* small screens shrink */
@media (max-width:640px) {
  :root {
    --circle-size: 30px;
  }
}

/* when container is cramped we reduce size using a helper class set by JS */
.bitField.small .byte {
  padding: 8px;
}

.bitField.small .bit {
  width: calc(var(--circle-size) * 0.8);
  height: calc(var(--circle-size) * 0.8);
}

.bitField.smaller .byte {
  padding: 6px;
}

.bitField.smaller .bit {
  width: calc(var(--circle-size) * 0.66);
  height: calc(var(--circle-size) * 0.66);
}


/* KB block (128×64 bits = 8192 bits) */
.kb-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  background: linear-gradient(0deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.006));
  min-width: 160px;
  /* ensure KB tiles can be tiled horizontally */
}

/* Canvas-based KB rendering (replaces the old grid approach) */
.kb-block .kb-canvas {
  display: block;
  width: 180px;
  /* smaller canvas so multiple KB tiles fit per row */
  height: auto;
  /* maintain aspect ratio */
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.8);
  image-rendering: pixelated;
  /* crisp pixel rendering for tiny canvas */
  transition: opacity 280ms ease;
}

/* Keep .kb-grid styles for backwards compatibility, but they're no longer used */
.kb-block .kb-grid {
  display: grid;
  /* 128 columns × 64 rows = 8192 bits */
  grid-template-columns: repeat(128, 1fr);
  grid-auto-rows: 1fr;
  gap: 1px;
  /* tighter spacing to keep KB block compact */
  width: 180px;
  height: calc(180px / 2);
}

.kb-block .kb-grid .cell {
  width: 100%;
  height: 100%;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.03);
  transition: background 200ms linear
}

.kb-block .kb-grid .cell.on {
  background: var(--fg);
  box-shadow: 0 0 6px rgba(0, 255, 120, 0.25)
}

.kb-block .kb-title {
  font-size: 11px;
  color: var(--muted)
}

/* MB block - grid of KB summaries (each tile represents a KB) */
.mb-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  background: linear-gradient(0deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.006));
  min-width: fit-content
}

.mb-block .mb-canvas {
  display: block;
  width: 220px;
  height: 220px;
  border-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.03);
  background: rgba(0, 0, 0, 0.8);
  image-rendering: pixelated;
  opacity: 0;
  /* start hidden then fade in via JS */
  transition: opacity 280ms ease;
}

.mb-block .mb-title {
  font-size: 11px;
  color: var(--muted)
}

/* When many byte groups are present, we disable per-bit transitions for performance */
.no-anim .bit {
  transition: none !important;
  box-shadow: none;
  /* reduce paint cost */
}

.bitField.tiny .byte {
  padding: 4px;
}

.bitField.tiny .bit {
  width: calc(var(--circle-size) * 0.5);
  height: calc(var(--circle-size) * 0.5);
}

.bitField.tinier .byte {
  padding: 4px;
}


.bitField.tinier .byte {
  width: calc(var(--circle-size) * 0.45);
  height: calc(var(--circle-size) * 0.45);
}

/* loader styles */
.loader {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.loader.hidden {
  display: none;
}

.loader .spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.06);
  border-top-color: var(--fg);
  animation: spin 1s linear infinite;
  box-shadow: 0 0 12px rgba(0, 255, 120, 0.2);
}

.loader .loader-label {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.loader .cancel-btn {
  appearance: none;
  pointer-events: auto;
  margin-top: 8px;
  margin-left: 12px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.06);
  color: var(--muted);
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer
}

.loader .cancel-btn:hover {
  border-color: rgba(255, 255, 255, 0.12);
  color: white
}

@keyframes spin {
  from {
    transform: rotate(0);
  }

  to {
    transform: rotate(360deg);
  }
}

/* allow per-container circle size override (set by JS) */
#bitField {
  --circle-size: var(--circle-size);
}

footer {
  color: var(--muted);
  opacity: 0.9;
  text-align: center;
  padding: 14px;
  font-size: 13px;
}

.units {
  font-weight: 600;
  color: var(--fg);
  font-size: 12px;
  margin-left: 6px;
}

.mobile-only table.step-table {
  width: 90vw;
}

.mobile-only table.step-table td button {
  width: 100%;
  padding-top: .6rem;
  padding-bottom: .7rem;
}

/* simple show/hide responsive helper scoped to this area */
.desktop-only {
  display: block;
}

.mobile-only {
  display: none;
}

@media (max-width: 640px) {
  .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: flex !important;
    gap: .5rem;
    flex-wrap: wrap;
    align-items: center;
  }
}

.step-btn {
  padding: .35rem .6rem;
  border-radius: 6px;
  background: #111;
  color: #dff;
  border: 1px solid #333;
  font-weight: 600;
}

.step-row {
  display: flex;
  gap: .4rem;
  align-items: center;
}

.step-label {
  font-weight: 700;
  margin-right: .25rem;
}

.modifier-tip.desktop-only {
  display: flex;
  flex-direction: column;
  gap: 1px;
  justify-content: center;
  align-items: center;
  padding-top: 1rem;
}

.key-tips {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 0.5rem;
}

.key-tips span {
  display: flex;
  gap: 0.2rem;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

/* media screen lg and above */
@media (min-width: 1092px) {
  .controls {
    flex-direction: row;
  }
}

@media (min-width: 1092px) {
  .key-tips {
    display: flex;
    align-items: center;
    gap: 1rem;
  }
}

.help-content {
  text-align: start;
}

#value-unit-reference {
  color: rgb(105, 105, 105) !important;
}