:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-2: #f472b6;
  --ok: #4ade80;
  --warn: #facc15;
  --error: #f87171;
  --border: #475569;
  --font-mono: "Fira Code", "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
  --font-ui: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

header h1 span {
  color: var(--accent);
}

.tagline {
  color: var(--muted);
  font-size: 0.8rem;
}

.actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

button {
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: var(--panel-2);
  color: var(--text);
  padding: 0.45rem 0.8rem;
  font-size: 0.9rem;
  font-family: var(--font-ui);
  transition: background 0.15s, border-color 0.15s;
}

button:hover:not(:disabled) {
  background: #475569;
  border-color: var(--accent);
}

button.primary {
  background: var(--accent);
  color: #0f172a;
  border-color: var(--accent);
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: #7dd3fc;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

main {
  display: grid;
  grid-template-columns: 260px 1fr 340px;
  height: calc(100% - 60px);
}

aside.lessons {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: auto;
}

aside.lessons h2 {
  margin: 0;
  padding: 1rem;
  font-size: 1rem;
  border-bottom: 1px solid var(--border);
}

aside.lessons ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

aside.lessons li {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.9rem;
}

aside.lessons li:hover {
  background: var(--panel-2);
}

aside.lessons li.active {
  background: rgba(56, 189, 248, 0.15);
  border-left: 3px solid var(--accent);
  padding-left: calc(1rem - 3px);
}

.editor-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.editor-toolbar .spacer { flex: 1; }

#editor {
  flex: 1;
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  padding: 1rem;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
}

#editor::placeholder {
  color: var(--muted);
}

.output-panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--border);
  min-width: 0;
}

.output-panel h2 {
  margin: 0;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border-bottom: 1px solid var(--border);
}

#output {
  flex: 1;
  overflow: auto;
  padding: 0.75rem 1rem;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  white-space: pre-wrap;
  line-height: 1.5;
}

#output .line { display: block; }
#output .in { color: var(--muted); }
#output .out { color: var(--text); }
#output .err { color: var(--error); }
#output .ok { color: var(--ok); }

.status-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: var(--panel-2);
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
}

.status-bar .ready { color: var(--ok); }
.status-bar .busy { color: var(--warn); }
.status-bar .error { color: var(--error); }

#loading {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 100;
}

#loading.hidden { display: none; }

#loading-details {
  max-width: 600px;
  margin-top: 1rem;
  padding: 0.75rem;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid var(--error);
  border-radius: 0.375rem;
  color: var(--error);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  white-space: pre-wrap;
  text-align: left;
  display: none;
}

#loading-details.show { display: block; }

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--panel-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  border-radius: 0.375rem;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
  opacity: 0;
  transform: translateY(1rem);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 50;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  aside.lessons { border-right: none; border-bottom: 1px solid var(--border); max-height: 180px; }
  .output-panel { border-left: none; border-top: 1px solid var(--border); min-height: 200px; }
}
