:root {
  color-scheme: light;
  --ink: #18212f;
  --muted: #667085;
  --line: #d9e1ea;
  --panel: #ffffff;
  --page: #eef3f7;
  --soft: #f7fafc;
  --nav: #132033;
  --nav-2: #1d314a;
  --accent: #0f8b8d;
  --accent-2: #d94f30;
  --good: #1f8a4c;
  --warn: #b94f00;
  --bad: #b42318;
  --shadow: 0 18px 45px rgba(24, 33, 47, .11);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

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

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: var(--nav);
  color: #fff;
  padding: 24px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 6px 22px;
}

.brand-logo {
  width: 68px;
  height: auto;
  border-radius: 8px;
  flex: 0 0 auto;
  box-shadow: 0 10px 22px rgba(0,0,0,.16);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 8px;
  background: #f5b84b;
  color: #172033;
  font-weight: 800;
  letter-spacing: 0;
}

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

.brand strong {
  font-size: 20px;
}

.brand div span {
  color: #b7c5d6;
  font-size: 13px;
  margin-top: 3px;
}

.current-lesson {
  margin: 0 0 16px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px;
  background: rgba(255,255,255,.06);
}

.current-lesson span,
.current-lesson strong,
.current-lesson small {
  display: block;
}

.current-lesson span {
  color: #95a6bb;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.current-lesson strong {
  margin-top: 5px;
  color: #fff;
  font-size: 14px;
  line-height: 1.3;
}

.current-lesson small {
  margin-top: 4px;
  color: #c8d5e4;
  line-height: 1.35;
}

.home-link {
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  background: rgba(255,255,255,.06);
  color: #fff;
  font-weight: 800;
  text-align: left;
  padding: 0 14px;
  margin-bottom: 14px;
}

.home-link:hover,
.home-link.active {
  background: #f5b84b;
  color: #172033;
}

.course-nav {
  display: grid;
  gap: 14px;
}

.chapter-block {
  display: grid;
  gap: 7px;
  border-radius: 8px;
}

.chapter-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 10px;
  border-top: 1px solid rgba(255,255,255,.1);
  border-radius: 8px;
  cursor: pointer;
  list-style: none;
}

.chapter-head::-webkit-details-marker {
  display: none;
}

.chapter-head::after {
  content: "+";
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: rgba(255,255,255,.08);
  color: #d9f6f5;
  font-weight: 800;
}

.chapter-block[open] .chapter-head,
.chapter-block.active .chapter-head {
  background: rgba(255,255,255,.06);
}

.chapter-block[open] .chapter-head::after {
  content: "-";
}

.chapter-head div {
  min-width: 0;
}

.chapter-head strong,
.chapter-head span,
.chapter-head small {
  display: block;
}

.chapter-head strong {
  color: #fff;
  font-size: 13px;
}

.chapter-head span,
.chapter-head small {
  color: #95a6bb;
  font-size: 11px;
}

.chapter-head small {
  flex: 0 0 auto;
}

.nav-item {
  width: 100%;
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 4px 10px;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 12px;
  color: #e8eef6;
  background: transparent;
  min-height: 62px;
}

.nav-item:hover,
.nav-item.active {
  background: var(--nav-2);
  border-color: rgba(255,255,255,.12);
}

.nav-item span {
  grid-row: span 2;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: rgba(255,255,255,.1);
  color: #d9f6f5;
  font-weight: 700;
  font-size: 12px;
}

.nav-item.done span {
  background: var(--good);
  color: #fff;
}

.nav-item strong {
  font-size: 14px;
  line-height: 1.2;
}

.nav-item small {
  color: #aebdd0;
  font-size: 12px;
}

.workspace {
  padding: 28px;
  display: grid;
  gap: 22px;
}

.database-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 180px)) minmax(260px, 1fr);
  align-items: stretch;
  gap: 12px;
}

.home-view {
  display: grid;
  gap: 18px;
}

.home-hero,
.home-menu,
.home-databases {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.home-hero {
  min-height: 280px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 24px;
  align-items: end;
  padding: 28px;
  background:
    linear-gradient(135deg, rgba(19,32,51,.92), rgba(15,139,141,.78)),
    linear-gradient(90deg, rgba(255,255,255,.08) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,.08) 1px, transparent 1px);
  background-size: auto, 28px 28px, 28px 28px;
  color: #fff;
}

.home-hero .eyebrow {
  color: #f5d38f;
}

.home-hero h2 {
  max-width: 860px;
  margin-bottom: 14px;
  font-size: 34px;
  line-height: 1.05;
}

.home-hero p {
  max-width: 760px;
  margin-bottom: 0;
  color: #dbe7f2;
  line-height: 1.65;
}

.home-actions {
  display: grid;
  gap: 10px;
}

.secondary-button {
  border: 1px solid rgba(255,255,255,.34);
  border-radius: 7px;
  min-height: 44px;
  padding: 0 16px;
  background: rgba(255,255,255,.08);
  color: #fff;
  font-weight: 800;
}

.home-section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.home-section-head h2 {
  margin-bottom: 0;
}

.home-section-head > span {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  color: #314155;
  font-size: 12px;
  font-weight: 800;
  background: var(--soft);
}

.home-chapters,
.database-cards {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.home-chapters {
  grid-template-columns: repeat(7, minmax(150px, 1fr));
}

.database-cards {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.home-card,
.database-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 16px;
  min-height: 150px;
}

.home-card {
  cursor: pointer;
}

.home-card:hover,
.database-card:hover {
  border-color: #0f8b8d;
  box-shadow: 0 14px 28px rgba(15, 139, 141, .12);
}

.home-card > span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  background: #e8f6f4;
  color: #087477;
  font-weight: 800;
  font-size: 12px;
}

.home-card h3,
.database-card strong {
  display: block;
  margin: 14px 0 6px;
  font-size: 16px;
  color: #172033;
}

.home-card p,
.database-card p,
.database-card span {
  color: var(--muted);
  line-height: 1.45;
  font-size: 13px;
}

.home-card small {
  display: block;
  margin-top: 14px;
  color: #0f8b8d;
  font-weight: 800;
}

.db-pill,
.database-strip p {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(24, 33, 47, .07);
}

.db-pill {
  padding: 14px;
}

.db-pill span,
.db-pill strong {
  display: block;
}

.db-pill span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.db-pill strong {
  margin-top: 4px;
  font-size: 20px;
}

.database-strip p {
  margin: 0;
  padding: 14px 16px;
  color: #425166;
  line-height: 1.5;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-weight: 800;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 42px;
  line-height: 1;
  max-width: 860px;
}

h2 {
  margin-bottom: 6px;
  font-size: 22px;
}

h3 {
  margin-bottom: 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
  color: var(--muted);
}

.score-card {
  min-width: 118px;
  padding: 16px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.score-card span,
.score-card strong {
  display: block;
}

.score-card span {
  color: var(--muted);
  font-size: 13px;
}

.score-card strong {
  font-size: 28px;
  margin-top: 3px;
}

.exam-brief,
.lesson-panel,
.editor-panel,
.result-panel,
.schema-section,
.data-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.exam-brief {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 22px;
}

.exam-brief p {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.brief-steps {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-content: center;
  gap: 8px;
  max-width: 420px;
}

.brief-steps span {
  border: 1px solid var(--line);
  background: var(--soft);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 800;
  color: #314155;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(260px, .85fr) minmax(360px, 1.2fr) minmax(320px, 1fr);
  gap: 16px;
  align-items: stretch;
}

.lesson-panel,
.editor-panel,
.result-panel {
  min-height: 515px;
  overflow: hidden;
}

.lesson-panel {
  display: grid;
  align-content: start;
}

.panel-head,
.panel-toolbar,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-head {
  justify-content: flex-start;
}

.panel-number {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e8f6f4;
  color: #087477;
  font-weight: 800;
}

.panel-head p,
.panel-toolbar p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.panel-toolbar .save-status {
  margin-top: 4px;
  color: #0f8b8d;
  font-size: 12px;
  font-weight: 800;
}

.task-box,
.explain-box,
.hint-box {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.task-box p,
.explain-box p,
.hint-box p {
  margin-bottom: 0;
  line-height: 1.65;
}

.hint-box {
  border-bottom: 0;
  background: #fff7ed;
}

.editor-panel,
.result-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.toolbar-actions,
.schema-tabs {
  display: flex;
  gap: 8px;
}

.panel-toolbar button,
.toolbar-actions button,
.schema-tab {
  border: 1px solid var(--line);
  background: var(--soft);
  color: var(--ink);
  min-height: 38px;
  border-radius: 7px;
  padding: 0 12px;
  font-weight: 700;
}

.schema-tab.active,
#solutionBtn.active {
  background: #e8f6f4;
  border-color: #94d2cf;
  color: #087477;
}

#sqlEditor {
  width: 100%;
  height: 100%;
  min-height: 320px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 20px;
  background: #111827;
  color: #e5edf7;
  font-family: Consolas, "Courier New", monospace;
  font-size: 15px;
  line-height: 1.6;
}

.run-row {
  border-top: 1px solid var(--line);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.run-button {
  flex: 0 0 auto;
  border: 0;
  border-radius: 7px;
  min-height: 44px;
  padding: 0 18px;
  background: var(--accent-2);
  color: #fff;
  font-weight: 800;
}

.next-button {
  flex: 0 0 auto;
  border: 1px solid #94d2cf;
  border-radius: 7px;
  min-height: 44px;
  padding: 0 16px;
  background: #e8f6f4;
  color: #087477;
  font-weight: 800;
}

.next-button:hover {
  background: #d9f4f1;
}

.feedback {
  margin: 0;
  color: var(--muted);
  line-height: 1.35;
}

.feedback.ok {
  color: var(--good);
  font-weight: 700;
}

.feedback.warn {
  color: var(--warn);
  font-weight: 700;
}

.feedback.bad {
  color: var(--bad);
  font-weight: 700;
}

.result-table-wrap {
  overflow: auto;
  padding: 18px;
}

#resultTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: #fff;
}

#resultTable th,
#resultTable td {
  border: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

#resultTable th {
  background: #edf6f8;
  color: #27384b;
  font-weight: 800;
}

.solution-box {
  margin: 0;
  border-top: 1px solid var(--line);
  padding: 14px 18px;
  white-space: pre-wrap;
  background: #f8fafc;
  color: #223044;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
}

.schema-section {
  overflow: hidden;
}

.schema-board-wrap {
  position: relative;
  overflow: auto;
  background:
    linear-gradient(#edf2f7 1px, transparent 1px),
    linear-gradient(90deg, #edf2f7 1px, transparent 1px);
  background-size: 26px 26px;
  min-height: 390px;
}

.relation-layer {
  position: absolute;
  inset: 0;
  min-width: 100%;
  min-height: 100%;
  pointer-events: none;
  z-index: 1;
}

.schema-board {
  position: relative;
  z-index: 2;
  padding: 28px;
  display: grid;
  gap: 28px 46px;
  width: max-content;
  min-width: 720px;
}

.table-card {
  border: 1px solid #cbd6e2;
  border-radius: 8px;
  background: rgba(255,255,255,.96);
  overflow: hidden;
  box-shadow: 0 10px 22px rgba(24, 33, 47, .08);
  cursor: pointer;
  position: relative;
  z-index: 2;
}

.table-card:hover {
  border-color: #0f8b8d;
  box-shadow: 0 14px 28px rgba(15, 139, 141, .16);
}

.table-card header {
  padding: 11px 12px;
  background: linear-gradient(135deg, #25364d, #1e455d);
  color: #fff;
  font-weight: 800;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.table-card header span:not(.table-name) {
  color: #c8d5e4;
  font-size: 12px;
  font-weight: 700;
}

.table-name {
  color: #fff;
  font-size: 15px;
}

.field {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  border-top: 1px solid #edf1f5;
  font-size: 13px;
  min-height: 34px;
  background: #fff;
  position: relative;
}

.field strong {
  color: #0b6f71;
}

.field em {
  color: var(--muted);
  font-style: normal;
  text-align: right;
  max-width: 120px;
}

.field.relation-field {
  background: #fff7ed;
}

.field.relation-field::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-2);
  position: absolute;
  left: -4px;
  top: 50%;
  transform: translateY(-50%);
  box-shadow: 0 0 0 3px #fff7ed;
}

.relation-note {
  grid-column: 1 / -1;
  background: #fff;
  border: 1px dashed #9fb0c3;
  border-radius: 8px;
  padding: 14px;
  color: #3c4b5e;
  line-height: 1.5;
  max-width: 980px;
}

.relation-line {
  stroke: #2f3b4c;
  stroke-width: 2;
  fill: none;
  stroke-linecap: square;
  stroke-linejoin: miter;
  filter: drop-shadow(0 1px 1px rgba(24, 33, 47, .2));
}

.relation-node {
  fill: #eef3f7;
  stroke: #2f3b4c;
  stroke-width: 2;
}

.data-section {
  overflow: hidden;
}

.data-note {
  margin: 0;
  color: var(--muted);
}

.data-tabs {
  display: flex;
  gap: 8px;
  padding: 14px 18px;
  overflow: auto;
  border-bottom: 1px solid var(--line);
}

.data-tab {
  flex: 0 0 auto;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  color: var(--ink);
  padding: 0 12px;
  font-weight: 800;
}

.data-tab.active {
  background: #25364d;
  color: #fff;
  border-color: #25364d;
}

.data-table-wrap {
  overflow: auto;
  padding: 18px;
  max-height: 360px;
}

#dataTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

#dataTable th,
#dataTable td {
  border: 1px solid var(--line);
  padding: 9px;
  text-align: left;
  vertical-align: top;
}

#dataTable th {
  background: #f1f5f9;
}

.legal-note {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 14px 16px;
  color: #667085;
  font-size: 12px;
  line-height: 1.5;
  border-top: 1px solid var(--line);
}

.legal-note strong {
  color: #314155;
  flex: 0 0 auto;
}

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

  .sidebar {
    position: static;
    height: auto;
    max-height: none;
  }

  .course-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .brand,
  .current-lesson {
    max-width: 720px;
  }

  .main-grid {
    grid-template-columns: 1fr;
  }

  .home-hero {
    grid-template-columns: 1fr;
  }

  .home-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .home-chapters {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .database-cards {
    grid-template-columns: 1fr;
  }

  .database-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .database-strip p {
    grid-column: 1 / -1;
  }

  .lesson-panel,
  .editor-panel,
  .result-panel {
    min-height: auto;
  }

  .schema-board {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: 16px;
  }

  .topbar,
  .database-strip,
  .exam-brief,
  .section-head,
  .run-row {
    flex-direction: column;
    align-items: stretch;
  }

  .database-strip {
    display: grid;
    grid-template-columns: 1fr;
  }

  .home-hero {
    min-height: auto;
    padding: 22px;
  }

  .home-hero h2 {
    font-size: 26px;
    line-height: 1.12;
  }

  .home-actions,
  .home-chapters {
    grid-template-columns: 1fr;
  }

  .home-section-head {
    flex-direction: column;
  }

  .course-nav,
  .schema-board {
    grid-template-columns: 1fr;
  }

  .sidebar {
    padding: 18px 12px;
  }

  .brand {
    align-items: flex-start;
  }

  .brand-logo {
    width: 58px;
  }

  .chapter-head {
    padding: 12px;
  }

  .nav-item {
    min-height: 58px;
  }

  .schema-board {
    min-width: 620px;
  }

  h1 {
    font-size: 30px;
    line-height: 1.08;
  }

  .panel-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
}
