@import url("https://fonts.googleapis.com/css2?family=Fraunces:wght@600&family=Instrument+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap");

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: "Instrument Sans", sans-serif;
  background: #f4efe7;
  background-image:
    radial-gradient(
      circle at top left,
      rgba(180, 160, 120, 0.18),
      transparent 35%
    ),
    linear-gradient(180deg, #f8f4ee 0%, #efe7dc 100%);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 10px 14px 12px;
  color: #2f2a24;
}

.app {
  width: 100%;
  max-width: min(1720px, calc(100vw - 28px));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 10px 2px;
}

.app-header h1 {
  font-family: "Fraunces", serif;
  font-size: clamp(2.1rem, 3vw, 3.1rem);
  font-weight: 600;
  letter-spacing: -0.03em;
  color: #1f1a14;
}

.app-header p {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.73rem;
  color: #6b6255;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(123, 106, 81, 0.2);
  padding: 5px 9px;
  border-radius: 999px;
}

.app-main {
  display: grid;
  grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
  gap: 22px;
  align-items: stretch;
  min-height: calc(100vh - 132px);
}

@media (max-width: 980px) {
  .app-main {
    grid-template-columns: 1fr;
  }
}

.controls {
  background: rgba(255, 252, 247, 0.9);
  border: 1px solid rgba(123, 106, 81, 0.18);
  border-radius: 18px;
  padding: 20px 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 10px;
  min-height: calc(100vh - 142px);
  box-shadow: 0 16px 40px rgba(91, 77, 54, 0.08);
}

.control-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-row label {
  font-size: 0.76rem;
  font-weight: 600;
  color: #51483d;
}

.control-row input,
.control-row select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #d6c8b4;
  background: #fffdf9;
  color: #2f2a24;
  font-family: "Instrument Sans", sans-serif;
  font-size: 0.92rem;
  outline: none;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}

.control-row input:focus,
.control-row select:focus {
  border-color: #9b8462;
  box-shadow: 0 0 0 3px rgba(155, 132, 98, 0.14);
}

.control-row select option {
  background: #fffdf9;
}

.buttons-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  border: 1px solid transparent;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-family: "Instrument Sans", sans-serif;
  font-weight: 600;
  font-size: 0.84rem;
  transition: all 0.15s ease;
}

#generateBtn {
  background: #3f6f5a;
  color: #fffdf8;
  width: 100%;
  padding: 11px;
}

#generateBtn:hover {
  background: #335c4a;
}

#prevStepBtn,
#nextStepBtn {
  background: #f6efe4;
  color: #3e362e;
  border-color: #ded0bd;
  flex: 1;
}

#prevStepBtn:hover,
#nextStepBtn:hover {
  background: #eee2d0;
}

#resetBtn {
  background: #f7e5e2;
  color: #90443e;
  border-color: #e7bdb7;
}

#resetBtn:hover {
  background: #efd2ce;
}

button:active {
  transform: scale(0.97);
}

.complexity-box {
  background: #f8f2ea;
  border: 1px solid #e3d5c2;
  border-radius: 12px;
  padding: 12px 14px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.75rem;
  line-height: 1.6;
  color: #62584a;
  margin-top: auto;
}

.complexity-box h3 {
  font-family: "Instrument Sans", sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: #2f2a24;
  margin-bottom: 6px;
}

.complexity-box p strong {
  color: #3f6f5a;
}

.visual-section {
  background: rgba(255, 252, 247, 0.94);
  border: 1px solid rgba(123, 106, 81, 0.18);
  border-radius: 20px;
  overflow: hidden;
  min-height: calc(100vh - 142px);
  box-shadow: 0 16px 40px rgba(91, 77, 54, 0.08);
}

.visual-wrapper {
  width: 100%;
  min-height: calc(100vh - 142px);
  max-height: calc(100vh - 142px);
  position: relative;
  overflow: auto;
  padding: 0;
}

#treeSvg {
  display: block;
  min-width: 100%;
  min-height: 100%;
}

.node {
  fill: #f9f4ec;
  stroke: #806d56;
  stroke-width: 2.2;
  transition:
    fill 0.2s ease,
    stroke 0.2s ease,
    opacity 0.2s ease;
}

.node-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 15px;
  font-weight: 500;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  fill: #2b241b;
}

.edge {
  stroke: rgba(128, 109, 86, 0.45);
  stroke-width: 2.2;
  marker-end: url(#arrowHead);
  stroke-dasharray: 4 4;
  stroke-linecap: round;
  opacity: 0.18;
  transition: opacity 0.2s ease;
}

.edge.active {
  opacity: 1;
  stroke: #3f6f5a;
  animation: dashFlow 1.2s linear infinite;
}

.edge:not(.hidden-step):not(.active) {
  opacity: 0.28;
}

@keyframes dashFlow {
  from {
    stroke-dashoffset: 10;
  }
  to {
    stroke-dashoffset: 0;
  }
}

.hidden-step {
  opacity: 0.06 !important;
}

.current-step .node {
  fill: #e7f0ea;
  stroke: #3f6f5a;
  stroke-width: 2.8;
}

.current-step .node-label {
  fill: #1f3f33;
}

.calc-bubble {
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  font-weight: 500;
  fill: #44392f;
  text-anchor: middle;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.calc-bubble.visible {
  opacity: 1;
}

.calc-bg {
  fill: rgba(250, 246, 239, 0.96);
  stroke: rgba(128, 109, 86, 0.35);
  stroke-width: 1.5;
  rx: 6;
  ry: 6;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.calc-bg.visible {
  opacity: 1;
}

.step-counter {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: #6d6458;
  text-align: center;
  letter-spacing: 0.03em;
}

.app-footer {
  text-align: center;
  color: #3e3b36;
  font-family: "IBM Plex Mono", monospace;
  font-size: 1 rem;
  letter-spacing: 0.03em;
  padding-top: 4px;
  border-top: 1px solid rgba(123, 106, 81, 0.12);
}

@media (max-width: 980px) {
  .controls {
    position: static;
    min-height: auto;
  }

  .app-main {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .visual-section,
  .visual-wrapper {
    min-height: 68vh;
    max-height: 68vh;
  }
}

@media (max-width: 640px) {
  body {
    padding: 14px 12px 20px;
  }

  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .controls,
  .visual-section {
    border-radius: 16px;
  }

  .buttons-row button {
    width: 100%;
  }
}

/* ── paste these at the very bottom of main.css ── */

/* Step Info Box */
.step-info-box {
  background: #f0ede6;
  border: 1px solid #d9ccb8;
  border-radius: 12px;
  padding: 12px 14px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.74rem;
  line-height: 1.65;
  color: #4a4035;
  min-height: 64px;
  transition: all 0.2s ease;
}

.step-info-box h4 {
  font-family: "Instrument Sans", sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: #2f2a24;
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}

.step-info-box .sib-line {
  padding: 1px 0;
  white-space: pre-wrap;
  word-break: break-all;
}

.step-info-box .sib-line strong {
  color: #3f6f5a;
}

.step-info-box.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #a09484;
  font-style: italic;
}

/* Code Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(32, 26, 18, 0.52);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open {
  display: flex;
}

.modal-box {
  background: #fffdf9;
  border: 1px solid rgba(123, 106, 81, 0.22);
  border-radius: 20px;
  width: 100%;
  max-width: 720px;
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 28px 64px rgba(60, 48, 30, 0.22);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid rgba(123, 106, 81, 0.14);
  gap: 12px;
}

.modal-header h2 {
  font-family: "Fraunces", serif;
  font-size: 1.35rem;
  font-weight: 600;
  color: #1f1a14;
}

.modal-tabs {
  display: flex;
  gap: 6px;
}

.modal-tab {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid #d6c8b4;
  background: #f6efe4;
  color: #6b5f52;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: 0.03em;
}

.modal-tab.active {
  background: #3f6f5a;
  color: #fffdf8;
  border-color: #3f6f5a;
}

.modal-tab:hover:not(.active) {
  background: #ede0cc;
}

.modal-close {
  background: #f7e5e2;
  color: #90443e;
  border: 1px solid #e7bdb7;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: "Instrument Sans", sans-serif;
  font-weight: 600;
  transition: all 0.15s ease;
}

.modal-close:hover {
  background: #efd2ce;
}

.modal-body {
  overflow-y: auto;
  padding: 20px 22px;
  flex: 1;
}

.code-panel {
  display: none;
}

.code-panel.active {
  display: block;
}

.code-panel pre {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
  line-height: 1.7;
  color: #2f2a24;
  background: #f4f0e8;
  border: 1px solid #ddd0bc;
  border-radius: 12px;
  padding: 16px 18px;
  overflow-x: auto;
  white-space: pre;
  tab-size: 2;
}

.pseudo-panel {
  display: none;
}

.pseudo-panel.active {
  display: block;
}

.pseudo-panel ol {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.8rem;
  line-height: 1.9;
  color: #3a3228;
  padding-left: 24px;
}

.pseudo-panel ol li {
  padding-left: 6px;
}

.pseudo-panel .kw {
  color: #3f6f5a;
  font-weight: 600;
}

.pseudo-panel .cm {
  color: #9a8b78;
  font-style: italic;
}

#codeBtn {
  background: #f6efe4;
  color: #3e362e;
  border: 1px solid #ded0bd;
  width: 100%;
}

#codeBtn:hover {
  background: #ede0cc;
}

.algo-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.algo-card {
  background: #fffdf9;
  border: 1.5px solid #d6c8b4;
  border-radius: 12px;
  padding: 12px 14px;
  cursor: pointer;
  transition: all 0.17s ease;
  display: flex;
  align-items: center;
  gap: 12px;
  user-select: none;
}

.algo-card:hover {
  border-color: #9b8462;
  background: #fdf8f0;
}

.algo-card.selected {
  border-color: #3f6f5a;
  background: #f0f7f3;
  box-shadow: 0 0 0 3px rgba(63, 111, 90, 0.13);
}

.algo-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
}

.algo-icon--k {
  background: #e8f2ee;
  color: #3f6f5a;
}
.algo-icon--m {
  background: #f0ece2;
  color: #7a5c2e;
}

.algo-meta {
  flex: 1;
  min-width: 0;
}

.algo-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: #1f1a14;
  line-height: 1.2;
}

.algo-sub {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.72rem;
  color: #7a6e62;
  margin-top: 2px;
}

.algo-badge {
  font-family: "IBM Plex Mono", monospace;
  font-size: 0.68rem;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.algo-badge--k {
  background: #e0f0e8;
  color: #2a5c46;
  border: 1px solid #b8ddc9;
}
.algo-badge--m {
  background: #f5ede0;
  color: #7a4e1e;
  border: 1px solid #e0c9a6;
}

.algo-check {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid #c8b9a4;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.algo-card.selected .algo-check {
  background: #3f6f5a;
  border-color: #3f6f5a;
}

.algo-check-inner {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fff;
  display: none;
}

.algo-card.selected .algo-check-inner {
  display: block;
}
