/* NR Polar Coding Tutorial — Cyber-Physical engineering theme */
#polar-tutorial {
  max-width: 800px;
  margin: 0 auto;
  font-family: 'Courier New', Courier, monospace;
  background: #0d1117;
  color: #c9d1d9;
  padding: 12px;
  border-radius: 8px;
  box-sizing: border-box;
}

#polar-tutorial * {
  box-sizing: border-box;
}

/* Blended scrollbars — track matches panel, thumb subtle; only visible on hover */
#polar-tutorial .polar-interleaver-table-wrap,
#polar-tutorial .polar-n-derivation,
#polar-tutorial .polar-matrix-view,
#polar-tutorial .polar-mapping-terminal-log,
#polar-tutorial .polar-table-5312-wrap {
  scrollbar-width: thin;
  scrollbar-color: #30363d #161b22;
}

#polar-tutorial .polar-interleaver-table-wrap::-webkit-scrollbar,
#polar-tutorial .polar-n-derivation::-webkit-scrollbar,
#polar-tutorial .polar-matrix-view::-webkit-scrollbar,
#polar-tutorial .polar-mapping-terminal-log::-webkit-scrollbar,
#polar-tutorial .polar-table-5312-wrap::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

#polar-tutorial .polar-interleaver-table-wrap::-webkit-scrollbar-track,
#polar-tutorial .polar-n-derivation::-webkit-scrollbar-track,
#polar-tutorial .polar-matrix-view::-webkit-scrollbar-track,
#polar-tutorial .polar-mapping-terminal-log::-webkit-scrollbar-track,
#polar-tutorial .polar-table-5312-wrap::-webkit-scrollbar-track {
  background: #161b22;
  border-radius: 3px;
}

#polar-tutorial .polar-interleaver-table-wrap::-webkit-scrollbar-thumb,
#polar-tutorial .polar-n-derivation::-webkit-scrollbar-thumb,
#polar-tutorial .polar-matrix-view::-webkit-scrollbar-thumb,
#polar-tutorial .polar-mapping-terminal-log::-webkit-scrollbar-thumb,
#polar-tutorial .polar-table-5312-wrap::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 3px;
}

#polar-tutorial .polar-interleaver-table-wrap::-webkit-scrollbar-thumb:hover,
#polar-tutorial .polar-n-derivation::-webkit-scrollbar-thumb:hover,
#polar-tutorial .polar-matrix-view::-webkit-scrollbar-thumb:hover,
#polar-tutorial .polar-mapping-terminal-log::-webkit-scrollbar-thumb:hover,
#polar-tutorial .polar-table-5312-wrap::-webkit-scrollbar-thumb:hover {
  background: #484f58;
}

#polar-tutorial .polar-stepper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
  padding: 8px 0;
  border-bottom: 1px solid #484f58;
}

#polar-tutorial .polar-step {
  font-size: 0.75rem;
  color: #484f58;
  border-bottom: 2px solid #484f58;
  padding: 5px 10px;
  cursor: default;
  flex: 1;
  min-width: 0;
  text-align: center;
}

#polar-tutorial .polar-step.active {
  color: #58a6ff;
  border-bottom-color: #58a6ff;
}

#polar-tutorial .polar-step.done {
  color: #3fb950;
  border-bottom-color: #3fb950;
}

#polar-tutorial .polar-control-panel {
  background: #161b22;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid #484f58;
  margin-bottom: 16px;
}

#polar-tutorial .polar-control-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

#polar-tutorial .polar-control-row:last-child {
  margin-bottom: 0;
}

#polar-tutorial .polar-infobit-row label {
  flex-shrink: 0;
}

#polar-tutorial .polar-infobit-display {
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  color: #c9d1d9;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 4px;
  padding: 6px 10px;
  min-height: 1.5em;
  word-break: break-all;
  flex: 1;
  max-width: 100%;
}

#polar-tutorial .polar-control-row label {
  color: #8b949e;
  font-size: 0.85rem;
  min-width: 60px;
}

#polar-tutorial .polar-control-row input[type="number"] {
  width: 72px;
  padding: 6px 8px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 4px;
  color: #c9d1d9;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
}

#polar-tutorial .polar-control-row input:focus {
  outline: none;
  border-color: #58a6ff;
  box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}

#polar-tutorial .polar-btn {
  padding: 8px 14px;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 6px;
  color: #c9d1d9;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

#polar-tutorial .polar-btn:hover {
  background: #30363d;
  border-color: #58a6ff;
}

#polar-tutorial .polar-btn.primary {
  background: #238636;
  border-color: #2ea043;
  color: #fff;
}

#polar-tutorial .polar-btn.primary:hover {
  background: #2ea043;
}

#polar-tutorial .polar-dashboard-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 700px) {
  #polar-tutorial .polar-dashboard-grid {
    grid-template-columns: 1fr;
  }
}

#polar-tutorial .polar-mother-table {
  background: #161b22;
  border: 1px solid #484f58;
  border-radius: 6px;
  padding: 12px;
  font-size: 0.8rem;
  color: #e6edf3;
}

#polar-tutorial .polar-mother-table table {
  width: 100%;
  border-collapse: collapse;
}

#polar-tutorial .polar-mother-table th,
#polar-tutorial .polar-mother-table td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid #21262d;
}

#polar-tutorial .polar-mother-table th {
  color: #b1bac4;
  font-weight: normal;
}

#polar-tutorial .polar-mother-table td {
  color: #e6edf3;
}

#polar-tutorial .polar-mother-table caption {
  color: #e6edf3;
}

#polar-tutorial .polar-rate-gauge-wrap {
  margin-top: 10px;
  padding: 8px;
  background: #0d1117;
  border-radius: 4px;
}

#polar-tutorial .polar-rate-gauge-wrap.warn {
  background: rgba(248, 81, 73, 0.15);
  border: 1px solid #f85149;
}

#polar-tutorial .polar-rate-gauge-label {
  font-size: 0.75rem;
  color: #b1bac4;
  margin-bottom: 4px;
}

#polar-tutorial .polar-rate-value {
  font-size: 1rem;
  font-weight: bold;
  color: #79c0ff;
  text-shadow: 0 0 1px rgba(0, 0, 0, 0.5);
}

#polar-tutorial .polar-rate-value.warn {
  color: #ff7b72;
}

/* N derivation panel (Step 1) */
#polar-tutorial .polar-n-derivation {
  margin-top: 16px;
  padding: 12px;
  background: #161b22;
  border: 1px solid #484f58;
  border-radius: 6px;
  font-size: 0.8rem;
  color: #e6edf3;
}

#polar-tutorial .polar-n-derivation-title {
  color: #b1bac4;
  font-weight: bold;
  margin-bottom: 10px;
  font-size: 0.85rem;
}

#polar-tutorial .polar-n-derivation-steps {
  margin: 0;
  padding-left: 1.25rem;
  line-height: 1.6;
  color: #e6edf3;
}

#polar-tutorial .polar-n-derivation-steps li {
  margin-bottom: 6px;
}

#polar-tutorial .polar-n-derivation-steps li:last-child {
  margin-bottom: 0;
}

/* Hide reliability heatmap in Step 1 (Mother Code) and Step 2 (Interleaving); show from Step 3 (Sub-channel Mapping) onward */
#polar-tutorial[data-current-stage="0"] .polar-heatmap-block,
#polar-tutorial[data-current-stage="1"] .polar-heatmap-block {
  display: none;
}

/* Reliability heatmap */
#polar-tutorial #polar-reliability-heatmap {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(12px, 1fr));
  gap: 2px;
  padding: 12px;
  background: #0d1117;
  border: 1px solid #484f58;
  border-radius: 6px;
  margin-bottom: 12px;
  min-height: 60px;
}

#polar-tutorial .polar-heatmap-cell {
  height: 22px;
  border-radius: 2px;
  position: relative;
  cursor: help;
  transition: transform 0.15s, box-shadow 0.15s;
}

#polar-tutorial .polar-heatmap-cell.polar-heatmap-cell-info {
  border: 2px solid #58a6ff;
}

#polar-tutorial .polar-heatmap-cell.polar-heatmap-cell-frozen {
  border: none;
}

#polar-tutorial .polar-heatmap-cell:hover {
  transform: scale(1.15);
  box-shadow: 0 0 8px rgba(88, 166, 255, 0.5);
  z-index: 5;
}

#polar-tutorial .polar-heatmap-cell.polar-heatmap-cell-scanning {
  transform: scale(1.2);
  box-shadow: 0 0 12px #58a6ff;
  z-index: 6;
  border: 2px solid #58a6ff;
}

#polar-tutorial .polar-heatmap-legend {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 0.75rem;
  color: #8b949e;
}

#polar-tutorial .polar-heatmap-legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

#polar-tutorial .polar-heatmap-legend .swatch {
  width: 14px;
  height: 14px;
  border-radius: 2px;
}

#polar-tutorial .polar-heatmap-legend .swatch.info {
  background: #58a6ff;
  border: 1px solid #79c0ff;
}

#polar-tutorial .polar-heatmap-legend .swatch.frozen {
  background: #484f58;
}

/* Step 3: Sub-channel Mapping */
#polar-tutorial .polar-mapping-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 12px;
}

#polar-tutorial .polar-mapping-panel {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 600px) {
  #polar-tutorial .polar-mapping-panel {
    grid-template-columns: 1fr;
  }
}

#polar-tutorial .polar-mapping-info-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#polar-tutorial .polar-mapping-step-info {
  padding: 10px 12px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 6px;
  font-size: 0.8rem;
  color: #e6edf3;
  line-height: 1.5;
}

#polar-tutorial .polar-mapping-scan {
  color: #58a6ff;
  margin-bottom: 6px;
}

#polar-tutorial .mapping-info-label {
  color: #58a6ff;
}

#polar-tutorial .mapping-frozen-label {
  color: #8b949e;
}

#polar-tutorial .polar-mapping-terminal-log {
  padding: 10px 12px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  font-size: 0.75rem;
  color: #3fb950;
  font-family: 'Courier New', monospace;
  color: #8b949e;
  max-height: 140px;
  overflow-y: auto;
}

#polar-tutorial .mapping-log-entry {
  font-family: 'Courier New', monospace;
  font-size: 0.7rem;
  border-left: 2px solid #58a6ff;
  padding-left: 8px;
  margin-bottom: 6px;
  animation: polar-scanIn 0.2s ease-out;
  color: #8b949e;
}

#polar-tutorial .mapping-log-info {
  color: #58a6ff;
}

#polar-tutorial .mapping-log-frozen {
  color: #8b949e;
}

@keyframes polar-scanIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

#polar-tutorial .polar-u-vector-wrap {
  padding: 10px 12px;
  background: #161b22;
  border: 1px solid #484f58;
  border-radius: 6px;
}

#polar-tutorial .polar-u-vector-wrap .polar-section-label {
  margin-bottom: 10px;
}

#polar-tutorial .polar-u-vector-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(28px, 1fr));
  gap: 4px;
}

#polar-tutorial .polar-u-cell {
  min-width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: bold;
  font-family: 'Courier New', monospace;
  border: 1px solid #30363d;
  color: #e6edf3;
}

#polar-tutorial .polar-u-cell.u-cell-empty {
  background: #21262d;
  color: #484f58;
}

@keyframes flyIn {
  from { opacity: 0; transform: translateX(-20px); }
  to { opacity: 1; transform: translateX(0); }
}

#polar-tutorial .polar-u-cell.mapped-info {
  background-color: #58a6ff;
  border: 2px solid #79c0ff;
  color: #0d1117;
  animation: flyIn 0.3s ease-out;
  box-shadow: 0 0 12px rgba(88, 166, 255, 0.4);
}

#polar-tutorial .polar-u-cell.mapped-frozen {
  background-color: #484f58;
  color: #8b949e;
  animation: flyIn 0.2s ease-in;
}

/* Interleaver table (3GPP PI_IL_MAX) */
#polar-tutorial .polar-interleaver-table-wrap {
  max-height: 200px;
  overflow: auto;
  margin-bottom: 12px;
  background: #0d1117;
  border: 1px solid #484f58;
  border-radius: 4px;
  padding: 8px;
}

#polar-tutorial .polar-il-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.7rem;
  color: #e6edf3;
}

#polar-tutorial .polar-il-table th,
#polar-tutorial .polar-il-table td {
  padding: 3px 6px;
  text-align: right;
  border: 1px solid #21262d;
}

#polar-tutorial .polar-il-table thead th {
  color: #0d1117;
  font-weight: bold;
  position: sticky;
  top: 0;
  background: #8b949e;
  border-color: #6e7681;
}

#polar-tutorial .polar-il-table tbody th {
  text-align: right;
  color: #0d1117;
  font-weight: bold;
  background: #8b949e;
  border-color: #6e7681;
}

#polar-tutorial .polar-il-table td.polar-il-cell-highlight {
  background: #58a6ff;
  color: #0d1117;
  font-weight: bold;
}

/* Master 3GPP Sequence Explorer ribbon (Sub-channel Mapping) */
#polar-tutorial .polar-master-q-container {
  margin-bottom: 14px;
  padding: 10px 12px;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 6px;
}

#polar-tutorial .polar-master-q-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: #f39c12;
  margin-bottom: 8px;
}

#polar-tutorial .polar-master-q-ribbon {
  display: flex;
  overflow-x: auto;
  padding: 10px 0;
  gap: 4px;
  border: 1px solid #30363d;
  border-radius: 4px;
  background: #0d1117;
  scrollbar-width: thin;
  scrollbar-color: #30363d #161b22;
}

#polar-tutorial .polar-master-q-ribbon::-webkit-scrollbar {
  height: 6px;
}

#polar-tutorial .polar-master-q-ribbon::-webkit-scrollbar-track {
  background: #161b22;
  border-radius: 3px;
}

#polar-tutorial .polar-master-q-ribbon::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 3px;
}

#polar-tutorial .polar-master-q-item {
  flex-shrink: 0;
  min-width: 44px;
  height: 52px;
  border: 1px solid #30363d;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: 'Courier New', monospace;
  transition: all 0.2s ease;
  opacity: 0.8;
  border-radius: 3px;
  background: #21262d;
  gap: 2px;
}

/* Status badge (high-priority so it works for all 1024 elements) */
#polar-tutorial .polar-master-q-item .polar-master-q-status-badge {
  font-size: 8px;
  padding: 1px 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.1);
  margin-bottom: 4px;
  font-weight: bold;
}

#polar-tutorial .polar-master-q-item .polar-m-idx {
  font-size: 9px;
  color: #8b949e;
}

#polar-tutorial .polar-master-q-item .polar-m-val {
  font-size: 12px;
  color: #c9d1d9;
  font-weight: bold;
}

/* Invalid (val >= N) – heavily dimmed so Active always overrides */
#polar-tutorial .polar-master-q-item.polar-master-q-invalid {
  opacity: 0.1 !important;
  background: #000 !important;
}

/* Scanned (past) items – greyed so they never override Active */
#polar-tutorial .polar-master-q-item.polar-master-q-scanned {
  opacity: 0.4;
  filter: grayscale(0.5);
}

/* Active base – must override Invalid/Scanned (high priority) */
#polar-tutorial .polar-master-q-item.polar-master-q-active {
  opacity: 1 !important;
  transform: scale(1.25);
  z-index: 1000;
  border: 2px solid #fff !important;
}

/* Frozen bit active (Orange) – data-is-info baked in during render */
#polar-tutorial .polar-master-q-item.polar-master-q-active[data-is-info="false"] {
  background: #f39c12 !important;
  border: 2px solid #fff !important;
  transform: scale(1.15);
  box-shadow: 0 0 15px #f39c12;
}

/* Info bit active (Blue) – data-is-info baked in during render */
#polar-tutorial .polar-master-q-item.polar-master-q-active[data-is-info="true"] {
  background: #58a6ff !important;
  border: 2px solid #fff !important;
  transform: scale(1.15);
  box-shadow: 0 0 20px #58a6ff;
}

#polar-tutorial .polar-master-q-item.polar-master-q-active .polar-m-idx,
#polar-tutorial .polar-master-q-item.polar-master-q-active .polar-m-val {
  color: #0d1117;
}

/* Badge readable when active */
#polar-tutorial .polar-master-q-item.polar-master-q-active .polar-master-q-status-badge {
  background: #000;
  color: #fff;
}

/* Mapping Monitor – bridge panel (source → dest) */
#polar-tutorial .polar-mapping-monitor {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #161b22;
  padding: 10px 12px;
  border: 1px solid #30363d;
  border-radius: 6px;
  margin-top: 10px;
  font-family: 'Fira Code', 'Courier New', monospace;
  font-size: 0.85rem;
}

#polar-tutorial .polar-mapping-monitor .polar-monitor-source {
  color: #f39c12;
}

#polar-tutorial .polar-mapping-monitor .polar-monitor-dest {
  color: #58a6ff;
}

#polar-tutorial .polar-mapping-monitor .polar-monitor-arrow {
  color: #8b949e;
  padding: 0 10px;
}

#polar-tutorial .polar-mapping-instruction {
  font-size: 0.75rem;
  color: #8b949e;
  margin-top: 8px;
}

#polar-tutorial .polar-table-5312-block {
  margin-bottom: 12px;
}

#polar-tutorial .polar-table-5312-hint {
  font-size: 0.75rem;
  color: #8b949e;
  margin-bottom: 6px;
}

#polar-tutorial .polar-table-5312-wrap {
  max-height: 180px;
  overflow: auto;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 4px;
}

#polar-tutorial .polar-table-5312-wrap .polar-table-5312 {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
  color: #c9d1d9;
}

#polar-tutorial .polar-table-5312-wrap .polar-table-5312 th,
#polar-tutorial .polar-table-5312-wrap .polar-table-5312 td {
  padding: 4px 8px;
  text-align: right;
  border: 1px solid #21262d;
}

#polar-tutorial .polar-table-5312-wrap .polar-table-5312 thead th {
  position: sticky;
  top: 0;
  background: #21262d;
  color: #8b949e;
  font-weight: bold;
}

#polar-tutorial .polar-table-5312-wrap .polar-table-5312 tbody tr.table-5312-done {
  background: #21262d;
  color: #8b949e;
  opacity: 0.6;
}

#polar-tutorial .polar-table-5312-wrap .polar-table-5312 tbody tr.table-5312-current {
  border-left: 3px solid #58a6ff;
}

#polar-tutorial .polar-table-5312-wrap .polar-table-5312 tbody tr.table-5312-current td {
  background: #388bfd;
  color: #0d1117;
  font-weight: bold;
  border-color: #58a6ff;
}

/* Row being animated from (fly-to-mailbox source) */
#polar-tutorial .polar-table-5312-wrap .polar-table-5312 tbody tr.table-5312-flying td {
  background: #f39c12;
  color: #0d1117;
  border-color: #f39c12;
  box-shadow: 0 0 8px rgba(243, 156, 18, 0.5);
}

/* Flying bit (Rank → Physical u-vector) */
.polar-flyer-info,
.polar-flyer-frozen {
  position: fixed;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  text-align: center;
  line-height: 20px;
  font-size: 12px;
  font-weight: bold;
  color: white;
  z-index: 9999;
  pointer-events: none;
  transition: transform 0.5s ease-in-out, opacity 0.5s ease-in;
}

.polar-flyer-info {
  background: #58a6ff;
  box-shadow: 0 0 10px #58a6ff;
}

.polar-flyer-frozen {
  background: #484f58;
}

#polar-tutorial .polar-interleaver-viz-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

#polar-tutorial .polar-interleaver-viz-row .polar-section-label {
  margin-bottom: 0;
  flex: 1;
  min-width: 200px;
}

#polar-tutorial .polar-interleaver-step-info {
  margin-bottom: 10px;
  padding: 10px 12px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 4px;
  font-size: 0.75rem;
  color: #e6edf3;
  font-family: 'Courier New', Courier, monospace;
}

#polar-tutorial .polar-il-step-placeholder {
  color: #8b949e;
}

#polar-tutorial .polar-il-step-pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

/* Interleaver canvas */
#polar-tutorial .polar-interleaver-section {
  margin-bottom: 16px;
  padding: 12px;
  background: #161b22;
  border: 1px solid #484f58;
  border-radius: 6px;
}

#polar-tutorial .polar-interleaver-section .polar-section-label {
  font-size: 0.8rem;
  color: #8b949e;
  margin-bottom: 8px;
}

#polar-tutorial #polar-interleaver-canvas {
  display: block;
  background: #0d1117;
  border-radius: 4px;
  max-width: 100%;
  box-shadow: 0 0 20px rgba(88, 166, 255, 0.08);
}

/* Butterfly canvas */
#polar-tutorial .polar-butterfly-section {
  margin-bottom: 16px;
  padding: 12px;
  background: #161b22;
  border: 1px solid #484f58;
  border-radius: 6px;
}

#polar-tutorial .polar-butterfly-section .polar-section-label {
  font-size: 0.8rem;
  color: #8b949e;
  margin-bottom: 8px;
}

#polar-tutorial .polar-transform-evolution-panel {
  background: #0d1117;
  padding: 12px 14px;
  border-radius: 6px;
  border: 1px solid #30363d;
  margin-bottom: 12px;
}

#polar-tutorial .polar-evolution-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.85rem;
  color: #c9d1d9;
  flex-wrap: wrap;
  gap: 12px;
}

#polar-tutorial .polar-evolution-title {
  font-weight: 600;
  color: #e6edf3;
}

#polar-tutorial .polar-evolution-spin-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

#polar-tutorial .polar-spin-group {
  display: inline-flex;
  align-items: center;
  gap: 0;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 6px;
  overflow: hidden;
}

#polar-tutorial .polar-spin-label {
  padding: 6px 10px;
  font-size: 0.8rem;
  color: #8b949e;
  border-right: 1px solid #30363d;
}

#polar-tutorial .polar-spin-btn {
  width: 28px;
  height: 32px;
  padding: 0;
  border: none;
  border-right: 1px solid #30363d;
  background: #21262d;
  color: #c9d1d9;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

#polar-tutorial .polar-spin-btn:last-of-type {
  border-right: none;
}

#polar-tutorial .polar-spin-btn:hover:not(:disabled) {
  background: #30363d;
  color: #f39c12;
}

#polar-tutorial .polar-spin-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#polar-tutorial .polar-spin-value {
  min-width: 48px;
  padding: 6px 10px;
  font-size: 0.85rem;
  font-family: 'Courier New', monospace;
  color: #e6edf3;
  text-align: center;
  background: #0d1117;
}

#polar-tutorial .polar-evolution-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

#polar-tutorial .polar-evolution-controls .polar-btn {
  flex-shrink: 0;
}

#polar-tutorial .polar-evolution-help {
  font-size: 0.75rem;
  color: #8b949e;
  margin: 6px 0 0;
  line-height: 1.4;
}

#polar-tutorial .polar-butterfly-canvas-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
}

#polar-tutorial #polar-canvas {
  display: block;
  background: #000;
  border-radius: 4px;
  max-width: 100%;
  box-shadow: 0 0 20px rgba(88, 166, 255, 0.1);
}

/* Math Inspector — real-time telemetry for active XOR */
#polar-tutorial #polar-math-inspector {
  flex: 1;
  min-width: 250px;
  max-width: 100%;
  background: #0d1117;
  border: 1px solid #f39c12;
  padding: 15px;
  font-family: 'Fira Code', 'Courier New', monospace;
  color: #c9d1d9;
  border-radius: 4px;
  box-shadow: 0 0 15px rgba(243, 156, 18, 0.2);
}

#polar-tutorial .inspector-header {
  color: #f39c12;
  font-weight: bold;
  border-bottom: 1px solid #30363d;
  margin-bottom: 10px;
  padding-bottom: 5px;
  font-size: 14px;
}

#polar-tutorial .math-line {
  font-size: 12px;
  margin: 5px 0;
}

#polar-tutorial .var {
  color: #58a6ff;
}

#polar-tutorial .op {
  color: #ff7b72;
  font-weight: bold;
}

#polar-tutorial .equation {
  background: #161b22;
  padding: 8px;
  margin-top: 10px;
  text-align: center;
  border-radius: 4px;
  border: 1px dashed #30363d;
  font-size: 16px;
}

#polar-tutorial .desc {
  font-size: 11px;
  color: #8b949e;
  margin-top: 8px;
  line-height: 1.4;
}

/* G_N matrix heatmap (Polar Transform stage) */
#polar-tutorial .polar-gn-heatmap-block {
  margin-top: 16px;
  padding: 12px;
  background: #161b22;
  border: 1px solid #484f58;
  border-radius: 6px;
}

#polar-tutorial .polar-gn-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  color: #c9d1d9;
  margin-bottom: 10px;
}

#polar-tutorial .polar-gn-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

#polar-tutorial .polar-gn-matrix-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

#polar-tutorial .polar-gn-heatmap-wrap .polar-section-label {
  font-size: 0.8rem;
  color: #8b949e;
  margin: 0;
}

#polar-tutorial #polar-gn-canvas {
  display: block;
  margin-top: -125px;
  background: #0d1117;
  border-radius: 4px;
  max-width: 100%;
  border: 1px solid #30363d;
}

#polar-tutorial .polar-gn-color-legend {
  margin-top: 30px;
  padding: 12px 14px;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
  font-size: 0.8rem;
  color: #c9d1d9;
  min-width: 180px;
}

#polar-tutorial .polar-gn-legend-title {
  font-weight: 600;
  color: #e6edf3;
  margin-bottom: 10px;
  font-size: 0.85rem;
}

#polar-tutorial .polar-gn-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  line-height: 1.4;
}

#polar-tutorial .polar-gn-legend-item:last-child {
  margin-bottom: 0;
}

#polar-tutorial .polar-gn-swatch {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 2px;
  border: 1px solid #484f58;
  flex-shrink: 0;
}

#polar-tutorial .polar-gn-swatch-black {
  background: #0d1117;
}

#polar-tutorial .polar-gn-swatch-white {
  background: #ffffff;
}

#polar-tutorial .polar-gn-swatch-blue {
  background: #58a6ff;
}

#polar-tutorial .polar-bit-node {
  cursor: help;
  transition: filter 0.2s;
}

#polar-tutorial .polar-bit-node:hover {
  filter: brightness(1.4);
}

/* Stage views */
#polar-tutorial .polar-stage-content {
  display: none;
  padding: 12px 0;
}

#polar-tutorial .polar-stage-content.active {
  display: block;
}

/* Output / codeword ribbon */
#polar-tutorial .polar-output-section {
  margin-bottom: 16px;
  padding: 12px;
  background: #161b22;
  border: 1px solid #484f58;
  border-radius: 6px;
}

#polar-tutorial .polar-codeword-ribbon {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 8px 0;
  font-size: 0.8rem;
}

#polar-tutorial .polar-codeword-bit {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 2px;
  color: #c9d1d9;
  font-family: 'Courier New', monospace;
}

/* Navigation buttons */
#polar-tutorial .polar-nav-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

#polar-tutorial .polar-btn-step {
  background: #161b22;
  border: 1px solid #30363d;
  color: #b1bac4;
  min-width: 90px;
}

#polar-tutorial .polar-btn-step:hover {
  background: #21262d;
  border-color: #484f58;
  color: #e6edf3;
}

#polar-tutorial .polar-btn-step:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#polar-tutorial .polar-tooltip-popup {
  position: fixed;
  background: #161b22;
  border: 1px solid #58a6ff;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.8rem;
  color: #c9d1d9;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  pointer-events: none;
  max-width: 280px;
}

#polar-tutorial .polar-xor-popup {
  position: fixed;
  background: #161b22;
  border: 1px solid #f39c12;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 0.85rem;
  color: #c9d1d9;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  pointer-events: none;
}

#polar-tutorial .polar-xor-popup code {
  color: #f39c12;
  font-family: 'Courier New', monospace;
}

/* Matrix view tab */
#polar-tutorial .polar-matrix-view {
  overflow-x: auto;
  margin-top: 8px;
  padding: 8px;
  background: #0d1117;
  border-radius: 4px;
  font-size: 0.7rem;
  max-height: 300px;
  overflow-y: auto;
}

#polar-tutorial .polar-matrix-view table {
  border-collapse: collapse;
}

#polar-tutorial .polar-matrix-view td {
  width: 14px;
  height: 14px;
  text-align: center;
  border: 1px solid #21262d;
  color: #8b949e;
}

#polar-tutorial .polar-matrix-view td.highlight-row {
  background: rgba(88, 166, 255, 0.25);
  color: #58a6ff;
}

#polar-tutorial .polar-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

#polar-tutorial .polar-tab {
  padding: 6px 12px;
  background: #21262d;
  border: 1px solid #30363d;
  border-radius: 4px;
  color: #8b949e;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: 'Courier New', monospace;
}

#polar-tutorial .polar-tab.active {
  background: #161b22;
  border-color: #58a6ff;
  color: #58a6ff;
}

#polar-tutorial .polar-tab:hover:not(.active) {
  border-color: #484f58;
  color: #c9d1d9;
}
