:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --danger: #dc2626;
  --shadow: 0 18px 50px rgba(17, 24, 39, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: white;
  padding: 10px 14px;
  font-weight: 750;
  cursor: pointer;
}

button:hover {
  transform: translateY(-1px);
}

button.ghost {
  background: #eef2ff;
  color: #1d4ed8;
}

button.danger {
  background: #fee2e2;
  color: var(--danger);
}

.shell {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, .84);
  backdrop-filter: blur(16px);
  overflow-y: auto;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 12px;
  background: var(--ink);
  color: white;
  font-weight: 900;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.course-item span,
.hint,
.mini-label {
  color: var(--muted);
}

.mini-label {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.course-list {
  display: grid;
  gap: 10px;
}

.course-item {
  position: relative;
  width: 100%;
  text-align: left;
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 14px;
  overflow: hidden;
}

.course-item::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--accent);
}

.course-item.active {
  border-color: var(--accent);
  box-shadow: 0 12px 24px rgba(37, 99, 235, .12);
}

.course-item strong,
.course-item span {
  display: block;
  padding-left: 6px;
}

.sidebar-card {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f9fafb;
}

.sidebar-card p:last-child {
  margin: 0;
}

.admin-open,
.mobile-menu {
  width: 100%;
  margin-top: 14px;
}

.mobile-menu {
  display: none;
}

.workspace {
  padding: 22px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(26px, 3vw, 42px);
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 18px;
}

.top-actions {
  display: flex;
  gap: 10px;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  color: var(--ink);
  padding: 11px 12px;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

.lesson-pane,
.editor-panel,
.preview-panel,
.ai-panel,
.admin-dialog section,
.admin-login {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.lesson-pane {
  padding: 16px;
}

.lesson-hero {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
  border-radius: 12px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 14%, white), white 62%);
  border: 1px solid color-mix(in srgb, var(--accent) 20%, var(--line));
}

.lesson-hero p {
  max-width: 860px;
}

.lesson-hero span {
  align-self: start;
  border-radius: 999px;
  background: white;
  padding: 8px 12px;
  color: var(--accent);
  font-weight: 800;
  white-space: nowrap;
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.content-block {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  background: #fff;
}

.content-block.note {
  background: #fffbeb;
}

.lesson-media {
  display: block;
  max-width: 100%;
  max-height: 440px;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.pdf-link {
  display: inline-flex;
  margin-top: 8px;
  border-radius: 10px;
  background: #eef2ff;
  color: #1d4ed8;
  padding: 10px 12px;
  text-decoration: none;
  font-weight: 800;
}

.practice-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.editor-panel,
.preview-panel,
.ai-panel {
  padding: 16px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.code-tabs {
  display: flex;
  gap: 7px;
  padding: 4px;
  border-radius: 12px;
  background: #f3f4f6;
}

.tab {
  padding: 8px 10px;
  background: transparent;
  color: var(--muted);
}

.tab.active {
  background: white;
  color: var(--ink);
  box-shadow: 0 3px 12px rgba(17, 24, 39, .08);
}

#codeEditor,
#adminHtml,
#adminCss,
#adminJs,
.json-area {
  min-height: 300px;
  border-color: #111827;
  background: #0f172a;
  color: #e5e7eb;
  font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
  line-height: 1.5;
  tab-size: 2;
}

.editor-actions {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

#previewFrame {
  width: 100%;
  min-height: 390px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
}

#runStatus,
#aiMode {
  border-radius: 999px;
  background: #ecfeff;
  color: #0e7490;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 850;
}

.ai-panel {
  margin-top: 16px;
}

.ai-compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.ai-compose textarea {
  min-height: 72px;
}

#aiAnswer {
  min-height: 120px;
  margin: 12px 0 0;
  padding: 14px;
  border-radius: 12px;
  background: #f8fafc;
  color: #1f2937;
  white-space: pre-wrap;
  font-family: inherit;
}

.empty {
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.hidden {
  display: none !important;
}

.admin-dialog {
  width: min(1180px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  border: 0;
  border-radius: 16px;
  padding: 16px;
}

.admin-dialog::backdrop {
  background: rgba(15, 23, 42, .42);
}

.dialog-close-row {
  display: flex;
  justify-content: flex-end;
  margin: 0 0 10px;
}

.admin-login {
  max-width: 460px;
  margin: 0 auto;
  padding: 20px;
}

.admin-login input,
.admin-login button {
  margin-top: 10px;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.admin-dialog section {
  padding: 16px;
  box-shadow: none;
}

.admin-dialog label {
  display: grid;
  gap: 6px;
  margin: 12px 0;
  color: #374151;
  font-weight: 750;
}

.lesson-admin {
  grid-row: span 2;
}

.admin-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.admin-row button:first-child {
  background: #f3f4f6;
  color: var(--ink);
  text-align: left;
}

.upload-box {
  display: grid;
  gap: 8px;
  margin: 12px 0;
  padding: 12px;
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  background: #f8fafc;
}

.hint {
  font-size: 13px;
}

code {
  border-radius: 6px;
  background: #f3f4f6;
  padding: 2px 5px;
}

@media (max-width: 980px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    padding: 14px;
  }

  .mobile-menu {
    display: block;
  }

  .course-list,
  .sidebar-card {
    display: none;
  }

  .sidebar.open .course-list,
  .sidebar.open .sidebar-card {
    display: grid;
  }

  .workspace {
    padding: 14px;
  }

  .topbar,
  .lesson-hero,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .ai-compose,
  .practice-grid,
  .content-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .top-actions,
  .editor-actions {
    display: grid;
  }

  .lesson-hero span {
    align-self: flex-start;
  }
}

@media (max-width: 560px) {
  .brand {
    align-items: flex-start;
  }

  #codeEditor,
  #previewFrame {
    min-height: 320px;
  }

  .code-tabs {
    width: 100%;
    justify-content: space-between;
  }

  .tab {
    flex: 1;
  }
}
