:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #5d6b7c;
  --border: #d9dee5;
  --accent: #2864d1;
  --accent-text: #ffffff;
  --header-bg: #f1f6fc;
  --header-stripe: #e7effa;
  --tagline-bg: #ffffff;
  --tagline-border: #cbd9ed;
  --tagline-text: #36567f;
  --badge-bg: #e7f4ed;
  --badge-text: #246044;
  --badge-promoted-bg: #fff0bf;
  --badge-promoted-text: #705000;
  --badge-investigator-bg: #d8f1f3;
  --badge-investigator-text: #14535b;
  --ok: #1a7a43;
  --warn: #8a5a00;
  --fail: #c53030;
  --user-bubble: #e4edfc;
  --bot-bubble: #ffffff;
  --radius: 10px;
  --font-ui: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", sans-serif;
  --guide-bg: #fff8e7;
  --guide-line: #e0a100;
  --chat-bg: #f0f5ff;
  --chat-line: #2f6fde;
  --settings-bg: #ecf8f1;
  --settings-line: #1a7a43;
  --tag-text: #ffffff;
  --guide-tag-text: #3a2900;
  --guide-strong: #7a5200;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c;
    --panel: #1b2129;
    --text: #e3e8ef;
    --muted: #93a1b3;
    --border: #2c3541;
    --accent: #5b8ff0;
    --accent-text: #0d1117;
    --header-bg: #1b2533;
    --header-stripe: #202e40;
    --tagline-bg: #1b2129;
    --tagline-border: #405673;
    --tagline-text: #b6ccef;
    --badge-bg: #163828;
    --badge-text: #98dbb4;
    --badge-promoted-bg: #3b3014;
    --badge-promoted-text: #f0cf75;
    --badge-investigator-bg: #153438;
    --badge-investigator-text: #9edce4;
    --user-bubble: #23324a;
    --bot-bubble: #1f2630;
    --guide-bg: #262011;
    --guide-line: #d69e2e;
    --chat-bg: #151d2c;
    --chat-line: #5b8ff0;
    --settings-bg: #13231b;
    --settings-line: #38a169;
    --ok: #48bb78;
    --warn: #d69e2e;
    --fail: #fc8181;
    --guide-strong: #d69e2e;
    --tag-text: #0d1117;
    --guide-tag-text: #0d1117;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); }

header.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem 1.25rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  background: repeating-linear-gradient(135deg, var(--header-bg) 0 8px, var(--header-stripe) 8px 10px);
  text-align: center;
}

header.top h1 { font-size: 1.15rem; margin: 0; }
.brand { display: flex; align-items: center; gap: 0.5rem; }
.brand img { display: block; }
.app-version { font-size: 0.75rem; font-weight: 400; color: var(--muted); white-space: nowrap; }
.model-info { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.4rem; }
.model-status {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font: 600 0.8rem var(--font-ui);
}
.model-status::before { content: ""; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: currentColor; }
.model-status.ready { color: var(--ok); }
.model-status.loading { color: var(--warn); }
.model-status.unavailable { color: var(--fail); }
.top-links { display: flex; gap: 0.9rem; }
.top-links a {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  font: 500 0.82rem/1.2 var(--font-ui);
  letter-spacing: 0.01em;
  color: var(--muted);
  text-decoration: none;
}
.top-links a:hover, .top-links a:focus-visible { color: var(--accent); text-decoration: underline; }
.done-group { display: flex; align-items: center; }
.done-btn {
  padding: 0.3rem 0.9rem;
  border-radius: 999px;
  font: 600 0.82rem/1.2 var(--font-ui);
}
.done-btn:hover { border-color: var(--accent); color: var(--accent); }

.help-btn {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  min-width: 24px;
  min-height: 24px;
  padding: 0;
  margin-left: 0.2rem;
  vertical-align: middle;
  border: 1px solid var(--muted);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font: 700 0.65rem/1 var(--font-ui);
}
.help-btn:hover, .help-btn:focus-visible { color: var(--accent); border-color: var(--accent); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: absolute;
  top: -4rem;
  left: 0.5rem;
  z-index: 10;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
}
.skip-link:focus { top: 0.5rem; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--muted);
}
.tagline { background: var(--tagline-bg); border-color: var(--tagline-border); color: var(--tagline-text); }

.experiment-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  width: fit-content;
  max-width: 100%;
  padding: 0.15rem 0.5rem;
  border: 1px solid currentColor;
  border-radius: 4px;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.35;
}
.experiment-badge.promoted { background: var(--badge-promoted-bg); color: var(--badge-promoted-text); }
.experiment-badge.investigator { background: var(--badge-investigator-bg); color: var(--badge-investigator-text); }
.badge-mark { white-space: nowrap; }

main.page {
  max-width: 760px;
  margin: 0 auto;
  padding: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.panel h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }

.notice {
  border-left: 4px solid var(--warn);
  padding: 0.5rem 0.75rem;
  background: var(--panel);
  margin-bottom: 1rem;
}

.notice.error { border-color: var(--fail); }
#boot-warning { visibility: hidden; animation: boot-warning-reveal 0s 3s forwards; }
@keyframes boot-warning-reveal { to { visibility: visible; } }

ul.checks { list-style: none; margin: 0; padding: 0; }

ul.checks li {
  display: grid;
  grid-template-columns: 1.5rem 1fr;
  gap: 0.25rem 0.5rem;
  padding: 0.35rem 0;
  border-bottom: 1px dashed var(--border);
}

ul.checks li:last-child { border-bottom: 0; }
ul.checks .icon { font-weight: bold; text-align: center; }
ul.checks .ok .icon, ul.checks li.ok .icon { color: var(--ok); }
ul.checks li.warn .icon { color: var(--warn); }
ul.checks li.fail .icon { color: var(--fail); }
ul.checks .detail { grid-column: 2; color: var(--muted); font-size: 0.875rem; }

.recommendation { font-size: 1.05rem; }
.panel-intro { margin: 0 0 0.75rem; color: var(--muted); }
#recommendation-explain { font-size: 0.85rem; line-height: 1.4; }
.welcome p { margin: 0; }

/* Step bar shown on every page: 1 Set up, 2 Choose an experiment, 3 Chat. */
.journey { padding: 0.4rem 1rem; border-bottom: 1px solid var(--border); background: var(--panel); }
.journey ol {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.35rem 1.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font: 500 0.85rem/1.2 var(--font-ui);
}
.journey li { position: relative; display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.25rem 0.75rem 0.25rem 0.3rem; border-radius: 999px; color: var(--muted); }
.journey li + li::before { content: ""; position: absolute; left: -1.3rem; top: 50%; width: 1rem; height: 2px; background: var(--border); }
.journey li[aria-current="step"] { background: var(--text); color: var(--panel); font-weight: 600; }
.journey li:has(> a) { padding: 0; }
.journey a {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0.75rem 0.2rem 0.25rem;
  border: 1px solid var(--muted);
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
}
.journey a:hover, .journey a:focus-visible { background: var(--bg); text-decoration: underline; }
.journey a.choose-experiment { background: var(--guide-line); border-color: var(--guide-line); color: var(--guide-tag-text); font-weight: 600; }
.journey a.choose-experiment .journey-num { border-color: currentColor; }
.journey .done-group { padding: 0; }
.journey .done-btn { display: inline-flex; align-items: center; gap: 0.4rem; padding: 0.2rem 0.75rem 0.2rem 0.25rem; }
.journey-num { display: inline-grid; place-items: center; width: 1.35rem; height: 1.35rem; border: 1.5px solid currentColor; border-radius: 50%; font-size: 0.75rem; font-weight: 700; }
@media (max-width: 600px) {
  header.top:has(.tagline) { gap: 0.4rem; padding: 0.6rem 0.75rem; }
  header.top .tagline { max-width: 100%; font-size: 0.75rem; line-height: 1.35; padding: 0.25rem 0.6rem; }
  .journey { padding: 0.4rem 0.75rem; }
  .journey ol { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.25rem; align-items: stretch; font-size: 0.8rem; }
  body.chat .journey ol { grid-template-columns: repeat(auto-fit, minmax(min(100%, 5.75em), 1fr)); }
  .journey li, .journey a { flex-direction: column; justify-content: flex-start; gap: 0.25rem; min-width: 0; min-height: 4.25rem; padding: 0.35rem 0.2rem; text-align: center; border-radius: 8px; overflow-wrap: anywhere; }
  .journey a { width: 100%; height: 100%; border: 0; }
  .journey .done-btn { flex: 1; flex-direction: column; width: 100%; gap: 0.25rem; padding: 0.35rem 0.2rem; border: 0; border-radius: 8px; }
  .journey-num { flex-shrink: 0; }
  .journey li + li::before { display: none; }
}

/* Experiment picker */
main.page-wide { max-width: 1120px; }
.setup-summary, .free-chat-panel { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem 1.5rem; }
.setup-summary > div, .free-chat-panel > div { flex: 1 1 22rem; min-width: 0; }
.setup-summary h2, .free-chat-panel h2 { margin-bottom: 0.25rem; }
.setup-summary p, .free-chat-panel p { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.pick-heading { margin: 0 0 1rem; padding: 1rem; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.pick-title { font-size: 1.2rem; margin: 0 0 0.3rem; color: var(--text); }
.pick-intro { margin: 0; overflow-wrap: anywhere; }
.experiment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
  gap: 0.75rem;
  margin: 0 0 1.25rem;
  padding: 0;
  list-style: none;
}
.experiment-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas: "num head" "obj obj";
  align-content: start;
  gap: 0.55rem 0.75rem;
  height: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-top-width: 5px;
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  transition: transform 0.15s, box-shadow 0.15s;
}
.experiment-card:hover, .experiment-card:focus-visible { transform: translateY(-2px); box-shadow: 0 6px 18px rgb(0 0 0 / 0.14); }
.experiment-card.tour-target, .experiment-card:hover, .experiment-card:focus-visible { border-color: var(--accent); background: var(--chat-bg); }
.experiment-num {
  grid-area: num;
  display: grid;
  place-items: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  background: var(--bg);
  color: var(--text);
  font-weight: 700;
}
.experiment-card.tour-target .experiment-num, .experiment-card:hover .experiment-num, .experiment-card:focus-visible .experiment-num { background: var(--accent); color: var(--accent-text); }
.experiment-head { grid-area: head; display: flex; flex-direction: column; align-items: flex-start; }
.experiment-title { font-size: 1.02rem; }
.experiment-meta { font-size: 0.8rem; color: var(--muted); }
.experiment-current { margin-top: 0.3rem; padding: 0.1rem 0.45rem; border: 1px solid var(--border); border-radius: 4px; background: var(--bg); color: var(--muted); font-size: 0.7rem; font-weight: 600; }
.experiment-objective { grid-area: obj; overflow-wrap: anywhere; }
@media (prefers-reduced-motion: reduce) { .experiment-card { transition: none; } .experiment-card:hover, .experiment-card:focus-visible { transform: none; } }

/* First-run tips: a small box with an arrow pointing at the next thing to click. */
.tour {
  position: fixed;
  z-index: 50;
  width: min(320px, calc(100vw - 16px));
  padding: 0.75rem 1rem;
  border: 2px solid var(--guide-line);
  border-radius: 12px;
  background: var(--guide-bg);
  color: var(--text);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.28);
  font-size: 0.92rem;
  text-align: left;
}
.tour-arrow {
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid var(--guide-line);
  background: var(--guide-bg);
  transform: translateX(-50%) rotate(45deg);
}
.tour[data-side="below"] .tour-arrow { top: -9px; border-right: 0; border-bottom: 0; }
.tour[data-side="above"] .tour-arrow { bottom: -9px; border-left: 0; border-top: 0; }
.tour[data-side="right"] .tour-arrow { left: -9px; border-top: 0; border-right: 0; transform: translateY(-50%) rotate(45deg); }
.tour-count { margin: 0; font: 700 0.7rem/1.4 var(--font-ui); letter-spacing: 0.06em; text-transform: uppercase; color: var(--guide-strong); }
.tour-title { margin: 0.1rem 0 0.3rem; font-size: 1rem; }
.tour-text { margin: 0 0 0.6rem; }
.tour-actions { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.tour-skip { font-size: 0.85rem; color: var(--muted); }
.tour .tour-next { padding: 0.35rem 1rem; background: var(--guide-line); border-color: var(--guide-line); color: var(--guide-tag-text); }
.setup-content { min-width: 0; display: contents; }
.setup-content > * { grid-column: 2; min-width: 0; margin: 0; }
.setup-page > .welcome { grid-column: 2; grid-row: 1; margin: 0; }
.setup-content > .setup-results { grid-row: 2; }
main.setup-page {
  max-width: 1120px;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}
.setup-sidebar { grid-column: 1; grid-row: 2; min-width: 0; display: flex; flex-direction: column; }
.setup-picker-sidebar, .setup-recommendation-sidebar { grid-column: 1; grid-row: 3; min-width: 0; display: flex; flex-direction: column; }
.setup-sidebar > *, .setup-picker-sidebar > *, .setup-recommendation-sidebar > * { flex-shrink: 0; }
.setup-recommendation-sidebar { align-self: stretch; }
.setup-recommendation-sidebar > .panel { flex: 1; margin: 0; }
.setup-content > #result { grid-row: 3; align-self: stretch; }
@media (min-width: 801px) {
  .setup-page:has(.tour-flow:not(.hidden)) > .setup-recommendation-sidebar,
  .setup-page:has(.tour-flow:not(.hidden)) > .setup-picker-sidebar,
  .setup-page:has(.tour-flow:not(.hidden)) .setup-content > #result,
  .setup-page:has(.tour-flow:not(.hidden)) .setup-content > #override { grid-row: 4; }
}
.setup-content > .tour-flow { grid-column: 2; grid-row: 3; max-width: none; margin: 0; }
.datacenter-intro { margin: 0 0 0.5rem; font-size: 0.85rem; color: var(--muted); }
.datacenter-title { display: flex; align-items: center; gap: 0.5rem; }
.datacenter-title img { flex: 0 0 36px; }
.debug-info { margin-top: 0.75rem; }
.debug-info summary { cursor: pointer; font-weight: 600; }
.debug-info pre { max-height: 16rem; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.75rem; }
dialog.first-welcome {
  box-sizing: border-box;
  width: min(560px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 1.5rem;
  border: 2px solid var(--guide-line);
  border-radius: 8px;
  background: var(--guide-bg);
  color: var(--text);
}
.first-welcome::backdrop { background: rgb(10 14 20 / 0.6); }
.first-welcome > img { display: block; margin: 0 auto 0.75rem; }
.first-welcome h2 { font-size: 1.5rem; text-align: center; }
.first-welcome p { line-height: 1.5; }
.first-welcome .primary { display: block; margin: 1rem auto 0; background: var(--guide-line); border-color: var(--guide-line); color: var(--guide-tag-text); }
.override-explanation { margin: 0; font-size: 0.75rem; overflow-wrap: anywhere; }
.setup-checks {
  background: var(--guide-bg);
  border-color: var(--guide-line);
  padding: 0.75rem;
  font-size: 0.8rem;
  line-height: 1.35;
}
.setup-checks h2 { font-size: 0.95rem; margin-bottom: 0.4rem; }
.check-reasons { list-style: none; padding: 0; margin: 0; font-size: 0.75rem; overflow-wrap: anywhere; }
.check-reasons li { padding: 0.3rem 0; border-bottom: 1px dashed var(--guide-line); }
.check-reasons li:last-child { border-bottom: 0; }
.check-reasons strong, .override-explanation strong { color: var(--guide-strong); }
.setup-results ul.checks li { gap: 0.1rem 0.4rem; padding: 0.25rem 0; font-size: 0.85rem; line-height: 1.3; }
.setup-results ul.checks .detail { font-size: 0.75rem; overflow-wrap: anywhere; }
.tour-sidebar {
  position: relative;
  top: auto;
  z-index: auto;
  width: 100%;
  margin-bottom: 1rem;
  background: var(--guide-bg);
  border-color: var(--guide-line);
  border-radius: 8px;
  box-shadow: none;
}
.tour-sidebar[data-side="left"] .tour-arrow {
  right: -9px;
  border-color: var(--guide-line);
  border-left: 0;
  border-bottom: 0;
  background: var(--guide-bg);
  transform: translateY(-50%) rotate(45deg);
}
.tour-sidebar .tour-arrow { border-color: var(--guide-line); background: var(--guide-bg); }
.tour-intro { grid-column: 1; grid-row: 1; align-self: start; margin-bottom: 0; }
.tour-intro[data-side="above"] .tour-arrow { top: auto; }
.tour-sidebar .tour-count { color: var(--guide-strong); }
.tour-sidebar .tour-next {
  background: var(--guide-line);
  border-color: var(--guide-line);
  color: var(--guide-tag-text);
}
@media (max-width: 800px) {
  main.setup-page { grid-template-columns: minmax(0, 1fr); }
  .setup-page > .welcome { grid-column: 1; }
  .setup-sidebar, .setup-picker-sidebar, .setup-recommendation-sidebar { grid-column: auto; grid-row: auto; height: auto; }
  .setup-content { display: block; }
  .setup-content > * { margin-bottom: 1rem; }
  .tour-sidebar { position: static; }
  .tour-sidebar .tour-arrow { display: none; }
  .tour-intro { grid-column: auto; grid-row: auto; }
}
.tour-target { outline: 3px solid var(--accent); outline-offset: 3px; animation: tour-pulse 1.6s ease-in-out infinite; }
@keyframes tour-pulse { 50% { outline-offset: 6px; outline-color: rgb(47 111 222 / 0.35); } }
@media (prefers-reduced-motion: reduce) { .tour-target { animation: none; } }

.countdown {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

button, .button {
  display: inline-block;
  font: inherit;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}

button.primary, .button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button:disabled { opacity: 0.5; cursor: not-allowed; }

fieldset { border: 1px solid var(--border); border-radius: 8px; margin: 0 0 1rem; }

label.option {
  display: block;
  padding: 0.35rem 0;
}

label.option.disabled { color: var(--muted); }
label.option small { display: block; margin-left: 1.6rem; color: var(--muted); }

select, input[type="number"], textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  max-width: 100%;
}

/* Chat page */
.leave-confirm { flex-shrink: 0; width: calc(100% - 2rem); max-width: 1088px; margin: 0.75rem auto 0; padding: 0.75rem 1rem; border: 1px solid var(--guide-line); border-radius: 8px; background: var(--guide-bg); }
.leave-confirm h2 { margin: 0; font-size: 1rem; color: var(--guide-strong); }
.leave-confirm p { margin: 0.25rem 0 0.75rem; font-size: 0.85rem; }
.leave-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.leave-confirm #leave-continue { background: var(--guide-line); border-color: var(--guide-line); color: var(--guide-tag-text); }
body.chat {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.chat-picker {
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow-y: auto;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto;
  grid-template-areas: "chat" "settings";
  gap: 0.75rem;
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  min-height: 0;
  padding: 0.75rem;
}

.workspace.with-guide {
  max-width: 1360px;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  grid-template-areas: "guide chat" "guide settings";
}

.zone {
  min-width: 0;
  border: 1px solid;
  border-top-width: 5px;
  border-radius: var(--radius);
}
.zone textarea, .zone input, .zone select { background: var(--panel); }
.zone-tag {
  display: inline-block;
  margin: 0;
  padding: 0.05rem 0.55rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tag-text);
}

.zone-guide {
  grid-area: guide;
  padding: 0.75rem 1rem 1rem;
  overflow-y: auto;
  font-size: 0.92rem;
  background: var(--guide-bg);
  border-color: var(--guide-line);
}
.zone-guide .zone-tag { background: var(--guide-line); color: var(--guide-tag-text); }

.zone-chat {
  grid-area: chat;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding: 0.6rem 0.75rem 0;
  background: var(--chat-bg);
  border-color: var(--chat-line);
}
.zone-chat .zone-tag { background: var(--chat-line); }

.zone-settings {
  grid-area: settings;
  max-height: 40dvh;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
  background: var(--settings-bg);
  border-color: var(--settings-line);
}
.zone-settings .zone-tag { background: var(--settings-line); margin-right: 0.4rem; }

summary { cursor: pointer; }
.task-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.75rem; margin-top: 0.5rem; }
.task-heading h2 { font-size: 1.2rem; margin: 0; }
.task-time, .mode-status, .zone-guide small { color: var(--muted); font-size: 0.8rem; }
.objective { font-weight: 600; margin: 0.4rem 0 0.75rem; }
.steps { padding-left: 1.3rem; margin: 0 0 0.75rem; }
.steps li { padding-left: 0.2rem; margin-bottom: 0.8rem; }
.steps li::marker { font-weight: 700; color: var(--guide-strong); }
.steps p { margin: 0; }
.step-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.45rem; }
.step-action {
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  border-width: 2px;
  font-size: 0.85rem;
  max-width: 100%;
  text-align: left;
}
.prompt-action { border-color: var(--chat-line); }
.prompt-action:hover { background: var(--chat-bg); }
.setting-action { border-color: var(--settings-line); }
.setting-action:hover { background: var(--settings-bg); }
.setting-action[aria-pressed="true"] { background: var(--settings-line); color: var(--tag-text); }
.guide-notice { border-left: 3px solid var(--guide-line); padding-left: 0.65rem; }
.challenges dt { font-weight: 600; }
.challenges dd { margin: 0.15rem 0 0.6rem; }
.mode-status { margin: 0.5rem 0; }
.link-button { padding: 0; border: 0; background: none; color: var(--accent); text-decoration: underline; font-size: inherit; }
.zone-guide details { border-top: 1px solid var(--guide-line); margin-top: 0.75rem; padding-top: 0.6rem; }
.zone-guide label { display: block; margin: 0.5rem 0 0.25rem; }
.notes-label { display: flex; align-items: center; gap: 0.3rem; }
.zone-guide textarea { width: 100%; }
.zone-guide details button { margin-top: 0.5rem; }
.zone-guide small { display: block; margin-top: 0.4rem; }
.zone-guide p, .zone-guide dd { overflow-wrap: anywhere; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.dialog-body:focus-visible { outline-offset: -3px; }

progress { width: 100%; height: 0.9rem; }

#load-text { font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }

#log {
  flex: 1;
  min-height: 80px;
  overflow-y: auto;
  padding: 0.75rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.msg {
  max-width: 88%;
  padding: 0.55rem 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.user { align-self: flex-end; background: var(--user-bubble); }
.msg.assistant { align-self: flex-start; background: var(--bot-bubble); }
.msg.system-note { align-self: center; font-size: 0.85rem; color: var(--muted); border-style: dashed; }
.msg .meta { display: block; margin-top: 0.3rem; font-size: 0.75rem; color: var(--muted); }

.turtle-sandbox {
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr);
  gap: 0.75rem;
  align-items: start;
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--border);
  white-space: normal;
}
.turtle-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.25rem;
}
.turtle-canvas { display: block; width: 200px; height: 200px; max-width: 100%; }
.turtle-axis { stroke: var(--border); }
.turtle-origin { fill: var(--muted); opacity: 0.6; }
.turtle-cursor { stroke: var(--panel); }
.turtle-controls { display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; }
.turtle-editor-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; font-size: 0.85rem; }
.turtle-title { display: inline-flex; align-items: center; gap: 0.25rem; }
.turtle-run { padding: 0.25rem 0.65rem; font-size: 0.82rem; font-weight: 600; border-color: var(--accent); color: var(--accent); }
.turtle-run:hover { background: var(--chat-bg); }
.turtle-code {
  width: 100%;
  font: 0.82rem/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
  min-height: 3.8rem;
}
.turtle-status { font-size: 0.8rem; }
.turtle-status.ok { color: var(--ok); }
.turtle-status.error { color: var(--fail); font-weight: 600; }
.turtle-hint { color: var(--muted); font-size: 0.75rem; line-height: 1.3; }
@media (max-width: 640px) {
  .turtle-sandbox { grid-template-columns: 1fr; }
  .turtle-canvas { width: 180px; height: 180px; }
}

.reply-progress { display: flex; align-items: center; gap: 0.65rem; max-width: 100%; white-space: normal; }
.warmup-note { min-width: 0; max-width: 26rem; padding: 0.4rem 0.6rem; border-left: 3px solid var(--guide-line); border-radius: 4px; background: var(--guide-bg); color: var(--guide-strong); font-size: 0.8rem; line-height: 1.4; overflow-wrap: anywhere; }
.thinking { display: inline-flex; flex-shrink: 0; gap: 0.3rem; padding: 0.35rem 0.1rem; }
.thinking .dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--muted);
  animation: thinking-bounce 1.2s infinite ease-in-out;
}
.thinking .dot:nth-child(2) { animation-delay: 0.15s; }
.thinking .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes thinking-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-0.35rem); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .thinking .dot { animation: none; opacity: 1; }
}

#composer {
  display: flex;
  gap: 0.9rem;
  padding: 0.9rem 0 0.8rem;
  border-top: 1px solid var(--border);
}

#composer textarea { flex: 1; min-width: 0; resize: none; min-height: 2.6rem; max-height: 9rem; }

#composer .buttons { display: grid; grid-template-columns: repeat(2, auto); gap: 0.5rem; align-content: start; }
#composer .composer-help { align-self: flex-start; margin: 0.2rem 0 0 -0.4rem; }

details.settings summary { cursor: pointer; color: var(--muted); padding: 0.15rem 0; }

.settings-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 0.75rem;
  align-items: center;
  margin-top: 0.5rem;
}

.settings-grid textarea { width: 100%; min-height: 5rem; resize: vertical; }
.settings-grid > * { min-width: 0; }
.setting-label { display: flex; align-items: center; gap: 0.3rem; }
.help-example { border-left: 3px solid var(--ok); padding-left: 0.75rem; }
.help-facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.45rem 0.9rem;
  margin: 0.9rem 0;
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  background: var(--bg);
  font-size: 0.92rem;
}
.help-facts dt { font-weight: 600; color: var(--muted); }
.help-facts dd { margin: 0; }
@media (max-width: 520px) {
  .help-facts { grid-template-columns: 1fr; }
  .help-facts dd { margin-bottom: 0.4rem; }
}

.zone-head { display: flex; align-items: center; gap: 0.2rem; }
.error-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.5rem 0 0; }
.error-actions:not(:has(button:not(.hidden))) { display: none; }
.no-model .zone-chat #log { opacity: 0.45; }

dialog.load-overlay {
  width: min(680px, calc(100% - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 1px solid var(--guide-line);
  border-top: 6px solid var(--guide-line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.35);
  overflow: hidden;
}
dialog.load-overlay[open] { display: flex; flex-direction: column; }
dialog.load-overlay::backdrop { background: rgb(10 14 20 / 0.6); backdrop-filter: blur(3px); }
dialog.load-overlay:focus, dialog.load-overlay:focus-visible { outline: none; }
.load-head { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.25rem 0.6rem; }
.load-status { flex: 1; min-width: 0; }
.load-overlay h2 { font-size: 1.15rem; margin: 0 0 0.5rem; }
.load-icon { flex: none; animation: load-bob 1.6s ease-in-out infinite; }
@keyframes load-bob { 50% { transform: translateY(-6px) rotate(-4deg); } }
@media (prefers-reduced-motion: reduce) { .load-icon { animation: none; } }

.load-phases {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0;
  padding: 0 1.25rem 0.85rem;
  list-style: none;
  counter-reset: phase;
  font-size: 0.8rem;
  line-height: 1.35;
}
.load-phases li {
  counter-increment: phase;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
}
.load-phases strong { display: block; margin-bottom: 0.15rem; font-size: 0.85rem; color: var(--text); }
.load-phases strong::before { content: counter(phase) ". "; color: var(--guide-strong); }
.load-phases li.done strong::before { content: "✓ "; color: var(--ok); }
.load-phases li.active { border: 2px solid var(--guide-line); color: var(--text); box-shadow: 0 2px 10px rgb(0 0 0 / 0.08); }
.load-phases li.done { border-color: var(--ok); }
.load-phases li:not(.active) span { display: none; }

.load-body {
  flex: 1;
  align-self: center;
  width: 95%;
  min-height: 8rem;
  overflow-y: auto;
  background: var(--guide-bg);
  padding: 0.85rem 1.25rem 0.1rem;
  border: 1px solid var(--guide-line);
}
.load-body:focus-visible { outline: 2px solid var(--guide-line); outline-offset: -2px; }
.lesson-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 0.75rem; }
.lesson {
  break-inside: avoid;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}
.lesson h3 { margin: 0 0 0.4rem; font-size: 1rem; color: var(--guide-strong); }
.lesson p { margin: 0.35rem 0; }
.lesson-facts { margin: 0; padding-left: 1.1rem; }
.lesson-facts li { margin-bottom: 0.35rem; }
.lesson-small { color: var(--muted); font-size: 0.8rem; }
.load-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; padding: 0.65rem 1.25rem 0.85rem; }
.load-foot small { color: var(--muted); }

@media (max-width: 640px) {
  .load-head { padding: 0.8rem 0.9rem 0.5rem; }
  .load-icon { width: 40px; height: 40px; }
  .load-phases { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 0 0.9rem 0.6rem; }
  .load-phases li:not(.active) span { display: none; }
  .load-body { padding: 0.7rem 0.9rem 0.1rem; }
  .load-foot { padding: 0.55rem 0.9rem 0.7rem; }
}

#error-panel { margin-top: 0.75rem; }

/* Licenses (page and popup) */
.licenses { font-size: 0.8rem; line-height: 1.45; }
.licenses h3 { font-size: 0.95rem; margin: 0.9rem 0 0.4rem; }
.licenses h3:first-child { margin-top: 0; }
.licenses h4 { font-size: 0.85rem; margin: 0.8rem 0 0.2rem; }
.licenses p { margin: 0.2rem 0; }
.licenses ul { margin: 0.2rem 0; padding-left: 1.2rem; }

dialog.overlay {
  width: min(640px, calc(100% - 2rem));
  max-height: 85vh;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  overflow: hidden;
}
dialog.overlay[open] { display: flex; flex-direction: column; }
dialog.overlay::backdrop { background: rgb(0 0 0 / 0.5); }
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem 0.5rem 1rem;
  border-bottom: 1px solid var(--border);
}
.dialog-header h2 { font-size: 1rem; margin: 0; }
.dialog-close { padding: 0.1rem 0.6rem; font-size: 1.2rem; line-height: 1; }
.dialog-body { overflow-y: auto; padding: 0.75rem 1rem 1rem; }

.hidden { display: none !important; }

@media (max-width: 800px) {
  body.chat { height: auto; min-height: 100dvh; }
  .workspace.with-guide { grid-template-columns: minmax(0, 1fr); grid-template-areas: "guide" "chat" "settings"; }
  .workspace { grid-template-rows: auto; padding: 0.5rem; }
  .zone-guide, .zone-settings { overflow-y: visible; max-height: none; }
  #log { min-height: 240px; max-height: 55dvh; flex: auto; }
}

@media (max-width: 520px) {
  .msg { max-width: 96%; }
  .settings-grid { grid-template-columns: 1fr; }
  #composer .buttons { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #composer button { padding: 0.5rem 0.25rem; font-size: 0.85rem; }
  #composer { flex-direction: column; gap: 0.6rem; }
  #composer .composer-help { align-self: flex-end; margin: 0; }
}
