/* =========================================================
   THINK INDUSTRIES — Code Lab styles (editor, board, serial)
   ========================================================= */
.ti-lab {
    border: 1px solid var(--ti-line, rgba(0, 255, 65, 0.3));
    border-radius: 14px;
    background: rgba(0, 0, 0, 0.35);
    margin: 22px 0 30px;
    overflow: hidden;
}
.ti-lab:not(.ti-lab-ready) script { display: none; }
.ti-lab.kind-example { border-color: rgba(0, 212, 255, 0.35); }

.ti-lab-head {
    display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
    padding: 10px 14px;
    background: rgba(0, 255, 65, 0.07);
    border-bottom: 1px solid rgba(0, 255, 65, 0.2);
}
.kind-example .ti-lab-head { background: rgba(0, 212, 255, 0.07); border-bottom-color: rgba(0, 212, 255, 0.2); }
.ti-lab-title { font-weight: 600; color: #fff; }
.ti-kind {
    font-family: 'Courier New', monospace; font-size: 0.7rem; letter-spacing: 1px;
    color: #000; background: var(--ti-green, #00ff41); padding: 2px 6px; border-radius: 3px; margin-right: 6px; vertical-align: middle;
}
.kind-example .ti-kind { background: var(--ti-blue, #00d4ff); }
.ti-passed { font-family: monospace; font-size: 0.75rem; color: var(--ti-green, #00ff41); border: 1px solid var(--ti-green, #00ff41); padding: 1px 6px; border-radius: 3px; margin-left: 6px; }

.ti-langs { display: inline-flex; border: 1px solid rgba(255, 255, 255, 0.2); border-radius: 6px; overflow: hidden; }
.ti-langs button {
    background: transparent; color: #aaa; border: 0; padding: 6px 12px; font-size: 0.8rem; cursor: pointer; font-family: inherit;
}
.ti-langs button + button { border-left: 1px solid rgba(255, 255, 255, 0.2); }
.ti-langs button.active { background: var(--ti-blue, #00d4ff); color: #000; font-weight: 600; }
.ti-langs button:not(.active):hover { color: #fff; }

.ti-lab > .ti-task { padding: 12px 16px 4px; color: #ddd; font-size: 0.95rem; }
.ti-lab > .ti-task p:first-child { margin-top: 0; }
.ti-task code, .ti-hint-list code, .ti-verdict code { background: #000; color: var(--ti-green, #00ff41); padding: 1px 5px; border-radius: 4px; }

.ti-lab-body { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 0; }
.ti-code-col { border-right: 1px solid rgba(255, 255, 255, 0.08); min-width: 0; display: flex; flex-direction: column; }
.ti-sim-col { min-width: 0; display: flex; flex-direction: column; }
/* Stacked (code on top, robot below) on phones and on tablets held upright */
@media (max-width: 900px) {
    .ti-lab-body { grid-template-columns: 1fr; }
    .ti-code-col { border-right: 0; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
}

/* Editor */
.ti-editor { flex: 1; min-height: 200px; min-width: 0; max-width: 100%; overflow: hidden; }
.ti-editor .CodeMirror, .ti-editor .CodeMirror * { box-sizing: content-box; } /* CodeMirror needs content-box */
.ti-editor .CodeMirror { height: auto; min-height: 200px; font-size: 14px; font-family: 'Cascadia Code', 'Consolas', 'Courier New', monospace; }
.ti-editor .CodeMirror-scroll { min-height: 200px; max-height: 520px; }
.ti-textarea {
    width: 100%; min-height: 260px; box-sizing: border-box; border: 0; resize: vertical;
    background: #05060a; color: #d7ffd9; font: 14px/1.5 'Consolas', 'Courier New', monospace; padding: 10px; tab-size: 4;
}
.cm-s-ti.CodeMirror { background: #05060a; color: #d7ffd9; }
.cm-s-ti .CodeMirror-gutters { background: #05060a; border-right: 1px solid #1c1f26; }
.cm-s-ti .CodeMirror-linenumber { color: #4a5160; }
.cm-s-ti .CodeMirror-cursor { border-left: 2px solid #00ff41; }
.cm-s-ti .CodeMirror-selected, .cm-s-ti.CodeMirror-focused .CodeMirror-selected { background: rgba(0, 212, 255, 0.22); }
.cm-s-ti .cm-keyword { color: #ff79c6; }
.cm-s-ti .cm-def { color: #50fa7b; }
.cm-s-ti .cm-variable { color: #e6edf3; }
.cm-s-ti .cm-variable-2 { color: #8be9fd; }
.cm-s-ti .cm-variable-3, .cm-s-ti .cm-type { color: #8be9fd; }
.cm-s-ti .cm-builtin { color: #8be9fd; }
.cm-s-ti .cm-number { color: #bd93f9; }
.cm-s-ti .cm-string { color: #f1fa8c; }
.cm-s-ti .cm-comment { color: #6a9955; font-style: italic; }
.cm-s-ti .cm-meta { color: #ffb86c; }
.cm-s-ti .cm-operator { color: #ff79c6; }
.cm-s-ti .cm-property { color: #66d9ef; }
.cm-s-ti .cm-atom { color: #bd93f9; }
.cm-s-ti .CodeMirror-matchingbracket { color: #fff !important; text-decoration: underline; }
.ti-err-line { background: rgba(255, 77, 77, 0.22); }

.ti-toolbar {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08); background: rgba(255, 255, 255, 0.02);
}
.ti-toolbar .ti-btn { padding: 8px 14px; font-size: 0.8rem; }
.ti-btn.ghost { border-color: rgba(255, 255, 255, 0.25); color: #ccc; }
.ti-btn.ghost:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.ti-run { background: var(--ti-green, #00ff41) !important; color: #000 !important; font-weight: bold; }
.ti-run:hover { box-shadow: 0 0 12px rgba(0, 255, 65, 0.6); }
.ti-check { border-color: var(--ti-blue, #00d4ff) !important; color: var(--ti-blue, #00d4ff) !important; }
.ti-check:hover { background: var(--ti-blue, #00d4ff) !important; color: #000 !important; }
.busy .ti-run, .busy .ti-check { opacity: 0.5; pointer-events: none; }
.ti-status { font-size: 0.8rem; color: var(--ti-amber, #ffb000); font-family: monospace; }

/* Board */
.ti-board { padding: 14px; background: radial-gradient(circle at 30% 20%, rgba(0, 90, 60, 0.25), transparent 60%), #071009; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.ti-board.empty { display: none; }
.ti-parts { display: flex; flex-wrap: wrap; gap: 12px; }
.ti-part {
    flex: 1 1 110px; max-width: 200px; min-width: 96px;
    background: rgba(0, 0, 0, 0.45); border: 1px solid rgba(0, 255, 65, 0.18); border-radius: 10px;
    padding: 10px; text-align: center;
}
.ti-part-label { font-size: 0.75rem; color: #bbb; margin-top: 6px; line-height: 1.3; }
.ti-part-label span { color: #666; font-family: monospace; }
.ti-part-label b { display: block; color: #fff; font-family: monospace; font-weight: normal; }
.ti-bulb {
    --v: 0; width: 34px; height: 34px; margin: 4px auto 0; border-radius: 50% 50% 45% 45%;
    background: color-mix(in srgb, var(--c) 25%, #111); border: 2px solid color-mix(in srgb, var(--c) 40%, #333);
    transition: background 0.05s, box-shadow 0.05s;
}
.ti-bulb.on {
    background: color-mix(in srgb, var(--c) calc(25% + var(--v) * 75%), #111);
    box-shadow: 0 0 calc(var(--v) * 22px) calc(var(--v) * 6px) var(--c);
}
.ti-buzz { font-size: 1.8rem; }
.ti-part-buzzer.on { border-color: var(--ti-amber, #ffb000); }
.ti-servo { width: 100%; max-width: 120px; height: auto; }
.ti-servo .arc { fill: none; stroke: #2b3a30; stroke-width: 4; }
.ti-servo .arm { stroke: var(--ti-green, #00ff41); stroke-width: 5; stroke-linecap: round; transition: all 0.08s linear; }
.ti-servo .hub { fill: #ddd; }
.ti-meter { height: 12px; background: #1a1d24; border-radius: 6px; overflow: hidden; margin-top: 10px; }
.ti-meter span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #00d4ff, #00ff41, #ffb000); transition: width 0.1s; }
.ti-slider { width: 100%; margin-top: 6px; accent-color: var(--ti-blue, #00d4ff); }
.ti-btn-part {
    width: 40px; height: 40px; border-radius: 8px; background: #333; border: 2px solid #555; cursor: pointer; padding: 6px; margin-top: 2px;
}
.ti-btn-part span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #c62828; box-shadow: 0 3px 0 #7f1717; transition: all 0.05s; }
.ti-btn-part.pressed span { transform: translateY(3px); box-shadow: 0 0 0 #7f1717; background: #ff5252; }
.ti-btn-part:disabled { cursor: default; }

.ti-grid {
    position: relative; display: grid; gap: 2px; margin: 12px auto 0; max-width: 420px;
    background: #0b0d12; padding: 2px; border-radius: 8px;
}
.ti-parts + .ti-grid { margin-top: 14px; }
.ti-grid .cell { aspect-ratio: 1; display: flex; align-items: center; justify-content: center; border-radius: 3px; font-size: clamp(0.8rem, 3vw, 1.3rem); }
.ti-grid .floor { background: #1d2430; }
.ti-grid .wall { background: repeating-linear-gradient(45deg, #3a2e12, #3a2e12 4px, #5a4718 4px, #5a4718 8px); }
.ti-bot {
    position: absolute; display: flex; align-items: center; justify-content: center;
    font-size: clamp(0.9rem, 3.4vw, 1.5rem); transition: left 0.25s linear, top 0.25s linear;
}
.ti-bot .dir {
    position: absolute; inset: 8%; border-radius: 50%; border: 2px solid transparent; border-top-color: var(--ti-green, #00ff41);
    transition: transform 0.2s;
}
.ti-bot.crash { animation: ti-shake 0.4s; filter: drop-shadow(0 0 6px #ff4d4d); }
.ti-bot.goal { filter: drop-shadow(0 0 8px #00ff41); }
@keyframes ti-shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* Serial monitor */
.ti-serial-head {
    display: flex; align-items: center; gap: 10px; padding: 6px 12px; font-family: monospace; font-size: 0.75rem; color: var(--ti-green, #00ff41);
    background: rgba(0, 255, 65, 0.06); border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.ti-clock { color: #888; margin-left: auto; }
.ti-replay { display: inline-flex; gap: 6px; align-items: center; }
.ti-speed, .ti-skip { background: #111; color: #ccc; border: 1px solid #333; border-radius: 4px; font-size: 0.75rem; padding: 2px 4px; cursor: pointer; }
.ti-serial {
    flex: 1; margin: 0; min-height: 120px; max-height: 240px; overflow: auto; padding: 10px 12px;
    background: #020304; color: #d7ffd9; font: 13px/1.45 'Consolas', 'Courier New', monospace; white-space: pre-wrap; word-break: break-word;
}
.ti-serial .ti-error { color: #ff7b7b; }
.ti-serial .ti-warn { color: var(--ti-amber, #ffb000); }
.ti-serial .ti-note { color: #888; }

.ti-verdict { padding: 12px 16px; font-size: 0.95rem; border-top: 1px solid rgba(255, 255, 255, 0.08); }
.ti-verdict.pass { background: rgba(0, 255, 65, 0.1); color: #b9ffc8; }
.ti-verdict.pass b { color: var(--ti-green, #00ff41); }
.ti-verdict.fail { background: rgba(255, 176, 0, 0.08); color: #ffe2a8; }
.ti-verdict.fail b { color: var(--ti-amber, #ffb000); }
.ti-muted { color: #999; }
.ti-hint-list { margin: 0; padding: 10px 16px 12px 36px; background: rgba(0, 212, 255, 0.05); border-top: 1px dashed rgba(0, 212, 255, 0.3); color: #cfefff; font-size: 0.92rem; }
.ti-hint-list li { margin: 4px 0; }

/* Lesson map at the top of each level page */
.ti-lesson-map { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 25px; padding: 0; list-style: none; }
.ti-lesson-map a {
    display: inline-block; padding: 6px 12px; border: 1px solid rgba(0, 212, 255, 0.35); border-radius: 20px;
    color: var(--ti-blue, #00d4ff); text-decoration: none; font-size: 0.85rem;
}
.ti-lesson-map a:hover { background: rgba(0, 212, 255, 0.12); }
.ti-lesson-map a.done { border-color: var(--ti-green, #00ff41); color: var(--ti-green, #00ff41); }
.ti-lesson-map a.done::before { content: '✔ '; }

/* Side-by-side language reference */
.ti-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 15px 0; }
.ti-compare > div { min-width: 0; }
.ti-compare h4 { margin: 0 0 4px; font-size: 0.8rem; color: var(--ti-blue, #00d4ff); font-family: monospace; letter-spacing: 1px; }
.ti-compare pre { margin: 0; }
@media (max-width: 600px) { .ti-compare { grid-template-columns: 1fr; } }

/* Touch screens: no double-tap zoom on buttons; code at 16px+ so iPads don't zoom in on tap; finger-sized controls */
.ti-lab button, .ti-lab select, .ti-grid { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
@media (pointer: coarse) {
    .ti-editor .CodeMirror, .ti-textarea { font-size: 16px; }
    .ti-langs button { padding: 10px 16px; font-size: 0.95rem; }
    .ti-toolbar .ti-btn { min-height: 44px; }
    .ti-speed, .ti-skip { font-size: 16px; padding: 6px 8px; }
}
/* Older iPads (iOS 15 and earlier) don't know color-mix() */
@supports not (color: color-mix(in srgb, red 50%, blue)) {
    .ti-bulb { background: #222; border-color: #444; }
    .ti-bulb.on { background: var(--c); }
}