:root {
  color-scheme: light dark;
  font-family: "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  background-color: #f9fafc;
  color: #1f2933;
}

body {
  margin: 0;
  padding: 0;
}

.sim-topbar {
  position: sticky;
  top: 0;
  z-index: 4200;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  box-shadow: 0 10px 22px -18px rgba(2, 6, 23, 0.55);
}

.sim-topbar-left,
.sim-topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sim-home,
.sim-admin {
  color: #fff;
  text-decoration: none;
  font-weight: 800;
  padding: 0.55rem 0.9rem;
  border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.sim-home:hover,
.sim-admin:hover,
.sim-home:focus,
.sim-admin:focus {
  background: rgba(255, 255, 255, 0.24);
}

.sim-title {
  font-weight: 900;
  opacity: 0.95;
  padding-left: 0.85rem;
  border-left: 2px solid rgba(255, 255, 255, 0.25);
}

.sim-eval {
  border: 1px solid rgba(255, 200, 0, 0.6);
  background: rgba(255, 200, 0, 0.22);
  color: #fff;
  font-weight: 900;
  border-radius: 0.75rem;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
}

.sim-eval:hover,
.sim-eval:focus {
  background: rgba(255, 200, 0, 0.35);
}

.sim-eval.done {
  border-color: rgba(0, 200, 80, 0.7);
  background: rgba(0, 200, 80, 0.25);
}

.sim-eval-overlay[hidden] { display: none; }
.sim-eval-overlay {
  position: fixed;
  inset: 0;
  z-index: 6500;
}

.sim-eval-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.sim-eval-panel {
  position: relative;
  width: 420px;
  max-width: calc(100vw - 2rem);
  margin: 10vh auto;
  border-radius: 1rem;
  background: #fff;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  overflow: hidden;
  max-height: calc(100dvh - 2rem);
  display: flex;
  flex-direction: column;
}

.sim-eval-head {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  padding: 1.1rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sim-eval-head h3 { margin: 0; font-size: 1.1rem; }

.sim-eval-close {
  background: rgba(255, 255, 255, 0.2);
  border: 0;
  color: #fff;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.sim-eval-close:hover,
.sim-eval-close:focus {
  background: rgba(255, 255, 255, 0.35);
}

.sim-eval-body {
  padding: 1.25rem;
  overflow: auto;
}

.sim-eval-field { margin-bottom: 1.1rem; }

.sim-eval-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 800;
  color: #1e293b;
  margin-bottom: 0.5rem;
}

.sim-eval-stars {
  display: flex;
  gap: 0.25rem;
  direction: rtl;
  justify-content: flex-end;
}

.sim-eval-stars input { display: none; }

.sim-eval-stars label {
  font-size: 1.9rem;
  color: #d1d5db;
  cursor: pointer;
  transition: color 0.15s;
  line-height: 1;
}

.sim-eval-stars label:hover,
.sim-eval-stars label:hover ~ label,
.sim-eval-stars input:checked ~ label {
  color: #f59e0b;
}

.sim-eval-comment {
  width: 100%;
  min-height: 80px;
  padding: 0.75rem;
  border: 2px solid #e2e8f0;
  border-radius: 0.5rem;
  font-size: 0.95rem;
  font-family: inherit;
  resize: vertical;
  box-sizing: border-box;
}

.sim-eval-comment:focus { outline: none; border-color: #667eea; }

.sim-eval-send {
  width: 100%;
  padding: 0.85rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border: none;
  border-radius: 0.6rem;
  font-size: 1rem;
  font-weight: 900;
  cursor: pointer;
}

.sim-eval-send:hover { box-shadow: 0 4px 15px rgba(102,126,234,0.4); }
.sim-eval-send:disabled { opacity: 0.6; cursor: not-allowed; }

.sim-eval-error {
  background: #fef2f2;
  color: #991b1b;
  padding: 0.75rem;
  border-radius: 0.75rem;
  font-size: 0.9rem;
  margin-bottom: 0.9rem;
}

.sim-eval-ok { text-align: center; padding: 1.4rem 0.5rem 0.75rem; }
.sim-eval-check { font-size: 3rem; margin-bottom: 0.5rem; }

header {
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #fff;
  padding: 3rem 1.5rem 2rem;
  text-align: center;
}

header h1 {
  margin-bottom: 1rem;
  font-size: clamp(2rem, 4vw, 3rem);
}

header p {
  max-width: 900px;
  margin: 0 auto 1rem;
}

.instructions {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 1rem;
  padding: 1.5rem;
  margin: 0 auto;
  max-width: 900px;
  text-align: left;
}

.instructions ol {
  padding-left: 1.5rem;
}

.instructions .disclaimer {
  margin-top: 1rem;
  font-size: 0.95rem;
}

main {
  padding: 2rem 1rem 4rem;
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  max-width: 1200px;
  margin: 0 auto;
}

.task {
  background: #fff;
  border-radius: 1rem;
  box-shadow: 0 20px 30px -20px rgba(15, 23, 42, 0.4);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: width 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
  position: relative;
}

.task.is-expanded {
  grid-column: 1 / -1;
  width: min(100%, 70rem);
  min-width: min(100%, 30vw);
  justify-self: center;
  box-shadow: 0 26px 46px -24px rgba(37, 99, 235, 0.55);
  transform: translateY(-2px);
}

.task h3 {
  margin: 0;
  color: #1e3a8a;
}

.task details {
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  padding: 0.5rem 1rem;
  background: #f8fafc;
}

.task details[open] {
  background: #eef2ff;
}

.task pre {
  white-space: pre-wrap;
  font-family: "Fira Code", "Courier New", monospace;
  margin: 0.5rem 0 0;
}

.task label {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-weight: 600;
}

.task .field {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.task .field-label {
  font-weight: 600;
}

.task select {
  border-radius: 0.75rem;
  border: 1px solid #cbd5f5;
  padding: 0.75rem;
  font-size: 1rem;
  font-family: inherit;
}

.solution-viewer {
  border-radius: 0.75rem;
  font-family: "Fira Code", "Courier New", monospace;
  background: #0b1220;
  color: #e5e7eb;
  border: 1px solid #cbd5f5;
  padding: 0.9rem;
  font-size: 0.95rem;
  line-height: 1.45;
  min-height: 9.5rem;
  white-space: pre;
  overflow: auto;
}

.solution-viewer.is-empty {
  background: #f8fafc;
  color: #475569;
  font-family: inherit;
  white-space: normal;
}

.monaco-error {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  border-radius: 0.75rem;
  padding: 1rem;
  color: #b91c1c;
  margin-bottom: 1rem;
}

.solution-viewer[role="button"] {
  cursor: pointer;
}

.solution-viewer[role="button"]:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.6);
  outline-offset: 2px;
}

.task-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 0.6rem;
  background: #ef4444;
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 12px -6px rgba(239, 68, 68, 0.65);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.task-close:hover,
.task-close:focus {
  background: #dc2626;
  box-shadow: 0 8px 16px -8px rgba(220, 38, 38, 0.7);
  transform: translateY(-1px);
  outline: none;
}

.task-close:focus-visible {
  box-shadow: 0 0 0 3px rgba(252, 165, 165, 0.55);
}

.task-close[hidden] {
  display: none;
}

.modal[hidden] { display: none; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 5000;
  overflow-y: auto;
  padding: 1rem 0;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.6);
  backdrop-filter: blur(6px);
}

.modal-panel {
  position: relative;
  width: min(980px, calc(100vw - 2rem));
  margin: 0 auto;
  border-radius: 1.25rem;
  background: #ffffff;
  box-shadow: 0 40px 80px -50px rgba(2, 6, 23, 0.9);
  overflow: hidden;
  max-height: calc(100dvh - 2rem);
  display: flex;
  flex-direction: column;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1.2rem 1.25rem;
  background: linear-gradient(135deg, #0f172a, #1e3a8a);
  color: #fff;
}

.modal-head-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.icon-btn {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.85rem;
  border: 0;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn svg {
  width: 1.35rem;
  height: 1.35rem;
  fill: currentColor;
}

.icon-btn:hover,
.icon-btn:focus {
  background: rgba(255, 255, 255, 0.26);
}

.icon-btn[aria-pressed="true"] {
  background: rgba(255, 255, 255, 0.34);
}

.icon-btn:focus-visible {
  outline: 3px solid rgba(252, 165, 165, 0.55);
  outline-offset: 2px;
}

.modal-kicker {
  font-size: 0.85rem;
  opacity: 0.9;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 800;
}

.modal-close {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.85rem;
  border: 0;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
}

.modal-close:hover,
.modal-close:focus {
  background: rgba(255, 255, 255, 0.26);
}

.modal-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  overflow: auto;
  min-height: 0;
}

.modal-info {
  display: grid;
  gap: 0.75rem;
}

.info-panel {
  border-radius: 0.9rem;
  border: 1px solid #cbd5f5;
  background: #f8fafc;
  overflow: hidden;
}

.info-head {
  padding: 0.75rem 0.9rem;
  font-weight: 900;
  background: #eef2ff;
  color: #0f172a;
}

.info-text {
  padding: 0.9rem;
  color: #0f172a;
}

.info-code {
  margin: 0;
  padding: 0.9rem;
  background: #0b1220;
  color: #e5e7eb;
  white-space: pre-wrap;
  font-family: "Fira Code", "Courier New", monospace;
  line-height: 1.45;
}

.modal-row {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
}

.modal-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-weight: 700;
}

.modal-field select {
  border-radius: 0.75rem;
  border: 1px solid #cbd5f5;
  padding: 0.7rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.btn-primary,
.btn-secondary {
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1.15rem;
  font-size: 1rem;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.2s ease, background 0.2s ease;
}

.btn-secondary {
  background: #e2e8f0;
  color: #0f172a;
}

.btn-secondary:hover,
.btn-secondary:focus {
  background: #cbd5e1;
  transform: translateY(-1px);
}

.btn-primary {
  background: #2563eb;
  color: #fff;
}

.btn-primary:hover,
.btn-primary:focus {
  background: #1e3a8a;
  transform: translateY(-1px);
}

.modal-editor {
  border-radius: 0.9rem;
  border: 1px solid #cbd5f5;
  background: #0b1220;
  height: clamp(220px, 52dvh, 560px);
  overflow: hidden;
}

.modal-editor textarea.solution-textarea {
  width: 100%;
  height: 100%;
  border: 0;
  resize: none;
  padding: 0.9rem;
  box-sizing: border-box;
  font-family: "Fira Code", "Courier New", monospace;
  font-size: 1rem;
  line-height: 1.45;
  background: #0b1220;
  color: #e5e7eb;
}

.modal-editor textarea.solution-textarea:focus {
  outline: none;
}

.feedback {
  min-height: 2.5rem;
  border-radius: 0.75rem;
  padding: 0.75rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  font-size: 0.95rem;
  white-space: pre-wrap;
  line-height: 1.5;
  max-height: none;
  overflow: auto;
  transition: max-height 0.2s ease;
  position: relative;
}

.feedback.loading {
  background: #dbeafe;
  border-color: #60a5fa;
  color: #1d4ed8;
}

.task:not(.is-expanded) .feedback {
  max-height: calc(1.5em * 3 + 1.5rem);
  overflow: hidden;
  cursor: pointer;
}

.task.is-expanded .feedback {
  cursor: default;
}

.task:not(.is-expanded) .feedback::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1.5rem;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(248, 250, 252, 0) 0%, #f8fafc 100%);
}

.task:not(.is-expanded) .feedback.loading::after {
  background: linear-gradient(180deg, rgba(219, 234, 254, 0) 0%, #dbeafe 100%);
}

.feedback:focus-visible {
  outline: 3px solid rgba(59, 130, 246, 0.6);
  outline-offset: 2px;
}

@media (prefers-color-scheme: dark) {
  :root {
    background-color: #0f172a;
    color: #e2e8f0;
  }

  header {
    background: linear-gradient(135deg, #0f172a, #1e3a8a);
  }

  .task {
    background: #111827;
    box-shadow: 0 20px 30px -20px rgba(15, 23, 42, 0.9);
  }

  .task.is-expanded {
    box-shadow: 0 28px 52px -26px rgba(59, 130, 246, 0.6);
  }

  .task details {
    background: #1f2937;
    border-color: #374151;
  }

  .task details[open] {
    background: #1f2a44;
  }

  .task select {
    background: #0f172a;
    border-color: #1e3a8a;
    color: #e2e8f0;
  }

  .task-close {
    background: #f87171;
    color: #0f172a;
    box-shadow: 0 10px 18px -12px rgba(248, 113, 113, 0.7);
  }

  .task-close:hover,
  .task-close:focus {
    background: #ef4444;
    color: #fff;
    box-shadow: 0 12px 22px -12px rgba(239, 68, 68, 0.75);
  }

  .solution-viewer { border-color: #1e3a8a; }
  .modal-panel { background: #111827; }
  .modal-body { color: #e2e8f0; }
  .info-panel { background: #111c2f; border-color: #1e3a8a; }
  .info-head { background: rgba(30, 58, 138, 0.35); color: #e2e8f0; }
  .info-text { color: #e2e8f0; }
  .btn-secondary { background: #243041; color: #e2e8f0; }
  .btn-secondary:hover,
  .btn-secondary:focus { background: #2e3a4b; }
  .modal-field select { background: #0f172a; border-color: #1e3a8a; color: #e2e8f0; }
  .sim-eval-panel { background: #111827; }
  .sim-eval-label { color: #e2e8f0; }
  .sim-eval-comment { background: #0f172a; border-color: #1e3a8a; color: #e2e8f0; }
  .sim-eval-error { background: rgba(239, 68, 68, 0.15); color: #fecaca; }

  .monaco-error {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(252, 165, 165, 0.4);
    color: #fecaca;
  }

  .feedback {
    background: #111c2f;
    border-color: #1e3a8a;
  }

  .task:not(.is-expanded) .feedback::after {
    background: linear-gradient(180deg, rgba(17, 28, 47, 0) 0%, #111c2f 100%);
  }

  .task:not(.is-expanded) .feedback.loading::after {
    background: linear-gradient(180deg, rgba(30, 58, 138, 0) 0%, rgba(30, 58, 138, 0.8) 100%);
  }
}

/* ===== Programmering Trin-for-Trin Theme Override ===== */
:root {
  color-scheme: light;
  --bg: #f8f1e6;
  --bg-2: #f2e7d4;
  --ink: #1f1c17;
  --ink-2: #3d352b;
  --accent: #d76c2a;
  --accent-2: #1d6c8f;
  --card: #fff8ef;
  --card-2: #fef4e2;
  --line: rgba(31, 28, 23, 0.16);
  --shadow: rgba(28, 20, 12, 0.18);
  --mono: "Fira Code", "Consolas", "Courier New", monospace;
  --serif: "Palatino", "Book Antiqua", "Times New Roman", serif;
  --sans: "Trebuchet MS", "Verdana", "Geneva", sans-serif;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: radial-gradient(circle at top, var(--bg), var(--bg-2));
}

.sim-topbar {
  background: linear-gradient(135deg, #2a6d8f 0%, #1d6c8f 45%, #d76c2a 100%);
  box-shadow: 0 12px 26px -16px var(--shadow);
}

.sim-home,
.sim-admin {
  background: rgba(255, 248, 239, 0.2);
  border: 1px solid rgba(255, 248, 239, 0.4);
}

.sim-eval {
  border: 1px solid rgba(255, 248, 239, 0.5);
  background: rgba(215, 108, 42, 0.45);
}

.sim-eval.done {
  border-color: rgba(80, 170, 115, 0.8);
  background: rgba(80, 170, 115, 0.45);
}

.sim-eval-panel {
  background: linear-gradient(140deg, var(--card), var(--card-2));
  box-shadow: 0 24px 60px -34px var(--shadow);
}

.sim-eval-head {
  background: linear-gradient(135deg, #1d6c8f, #d76c2a);
}

.sim-eval-label {
  color: var(--ink);
}

.sim-eval-comment {
  border-color: var(--line);
  background: #fffdf7;
  color: var(--ink);
}

.sim-eval-comment:focus {
  border-color: rgba(29, 108, 143, 0.45);
}

.sim-eval-send {
  background: linear-gradient(135deg, #1d6c8f, #d76c2a);
}

header {
  background: linear-gradient(145deg, #efe2cd, #f8f1e6);
  color: var(--ink);
}

header h1 {
  font-family: var(--serif);
  color: var(--ink);
}

header p {
  color: var(--ink-2);
}

.instructions {
  background: rgba(255, 248, 239, 0.85);
  border: 1px solid var(--line);
  color: var(--ink-2);
}

.instructions h2 {
  font-family: var(--serif);
  color: var(--ink);
}

main {
  max-width: 1200px;
  gap: 1.7rem;
}

.task {
  background: linear-gradient(140deg, var(--card), var(--card-2));
  border: 1px solid var(--line);
  box-shadow: 0 18px 36px -28px var(--shadow);
}

.task.is-expanded {
  box-shadow: 0 24px 42px -28px rgba(29, 108, 143, 0.4);
}

.task h3 {
  color: var(--ink);
  font-family: var(--serif);
}

.task details {
  background: rgba(255, 255, 255, 0.55);
  border-color: var(--line);
}

.task details[open] {
  background: rgba(238, 246, 249, 0.85);
}

.task select,
.modal-field select {
  border-color: var(--line);
  background: #fffdf9;
  color: var(--ink);
}

.solution-viewer {
  background: #10100f;
  color: #f9f4e7;
  border-color: rgba(249, 244, 231, 0.24);
}

.solution-viewer.is-empty {
  background: rgba(255, 255, 255, 0.6);
  color: var(--ink-2);
}

.task-close {
  background: #c84f3e;
}

.modal-backdrop {
  background: rgba(42, 34, 23, 0.56);
}

.modal-panel {
  background: linear-gradient(140deg, var(--card), var(--card-2));
  box-shadow: 0 34px 70px -42px var(--shadow);
}

.modal-head {
  background: linear-gradient(135deg, #1d6c8f, #d76c2a);
}

.info-panel,
.modal-editor,
.feedback {
  border-color: var(--line);
}

.info-panel,
.feedback {
  background: #fffdf7;
}

#modalFeedback {
  background: #fff8ec;
  color: var(--ink);
  border-color: rgba(31, 28, 23, 0.22);
  font-size: 1rem;
  line-height: 1.65;
  letter-spacing: 0.1px;
  padding: 0.9rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.info-head {
  background: rgba(29, 108, 143, 0.14);
  color: var(--ink);
}

.info-text {
  color: var(--ink-2);
}

.info-code,
.modal-editor,
.modal-editor textarea.solution-textarea {
  background: #10100f;
  color: #f9f4e7;
  font-family: var(--mono);
}

.btn-secondary {
  background: #f3e7d5;
  color: var(--ink-2);
}

.btn-secondary:hover,
.btn-secondary:focus {
  background: #ead7bd;
}

.btn-primary {
  background: #1d6c8f;
}

.btn-primary:hover,
.btn-primary:focus {
  background: #175876;
}

.feedback.loading {
  background: rgba(29, 108, 143, 0.14);
  border-color: rgba(29, 108, 143, 0.45);
  color: #12485f;
}

.task:not(.is-expanded) .feedback::after {
  background: linear-gradient(180deg, rgba(255, 253, 247, 0) 0%, #fffdf7 100%);
}

.task:not(.is-expanded) .feedback.loading::after {
  background: linear-gradient(180deg, rgba(236, 247, 251, 0) 0%, #ecf7fb 100%);
}

.main-footer {
  text-align: center;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  color: var(--ink-2);
  border-top: 1px solid var(--line);
  background: rgba(255, 248, 239, 0.72);
}
