/* ── Reset & base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --topbar-h:  48px;
  --base-size: 13px;
}

/* ── Dark theme (default) ───────────────────────────────────────────── */
html, html[data-theme="dark"] {
  --bg:      #1e1e2e;
  --surface: #181825;
  --surface2:#313244;
  --border:  #45475a;
  --text:    #cdd6f4;
  --dim:     #6c7086;
  --green:   #a6e3a1;
  --red:     #f38ba8;
  --blue:    #89b4fa;
  --yellow:  #f9e2af;
}

/* ── Light theme ────────────────────────────────────────────────────── */
html[data-theme="light"] {
  --bg:      #eff1f5;
  --surface: #e6e9ef;
  --surface2:#ccd0da;
  --border:  #bcc0cc;
  --text:    #4c4f69;
  --dim:     #9ca0b0;
  --green:   #40a02b;
  --red:     #d20f39;
  --blue:    #1e66f5;
  --yellow:  #df8e1d;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, 'Cascadia Code', 'Fira Code', monospace;
  font-size: var(--base-size);
  overflow: hidden;
}

/* ── Top bar ────────────────────────────────────────────────────────── */
#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#brand {
  font-weight: bold;
  color: var(--blue);
  white-space: nowrap;
  margin-right: 8px;
}

#device-controls, #exercise-controls, #run-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

#exercise-controls { flex: 1; }

#font-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

#exercise-select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-family: inherit;
  font-size: 12px;
  width: 100%;
  max-width: 300px;
}

/* ── Main layout ────────────────────────────────────────────────────── */
#layout {
  display: flex;
  height: calc(100vh - var(--topbar-h));
  overflow: hidden;
}

/* ── Left panel ─────────────────────────────────────────────────────── */
#panel-left {
  width: 360px;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
  flex-shrink: 0;
}

#panel-divider {
  width: 5px;
  cursor: col-resize;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.15s;
}
#panel-divider:hover, #panel-divider.dragging {
  background: var(--blue);
}

#tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  padding: 8px;
  background: none;
  border: none;
  color: var(--dim);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab:hover:not(.active) { color: var(--text); }

.tab-content { display: none; flex: 1; overflow-y: auto; padding: 16px; }
.tab-content.active { display: block; }

#tab-description { overflow: hidden; padding: 0; }
#tab-description.active { display: flex; flex-direction: column; }

#description-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

#description-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  font-size: 11px;
}

#description-content h1 { font-size: 1.15em; margin-bottom: 12px; color: var(--blue); }
#description-content h2 { font-size: 1em; margin: 16px 0 6px; color: var(--yellow); }
#description-content h3 { font-size: 0.9em; margin: 12px 0 4px; color: var(--text); }
#description-content p  { margin-bottom: 8px; line-height: 1.55; color: var(--text); }
#description-content ul, #description-content ol { padding-left: 18px; margin-bottom: 8px; }
#description-content li { line-height: 1.6; }
#description-content code {
  background: var(--surface2);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: inherit;
  color: var(--green);
}
#description-content pre {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px 12px;
  overflow-x: auto;
  margin-bottom: 10px;
}
#description-content pre code {
  background: none;
  padding: 0;
  color: var(--text);
}
#description-content blockquote {
  border-left: 3px solid var(--blue);
  padding-left: 10px;
  color: var(--dim);
  margin: 8px 0;
}
#description-content hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
#description-content table { border-collapse: collapse; width: 100%; margin-bottom: 10px; }
#description-content th { background: var(--surface2); padding: 4px 8px; color: var(--blue); text-align: left; }
#description-content td { padding: 4px 8px; border-bottom: 1px solid var(--border); }

/* ── Hints tab ──────────────────────────────────────────────────────────── */
#tab-hints {
  padding: 0;
  overflow: hidden;
}
#tab-hints.active { display: flex; flex-direction: column; }

#hints-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 11px;
}

#hints-config {
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  padding: 12px;
  flex-shrink: 0;
  overflow-y: auto;
  max-height: 50%;
}
.hints-config-inner { display: flex; flex-direction: column; gap: 6px; }
.config-label { font-size: 11px; color: var(--dim); }
#hints-config select,
#hints-config input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 8px;
}

#hints-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hint-msg { display: flex; flex-direction: column; gap: 2px; max-width: 92%; }
.hint-msg-user      { align-self: flex-end;   align-items: flex-end; }
.hint-msg-assistant { align-self: flex-start; }
.hint-msg-role { font-size: 10px; color: var(--dim); }
.hint-msg-text {
  font-size: 12px;
  line-height: 1.55;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
}
.hint-msg-user      .hint-msg-text { background: var(--surface2); }
.hint-msg-assistant .hint-msg-text { background: var(--surface); border: 1px solid var(--border); }
.hint-msg-thinking  .hint-msg-text { color: var(--dim); font-style: italic; }

#hints-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
#hints-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 8px;
}
#hints-input:focus { border-color: var(--blue); }

.placeholder { color: var(--dim); font-style: italic; }

/* ── Landing page ───────────────────────────────────────────────────── */
.landing-hero { margin-bottom: 20px; }
.landing-hero p { color: var(--text); line-height: 1.5; margin-top: 6px; font-size: 0.95em; }

.landing-card {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--blue);
  border-radius: 4px;
  margin-bottom: 8px;
  background: var(--surface);
}
.landing-card-num {
  font-size: 1.3em;
  font-weight: 700;
  color: var(--blue);
  min-width: 1.4em;
  line-height: 1.2;
  flex-shrink: 0;
}
.landing-card-body strong { color: var(--text); }
.landing-card-body p { margin: 3px 0 0; color: var(--dim); font-size: 0.88em; }

.landing-ui-item {
  display: flex;
  gap: 12px;
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.landing-ui-item:last-child { border-bottom: none; }
.landing-ui-label {
  flex-shrink: 0;
  min-width: 120px;
  font-size: 0.78em;
  font-weight: 600;
  color: var(--surface);
  background: var(--blue);
  border-radius: 3px;
  padding: 2px 7px;
  text-align: center;
}
.landing-ui-desc { color: var(--dim); font-size: 0.88em; line-height: 1.45; }

.landing-start {
  margin-top: 20px;
  text-align: center;
  color: var(--dim);
  font-style: italic;
  font-size: 0.9em;
}

/* ── editor-no-exercise overview panel ──────────────────────────────── */
#editor-no-exercise {
  overflow-y: auto;
  padding: 24px 28px;
}
#editor-no-exercise h1 { font-size: 1.25em; font-weight: 700; color: var(--blue); margin: 0 0 8px; }
#editor-no-exercise h2 { font-size: 1em; font-weight: 600; color: var(--yellow); margin: 20px 0 10px; }

.landing-console-msg { display: none; }
#editor-no-exercise.console-mode .landing-overview { display: none; }
#editor-no-exercise.console-mode .landing-console-msg { display: block; }

/* ── Right panel ────────────────────────────────────────────────────── */
#panel-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Editor pane ────────────────────────────────────────────────────── */
#editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-bottom: 1px solid var(--border);
}

#editor-tabs {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

#editor-tabs-end {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
  margin-left: auto;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
}

.editor-tab {
  padding: 6px 14px;
  background: none;
  border: none;
  color: var(--dim);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.editor-tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.editor-tab:hover:not(.active) { color: var(--text); }

.editor-tab-content {
  display: none;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.editor-tab-content.active { display: flex; }

.editor-file-toolbar, #settings-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 11px;
}

#settings-status {
  flex: 1;
  color: var(--dim);
}

/* CodeMirror fills the remaining space */
.CodeMirror {
  flex: 1;
  height: 100% !important;
  font-family: inherit !important;
  font-size: var(--base-size) !important;
}
.CodeMirror-scroll { height: 100%; }

/* ── Console pane ───────────────────────────────────────────────────── */
#console-divider {
  height: 5px;
  cursor: row-resize;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.15s;
}
#console-divider:hover, #console-divider.dragging {
  background: var(--blue);
}

#console-pane {
  height: 220px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: var(--surface);
}

#console-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--dim);
  flex-shrink: 0;
}

#console-output {
  flex: 1;
  overflow-y: auto;
  padding: 6px 12px;
  font-size: var(--base-size);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
}

#console-input-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.prompt { color: var(--blue); }

#console-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: var(--base-size);
}

/* ── Buttons ────────────────────────────────────────────────────────── */
.btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface2);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary  { background: var(--blue);  color: var(--surface); border-color: var(--blue); }
.btn-primary:hover:not(:disabled) { opacity: 0.85; color: var(--surface); }
.btn-success  { background: var(--green); color: var(--surface); border-color: var(--green); }
.btn-success:hover:not(:disabled) { opacity: 0.85; color: var(--surface); }
.btn-danger   { color: var(--red); border-color: var(--red); }
.btn-ghost    { background: none; }
.btn-tiny     { padding: 2px 8px; font-size: 11px; }

/* ── Status badge ───────────────────────────────────────────────────── */
.status-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid;
}
.status-connected    { color: var(--green);  border-color: var(--green); }
.status-disconnected { color: var(--dim);    border-color: var(--dim); }

/* ── Modal ──────────────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#modal-overlay.hidden { display: none; }

#modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  width: 400px;
  max-width: 90vw;
}
#modal-title { font-size: 14px; margin-bottom: 12px; color: var(--blue); }
#modal-body  { margin-bottom: 16px; line-height: 1.6; color: var(--text); }
#modal-footer { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Progress bar ───────────────────────────────────────────────────── */
#progress-bar-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 16px;
  z-index: 50;
}
#progress-bar-container.hidden { display: none; }

#progress-bar-label { font-size: 12px; color: var(--dim); margin-bottom: 6px; }
#progress-bar-track {
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}
#progress-bar-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 3px;
  transition: width 0.2s ease;
  width: 0%;
}

/* ── Utility ────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.dim    { color: var(--dim); }

/* ── File browser ───────────────────────────────────────────────────── */
#file-browser {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}
#file-browser.active { display: flex; }

#file-browser-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  font-size: 11px;
}

#file-browser-breadcrumb {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 1px;
  flex-wrap: wrap;
}

.breadcrumb-seg {
  background: none;
  border: none;
  color: var(--blue);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 3px;
}
.breadcrumb-seg:hover { background: var(--surface2); }
.breadcrumb-sep     { color: var(--dim); user-select: none; padding: 0 1px; }
.breadcrumb-current { color: var(--text); padding: 1px 4px; font-size: 11px; }

#file-browser-status {
  color: var(--dim);
  font-style: italic;
  white-space: nowrap;
  font-size: 11px;
}

#file-browser-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.file-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 16px;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: var(--base-size);
  color: var(--text);
  cursor: pointer;
}
.file-entry:hover    { background: var(--surface2); }
.file-entry-dir      { color: var(--blue); }
.file-entry-icon     { color: var(--dim); width: 1em; text-align: center; flex-shrink: 0; }

/* ── Device file tabs ───────────────────────────────────────────────── */
.editor-tab-solution {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding-right: 6px;
  font-style: italic;
  color: var(--dim);
}
.editor-tab-solution.active { color: var(--yellow); }

.editor-tab-device {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding-right: 6px;
}

.tab-close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  padding: 0;
  background: none;
  border: none;
  border-radius: 3px;
  color: var(--dim);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.tab-close-btn:hover { background: var(--surface2); color: var(--red); }

.device-file-status {
  flex: 1;
  color: var(--dim);
  font-size: 11px;
}
