/*
 * RegEx reference and interactive tutorial pages.
 *
 * The two tutorial pages share the same runtime classes, so keep the rules in
 * one module instead of duplicating a style block in both Markdown pages.
 */

.qr-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin: 2rem 0;
  font-size: 0.9em;
}

.qr-card {
  background: var(--bg-color-secondary, #f8f9fa);
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.qr-card h3 {
  margin: 0;
  padding: 1rem;
  font-size: 1.1em;
  font-weight: 600;
  background: var(--bg-color-tertiary, #eef2f5);
  border-bottom: 1px solid var(--border-color, #e0e0e0);
  color: var(--text-color-primary, #333);
}

.qr-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.qr-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color, #f0f0f0);
}

.qr-item:last-child {
  border-bottom: none;
}

.qr-token {
  background: var(--bg-code, #eaeeef);
  color: #c7254e;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-family: "Fira Code", "Cascadia Code", monospace;
  font-weight: 700;
  font-size: 0.95em;
  white-space: nowrap;
}

.qr-desc {
  flex: 1;
  text-align: right;
  padding-left: 1rem;
  color: var(--text-color-secondary, #666);
  line-height: 1.3;
}

.rt-progress {
  background: #e9ecef;
  border-radius: 8px;
  height: 12px;
  margin-bottom: 1.5em;
  overflow: hidden;
}

.rt-progress-fill {
  background: linear-gradient(90deg, #2774AE, #005587);
  height: 100%;
  border-radius: 8px;
  transition: width 0.4s ease;
  width: 0%;
}

.rt-progress-label {
  text-align: right;
  font-size: 0.9em;
  font-weight: 600;
  color: #555;
  margin-bottom: 0.4em;
}

.rt-exercise {
  background: #fff;
  border: 1px solid #ddd;
  border-left: 4px solid #2774AE;
  border-radius: 6px;
  padding: 1.2em 1.4em;
  margin-bottom: 1.5em;
  transition: border-color 0.3s;
}

.rt-exercise.rt-complete {
  border-left-color: #28a745;
}

.rt-ex-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5em;
}

.rt-ex-title {
  font-size: 1.15em;
  font-weight: 700;
  color: #005587;
}

.rt-ex-status {
  font-size: 1.3em;
  color: #28a745;
  min-width: 1.4em;
  text-align: right;
}

.rt-goal {
  margin: 0.3em 0 1em;
  line-height: 1.5;
}

.rt-text-box,
.rt-tests,
.rt-parsons {
  margin-bottom: 1em;
}

.rt-text-label,
.rt-tests-label,
.rt-parsons-label,
.rt-fixer-label {
  font-size: 0.9em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #666;
  margin-bottom: 0.3em;
}

.rt-sample {
  font-family: "Courier New", Courier, monospace;
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  padding: 0.8em 1em;
  line-height: 1.7;
  word-break: break-word;
  font-size: 0.95em;
}

.rt-match {
  background: #FFD100;
  color: #000;
  padding: 1px 2px;
  border-radius: 3px;
  font-weight: 600;
}

.rt-input-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 0.8em;
}

.rt-delim {
  font-family: "Courier New", Courier, monospace;
  font-size: 1.2em;
  color: #555;
  font-weight: 700;
}

.rt-input {
  font-family: "Courier New", Courier, monospace;
  font-size: 1.05em;
  border: 2px solid #ccc;
  border-radius: 4px;
  padding: 0.4em 0.6em;
  flex: 1;
  min-width: 0;
  transition: border-color 0.2s;
}

.rt-input:focus {
  border-color: #2774AE;
  outline: none;
  box-shadow: 0 0 0 3px rgba(39, 116, 174, 0.15);
}

.rt-input-fixer .rt-input {
  border-color: #dc3545;
  background: #fff5f5;
}

.rt-error,
.rt-result,
.rt-print-answer {
  display: none;
}

.rt-error {
  color: #dc3545;
  font-size: 0.9em;
  margin-bottom: 0.5em;
  font-family: monospace;
}

.rt-test {
  padding: 0.25em 0;
  font-size: 0.92em;
  transition: color 0.2s;
}

.rt-test-icon {
  display: inline-block;
  width: 1.2em;
  text-align: center;
}

.rt-test-pass,
.rt-test-pass .rt-test-label {
  color: #1f7a34;
}

.rt-test-fail,
.rt-test-fail .rt-test-label {
  color: #dc3545;
}

.rt-test-pass .rt-test-icon,
.rt-test-fail .rt-test-icon {
  font-weight: 700;
}

.rt-test-input {
  font-size: 0.95em;
  background: #f0f0f0;
  padding: 1px 5px;
  border-radius: 3px;
}

.rt-test-label {
  color: #666;
  font-size: 0.9em;
}

.rt-actions,
.rt-parsons-bank,
.rt-parsons-drop,
.rt-viz-ctrls {
  display: flex;
  flex-wrap: wrap;
}

.rt-actions {
  gap: 0.6em;
  margin-bottom: 0.5em;
}

.rt-btn {
  padding: 0.45em 1.2em;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.92em;
  font-weight: 600;
  transition: background 0.2s, transform 0.1s;
}

.rt-btn:active {
  transform: scale(0.97);
}

.rt-btn-check {
  background: #2774AE;
  color: #fff;
}

.rt-btn-check:hover {
  background: #005587;
}

.rt-btn-skip {
  background: #e9ecef;
  color: #333;
}

.rt-btn-skip:hover {
  background: #dee2e6;
}

.rt-btn-clear {
  background: #f8d7da;
  color: #721c24;
  font-size: 0.9em;
  padding: 0.3em 0.8em;
  margin-top: 0.4em;
}

.rt-btn-clear:hover {
  background: #f5c6cb;
}

.rt-result {
  padding: 0.6em 1em;
  border-radius: 4px;
  font-size: 0.92em;
  margin-top: 0.3em;
}

.rt-result-pass {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.rt-result-fail {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.rt-parsons-bank {
  gap: 6px;
  min-height: 42px;
  padding: 0.5em;
  background: #f8f9fa;
  border: 1px dashed #767676;
  border-radius: 4px;
  margin-bottom: 0.5em;
}

.rt-parsons-target {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 0.4em;
}

.rt-parsons-drop {
  gap: 4px;
  min-height: 36px;
  min-width: 120px;
  flex: 1;
  padding: 0.3em 0.5em;
  background: #fff;
  border: 2px dashed #2774AE;
  border-radius: 4px;
}

.rt-frag {
  display: inline-block;
  padding: 0.3em 0.7em;
  background: #e7f1fa;
  border: 1px solid #2774AE;
  border-radius: 4px;
  cursor: grab;
  font-family: "Courier New", Courier, monospace;
  font-size: 1em;
  font-weight: 600;
  line-height: 1.4;
  color: #111;
  user-select: none;
  transition: background 0.15s, transform 0.15s;
}

.rt-frag:hover {
  background: #d0e4f5;
  transform: translateY(-1px);
}

.rt-frag:focus-visible {
  outline: 3px solid #005587;
  outline-offset: 2px;
}

.rt-frag.rt-dragging {
  opacity: 0.4;
}

.rt-hint {
  margin-bottom: 0.8em;
  font-size: 0.9em;
}

.rt-hint summary {
  cursor: pointer;
  color: #2774AE;
  font-weight: 600;
}

.rt-hint p {
  margin: 0.3em 0 0;
  color: #555;
}

.rt-viz {
  margin-top: 1em;
  background: #f4f7fb;
  border: 1px solid #d0dae8;
  border-radius: 6px;
  padding: 1em 1.2em;
}

.rt-viz-title {
  font-weight: 700;
  font-size: 1em;
  margin-bottom: 0.8em;
  color: #005587;
}

.rt-viz-sc {
  margin-bottom: 1.2em;
}

.rt-viz-sc:last-child {
  margin-bottom: 0;
}

.rt-viz-sc-label {
  font-weight: 600;
  font-size: 0.95em;
  margin-bottom: 0.4em;
  color: #333;
}

.rt-viz-row {
  margin-bottom: 0.3em;
  font-size: 0.92em;
}

.rt-viz-rl {
  font-weight: 600;
  display: inline-block;
  width: 55px;
  color: #555;
}

.rt-viz-re,
.rt-viz-str {
  font-family: "Courier New", Courier, monospace;
  letter-spacing: 0.05em;
  font-size: 1.05em;
  background: #fff;
  padding: 3px 6px;
  border-radius: 3px;
  border: 1px solid #ddd;
  display: inline-block;
}

.rt-viz-desc {
  margin: 0.6em 0;
  font-size: 0.9em;
  line-height: 1.5;
  min-height: 2.5em;
  color: #333;
}

.rt-viz-ctrls {
  gap: 0.4em;
  align-items: center;
}

.rt-viz-btn {
  padding: 0.3em 0.8em;
  border: 1px solid #767676;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9em;
  transition: background 0.15s;
}

.rt-viz-btn:hover {
  background: #e9ecef;
}

.rt-viz-btn-p {
  font-weight: 600;
  border-color: #2774AE;
  color: #2774AE;
}

.rt-viz-counter {
  font-size: 0.9em;
  color: #555;
  margin-left: 0.4em;
}

.rt-viz-hl-re {
  background: #FFD100;
  color: #000;
  padding: 1px 2px;
  border-radius: 2px;
  font-weight: 700;
}

.rt-viz-hl-m {
  background: #d4edda;
  border-radius: 2px;
}

.rt-viz-cur {
  border-bottom: 3px solid #dc3545;
  font-weight: 700;
}

.rt-self-explain {
  margin-top: 0.8em;
  padding: 0.8em 1em;
  background: #f0f7ff;
  border: 1px solid #b8d4f0;
  border-radius: 6px;
}

.rt-se-title {
  color: #005587;
  font-weight: 600;
  font-size: 0.95em;
  margin: 0;
}

.rt-se-question {
  margin: 0.5em 0 0.3em;
  font-size: 0.93em;
  line-height: 1.5;
}

.rt-se-think {
  margin: 0 0 0.5em;
  font-size: 0.9em;
  color: #666;
  font-style: italic;
}

.rt-se-answer {
  margin-top: 0.3em;
}

.rt-se-answer > summary {
  cursor: pointer;
  color: #2774AE;
  font-size: 0.9em;
  font-weight: 600;
}

.rt-se-answer p {
  margin: 0.3em 0 0;
  font-size: 0.9em;
  line-height: 1.5;
  color: #333;
}

.rt-exercise :is(
  p, li, button, summary, input, textarea, code,
  .rt-progress-label, .rt-text-label, .rt-tests-label, .rt-parsons-label,
  .rt-fixer-label, .rt-test, .rt-test-label, .rt-error, .rt-btn, .rt-result,
  .rt-hint, .rt-viz-row, .rt-viz-desc, .rt-viz-btn, .rt-viz-counter,
  .rt-se-title, .rt-se-question, .rt-se-think, .rt-se-answer
) {
  font-size: max(1em, var(--font-size-readable-min, 16px));
}

html.dark-mode .qr-card {
  background: #1e1e1e;
  border-color: #333;
}

html.dark-mode .qr-card h3 {
  background: #252526;
  border-bottom-color: #333;
  color: #ddd;
}

html.dark-mode .qr-item {
  border-bottom-color: #2d2d2d;
}

html.dark-mode .qr-token {
  background: #2d2d2d;
  color: #f87a85;
}

html.dark-mode .qr-desc {
  color: #aaa;
}

html.dark-mode .rt-exercise {
  background: #1e1e1e;
  border-color: #444;
  color: #ddd;
}

html.dark-mode .rt-exercise.rt-complete {
  border-left-color: #28a745;
}

html.dark-mode .rt-ex-title,
html.dark-mode .rt-viz-title,
html.dark-mode .rt-hint summary,
html.dark-mode .rt-se-title,
html.dark-mode .rt-se-answer > summary {
  color: #7ec8e3;
}

html.dark-mode .rt-sample,
html.dark-mode .rt-input,
html.dark-mode .rt-viz-re,
html.dark-mode .rt-viz-str,
html.dark-mode .rt-viz-btn {
  background: #2a2a2a;
  border-color: #555;
  color: #ddd;
}

html.dark-mode .rt-input:focus {
  border-color: #7ec8e3;
  box-shadow: 0 0 0 3px rgba(126, 200, 227, 0.15);
}

html.dark-mode .rt-input-fixer .rt-input,
html.dark-mode .rt-btn-clear {
  background: #3a1a1a;
  border-color: #dc3545;
}

html.dark-mode .rt-btn-clear,
html.dark-mode .rt-error {
  color: #e87e7e;
}

html.dark-mode .rt-btn-clear:hover {
  background: #4a2a2a;
}

html.dark-mode .rt-test-input {
  background: #333;
  color: #ddd;
}

html.dark-mode .rt-test-label,
html.dark-mode .rt-progress-label,
html.dark-mode .rt-text-label,
html.dark-mode .rt-tests-label,
html.dark-mode .rt-parsons-label,
html.dark-mode .rt-fixer-label,
html.dark-mode .rt-se-think {
  color: #aaa;
}

html.dark-mode .rt-btn-skip {
  background: #333;
  color: #ccc;
}

html.dark-mode .rt-btn-skip:hover,
html.dark-mode .rt-viz-btn:hover {
  background: #444;
}

html.dark-mode .rt-parsons-bank {
  background: #2a2a2a;
  border-color: #555;
}

html.dark-mode .rt-parsons-drop {
  background: #1e1e1e;
  border-color: #7ec8e3;
}

html.dark-mode .rt-frag {
  background: #1a3a5c;
  border-color: #7ec8e3;
  color: #ddd;
}

html.dark-mode .rt-frag:hover {
  background: #254a6e;
}

html.dark-mode .rt-frag:focus-visible {
  outline-color: #FFD100;
}

html.dark-mode .rt-viz,
html.dark-mode .rt-self-explain {
  background: #1a2a3a;
  border-color: #3a5a7a;
}

html.dark-mode .rt-viz-desc,
html.dark-mode .rt-goal,
html.dark-mode .rt-hint p,
html.dark-mode .rt-se-answer p {
  color: #ccc;
}

html.dark-mode .rt-progress {
  background: #333;
}

html.dark-mode .rt-match {
  background: #b8960a;
  color: #fff;
}

html.dark-mode .rt-result-pass {
  background: #1a3a1a;
  color: #7ec87e;
  border-color: #2a5a2a;
}

html.dark-mode .rt-result-fail {
  background: #3a1a1a;
  color: #e87e7e;
  border-color: #5a2a2a;
}

html.dark-mode .rt-test-pass,
html.dark-mode .rt-test-pass .rt-test-label {
  color: #5dd66c;
}

html.dark-mode .rt-test-fail,
html.dark-mode .rt-test-fail .rt-test-label {
  color: #ff6b78;
}

html.dark-mode .rt-viz-rl,
html.dark-mode .rt-viz-counter {
  color: #b0b0b0;
}

html.dark-mode .rt-viz-sc-label,
html.dark-mode .rt-se-question {
  color: #ddd;
}

@media print {
  .rt-progress,
  .rt-actions,
  .rt-viz-ctrls,
  .rt-btn-clear,
  .rt-parsons-label {
    display: none !important;
  }

  .rt-print-answer {
    display: block !important;
    margin-top: 0.5em;
    padding: 0.4em 0.8em;
    background: #f0f0f0 !important;
    border-radius: 4px;
    color: #111 !important;
  }

  .qr-card,
  .qr-card h3,
  .qr-token,
  .rt-exercise,
  .rt-sample,
  .rt-input,
  .rt-parsons-bank,
  .rt-parsons-drop,
  .rt-viz,
  .rt-viz-re,
  .rt-viz-str,
  .rt-self-explain {
    background: #fff !important;
    border-color: #767676 !important;
    color: #111 !important;
    box-shadow: none !important;
  }

  .rt-exercise {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .rt-parsons-bank,
  .rt-parsons-target {
    display: none !important;
  }

  .rt-viz {
    break-inside: avoid;
  }
}
