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

html, body {
  height: 100vh;
  overflow: hidden;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
.app-header {
  background: linear-gradient(135deg, #16213e, #1a1a2e);
  border-bottom: 2px solid #007acc;
  padding: 8px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}

.progress-container {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.progress-bar {
  width: 200px;
  height: 8px;
  background: #2d2d30;
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #007acc, #00b4d8);
  border-radius: 4px;
  transition: width 0.4s ease;
  width: 0;
}

.progress-text {
  font-size: 0.8rem;
  color: #9ca3af;
  white-space: nowrap;
}

/* ── Main Layout ── */
.app-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Tutorial Panel (Left) ── */
.tutorial-panel {
  width: 380px;
  min-width: 320px;
  background: #16213e;
  border-right: 1px solid #2d2d30;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* Mode tabs (Lektioner / Udfordringer) */
.mode-tabs {
  display: flex;
  border-bottom: 1px solid #2d2d30;
  flex-shrink: 0;
}

.mode-tab {
  flex: 1;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: #777;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.mode-tab:hover {
  color: #bbb;
}

.mode-tab.active {
  color: #fff;
  border-bottom-color: #007acc;
}

.mode-badge {
  background: #3e3e42;
  color: #9ca3af;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 8px;
  font-weight: 500;
}

.mode-tab.active .mode-badge {
  background: #007acc;
  color: #fff;
}

.lesson-list {
  display: flex;
  gap: 4px;
  padding: 8px 16px;
  border-bottom: 1px solid #2d2d30;
  flex-wrap: wrap;
  max-height: 120px;
  overflow-y: auto;
  flex-shrink: 0;
}

.lesson-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  background: #1a1a2e;
  border: 1px solid #2d2d30;
  transition: all 0.2s;
}

.lesson-item:hover {
  border-color: #007acc;
}

.lesson-item.active {
  background: #007acc;
  border-color: #007acc;
  color: #fff;
}

.lesson-item.completed .lesson-num {
  color: #4ade80;
}

.lesson-num {
  font-weight: 700;
  font-size: 0.8rem;
  min-width: 16px;
  text-align: center;
}

.lesson-name {
  white-space: nowrap;
}

.lesson-header {
  padding: 16px 20px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.lesson-header h2 {
  font-size: 1.1rem;
  color: #fff;
  margin-bottom: 4px;
}

.lesson-header p {
  font-size: 0.85rem;
  color: #007acc;
  font-style: italic;
}

.narrative-area {
  padding: 16px 20px;
  flex: 1;
  font-size: 0.9rem;
  line-height: 1.65;
  color: #d1d5db;
  overflow-y: auto;
}

.narrative-area strong {
  color: #60a5fa;
}

.narrative-area code {
  background: rgba(0, 122, 204, 0.15);
  color: #7dd3fc;
  padding: 1px 5px;
  border-radius: 3px;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.85em;
}

.hint-area {
  padding: 10px 20px;
  background: rgba(250, 204, 21, 0.08);
  border-top: 1px solid rgba(250, 204, 21, 0.2);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.82rem;
  color: #fbbf24;
}

.hint-area.hidden {
  display: none;
}

.step-footer {
  padding: 12px 20px;
  border-top: 1px solid #2d2d30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
}

.step-action {
  font-size: 0.85rem;
  color: #9ca3af;
  font-style: italic;
}

.step-action.hidden {
  display: none;
}

.btn-next {
  padding: 8px 18px;
  background: #007acc;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.2s;
  white-space: nowrap;
}

.btn-next:hover {
  background: #005fa3;
}

.btn-next.hidden {
  display: none;
}

/* ── Simulator Panel (Right) ── */
.simulator-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #1e1e1e;
  min-width: 0;
}

/* ── Debug Toolbar ── */
.debug-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: #2d2d30;
  border-bottom: 1px solid #3e3e42;
  flex-shrink: 0;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  color: #ccc;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.toolbar-btn:hover:not(:disabled) {
  background: #3e3e42;
  border-color: #555;
}

.toolbar-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.toolbar-btn.start .tb-icon,
.toolbar-btn.continue .tb-icon {
  color: #4ade80;
}

.toolbar-btn.stop .tb-icon {
  color: #f87171;
}

.tb-icon {
  font-size: 0.9rem;
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: #555;
  margin: 0 4px;
}

/* ── Editor ── */
.editor-wrapper {
  flex: 1;
  min-height: 0;
  position: relative;
}

#editor-container {
  width: 100%;
  height: 100%;
}

/* Breakpoint hint glyph: hollow red ring */
.breakpoint-hint-glyph {
  border: 2px solid #e5140099;
  border-radius: 50%;
  width: 12px !important;
  height: 12px !important;
  margin-left: 4px;
  margin-top: 4px;
  display: inline-block;
  animation: pulse-ring 1.5s ease-in-out infinite;
}

@keyframes pulse-ring {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* Breakpoint glyph: red circle */
.breakpoint-glyph {
  background: #e51400;
  border-radius: 50%;
  width: 12px !important;
  height: 12px !important;
  margin-left: 4px;
  margin-top: 4px;
  display: inline-block;
}

/* Execution pointer: yellow arrow + highlighted line */
.execution-line {
  background: rgba(255, 255, 0, 0.12) !important;
}

.execution-glyph {
  width: 0 !important;
  height: 0 !important;
  border-left: 10px solid #ffcc00;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  margin-left: 2px;
  margin-top: 3px;
}

/* ── Bottom Panels ── */
.bottom-panels {
  height: 180px;
  min-height: 100px;
  border-top: 2px solid #007acc;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.panel-tabs {
  display: flex;
  background: #2d2d30;
  border-bottom: 1px solid #3e3e42;
  flex-shrink: 0;
}

.tab-btn {
  padding: 6px 16px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: #999;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn:hover {
  color: #ddd;
}

.tab-btn.active {
  color: #fff;
  border-bottom-color: #007acc;
}

.tab-panel {
  display: none;
  overflow: auto;
  flex: 1;
  padding: 8px 12px;
  font-size: 0.82rem;
  background: #1e1e1e;
}

.tab-panel.active {
  display: block;
}

/* Variable tables */
.var-table {
  width: 100%;
  border-collapse: collapse;
}

.var-table th {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 1px solid #3e3e42;
  color: #9ca3af;
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.var-table td {
  padding: 4px 8px;
  border-bottom: 1px solid rgba(62, 62, 66, 0.4);
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.82rem;
}

.var-table td:first-child {
  color: #9cdcfe;
}

.var-table td:nth-child(2) {
  color: #ce9178;
}

/* Watch panel */
.watch-input-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}

.watch-input-row input {
  flex: 1;
  padding: 4px 8px;
  background: #3c3c3c;
  border: 1px solid #555;
  border-radius: 3px;
  color: #eee;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.82rem;
}

.watch-input-row input:focus {
  outline: none;
  border-color: #007acc;
}

.watch-input-row button {
  padding: 4px 12px;
  background: #007acc;
  color: #fff;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  font-size: 0.78rem;
}

.watch-remove {
  background: transparent;
  border: none;
  color: #f87171;
  cursor: pointer;
  font-size: 1rem;
  padding: 0 4px;
}

/* Call Stack */
.callstack-list {
  list-style: none;
}

.callstack-list li {
  padding: 4px 8px;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.82rem;
  border-bottom: 1px solid rgba(62, 62, 66, 0.4);
  color: #ccc;
}

.callstack-list li.active {
  background: rgba(0, 122, 204, 0.15);
  color: #fff;
  font-weight: 600;
}

/* Output */
.output-content {
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  font-size: 0.82rem;
  color: #dcdcaa;
  white-space: pre-wrap;
  margin: 0;
}

/* ── Quiz Modal ── */
.quiz-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1000;
}

.quiz-overlay.hidden {
  display: none;
}

.quiz-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #1e1e2e;
  border: 1px solid #007acc;
  border-radius: 12px;
  padding: 28px 32px;
  max-width: 560px;
  width: 90%;
  z-index: 1001;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.quiz-modal.hidden {
  display: none;
}

.quiz-modal h3 {
  font-size: 1rem;
  color: #007acc;
  margin-bottom: 16px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 600;
}

.quiz-question {
  font-size: 1rem;
  color: #e0e0e0;
  margin-bottom: 16px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.quiz-options.hidden {
  display: none;
}

.quiz-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: #2d2d30;
  border: 1px solid #3e3e42;
  border-radius: 6px;
  color: #d1d5db;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
}

.quiz-option:hover:not(:disabled) {
  border-color: #007acc;
  background: #333;
}

.quiz-option:disabled {
  cursor: default;
}

.quiz-option.correct {
  border-color: #4ade80;
  background: rgba(74, 222, 128, 0.1);
  color: #4ade80;
}

.quiz-option.wrong {
  border-color: #f87171;
  background: rgba(248, 113, 113, 0.1);
  color: #f87171;
}

.quiz-ai-area {
  margin-bottom: 16px;
}

.quiz-ai-area.hidden {
  display: none;
}

.quiz-ai-area textarea {
  width: 100%;
  padding: 10px 12px;
  background: #2d2d30;
  border: 1px solid #3e3e42;
  border-radius: 6px;
  color: #e0e0e0;
  font-family: "Segoe UI", sans-serif;
  font-size: 0.9rem;
  resize: vertical;
  margin-bottom: 8px;
}

.quiz-ai-area textarea:focus {
  outline: none;
  border-color: #007acc;
}

.btn-primary {
  padding: 8px 18px;
  background: #007acc;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.btn-primary:hover {
  background: #005fa3;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: default;
}

.quiz-feedback {
  font-size: 0.88rem;
  line-height: 1.5;
  padding: 8px 0;
  min-height: 24px;
}

.quiz-feedback.correct {
  color: #4ade80;
}

.quiz-feedback.wrong {
  color: #fbbf24;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .app-main {
    flex-direction: column;
  }

  .tutorial-panel {
    width: 100%;
    min-width: 0;
    max-height: 35vh;
    border-right: none;
    border-bottom: 2px solid #007acc;
  }

  .simulator-panel {
    flex: 1;
    min-height: 0;
  }

  .app-header {
    flex-direction: column;
    gap: 6px;
    padding: 6px 16px;
  }

  .debug-toolbar {
    flex-wrap: wrap;
  }
}

/* ── Scrollbar styling ── */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: #1e1e1e;
}

::-webkit-scrollbar-thumb {
  background: #424242;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* ── Challenge Mode ── */
.challenge-item .lesson-num {
  font-size: 0.7rem;
  color: #fbbf24;
}

.challenge-item.completed .lesson-num {
  color: #4ade80;
}

.challenge-stars {
  font-size: 0.6rem;
  color: #fbbf24;
  margin-left: auto;
  letter-spacing: -1px;
}

.challenge-output-box {
  padding: 10px 20px;
  border-top: 1px solid #2d2d30;
  font-size: 0.82rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.challenge-output-box.hidden {
  display: none;
}

.co-row {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.co-label {
  font-weight: 600;
  white-space: nowrap;
  min-width: 72px;
}

.co-expected .co-label { color: #4ade80; }
.co-expected .co-value {
  color: #4ade80;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
}

.co-actual .co-label { color: #f87171; }
.co-actual .co-value {
  color: #f87171;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
}

.btn-report {
  padding: 8px 18px;
  background: #b45309;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.2s;
  white-space: nowrap;
}

.btn-report:hover:not(:disabled) {
  background: #92400e;
}

.btn-report:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-report.hidden {
  display: none;
}

/* Bug line decorations */
.bug-line-correct {
  background: rgba(74, 222, 128, 0.15) !important;
  border-left: 3px solid #4ade80;
}

.bug-line-wrong {
  background: rgba(248, 113, 113, 0.15) !important;
  border-left: 3px solid #f87171;
}

/* ── Utility ── */
.hidden {
  display: none !important;
}
