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

:root {
  --bg-primary: #1e1e2e;
  --bg-secondary: #181825;
  --bg-surface: #313244;
  --bg-hover: #45475a;
  --text-primary: #cdd6f4;
  --text-secondary: #a6adc8;
  --text-muted: #6c7086;
  --accent: #89b4fa;
  --accent-hover: #74c7ec;
  --green: #a6e3a1;
  --red: #f38ba8;
  --yellow: #f9e2af;
  --orange: #fab387;
  --border: #45475a;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --font-mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --header-height: 48px;
  --toolbar-height: 40px;
}

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

.hidden { display: none !important; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: var(--bg-primary);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); }
.btn-small {
  padding: 4px 10px;
  font-size: 12px;
  background: var(--bg-surface);
  color: var(--text-secondary);
}
.btn-small:hover:not(:disabled) { background: var(--bg-hover); }
.btn-run {
  background: var(--green);
  color: var(--bg-primary);
  font-weight: 600;
}
.btn-run:hover:not(:disabled) { background: #8cd895; }
.btn-submit {
  background: var(--accent);
  color: var(--bg-primary);
  font-weight: 600;
}
.btn-submit:hover:not(:disabled) { background: var(--accent-hover); }
.btn-hint {
  background: transparent;
  color: var(--yellow);
  border: 1px solid var(--yellow);
  font-size: 13px;
}
.btn-hint:hover { background: rgba(249,226,175,0.1); }
.btn-nav {
  background: var(--bg-surface);
  color: var(--text-primary);
  flex: 1;
}
.btn-nav:hover:not(:disabled) { background: var(--bg-hover); }

/* ===== Landing Page ===== */
.landing-page {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 60px 20px;
  min-height: 100vh;
}
.landing-container {
  max-width: 480px;
  width: 100%;
}
.landing-header {
  text-align: center;
  margin-bottom: 32px;
}
.landing-header h1 {
  font-size: 48px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -1px;
}
.tagline {
  color: var(--text-secondary);
  font-size: 18px;
  margin-top: 8px;
}

/* Auth Card */
.auth-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-bottom: 40px;
}
.auth-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  padding: 3px;
}
.auth-tab {
  flex: 1;
  padding: 8px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.auth-tab.active {
  background: var(--accent);
  color: var(--bg-primary);
  font-weight: 600;
}
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}
.form-group input {
  padding: 10px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-sans);
  outline: none;
  transition: border 0.15s;
}
.form-group input:focus { border-color: var(--accent); }
.form-error {
  color: var(--red);
  font-size: 13px;
  min-height: 0;
}
.form-error:not(:empty) { min-height: 20px; }

.auth-divider {
  text-align: center;
  margin: 20px 0;
  position: relative;
  color: var(--text-muted);
  font-size: 13px;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border);
}
.auth-divider::before { left: 0; }
.auth-divider::after { right: 0; }
.auth-card .btn-secondary { width: 100%; justify-content: center; }
.guest-note {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Features */
.features {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}
.feature {
  text-align: center;
  padding: 16px;
}
.feature-icon { font-size: 32px; margin-bottom: 8px; }
.feature h3 { font-size: 14px; margin-bottom: 4px; }
.feature p { font-size: 13px; color: var(--text-secondary); }

/* ===== App Layout ===== */
.app-page { overflow: hidden; height: 100vh; }

.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: var(--header-height);
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}
.app-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}
.progress-container {
  width: 160px;
  height: 6px;
  background: var(--bg-surface);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.3s ease;
  width: 0%;
}
.progress-text {
  font-size: 12px;
  color: var(--text-muted);
}
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.shortcut-hint {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-surface);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}
.user-display {
  font-size: 13px;
  color: var(--text-secondary);
}

/* Panels */
.app-panels {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Left Panel */
.panel-left {
  width: 300px;
  min-width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.panel-toggle {
  display: none;
  cursor: pointer;
  padding: 8px 12px;
  color: var(--text-secondary);
  font-size: 18px;
}

/* Module Navigation */
.module-nav {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
.module-nav h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
#module-list {
  list-style: none;
}
.module-item {
  margin-bottom: 4px;
}
.module-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}
.module-title:hover { background: var(--bg-surface); }
.module-title.active { color: var(--accent); }
.module-progress {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
}
.exercise-list {
  list-style: none;
  padding-left: 20px;
}
.exercise-list-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}
.exercise-list-item:hover { background: var(--bg-surface); }
.exercise-list-item.active {
  background: var(--bg-surface);
  color: var(--text-primary);
}
.exercise-list-item.completed .exercise-check { color: var(--green); }
.exercise-list-item.locked { opacity: 0.5; cursor: not-allowed; }
.exercise-check {
  font-size: 12px;
  width: 16px;
  text-align: center;
  color: var(--text-muted);
}

/* Exercise Info */
.exercise-info {
  padding: 16px;
  flex: 1;
  overflow-y: auto;
}
.exercise-header {
  margin-bottom: 12px;
}
.exercise-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  background: var(--accent);
  color: var(--bg-primary);
  border-radius: 10px;
  font-weight: 600;
  margin-bottom: 6px;
}
#exercise-title {
  font-size: 20px;
  font-weight: 600;
}
#exercise-description {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 16px;
}
#exercise-description code {
  background: var(--bg-surface);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--orange);
}
.exercise-instructions h3 {
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--text-secondary);
}
#exercise-instructions {
  padding-left: 20px;
  font-size: 14px;
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#exercise-instructions li { line-height: 1.5; }
#exercise-instructions code {
  background: var(--bg-surface);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--orange);
}

.exercise-actions { margin-top: 16px; }
.hint-box {
  margin-top: 10px;
  padding: 10px;
  background: rgba(249,226,175,0.08);
  border: 1px solid rgba(249,226,175,0.2);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--yellow);
  line-height: 1.5;
}

/* Exercise Navigation */
.exercise-nav {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

/* Center Panel: Editor */
.panel-center {
  flex: 1;
  min-width: 0;
}
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  height: var(--toolbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}
.editor-container {
  flex: 1;
  overflow: hidden;
}

/* Right Panel: Output */
.panel-right {
  width: 340px;
  min-width: 240px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
}
.output-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.output-header h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}
.output-container {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 13px;
}
#output {
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--text-primary);
}
.output-line { display: block; }
.output-stdout { color: var(--text-primary); }
.output-stderr { color: var(--red); }
.output-error { color: var(--red); font-weight: 500; }
.output-info { color: var(--text-muted); font-style: italic; }
.output-input { color: var(--yellow); }

/* Validation Result */
.validation-result {
  padding: 12px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.validation-result.success {
  background: rgba(166,227,161,0.1);
  border-top-color: var(--green);
  color: var(--green);
}
.validation-result.failure {
  background: rgba(243,139,168,0.1);
  border-top-color: var(--red);
  color: var(--red);
}
.validation-result .feedback-list {
  list-style: none;
  margin-top: 6px;
}
.validation-result .feedback-list li {
  padding: 2px 0;
}
.validation-result .feedback-list li::before {
  content: '  ';
}
.validation-result.success .feedback-list li::before {
  content: '\2713  ';
  color: var(--green);
}
.validation-result.failure .feedback-list li::before {
  content: '\2717  ';
  color: var(--red);
}
.show-solution-btn {
  display: inline-block;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.show-solution-btn:hover { background: var(--bg-surface); }

/* ===== Animations ===== */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes popIn {
  0% { opacity: 0; transform: scale(0.8); }
  50% { transform: scale(1.05); }
  100% { opacity: 1; transform: scale(1); }
}
@keyframes confetti-fall {
  0% { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(120px) rotate(720deg); opacity: 0; }
}
@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 0 0 rgba(166,227,161,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(166,227,161,0); }
}

.exercise-info { animation: slideIn 0.2s ease; }
.modal-content { animation: popIn 0.3s ease; }
.validation-result.success { animation: slideIn 0.2s ease; }
.validation-result.failure { animation: slideIn 0.2s ease; }

.btn-submit.success-pulse {
  animation: pulse-green 0.6s ease 2;
  background: var(--green);
}

/* Confetti particles */
.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 600;
  overflow: hidden;
}
.confetti {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  animation: confetti-fall 1.5s ease forwards;
}

/* Error line highlight in editor */
.error-line {
  background: rgba(243,139,168,0.15) !important;
}
.error-line-gutter {
  background: var(--red);
  width: 3px !important;
  margin-left: 3px;
}

/* ===== Loading Screen ===== */
.loading-screen {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: var(--bg-primary);
  z-index: 1000;
  transition: opacity 0.3s;
}
.loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}
.loading-content {
  text-align: center;
}
.loading-content h1 {
  font-size: 48px;
  color: var(--accent);
  margin-bottom: 24px;
}
.loading-bar-container {
  width: 300px;
  height: 4px;
  background: var(--bg-surface);
  border-radius: 2px;
  margin: 0 auto 16px;
  overflow: hidden;
}
.loading-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s ease;
}
#loading-status {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.loading-tip {
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: rgba(0,0,0,0.6);
  z-index: 500;
}
.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.success-icon {
  font-size: 64px;
  margin-bottom: 12px;
}
.success-content h2 {
  font-size: 24px;
  margin-bottom: 8px;
}
.success-content p {
  color: var(--text-secondary);
  margin-bottom: 20px;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .app-panels {
    flex-direction: column;
  }
  .panel-left {
    width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .panel-right {
    width: 100%;
    max-height: 30vh;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .panel-toggle { display: block; }
  .module-nav { display: none; }
  .module-nav.open { display: block; }
  .features { grid-template-columns: 1fr; }
  .shortcut-hint { display: none; }
  .progress-container { width: 100px; }
}

@media (max-width: 600px) {
  .landing-header h1 { font-size: 36px; }
  .tagline { font-size: 16px; }
  .auth-card { padding: 20px; }
}
