:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --border: #475569;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --green: #34d399;
  --yellow: #fbbf24;
  --red: #f87171;
  --cyan: #22d3ee;
}

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

body {
  font-family: 'Segoe UI', 'Noto Sans KR', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

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

/* ── Login Page ── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 48px 40px;
  text-align: center;
  max-width: 420px;
  width: 90%;
}

.login-card h1 {
  font-size: 28px;
  margin-bottom: 8px;
  color: var(--primary-hover);
}

.login-card .subtitle {
  color: var(--text-dim);
  margin-bottom: 32px;
  font-size: 14px;
}

.google-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: #fff;
  color: #333;
  padding: 12px 32px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: box-shadow 0.2s;
  text-decoration: none;
}

.google-btn:hover {
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
  text-decoration: none;
}

.google-btn img {
  width: 20px;
  height: 20px;
}

.login-note {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-dim);
}

.error-msg {
  background: rgba(248, 113, 113, 0.15);
  color: var(--red);
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 14px;
}

/* ── Top Nav ── */
.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topnav-brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary-hover);
}

.topnav-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
}

.topnav-user img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
}

.topnav-user .role-badge {
  background: var(--primary);
  color: #fff;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.btn-logout {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.btn-logout:hover { color: var(--text); border-color: var(--text-dim); }

/* ── Dashboard ── */
.dashboard {
  max-width: 1000px;
  margin: 0 auto;
  padding: 32px 24px;
}

.dashboard h2 {
  font-size: 22px;
  margin-bottom: 20px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.1s;
}

.card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.card h3 {
  font-size: 17px;
  margin-bottom: 6px;
}

.card .meta {
  font-size: 13px;
  color: var(--text-dim);
}

.card .code-badge {
  display: inline-block;
  background: var(--surface2);
  padding: 2px 8px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 12px;
  color: var(--yellow);
  margin-top: 8px;
}

.card-add {
  border: 2px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  color: var(--text-dim);
  font-size: 15px;
}

.card-add:hover {
  border-color: var(--primary);
  color: var(--primary-hover);
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 90%;
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal h3 {
  margin-bottom: 16px;
  font-size: 18px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 4px;
  font-weight: 600;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

.form-group textarea {
  min-height: 100px;
  resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  padding: 10px 24px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

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

.btn-secondary {
  background: transparent;
  color: var(--text-dim);
  padding: 10px 24px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

.btn-secondary:hover { color: var(--text); border-color: var(--text-dim); }

.btn-danger {
  background: var(--red);
  color: #fff;
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

.btn-row { display: flex; gap: 10px; margin-top: 16px; }

/* ── Classroom Detail ── */
.classroom-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.classroom-page h2 {
  font-size: 22px;
  margin-bottom: 4px;
}

.classroom-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

/* ── Classroom Tabs ── */
.classroom-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
}

.classroom-tabs .tab-btn {
  padding: 10px 24px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  color: var(--text-dim);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

.classroom-tabs .tab-btn:hover {
  color: var(--text);
}

.classroom-tabs .tab-btn.active {
  color: var(--primary-hover);
  border-bottom-color: var(--primary-hover);
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-size: 12px;
}

.student-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
}

.student-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
}

.student-chip img {
  width: 20px;
  height: 20px;
  border-radius: 50%;
}

.student-chip .remove-btn {
  background: none;
  border: none;
  color: var(--red);
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
}

.lesson-list {
  list-style: none;
}

.lesson-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.lesson-item:hover { border-color: var(--primary); }

.lesson-item.dragging {
  opacity: 0.4;
  border-color: var(--primary);
  border-style: dashed;
}

.lesson-item .drag-handle {
  cursor: grab;
  color: var(--text-dim);
  font-size: 16px;
  margin-right: 8px;
  padding: 2px 4px;
  user-select: none;
  flex-shrink: 0;
}

.lesson-item .drag-handle:hover {
  color: var(--text);
}

.lesson-item .drag-handle:active {
  cursor: grabbing;
}

.lesson-item .lesson-num {
  color: var(--primary-hover);
  font-weight: 700;
  margin-right: 12px;
  min-width: 28px;
}

.lesson-item .lesson-title {
  flex: 1;
}

.lesson-item .lesson-actions {
  display: flex;
  gap: 8px;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}

.btn-sm:hover { color: var(--text); border-color: var(--text-dim); }

/* ── Role Selection ── */
.role-select {
  display: flex;
  gap: 20px;
  justify-content: center;
  margin-top: 24px;
}

.role-card {
  background: var(--surface2);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 24px 32px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
  width: 160px;
}

.role-card:hover { border-color: var(--primary); }
.role-card .role-icon { font-size: 36px; margin-bottom: 8px; }
.role-card .role-name { font-weight: 600; }

/* ── Learn Page (IDE) ── */
.learn-container {
  display: flex;
  height: calc(100vh - 49px);
  overflow: hidden;
}

.lesson-panel {
  width: 45%;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  border-right: 3px solid var(--border);
  overflow: hidden;
}

.lesson-panel .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
}

.lesson-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--bg);
  font-size: 15px;
  line-height: 1.8;
}

.lesson-content h1, .lesson-content h2, .lesson-content h3 {
  color: var(--primary-hover);
  margin: 16px 0 8px;
}

.lesson-content code {
  background: var(--surface2);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Consolas', 'D2Coding', monospace;
  font-size: 14px;
}

.lesson-content pre {
  background: var(--surface);
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 12px 0;
}

.lesson-content pre code {
  background: none;
  padding: 0;
}

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

.ide-editor {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-bottom: 3px solid var(--border);
}

.ide-editor .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  flex-shrink: 0;
}

.ide-editor #editor-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.ide-output {
  height: 35%;
  min-height: 100px;
  display: flex;
  flex-direction: column;
}

.ide-output .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  flex-shrink: 0;
}

.ide-output #output {
  flex: 1;
  background: #0d1117;
  padding: 12px;
  font-family: 'Consolas', 'D2Coding', monospace;
  font-size: 14px;
  line-height: 1.6;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text);
}

.ide-output #output .out-line { color: var(--text); }
.ide-output #output .err-line { color: var(--red); }
.ide-output #output .info-line { color: var(--cyan); font-style: italic; }
.ide-output #output .input-prompt-text { color: var(--yellow); }
.ide-output #output .input-echo {
  color: var(--green);
  border: 1px solid var(--green);
  border-radius: 4px;
  padding: 0 6px;
  margin-left: 2px;
}

.ide-output .input-row {
  display: flex;
  align-items: baseline;
  line-height: 1.6;
}

.ide-output .input-row .prompt-label {
  color: var(--yellow);
  white-space: pre;
  font-size: 14px;
}

.ide-output .input-row input {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--primary);
  outline: none;
  color: var(--green);
  font-family: 'Consolas', 'D2Coding', monospace;
  font-size: 14px;
  padding: 0 4px;
  caret-color: var(--green);
}

.toolbar-btns {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-run-ide {
  background: var(--primary);
  color: #fff;
  padding: 4px 14px;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-run-ide:hover { background: var(--primary-hover); }
.btn-run-ide:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-stop-ide {
  background: var(--red);
  color: #fff;
  padding: 4px 14px;
  border: none;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: none;
}

.btn-icon {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.btn-icon:hover { color: var(--text); border-color: var(--text-dim); }

.save-status {
  font-size: 11px;
  color: var(--text-dim);
}

.save-status.saved { color: var(--green); }

/* Lesson navigation */
.lesson-nav {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.lesson-nav button {
  flex: 1;
  padding: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}

.lesson-nav button:hover { border-color: var(--primary); }
.lesson-nav button:disabled { opacity: 0.3; cursor: not-allowed; }

/* Responsive */
@media (max-width: 768px) {
  .learn-container { flex-direction: column; }
  .lesson-panel { width: 100%; height: 40%; border-right: none; border-bottom: 3px solid var(--border); min-width: 0; }
  .ide-panel { height: 60%; }
}

/* ── Editor HTML (for teacher) ── */
.html-editor-wrap {
  width: 100%;
  min-height: 300px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.html-editor-wrap textarea {
  width: 100%;
  min-height: 300px;
  padding: 12px;
  background: var(--bg);
  color: var(--text);
  border: none;
  font-family: 'Consolas', 'D2Coding', monospace;
  font-size: 14px;
  resize: vertical;
}

.html-editor-wrap textarea:focus {
  outline: none;
}

.preview-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 8px;
}

.preview-toggle button {
  padding: 6px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
}

.preview-toggle button:first-child { border-radius: 6px 0 0 6px; }
.preview-toggle button:last-child { border-radius: 0 6px 6px 0; }
.preview-toggle button.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.html-preview {
  min-height: 200px;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  line-height: 1.7;
}
