/* Interactive lesson widgets (assets/js/course-widgets.js, docs/course_widgets.md).
   Matches the quiz block: white card, orangered accent. */
[data-kr-widget] {
  margin: 1.5rem 0;
  padding: 1rem 1.25rem;
  border: 1px solid #e3e3e3;
  border-left: 4px solid orangered;
  border-radius: 8px;
  background: #fffaf7;
}
[data-kr-widget]:not(.is-live) > .kr-w-fallback { display: block; }
.kr-w-head { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; align-items: baseline; justify-content: space-between; margin-bottom: 0.75rem; }
.kr-w-label { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: orangered; }
.kr-w-hint { font-size: 0.85rem; color: #555; }
.kr-w-btn { background: white; border: 1px solid #ccc; border-radius: 6px; padding: 0.35rem 0.75rem; cursor: pointer; font-size: 0.9rem; color: #222; transition: border-color 0.15s, background 0.15s; }
.kr-w-btn:hover:not(:disabled) { border-color: orangered; background: #fff3ee; }
.kr-w-btn:focus-visible, .kr-mx-led:focus-visible, .kr-mx-level:focus-visible { outline: 2px solid #0d6efd; outline-offset: 2px; }
.kr-w-btn:disabled { opacity: 0.5; cursor: default; }
.kr-w-btn-main { background: orangered; border-color: orangered; color: white; font-weight: 600; }
.kr-w-btn-main:hover:not(:disabled) { background: #e03e00; border-color: #e03e00; }

/* LED matrix painter */
.kr-mx-layout { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; align-items: flex-start; }
.kr-mx-board { flex: 1 1 320px; max-width: 520px; }
.kr-mx-side { flex: 1 1 200px; display: grid; gap: 0.75rem; }
.kr-mx-grid { background: #10151c; border-radius: 10px; padding: 10px; display: grid; gap: 4px; touch-action: none; user-select: none; }
.kr-mx-row { display: grid; grid-template-columns: repeat(13, 1fr); gap: 4px; }
.kr-mx-led { --kr-led: 0; aspect-ratio: 1; min-width: 0; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  background: color-mix(in srgb, #4aa8ff calc(var(--kr-led) * 100%), #25303d); }
.kr-mx-led.is-on { box-shadow: 0 0 calc(var(--kr-led) * 8px) rgba(74, 168, 255, 0.9); }
.kr-mx-status { margin: 0.4rem 0 0; font-size: 0.85rem; color: #555; }
.kr-mx-caption { display: block; font-size: 0.8rem; font-weight: 600; color: #444; margin-bottom: 0.25rem; }
.kr-mx-levels { display: flex; gap: 4px; flex-wrap: wrap; }
.kr-mx-level { --kr-led: 1; width: 2rem; height: 2rem; border-radius: 6px; border: 2px solid transparent; cursor: pointer; font-size: 0.8rem; font-weight: 600; color: white;
  background: color-mix(in srgb, #1f7fe0 calc(var(--kr-led) * 100%), #25303d); }
.kr-mx-level.is-picked { border-color: orangered; }
.kr-mx-buttons { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.kr-mx-out { margin-top: 1rem; }
.kr-mx-out-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.35rem; }
.kr-mx-out-head .kr-mx-caption { margin: 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.kr-mx-code { box-sizing: border-box; width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.8rem; line-height: 1.35; border: 1px solid #ccc; border-radius: 6px; padding: 0.5rem 0.75rem; background: white; color: #222; resize: vertical; white-space: pre; }

/* Bridge step-through */
.kr-br-lanes { display: grid; grid-template-columns: 1fr 2rem 1fr 2rem 1fr; align-items: stretch; }
.kr-br-lane { border: 2px solid #ddd; border-radius: 8px; background: white; padding: 0.6rem 0.75rem; min-height: 7rem; position: relative; opacity: 0.55; transition: opacity 0.2s, border-color 0.2s; min-width: 0; }
.kr-br-lane.is-active { opacity: 1; border-color: orangered; }
.kr-br-lane.is-stuck { border-color: #b02a37; background: #fdf1f2; }
.kr-br-lane.is-fixed { border-color: #198754; background: #f1faf5; }
.kr-br-lane-title { font-weight: 700; }
.kr-br-lane-sub { font-size: 0.75rem; color: #555; margin-bottom: 0.4rem; }
.kr-br-code { margin: 0; padding: 0.4rem 0.5rem; background: #f4f4f4; border-radius: 4px; font-size: 0.72rem; line-height: 1.35; white-space: pre-wrap; overflow-wrap: anywhere; }
.kr-br-gap { display: flex; align-items: center; justify-content: center; font-size: 1.4rem; color: #ccc; }
.kr-br-gap.is-crossing { color: orangered; font-weight: 700; }
.kr-br-led { position: absolute; top: 0.6rem; right: 0.6rem; width: 0.9rem; height: 0.9rem; border-radius: 50%; background: #d9d9d9; border: 1px solid #bbb; }
.kr-br-led.is-on { background: #ff3b30; border-color: #c41e14; box-shadow: 0 0 8px rgba(255, 59, 48, 0.8); }
.kr-br-wire { margin-top: 0.75rem; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; background: #10151c; color: #9fd0ff; border-radius: 6px; padding: 0.4rem 0.75rem; overflow-wrap: anywhere; }
.kr-br-text { margin: 0.75rem 0; min-height: 4.5em; }
.kr-br-nav { display: flex; gap: 0.5rem; align-items: center; }
.kr-br-count { font-size: 0.85rem; color: #555; margin-left: auto; }

/* Sorter */
.kr-so-card { background: white; border: 1px solid #ccc; border-radius: 8px; padding: 1rem; font-weight: 600; font-size: 1.05rem; text-align: center; }
.kr-so-card.is-done { border-color: #198754; color: #198754; }
.kr-so-picks { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; margin: 0.75rem 0; }
.kr-so-pick { flex: 1 1 10rem; max-width: 16rem; padding: 0.6rem 0.75rem; font-weight: 600; }
.kr-so-progress { font-size: 0.85rem; color: #555; }
.kr-so-why { margin: 0 0 0.75rem; min-height: 3em; }
.kr-so-why.is-right { color: #146c43; }
.kr-so-why.is-wrong { color: #b02a37; }
.kr-so-buckets { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.kr-so-bucket { background: white; border: 1px dashed #bbb; border-radius: 8px; padding: 0.5rem 0.75rem; min-height: 4rem; }
.kr-so-bucket-title { font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: #444; }
.kr-so-list { margin: 0.35rem 0 0; padding-left: 1.1rem; font-size: 0.9rem; }
.kr-so-list .was-wrong { color: #b02a37; }

@media (max-width: 575px) {
  .kr-br-lanes { grid-template-columns: 1fr; }
  .kr-br-gap { height: 1.6rem; transform: rotate(90deg); }
  .kr-br-lane { min-height: 0; }
  .kr-so-buckets { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .kr-br-lane, .kr-w-btn { transition: none; }
}

/* Uno Q simulator */
.kr-sim-layout { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; align-items: flex-start; margin-bottom: 0.75rem; }
.kr-sim-code { flex: 3 1 340px; min-width: 0; }
.kr-sim-board { flex: 2 1 260px; min-width: 0; max-width: 420px; }
.kr-sim-editor { box-sizing: border-box; width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.8rem; line-height: 1.4; border: 1px solid #ccc; border-radius: 6px; padding: 0.5rem 0.75rem; background: white; color: #222; resize: vertical; white-space: pre; overflow: auto; tab-size: 4; }
.kr-sim-buttons { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; margin-top: 0.5rem; }
.kr-sim-grid .kr-mx-led { cursor: default; display: block; }
.kr-sim-leds { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; margin: 0.6rem 0; font-size: 0.8rem; color: #444; }
.kr-sim-led-box { display: inline-flex; align-items: center; gap: 0.35rem; }
.kr-sim-led { width: 0.9rem; height: 0.9rem; border-radius: 50%; background: #d9d9d9; border: 1px solid #bbb; }
.kr-sim-led.is-on { border-color: #888; box-shadow: 0 0 8px rgba(0, 0, 0, 0.35); }
.kr-sim-potbox { display: grid; grid-template-columns: 1fr auto; gap: 0 0.5rem; align-items: center; margin: 0.5rem 0; font-size: 0.85rem; }
.kr-sim-potbox .kr-mx-caption { grid-column: 1 / -1; }
.kr-sim-pot { width: 100%; }
.kr-sim-sketch { font-size: 0.8rem; color: #555; margin: 0.5rem 0; }
.kr-sim-msg { display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; align-items: baseline; font-size: 0.78rem; padding: 0.2rem 0; border-top: 1px solid #eee; }
.kr-sim-who { font-weight: 600; color: #444; }
.kr-sim-up .kr-sim-who { color: #0b6b3a; }
.kr-sim-count { margin-left: auto; color: #555; }
.kr-sim-out { margin: 0; min-height: 3rem; max-height: 12rem; overflow: auto; background: #10151c; color: #e6edf3; border-radius: 6px; padding: 0.5rem 0.75rem; font-size: 0.8rem; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Confidence demo, and the score rows the move detector shares */
.kr-cf-control { display: flex; flex-wrap: wrap; gap: 0.25rem 0.5rem; align-items: center; margin-bottom: 0.75rem; }
.kr-cf-slider { flex: 1 1 12rem; }
.kr-cf-row { display: grid; grid-template-columns: 5.5rem 1fr 3rem 4.5rem; gap: 0.5rem; align-items: center; font-size: 0.85rem; padding: 0.2rem 0; }
.kr-md-table .kr-cf-row { grid-template-columns: 5.5rem 1fr 3rem; }
.kr-cf-track { background: #eee; border-radius: 4px; height: 0.7rem; overflow: hidden; }
.kr-cf-bar { display: block; height: 100%; background: #198754; }
.kr-cf-row.is-out { color: #777; }
.kr-cf-row.is-out .kr-cf-bar { background: #bbb; }
.kr-cf-row.is-best { font-weight: 700; }
.kr-cf-score { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; text-align: right; }
.kr-cf-result, .kr-cb-result, .kr-md-text { margin: 0.75rem 0 0.25rem; font-weight: 600; }

/* Cost break-even */
.kr-cb-fields { display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem; }
.kr-cb-field { flex: 1 1 12rem; }
.kr-cb-input { box-sizing: border-box; width: 100%; padding: 0.35rem 0.5rem; border: 1px solid #ccc; border-radius: 6px; font-size: 1rem; }

/* Move detector */
.kr-md-layout { display: flex; flex-wrap: wrap; gap: 1rem 1.5rem; }
.kr-md-col { flex: 1 1 240px; max-width: 360px; min-width: 0; }
.kr-md-board { display: grid; grid-template-columns: repeat(8, 1fr); border: 2px solid #444; border-radius: 4px; overflow: hidden; }
.kr-md-sq { position: relative; aspect-ratio: 1; min-width: 0; padding: 0; border: 0; background: #f0d9b5; display: flex; align-items: center; justify-content: center; }
.kr-md-sq.is-dark { background: #b58863; }
button.kr-md-sq:not(:disabled) { cursor: pointer; }
button.kr-md-sq:focus-visible { outline: 3px solid #0d6efd; outline-offset: -3px; }
.kr-md-sq.is-picked { box-shadow: inset 0 0 0 3px orangered; }
.kr-md-sq.is-target::after { content: ""; width: 30%; height: 30%; border-radius: 50%; background: rgba(255, 69, 0, 0.75); }
.kr-md-piece { width: 74%; height: 74%; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: clamp(0.6rem, 2.4vw, 0.95rem); background: #222; color: #ffd84a; border: 1px solid #000; }
.kr-md-piece.is-white { background: #fff6dc; color: #b3261e; border-color: #8a7a55; }
.kr-md-glow { position: absolute; inset: 0; background: #00c2ff; opacity: 0; transition: opacity 0.3s; }
.kr-md-noise { font-size: 0.85rem; }

/* Simulator: the pretend phone page */
.kr-sim-phone { margin: 0.75rem 0; padding: 0.6rem 0.75rem; border: 2px solid #444; border-radius: 14px; background: #f4f4f4; text-align: center; font-size: 0.85rem; }
.kr-sim-phone.is-over { background: #ffd9d6; }
.kr-sim-phone .kr-mx-caption { text-align: left; font-weight: 400; color: #555; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.kr-sim-phone-title { font-weight: 700; font-size: 1rem; }
.kr-sim-phone-reading { font-size: 2.6rem; font-weight: 700; line-height: 1.2; }
.kr-sim-phone input { width: 100%; }
.kr-sim-phone-state { color: #555; font-size: 0.8rem; }
