/* Thin Ice lab */
.lab {
  --ice: #7fd6ff;
  --ice-dim: rgba(127, 214, 255, 0.35);
  --glass: rgba(9, 11, 14, 0.62);
  max-width: 1440px; margin: 0 auto 0;
  border: 1px solid var(--line-strong);
  background: #07080a;
  position: relative;
  box-shadow: 0 40px 120px -40px rgba(0, 0, 0, 0.9), 0 0 0 1px rgba(255, 255, 255, 0.015) inset;
}
.lab::before, .lab::after { content: ""; position: absolute; width: 22px; height: 22px; border: 2px solid var(--accent); pointer-events: none; z-index: 3; }
.lab::before { top: -7px; left: -7px; border-right: none; border-bottom: none; }
.lab::after { bottom: -7px; right: -7px; border-left: none; border-top: none; }
.lab-wrap { padding: 0 3vw 10vh; }

.lab button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
.lab button:disabled { opacity: 0.35; cursor: default; }
.lab code { font-family: var(--mono); font-size: 0.9em; color: var(--txt); }

/* top bar */
.lab-bar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.lab-title { font-family: var(--mono); font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; display: flex; align-items: center; gap: 10px; }
.lab-title .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.lab[data-running] .lab-title .dot { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; box-shadow: 0 0 2px var(--accent); } }
.lab-title .ver { color: var(--dim); }
.modes { display: flex; border: 1px solid var(--line-strong); }
.modes button { font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); padding: 9px 14px; transition: color .2s, background .2s; position: relative; }
.modes button + button { border-left: 1px solid var(--line-strong); }
.modes button:hover { color: var(--txt); background: var(--panel); }
.modes button[aria-selected="true"] { color: var(--txt); background: #13161b; }
.modes button[aria-selected="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--accent); }

/* main grid */
.lab-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(330px, 1fr); height: min(80vh, 740px); min-height: 520px; }
.stage { position: relative; overflow: hidden; background: radial-gradient(120% 90% at 30% 0%, #1b130e 0%, #07080a 60%); touch-action: pan-y; }
.lake-canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; display: block; }
.stage::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(120% 100% at 50% 40%, transparent 55%, rgba(0, 0, 0, 0.55) 100%); }
.poster { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--dim); font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; transition: opacity .8s; }
.poster b { display: block; font-family: var(--grot); font-weight: 500; font-size: clamp(34px, 5vw, 64px); letter-spacing: -0.03em; text-transform: none; color: var(--txt); margin-bottom: 10px; }
.poster b span { color: var(--accent); }
.lab.ready .poster { opacity: 0; pointer-events: none; }

.lake-labels { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.lake-labels span { position: absolute; left: 0; top: 0; will-change: transform; white-space: nowrap; }
.axis { font-family: var(--mono); font-size: 10px; color: rgba(190, 200, 212, 0.55); letter-spacing: 0.06em; }
.reading { font-family: var(--mono); font-size: 9.5px; line-height: 1.5; padding: 0 5px; color: #d6eefa; background: rgba(4, 8, 12, 0.62); border: 1px solid var(--ice-dim); opacity: 0; transition: opacity .5s; backdrop-filter: blur(4px); }
.reading.bad { color: #ffb08a; border-color: rgba(255, 77, 0, 0.6); }
.reading.in { opacity: 1; }
.lab.is-flat .lake-labels { display: none; }

.hud { position: absolute; z-index: 2; display: flex; gap: 6px; }
.hud-tl { top: 14px; left: 14px; }
.hud-tr { top: 14px; right: 14px; }
.chip, .lab .toggle { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.08em; padding: 6px 10px; border: 1px solid rgba(255, 255, 255, 0.08); background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); color: var(--txt); }
.chip[data-kind="tool_use"] { color: var(--ice); border-color: var(--ice-dim); }
.chip[data-kind="end_turn"] { color: #b5f0c7; border-color: rgba(181, 240, 199, 0.4); }
.chip[data-kind="your turn"] { color: var(--accent); border-color: rgba(255, 77, 0, 0.5); }
.chip[data-kind="error"], .chip[data-kind="refusal"] { color: #ffb08a; }
.lab[data-waiting] .chip#stopChip::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 7px; border-radius: 50%; background: var(--ice); animation: pulse 0.9s infinite; }
.lab .toggle { cursor: pointer; text-transform: uppercase; transition: border-color .2s, color .2s; }
.lab .toggle::before { content: ""; display: inline-block; width: 7px; height: 7px; border: 1px solid currentColor; border-radius: 50%; margin-right: 8px; vertical-align: 0; transition: background .2s; }
.lab .toggle[aria-pressed="true"] { color: var(--ice); border-color: var(--ice-dim); }
.lab .toggle[aria-pressed="true"]::before { background: var(--ice); box-shadow: 0 0 8px var(--ice); }

.caption { position: absolute; z-index: 2; left: 14px; right: 14px; top: 58px; display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: start; padding: 13px 16px; background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid rgba(255, 255, 255, 0.07); max-width: 620px; }
.caption .cap-k { font-family: var(--mono); font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); padding-top: 3px; white-space: nowrap; }
.caption p { font-size: 13.5px; line-height: 1.55; color: #d9dde3; margin: 0; }
.caption code { color: var(--ice); font-size: 12px; }
.caption.pop { animation: capIn .45s cubic-bezier(.2, .7, .2, 1); }
@keyframes capIn { from { opacity: 0.2; transform: translateY(6px); } }

/* side panel */
.side { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: #090a0d; }
.side-tabs { display: flex; border-bottom: 1px solid var(--line); }
.side-tabs button { flex: 1; font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); padding: 12px 8px; position: relative; transition: color .2s; }
.side-tabs button + button { border-left: 1px solid var(--line); }
.side-tabs button:hover { color: var(--txt); }
.side-tabs button[aria-selected="true"] { color: var(--txt); }
.side-tabs button[aria-selected="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: var(--ice); }
.side-tabs .count { color: var(--ice); margin-left: 4px; }
.side-body { flex: 1; min-height: 0; position: relative; }
.pane { position: absolute; inset: 0; overflow: auto; padding: 14px; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.pane-tools { display: flex; justify-content: flex-end; margin: -4px 0 10px; }
.lab .mini { font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); border: 1px solid var(--line-strong) !important; padding: 5px 9px !important; }
.lab .mini[aria-pressed="true"] { color: var(--ice); border-color: var(--ice-dim) !important; }

.msgs { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.msgs.raw { display: none; }
.raw-json { font-family: var(--mono); font-size: 11px; line-height: 1.6; color: #c9d1da; white-space: pre-wrap; word-break: break-word; margin: 0; }
.msg { border: 1px solid var(--line); background: #0c0e11; opacity: 0; transform: translateY(8px); transition: opacity .4s ease, transform .4s cubic-bezier(.2, .7, .2, 1); }
.msg.in { opacity: 1; transform: none; }
.msg .role { display: flex; justify-content: space-between; padding: 7px 10px; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }
.msg.assistant .role span:first-child { color: var(--accent); }
.msg.user .role span:first-child { color: var(--ice); }
.msg .role .n { letter-spacing: 0.04em; text-transform: none; }
.msg.pending .role::after { content: "running"; color: var(--ice); animation: pulse 1s infinite; }
.blk { padding: 8px 10px; font-size: 13px; line-height: 1.55; border-top: 1px dashed var(--line); }
.blk:first-of-type { border-top: none; }
.role + .blk { border-top: none; }
.blk .k { display: block; font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); margin-bottom: 3px; }
.blk.text { color: #e3e6ea; }
.blk.think { color: var(--dim); font-style: italic; font-size: 12.5px; }
.blk.think .k { font-style: normal; }
.blk.use, .blk.res { position: relative; padding-left: 14px; transition: background .2s; }
.blk.use::before, .blk.res::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 2px; background: var(--tag); opacity: 0.8; }
.blk.use b { font-family: var(--mono); font-weight: 500; font-size: 12.5px; color: var(--tag); margin-right: 8px; }
.blk.use code, .blk.res code { font-size: 11.5px; color: #c9d1da; word-break: break-word; }
.blk .tid { display: block; font-family: var(--mono); font-size: 9.5px; color: #59606b; margin-top: 3px; }
.blk.res { background: rgba(127, 214, 255, 0.025); }
.blk.res.err { background: rgba(255, 77, 0, 0.06); }
.blk.res.err .k { color: var(--accent); }
.blk.link { background: rgba(127, 214, 255, 0.08); }

pre.loop { margin: 0; font-family: var(--mono); font-size: 11.5px; line-height: 1.75; color: #c7ccd4; }
pre.loop .ln { display: block; padding: 0 8px; margin: 0 -8px; border-left: 2px solid transparent; transition: background .3s, border-color .3s; white-space: pre; }
pre.loop .ln.on { background: rgba(255, 77, 0, 0.13); border-left-color: var(--accent); color: var(--txt); }
pre.loop .c, .tools-json .c { color: #5c636e; }
pre.loop .s { color: #ffb36b; }
pre.loop .kw { color: var(--ice); }
.req { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.req pre, .tools-json { margin: 6px 0 0; font-family: var(--mono); font-size: 11px; line-height: 1.6; color: #c7ccd4; white-space: pre-wrap; word-break: break-word; }

/* composer: You're the model */
.composer { border-top: 1px solid var(--accent); background: linear-gradient(180deg, rgba(255, 77, 0, 0.07), transparent 60%), #0b0c0f; padding: 14px; display: grid; gap: 10px; transform: translateY(10px); opacity: 0; transition: transform .35s cubic-bezier(.2, .7, .2, 1), opacity .35s; }
.composer.in { transform: none; opacity: 1; }
.cmp-head { font-family: var(--grot); font-weight: 500; font-size: 17px; letter-spacing: -0.01em; }
.cmp-head span { color: var(--accent); }
.composer textarea { width: 100%; resize: none; height: 42px; background: #07080a; border: 1px solid var(--line-strong); color: var(--txt); font: 13px var(--sans); padding: 8px 10px; }
.composer textarea:focus, .livebox input:focus, .livebox select:focus { outline: none; border-color: var(--ice-dim); }
.tool-btns { display: grid; gap: 6px; }
.tool-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tool-row .tn { font-family: var(--mono); font-size: 11px; color: var(--ice); min-width: 92px; }
.tool-row button { font-family: var(--mono); font-size: 10.5px; padding: 6px 9px; border: 1px solid var(--line-strong); color: #d4d8de; transition: all .15s; }
.tool-row button:hover { border-color: var(--ice); color: var(--ice); background: rgba(127, 214, 255, 0.06); }
.tool-row button:active { transform: scale(0.96); }
.draft { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.draft li { font-size: 12px; display: flex; align-items: center; gap: 8px; padding: 6px 8px; border: 1px dashed var(--line-strong); }
.draft li .k { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); }
.draft li b { font-family: var(--mono); font-weight: 500; color: var(--ice); }
.draft li code { color: var(--dim); font-size: 11px; }
.draft li button { margin-left: auto; color: var(--dim); font-size: 16px; line-height: 1; }
.draft li.empty { color: var(--dim); }
.cmp-actions { display: flex; gap: 8px; }
.btn-p, .btn-s { font-family: var(--mono) !important; font-size: 11px !important; letter-spacing: 0.12em; text-transform: uppercase; padding: 11px 16px !important; transition: all .2s; }
.btn-p { background: var(--accent) !important; color: #000 !important; flex: 1; }
.btn-p:hover:not(:disabled) { background: #ff6a2b !important; }
.btn-s { border: 1px solid var(--line-strong) !important; color: var(--dim) !important; }
.btn-s:hover { color: var(--txt) !important; border-color: var(--dim) !important; }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* live */
.livebox { border-top: 1px solid var(--line); padding: 14px; display: grid; gap: 8px; background: #0b0c0f; }
.livebox label { font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--dim); }
.livebox input, .livebox select { width: 100%; background: #07080a; border: 1px solid var(--line-strong); color: var(--txt); font: 13px var(--mono); padding: 9px 10px; }
.livebox .row { display: flex; gap: 8px; }
.livebox .fine { font-size: 11.5px; line-height: 1.5; color: var(--dim); margin: 0; }
.livebox .err { color: #ffb08a; font-size: 12.5px; margin: 0; min-height: 0; }
.lab:not([data-running]) #stopLive { display: none; }
.lab[data-running] #runLive { display: none; }

/* footer: transport, concepts, tokens */
.lab-foot { display: grid; grid-template-columns: auto 1fr auto; gap: 18px; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.transport { display: flex; gap: 6px; }
.transport button { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--dim); border: 1px solid var(--line-strong); padding: 8px 12px; transition: all .2s; }
.transport button:hover:not(:disabled) { color: var(--txt); border-color: var(--dim); }
.transport #playBtn { color: var(--txt); border-color: var(--accent); }
.concepts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.concept { font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: #59606b; padding: 5px 9px; border: 1px solid var(--line); display: inline-flex; align-items: center; gap: 7px; transition: color .4s, border-color .4s; cursor: help; }
.concept i { width: 6px; height: 6px; border-radius: 50%; background: #2a2e35; transition: background .4s, box-shadow .4s; }
.concept.on { color: var(--txt); border-color: var(--line-strong); }
.concept.on i { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.concept.pop { animation: conceptPop .7s cubic-bezier(.2, .7, .2, 1); }
@keyframes conceptPop { 30% { transform: scale(1.08); border-color: var(--accent); } }
.concept-count { font-family: var(--mono); font-size: 10px; color: var(--dim); align-self: center; margin-left: 4px; }
.tokens { display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; column-gap: 12px; align-items: end; }
.tokens .label { grid-column: 1 / 3; font-size: 9.5px; margin-bottom: 6px; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 34px; min-width: 150px; max-width: 220px; border-bottom: 1px solid var(--line-strong); }
.bar { width: 6px; background: linear-gradient(180deg, var(--ice), rgba(127, 214, 255, 0.35)); position: relative; transition: height .5s cubic-bezier(.2, .7, .2, 1); min-height: 2px; display: flex; flex-direction: column-reverse; }
.bar .cached { display: block; width: 100%; background: #2f6f86; transition: height .5s; }
.bar.wait { animation: pulse 0.9s infinite; }
#tokNote { font-family: var(--mono); font-size: 10px; color: var(--dim); white-space: nowrap; }
#tokNote .cache { color: #6fb3c9; }

/* mobile */
@media (max-width: 900px) {
  .lab-wrap { padding: 0 0 8vh; }
  .lab { border-left: none; border-right: none; }
  .lab::before, .lab::after { display: none; }
  .lab-bar { padding: 10px 12px; }
  .modes { width: 100%; }
  .modes button { flex: 1; padding: 10px 6px; font-size: 10px; letter-spacing: 0.06em; }
  .lab-grid { grid-template-columns: 1fr; height: auto; min-height: 0; }
  .stage { height: min(112vw, 68vh); }
  .side { border-left: none; border-top: 1px solid var(--line); height: 470px; }
  .lab-grid > .caption { position: static; max-width: none; grid-template-columns: 1fr; gap: 4px; padding: 10px 14px; min-height: 86px; align-content: start; background: #0b0c0f; border: none; border-top: 1px solid var(--line); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .hud-tr { top: auto; bottom: 8px; }
  .caption p { font-size: 12.5px; }
  .hud-tl { top: 8px; left: 8px; } .hud-tr { right: 8px; }
  .lab-foot { grid-template-columns: 1fr; gap: 12px; }
  .transport { flex-wrap: wrap; }
  .concepts { justify-content: flex-start; }
  .bars { max-width: none; flex: 1; }
  .tokens { grid-template-columns: 1fr auto; }
}
@media (prefers-reduced-motion: reduce) {
  .msg, .composer { transition: none; }
  .caption.pop, .concept.pop { animation: none; }
}
.lab [hidden] { display: none !important; }
/* compact composer, so the messages above it stay readable */
.composer { padding: 10px 14px 12px; gap: 8px; }
.cmp-head { font-size: 15px; }
.composer textarea { height: 34px; padding: 7px 10px; font-size: 12.5px; }
.tool-btns { gap: 5px; }
.lab .tool-row button { padding: 4px 8px; }
.draft { max-height: 92px; overflow-y: auto; }
.draft li { padding: 4px 8px; }
.lab .btn-p, .lab .btn-s { padding: 9px 14px !important; }
