:root {
  --if-color:    #10b981;
  --if-light:    #d1fae5;
  --if-dark:     #065f46;
  --for-color:   #3b82f6;
  --for-light:   #dbeafe;
  --for-dark:    #1e40af;
  --while-color: #8b5cf6;
  --while-light: #ede9fe;
  --while-dark:  #5b21b6;
}

/* ===== Layout ===== */
.wrap {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.lead {
  text-align: center;
  color: var(--muted-color);
  font-size: 1rem;
  margin: -12px 0 0;
}

/* ===== Section header ===== */
.sec-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.sec-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  color: #1a202c;
}

.badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 800;
  font-family: 'Courier New', monospace;
}

.if-badge    { background: var(--if-light);    color: var(--if-dark); }
.for-badge   { background: var(--for-light);   color: var(--for-dark); }
.while-badge { background: var(--while-light); color: var(--while-dark); }

.kw { color: #7c3aed; font-weight: 800; }

/* ===== Controls ===== */
.controls-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin: 12px 0 4px;
}

.input-group { display: flex; flex-direction: column; gap: 4px; }

.input-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted-color);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.demo-input {
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
  width: 110px;
  background: #fff;
  color: #1a202c;
  transition: border-color .2s;
}

.demo-input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(0,120,215,.12);
}

.mono { font-family: 'Courier New', monospace; }

.action-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter .15s, transform .1s;
}

.action-btn:active { transform: scale(.96); }
.action-btn:disabled { opacity: .45; cursor: not-allowed; }

.reset-btn { background: #fff; color: #6b7280; border: 1.5px solid var(--border); }
.reset-btn:hover { background: #f9fafb; }

/* ===== Code block ===== */
.code-block {
  background: #1e293b;
  border-radius: 10px;
  padding: 10px 16px 14px;
  margin: 12px 0;
}

.code-label {
  font-size: 0.68rem;
  color: #64748b;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.code-block pre { margin: 0; white-space: pre-wrap; }

.code-block code {
  font-family: 'Courier New', 'Consolas', monospace;
  font-size: .92rem;
  color: #e2e8f0;
  line-height: 1.6;
}

/* ===== Note ===== */
.concept-note {
  background: #f0f9ff;
  border-left: 4px solid var(--brand);
  padding: 12px 16px;
  border-radius: 0 8px 8px 0;
  font-size: .88rem;
  line-height: 1.75;
  color: #0c4a6e;
}

.concept-note code {
  background: #dbeafe;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: .85em;
  color: #1d4ed8;
}

/* ===== if Flowchart ===== */
.fc {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 16px 0;
}

.fc-box {
  padding: 10px 20px;
  border: 2.5px solid #94a3b8;
  border-radius: 8px;
  font-family: 'Courier New', monospace;
  font-size: .92rem;
  text-align: center;
  background: #f8fafc;
  transition: border-color .25s, background .25s, box-shadow .25s;
}

.fc-cond { font-weight: 700; }
.fc-cond.is-true  { border-color: var(--if-color); background: var(--if-light); }
.fc-cond.is-false { border-color: #ef4444;          background: #fef2f2; }

.fc-action { font-size: .85rem; }
.fc-action-hint { font-size: .75rem; color: var(--muted-color); font-family: var(--font); }

.fc-end { border-color: #94a3b8; background: #f1f5f9; color: #64748b; font-size: .85rem; }

/* if fork */
.fc-fork {
  display: flex;
  gap: 20px;
  padding-top: 20px;
  position: relative;
}

.fc-fork::before {
  content: '';
  position: absolute;
  top: 0; left: 50%;
  width: 1px; height: 20px;
  background: #94a3b8;
  transform: translateX(-50%);
}

.fc-fork-branch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  opacity: .3;
  transition: opacity .25s;
}

.fc-fork-branch.active { opacity: 1; }

.fc-fork-lbl {
  font-size: .78rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
}

.true-branch  .fc-fork-lbl { background: var(--if-light);  color: var(--if-dark); }
.false-branch .fc-fork-lbl { background: #fef2f2;           color: #991b1b; }

.fc-branch-box {
  padding: 10px 16px;
  border: 2px solid;
  border-radius: 8px;
  font-family: 'Courier New', monospace;
  font-size: .85rem;
  text-align: center;
  min-width: 130px;
}

.if-true-box  { border-color: var(--if-color); background: var(--if-light);  color: var(--if-dark); }
.if-false-box { border-color: #ef4444;          background: #fef2f2;          color: #991b1b; }

/* ===== Loop Flowchart (for / while) ===== */
.lfc { margin: 16px 0; }

.lfc-top {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.lfc-exit {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lfc-exit-arrow { font-size: .78rem; color: var(--muted-color); white-space: nowrap; }

.for-cond   { border-color: var(--for-color);   background: var(--for-light);   font-weight: 700; }
.while-cond { border-color: var(--while-color); background: var(--while-light); font-weight: 700; }

/* loop body: left+bottom border shows the cycle */
.lfc-body {
  margin-left: 28px;
  padding: 8px 0 4px 16px;
  border-left: 3px solid;
  border-bottom: 3px solid;
  border-radius: 0 0 0 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.for-lfc-body   { border-color: var(--for-color); }
.while-lfc-body { border-color: var(--while-color); }

.for-action   { border-color: var(--for-color);   background: var(--for-light);   color: var(--for-dark); }
.while-action { border-color: var(--while-color); background: var(--while-light); color: var(--while-dark); }

.lfc-back-arrow {
  font-size: .75rem;
  color: var(--muted-color);
  padding-bottom: 4px;
}

/* ===== Indent visualizer ===== */
.iv {
  margin: 16px 0;
  font-family: 'Courier New', 'Consolas', monospace;
  font-size: .9rem;
  background: #f8fafc;
  border: 1.5px solid var(--border-soft);
  border-radius: 10px;
  padding: 14px 16px;
  line-height: 2;
}

.iv-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.iv-line code {
  background: none;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
  color: #1e293b;
  white-space: pre;
}

.iv-tag {
  font-family: var(--font);
  font-size: .7rem;
  font-weight: 600;
  color: var(--muted-color);
  white-space: nowrap;
  flex-shrink: 0;
}

.iv-scope {
  border-left: 3px solid #cbd5e1;
  margin-left: 8px;
  padding-left: 12px;
  border-radius: 0 0 0 4px;
}

.iv-if-scope, .iv-else-scope { border-color: var(--if-color);    background: rgba(16,185,129,.04); }
.iv-for-scope                { border-color: var(--for-color);   background: rgba(59,130,246,.04); }
.iv-while-scope              { border-color: var(--while-color); background: rgba(139,92,246,.04); }

.iv-outside code { color: #9ca3af; }
.iv-outside .iv-tag { color: #9ca3af; }

/* Nested example tag pills */
.iv-tag-for { background: var(--for-light);   color: var(--for-dark);   padding: 0 6px; border-radius: 4px; }
.iv-tag-if  { background: var(--if-light);    color: var(--if-dark);    padding: 0 6px; border-radius: 4px; }
.iv-tag-out { background: #f1f5f9;            color: #6b7280;           padding: 0 6px; border-radius: 4px; }

/* ===== Indent rule legend ===== */
.indent-rule {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
  padding: 14px 16px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1.5px solid var(--border-soft);
  font-size: .88rem;
  color: #374151;
}

.indent-rule-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.indent-rule-bar {
  width: 4px;
  height: 22px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ===== for step demo ===== */
.for-visual {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 0;
  min-height: 86px;
  align-items: flex-end;
  margin: 8px 0;
}

.for-box { display: flex; flex-direction: column; align-items: center; gap: 4px; }

.for-index {
  font-size: .68rem;
  font-weight: 700;
  color: var(--muted-color);
  font-family: monospace;
}

.for-cell {
  width: 62px;
  height: 62px;
  border: 2px solid #93c5fd;
  border-radius: 10px;
  background: #eff6ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--for-dark);
  font-family: 'Courier New', monospace;
  transition: all .2s;
}

.for-cell.pending { border-color: #d1d5db; background: #f9fafb; color: #9ca3af; }
.for-cell.active  {
  border-color: var(--for-color); background: var(--for-light); color: var(--for-dark);
  box-shadow: 0 0 0 3px rgba(59,130,246,.2); transform: translateY(-5px);
}
.for-cell.done { border-color: #6ee7b7; background: #f0fdf4; color: var(--if-dark); }

.step-hint {
  font-size: .8rem;
  color: var(--muted-color);
  min-height: 1.2em;
  margin-bottom: 4px;
}

.for-step-btn { background: var(--for-color); color: #fff; }
.for-step-btn:hover:not(:disabled) { filter: brightness(.9); }

/* ===== while step demo ===== */
.while-visual {
  display: flex;
  align-items: flex-start;
  gap: 32px;
  margin: 16px 0;
  flex-wrap: wrap;
}

.while-var-area { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: 0 0 auto; }

.sub-label {
  font-size: .72rem;
  font-weight: 700;
  color: var(--muted-color);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.var-box {
  position: relative;
  width: 110px;
  min-height: 88px;
  border: 3px solid var(--while-color);
  border-radius: 12px;
  background: var(--while-light);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 10px 8px;
}

.var-tag {
  position: absolute;
  top: -12px; left: 10px;
  background: var(--while-color);
  color: #fff;
  font-size: .73rem;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 5px;
  font-family: 'Courier New', monospace;
}

.var-val {
  font-size: 2rem;
  font-weight: 800;
  color: var(--while-dark);
  font-family: 'Courier New', monospace;
}

.var-box.pop { animation: varPop .3s ease; }

@keyframes varPop {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.12); }
  100% { transform: scale(1); }
}

.while-flow { display: flex; flex-direction: column; gap: 4px; flex: 1 1 auto; }

.flow-step {
  border: 2px solid var(--border-soft);
  border-radius: 10px;
  padding: 12px 16px;
  background: #fafafa;
  max-width: 300px;
  opacity: .3;
  transition: opacity .25s, border-color .25s, background .25s, box-shadow .25s;
}

.flow-step.active {
  opacity: 1;
  border-color: var(--while-color);
  background: var(--while-light);
  box-shadow: 0 0 0 3px rgba(139,92,246,.15);
}

.flow-step.done { opacity: .7; border-color: #c4b5fd; background: #f5f3ff; }

.flow-step-title {
  font-size: .7rem;
  font-weight: 700;
  color: var(--while-color);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 4px;
}

.flow-step-body { font-family: 'Courier New', monospace; font-size: .9rem; color: #1a202c; }

.flow-result { margin-top: 6px; font-size: .82rem; font-weight: 700; color: var(--muted-color); }
.flow-result.is-true  { color: var(--if-color); }
.flow-result.is-false { color: #ef4444; }

.flow-arrow { font-size: .78rem; color: var(--muted-color); padding-left: 14px; line-height: 1.8; }

.while-step-btn { background: var(--while-color); color: #fff; }
.while-step-btn:hover:not(:disabled) { filter: brightness(.9); }

/* ===== for vs while ===== */
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 16px;
}

.compare-card { border-radius: 12px; padding: 20px; border: 2px solid transparent; }
.for-theme    { background: var(--for-light);   border-color: #93c5fd; }
.while-theme  { background: var(--while-light); border-color: #c4b5fd; }

.compare-title { font-size: 1rem; font-weight: 800; margin-bottom: 12px; font-family: 'Courier New', monospace; }
.for-theme   .compare-title { color: var(--for-dark); }
.while-theme .compare-title { color: var(--while-dark); }

.compare-list { font-size: .85rem; padding-left: 18px; line-height: 2; color: #374151; margin: 0 0 12px; }

.compare-code {
  font-family: 'Courier New', monospace;
  font-size: .82rem;
  background: #1e293b;
  color: #e2e8f0;
  padding: 8px 12px;
  border-radius: 6px;
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .fc-fork      { flex-direction: column; align-items: center; }
  .lfc-top      { flex-direction: column; align-items: flex-start; }
  .compare-grid { grid-template-columns: 1fr; }
  .while-visual { flex-direction: column; }
  .flow-step    { max-width: 100%; }
  .iv           { font-size: .78rem; }
}
