:root {
  --bg: #fdfdf5;
  --surface: rgba(255, 255, 255, 0.98);
  --surface-strong: #ffffff;
  --ink: #16262d;
  --muted: #6b7280;
  --line: rgba(49, 83, 106, 0.12);
  --accent: #31536a;
  --accent-soft: rgba(49, 83, 106, 0.1);
  --success: #2d6a4f;
  --success-soft: rgba(45, 106, 79, 0.12);
  --danger: #91473b;
  --danger-soft: rgba(145, 71, 59, 0.16);
  --gold: #b8860b;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(145, 71, 59, 0.08), transparent 24%),
    radial-gradient(circle at 90% 0%, rgba(49, 83, 106, 0.1), transparent 28%),
    linear-gradient(180deg, #ece1d1 0%, #f8f4ee 34%, #f2ede6 100%);
}

button,
textarea {
  font: inherit;
}

.app-shell {
  width: min(1400px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 28px;
}

.topbar {
  display: grid;
  gap: 18px;
  padding: 20px;
  border-radius: 30px;
  background: rgba(255, 251, 245, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.66);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 62px;
  height: 62px;
  border-radius: 18px;
  background: linear-gradient(135deg, var(--ink), #29404c);
  color: #fff8ef;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.brand h1,
.card-heading h2,
.card-heading h3 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
}

.brand h1 {
  font-size: clamp(2rem, 5vw, 3.6rem);
  line-height: 0.98;
}

.status-row,
.question-meta,
.action-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.coach-grid,
.workspace-grid {
  display: grid;
  gap: 16px;
}

.status-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.status-card,
.question-card,
.editor-card {
  border-radius: 26px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, 0.66);
  box-shadow: var(--shadow);
}

.status-card span,
.meta-card span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.status-card strong,
.meta-card strong {
  font-size: 1.15rem;
}

.trainer-layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 20px;
  margin-top: 18px;
  align-items: start;
}

.question-panel,
.workspace-panel {
  display: grid;
  gap: 18px;
}

.question-panel {
  position: sticky;
  top: 18px;
}

.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.compact-heading {
  margin-bottom: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.question-prompt,
.adaptive-feedback,
.coach-card p,
.editor-meta,
.schema-intro,
.schema-caption {
  margin: 0;
  color: var(--muted);
  line-height: 1.75;
}

.question-meta {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 18px;
}

.meta-card,
.coach-card,
.mastery-card,
.schema-group {
  border-radius: 18px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.48);
}

.schema-builder {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.schema-palette {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.schema-group {
  display: grid;
  gap: 12px;
}

.schema-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.schema-group h4,
.schema-chip-row h5 {
  margin: 0;
}

.schema-chip-row {
  display: grid;
  gap: 10px;
}

.schema-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.schema-chip {
  border: 1px solid rgba(49, 83, 106, 0.16);
  border-radius: 999px;
  padding: 9px 12px;
  background: rgba(49, 83, 106, 0.08);
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: transform 180ms ease, background 180ms ease;
}

.schema-chip:hover {
  transform: translateY(-1px);
  background: rgba(49, 83, 106, 0.14);
}

.schema-chip:active {
  cursor: grabbing;
}

.schema-chip.table-chip {
  background: rgba(143, 102, 50, 0.1);
  border-color: rgba(143, 102, 50, 0.16);
  color: var(--gold);
}

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

.action-row.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 14px 0 0;
}

.ghost-button,
.solid-button {
  border: 0;
  border-radius: 16px;
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, color 180ms ease;
}

.ghost-button {
  background: rgba(22, 38, 45, 0.08);
  color: var(--ink);
}

.solid-button {
  background: linear-gradient(135deg, var(--ink), #29404c);
  color: #fff8ef;
}

.ghost-button.secondary-action {
  background: var(--danger-soft);
  color: var(--danger);
}

.ghost-button.secondary-action:hover {
  background: rgba(145, 71, 59, 0.25);
}

.ghost-button:hover,
.solid-button:hover {
  transform: translateY(-1px);
}

.coach-grid {
  grid-template-columns: 1fr;
  margin-top: 16px;
}

.mastery-grid {
  display: grid;
  gap: 12px;
}

.mastery-card {
  display: grid;
  gap: 8px;
}

.mastery-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.mastery-meter {
  height: 10px;
  border-radius: 999px;
  background: rgba(22, 38, 45, 0.08);
  overflow: hidden;
}

.mastery-meter span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--success));
}

/* Course Tracker (Domino's Style) */
.course-tracker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px 0;
}

.step-node {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  margin-bottom: 20px;
}

.step-node::before {
  display: none; /* Connections look messy in wrapped layout */
}

.step-node:last-child::before {
  display: none;
}

.step-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-strong);
  border: 3px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  font-size: 0.85rem;
  font-weight: 800;
  transition: all 0.3s ease;
  margin-bottom: 12px;
}

.step-node.completed .step-circle {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.step-node.completed::before {
  background: var(--success);
}

.step-node.current .step-circle {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 0 15px rgba(49, 83, 106, 0.4);
  animation: step-pulse 2s infinite;
}

.step-label {
  font-size: 0.65rem;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 4px;
}

.step-node.current .step-label {
  color: var(--accent);
}

@keyframes step-pulse {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(49, 83, 106, 0.4); }
  70% { transform: scale(1.08); box-shadow: 0 0 0 10px rgba(49, 83, 106, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(49, 83, 106, 0); }
}

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

.final-card {
  background: linear-gradient(180deg, rgba(255, 251, 245, 0.98), rgba(247, 242, 234, 0.98));
}

.editor-label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.sql-editor {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  border: 1px solid rgba(255, 255, 255, 0.66);
  border-radius: 22px;
  padding: 18px;
  background: #122129;
  color: #f5eada;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  line-height: 1.6;
}

.sql-editor:focus {
  outline: 2px solid rgba(49, 83, 106, 0.28);
  outline-offset: 3px;
}

.sql-editor.drop-target {
  outline: 2px solid rgba(49, 83, 106, 0.48);
  outline-offset: 3px;
}

.result-panel {
  margin-top: 16px;
  min-height: 150px;
}

.result-table-wrapper {
  overflow-x: auto;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.62);
}

.result-table {
  width: 100%;
  border-collapse: collapse;
}

.result-table th,
.result-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.result-table th {
  background: rgba(22, 38, 45, 0.08);
}

.result-empty,
.result-error,
.result-success {
  padding: 16px 18px;
  border-radius: 18px;
  line-height: 1.7;
}

.result-empty {
  background: rgba(255, 255, 255, 0.54);
  color: var(--muted);
}

.result-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.result-success {
  background: var(--success-soft);
  color: var(--success);
}

.task-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  min-height: 36px;
  padding: 7px 12px;
  border-radius: 999px;
  font-weight: 700;
}

.task-status.pending,
.task-status.active {
  background: rgba(22, 38, 45, 0.08);
  color: var(--muted);
}

.task-status.passed {
  background: var(--success-soft);
  color: var(--success);
}

.task-status.failed {
  background: var(--danger-soft);
  color: var(--danger);
}

@media (max-width: 1160px) {
  .trainer-layout,
  .workspace-grid,
  .status-row,
  .question-meta,
  .action-row,
  .action-row.compact {
    grid-template-columns: 1fr;
  }

  .question-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 18px, 1400px);
    padding-top: 12px;
  }

  .topbar,
  .status-card,
  .question-card,
  .editor-card {
    padding: 18px;
  }

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

  .brand-mark {
    width: 54px;
    height: 54px;
  }
}
