:root {
  --bg: #071018;
  --panel: #0d1b24;
  --panel-2: #102430;
  --line: #1e3a48;
  --text: #e7f4f4;
  --muted: #8aa8b3;
  --accent: #3ecfb2;
  --accent-2: #f0c14b;
  --warn: #ff8a5b;
  --bio: #5eead4;
  --phy: #7dd3fc;
  --chem: #f9a8d4;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, #123445 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #1a2a18 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 16, 24, 0.82);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 260px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: conic-gradient(from 210deg, #00a3dd, #fad201, #00a651, #00a3dd);
  box-shadow: 0 0 18px rgba(62, 207, 178, 0.35);
}
.brand h1 { font-size: 16px; margin: 0; letter-spacing: 0.01em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }

.subjects { display: flex; gap: 8px; flex: 1; justify-content: center; flex-wrap: wrap; }
.subject-btn, .ghost-btn, .lab-controls button, .composer button, .tutor-head button, .dialog-actions button {
  font-family: inherit;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
}
.subject-btn.is-active {
  background: linear-gradient(180deg, #1a4a44, #12353a);
  border-color: var(--accent);
  color: var(--bio);
}
.ghost-btn { margin-left: auto; color: var(--muted); }

.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.7fr);
}

.lab {
  position: relative;
  min-height: 0;
  background: #050b10;
}
#scene { width: 100%; height: 100%; display: block; }

.lab-hud {
  position: absolute;
  z-index: 2;
  left: 16px; right: 16px; top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}
.lab-hud h2 { margin: 0; font-size: 22px; }
.lab-hud p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
#part-chip {
  pointer-events: auto;
  background: rgba(13, 27, 36, 0.8);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  color: var(--accent);
}

.lab-controls {
  position: absolute;
  z-index: 2;
  left: 16px; right: 16px; bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: rgba(13, 27, 36, 0.78);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.lab-controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.lab-controls input[type="range"] { width: 120px; accent-color: var(--accent); }
.lab-controls button.primary, .composer button, #snap-btn, #save-key {
  background: var(--accent);
  color: #06201a;
  border-color: transparent;
  font-weight: 600;
}

.tutor {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--panel);
}
.tutor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}
.tutor-head span { display: block; color: var(--muted); font-size: 12px; }
.messages {
  flex: 1;
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.bubble {
  max-width: 95%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.bubble.user {
  align-self: flex-end;
  background: #16313c;
  border: 1px solid #234a58;
}
.bubble.tutor {
  align-self: flex-start;
  background: #10241c;
  border: 1px solid #1d4a3a;
}
.bubble img {
  display: block;
  max-width: 180px;
  border-radius: 8px;
  margin-bottom: 8px;
}
.bubble strong { color: var(--accent-2); }

.composer {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}
.composer textarea {
  width: 100%;
  resize: vertical;
  min-height: 56px;
  background: #07141b;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  font-family: inherit;
}
.snap-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
}
.snap-preview img { width: 72px; height: 44px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.hidden { display: none !important; }

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  padding: 20px;
  width: min(420px, 92vw);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog input {
  width: 100%;
  margin: 12px 0;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #07141b;
  color: var(--text);
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
code { font-family: var(--mono); font-size: 12px; color: var(--accent); }

@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(48vh, 1fr) minmax(40vh, 1fr); }
  .tutor { border-left: 0; border-top: 1px solid var(--line); }
  .topbar { flex-wrap: wrap; }
}
