:root {
  --bg: #ffffff;
  --text: #1a1a2e;
  --border: #e0e0e0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --code-bg: #f5f5f5;
  --output-bg: #1e1e1e;
  --output-text: #d4d4d4;
  --error-text: #ef4444;
  --font-mono: 'Fira Code', 'Consolas', 'Monaco', monospace;
  --font-body: system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}

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

header h1 { font-size: 1.25rem; }

#pyodide-status {
  font-size: 0.85rem;
  color: #888;
}

/* ===== Main layout: single column ===== */
#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* ===== Course content ===== */
.course-section {
  width: 100%;
}

.course-content h1 { font-size: 1.5rem; margin: 1rem 0 0.5rem; }
.course-content h2 { font-size: 1.25rem; margin: 1.5rem 0 0.5rem; }
.course-content h3 { font-size: 1.1rem; margin: 0.75rem 0 0.5rem; }
.course-content p { margin: 0.5rem 0; }
.course-content img { max-width: 300px; border-radius: 4px; margin: 0.5rem 0; }

.course-content code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.course-content > pre code,
.code-pair-static pre code {
  display: block;
}

/* ===== Side-by-side code example + editor ===== */
.code-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 0.75rem 0;
  align-items: start;
}

@media (max-width: 800px) {
  .code-pair {
    grid-template-columns: 1fr;
  }
}

/* Static code (left) */
.code-pair-static pre {
  background: var(--code-bg);
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0;
  height: 100%;
}

/* Editor side (right) */
.code-pair-editor {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.inline-editor-container {
  min-height: 120px;
}

.inline-editor-container .cm-editor {
  height: 100%;
}

.code-pair-editor .btn-sm {
  border-radius: 0;
  padding: 0.35rem 1rem;
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
}

.inline-output {
  min-height: 40px;
  border-top: 1px solid var(--border);
}

/* ===== Innleveringsoppgave section ===== */
.innlevering-section {
  border: 2px solid var(--accent);
  border-radius: 8px;
  overflow: hidden;
}

.section-header {
  padding: 0.6rem 1rem;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 1rem;
}

.innlevering-editor-container {
  min-height: 180px;
}

.innlevering-editor-container .cm-editor {
  height: 100%;
}

/* ===== Buttons ===== */
.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-danger {
  background: var(--error-text);
  color: white;
}

.btn-danger:hover { background: #dc2626; }

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-check {
  background: #16a34a;
  color: white;
}

.btn-check:hover {
  background: #15803d;
}

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--code-bg);
  border-top: 1px solid var(--border);
}

/* ===== Output area ===== */
.output-area {
  background: var(--output-bg);
  color: var(--output-text);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  padding: 0.75rem;
  min-height: 60px;
  white-space: pre-wrap;
}

.output-area .error { color: var(--error-text); }

/* ===== Grading Result Styles ===== */

.grading-result {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.grading-summary {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.grading-categories {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.star-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.star-label {
  font-size: 0.85rem;
  font-weight: 500;
  min-width: 80px;
}

.stars {
  font-size: 1.1rem;
  color: #eab308;
  letter-spacing: 2px;
}

.grading-totalscore {
  font-size: 0.85rem;
  color: #666;
  margin-top: 0.25rem;
}

.grading-oppsummering {
  font-size: 0.9rem;
  margin-top: 0.5rem;
  font-style: italic;
}

/* Expandable detail sections */
.grading-details {
  margin-top: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.grading-details summary {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  background: var(--code-bg);
  font-size: 0.9rem;
  font-weight: 500;
}

.grading-details[open] summary {
  border-bottom: 1px solid var(--border);
}

.grading-details p,
.grading-improvement {
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
}

.grading-improvement pre {
  background: var(--code-bg);
  padding: 0.5rem;
  border-radius: 4px;
  margin-top: 0.25rem;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  overflow-x: auto;
  white-space: pre-wrap;
}

/* Loading spinner */
.grading-loading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  color: #666;
  font-size: 0.9rem;
}

.grading-loading::before {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Error state */
.grading-error {
  padding: 0.75rem;
  color: var(--error-text);
  font-size: 0.9rem;
}
