:root {
  --bg: #08111d;
  --bg-strong: #060d18;
  --panel: rgba(14, 24, 39, 0.95);
  --panel-alt: rgba(17, 28, 45, 0.92);
  --panel-soft: rgba(23, 35, 56, 0.95);
  --border: rgba(124, 161, 212, 0.22);
  --border-strong: rgba(118, 190, 255, 0.4);
  --text: #eaf3ff;
  --muted: #9bb3d1;
  --blue: #58a6ff;
  --cyan: #63e6ff;
  --green: #3ddc97;
  --orange: #ffb454;
  --danger: #ff7a7a;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background:
    radial-gradient(circle at top, rgba(66, 118, 204, 0.2), transparent 35%),
    linear-gradient(180deg, var(--bg-strong), var(--bg));
  color: var(--text);
}

body {
  padding: 28px;
}

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

button {
  cursor: pointer;
}

.app-shell {
  max-width: 1500px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  margin-bottom: 20px;
  background: rgba(12, 20, 33, 0.85);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(2rem, 2vw, 2.6rem);
  letter-spacing: 0.04em;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.badge {
  padding: 8px 14px;
  border: 1px solid rgba(99, 230, 255, 0.35);
  border-radius: 999px;
  background: rgba(18, 42, 60, 0.8);
  color: var(--cyan);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: 1.1fr 1.8fr 1.1fr;
  gap: 20px;
  min-height: 460px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-heading {
  padding: 18px 18px 8px;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.explorer-panel,
.editor-panel,
.flow-panel,
.visualization-panel {
  position: relative;
}

.explorer-panel {
  padding-bottom: 18px;
}

.db-name {
  margin: 6px 18px 16px;
  color: var(--cyan);
  font-weight: 700;
  font-size: 1.1rem;
}

.table-button {
  display: block;
  width: 100%;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid rgba(88, 166, 255, 0.35);
  border-radius: 12px;
  background: rgba(26, 43, 63, 0.95);
  color: var(--text);
  text-align: left;
  font-weight: 700;
  letter-spacing: 0.04em;
  transition: all 0.2s ease;
}

.table-button:hover {
  transform: translateY(-1px);
  border-color: rgba(99, 230, 255, 0.7);
  box-shadow: 0 8px 18px rgba(88, 166, 255, 0.15);
}

.table-preview {
  margin: 16px 18px 0;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(7, 15, 25, 0.8);
  overflow: hidden;
  min-height: 260px;
}

.table-preview.hidden {
  display: none;
}

.editor-panel {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 19, 30, 0.85);
}

.toolbar-title {
  font-weight: 700;
  letter-spacing: 0.04em;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

select,
input,
button {
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(21, 34, 49, 0.95);
  color: var(--text);
  transition: all 0.2s ease;
}

select {
  min-width: 150px;
  padding: 9px 12px;
}

button {
  padding: 9px 14px;
}

button:hover {
  border-color: rgba(99, 230, 255, 0.6);
  box-shadow: 0 8px 18px rgba(99, 230, 255, 0.12);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(99, 230, 255, 0.72);
  outline-offset: 2px;
}

.topbar-actions,
.quick-start-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.version-badge {
  padding: 6px 10px;
  border: 1px solid rgba(99, 230, 255, 0.42);
  border-radius: 999px;
  color: var(--cyan);
  background: rgba(99, 230, 255, 0.08);
  font-size: 0.75rem;
  font-weight: 700;
}

.intro-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(88, 166, 255, 0.11), rgba(99, 230, 255, 0.05));
}

.intro-panel h2 {
  margin: 0;
  font-size: clamp(1.1rem, 2vw, 1.45rem);
}

.intro-panel p {
  margin: 6px 0 0;
  color: var(--muted);
}

.quick-start-actions button {
  white-space: nowrap;
}

.database-actions {
  display: grid;
  gap: 8px;
}

.help-tip {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin-left: 4px;
  padding: 0;
  border-radius: 50%;
  color: var(--cyan);
  font-size: 0.72rem;
  vertical-align: middle;
}

.help-popover {
  position: fixed;
  z-index: 150;
  max-width: 280px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #101c2d;
  color: var(--text);
  box-shadow: var(--shadow);
  font-size: 0.8rem;
  line-height: 1.45;
}

.concept-help {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.76rem;
}

.concept-help .help-tip {
  width: auto;
  height: auto;
  margin: 0;
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 0.7rem;
}

.custom-empty-hint {
  margin: 8px 0 0;
  padding: 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 9px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.4;
}

.shortcut-hint {
  color: var(--muted);
  font-size: 0.72rem;
}

.about-modal {
  width: min(650px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 22px;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}

.about-purpose {
  color: var(--cyan);
  font-weight: 700;
}

.feature-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.feature-chips span {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.78rem;
}

.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 200;
  width: min(390px, calc(100vw - 40px));
}

.toast {
  padding: 13px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: #13233a;
  box-shadow: var(--shadow);
  color: var(--text);
  animation: toast-in 0.22s ease-out;
}

.toast.success { border-color: rgba(61, 220, 151, 0.55); }
.toast.error { border-color: rgba(255, 122, 122, 0.6); }

.stage-transition-cue {
  margin-bottom: 10px;
  padding: 8px 11px;
  border-left: 3px solid var(--cyan);
  border-radius: 7px;
  background: rgba(88, 166, 255, 0.08);
  color: var(--muted);
  font-size: 0.82rem;
  animation: cue-in 0.3s ease-out;
}

.stage-transition-table {
  animation: stage-in 0.32s ease-out;
}

.join-key-cell {
  background: rgba(255, 180, 84, 0.14);
  color: var(--orange);
  font-weight: 700;
}

.null-cell {
  color: var(--danger);
  font-style: italic;
}

.timeline-item.committed { border-color: rgba(61, 220, 151, 0.45); }
.timeline-item.pending { border-color: rgba(255, 180, 84, 0.55); }
.timeline-item.rolled-back,
.timeline-item.discarded { opacity: 0.62; border-style: dashed; }

.query-tree-node:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--cyan);
}

.query-tree.compact .query-tree-node {
  min-width: 145px;
  max-width: 210px;
  padding: 8px 10px;
}

.query-tree.compact .query-tree-children {
  gap: 18px;
  padding-top: 20px;
}

.presentation-mode body { padding: 14px; }

body.presentation-mode {
  padding: 14px;
}

.presentation-mode .intro-panel,
.presentation-mode .explorer-panel,
.presentation-mode #resetQueryBtn,
.presentation-mode #resetDemoBtn,
.presentation-mode #aboutProjectBtn,
.presentation-mode #clearCustomDataBtn,
.presentation-mode .shortcut-hint {
  display: none;
}

.presentation-mode .workspace {
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.85fr);
}

.presentation-mode .editor-panel,
.presentation-mode .flow-panel {
  display: flex;
}

.presentation-mode #sqlEditor {
  min-height: 380px;
  font-size: 1.12rem;
}

.presentation-mode .visualization-panel,
.presentation-mode .transaction-panel {
  font-size: 1.05rem;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes cue-in {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes stage-in {
  from { opacity: 0.25; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (max-width: 800px) {
  body { padding: 14px; }
  .intro-panel,
  .topbar-actions { align-items: stretch; flex-direction: column; }
  .quick-start-actions button { flex: 1 1 100%; }
  .presentation-mode .workspace { grid-template-columns: 1fr; }
}

.transaction-panel {
  margin-top: 20px;
  padding: 0 18px 18px;
}

.transaction-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

.transaction-heading .panel-heading {
  padding-left: 0;
}

.transaction-heading h2 {
  margin: 2px 0 14px;
  font-size: 1.15rem;
}

.transaction-status {
  padding: 7px 12px;
  border: 1px solid rgba(61, 220, 151, 0.5);
  border-radius: 999px;
  color: var(--green);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.transaction-status.inactive {
  border-color: var(--border);
  color: var(--muted);
}

.transaction-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.transaction-summary-grid > div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(7, 15, 25, 0.62);
  color: var(--text);
  overflow-wrap: anywhere;
}

.summary-label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.transaction-timeline-wrap {
  margin-top: 14px;
}

.transaction-timeline {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.timeline-item {
  position: relative;
  flex: 0 0 auto;
  min-width: 150px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: rgba(17, 28, 45, 0.92);
}

.timeline-item:not(:last-child)::after {
  content: "→";
  position: absolute;
  right: -10px;
  top: 50%;
  color: var(--cyan);
  transform: translate(50%, -50%);
}

.timeline-type {
  color: var(--cyan);
  font-weight: 700;
}

.timeline-detail,
.timeline-status {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.72rem;
}

@media (max-width: 900px) {
  .transaction-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .transaction-summary-grid {
    grid-template-columns: 1fr;
  }
}

input {
  padding: 9px 12px;
  outline: none;
}

input:focus,
select:focus {
  border-color: rgba(99, 230, 255, 0.7);
  box-shadow: 0 0 0 3px rgba(99, 230, 255, 0.08);
}

.table-list {
  display: grid;
  gap: 8px;
  margin: 0 18px;
}

.table-button.active {
  border-color: rgba(99, 230, 255, 0.85);
  background: linear-gradient(135deg, rgba(88, 166, 255, 0.22), rgba(99, 230, 255, 0.12));
  color: var(--cyan);
}

.table-list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: center;
}

.table-kind-badge {
  justify-self: end;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.table-list-item.custom .table-kind-badge {
  color: var(--cyan);
}

.table-item-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.table-item-actions button {
  padding: 5px 9px;
  font-size: 0.72rem;
}

.database-actions {
  margin: 14px 18px 0;
}

.create-table-button {
  width: 100%;
  border-color: rgba(99, 230, 255, 0.45);
  color: var(--cyan);
}

.database-message {
  margin: 12px 18px 0;
  color: var(--orange);
  font-size: 0.8rem;
  line-height: 1.4;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 7, 13, 0.82);
  backdrop-filter: blur(5px);
}

.modal-backdrop.hidden {
  display: none;
}

.table-editor-modal {
  width: min(1080px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
  padding: 20px;
}

.table-editor-header,
.editor-section-heading,
.table-editor-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.table-editor-header .panel-heading {
  padding: 0;
}

.table-editor-header h2,
.editor-section-heading h3 {
  margin: 5px 0 0;
}

.form-field {
  display: grid;
  gap: 7px;
  margin: 18px 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
}

.column-editor {
  display: grid;
  gap: 8px;
  margin: 12px 0 20px;
}

.column-definition {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) 150px auto;
  gap: 8px;
}

.custom-rows-editor {
  margin-top: 12px;
  overflow-x: auto;
}

.custom-row-grid {
  width: 100%;
  border-collapse: collapse;
}

.custom-row-grid th,
.custom-row-grid td {
  padding: 7px;
  border: 1px solid var(--border);
}

.custom-row-grid th {
  color: var(--cyan);
  text-align: left;
  font-size: 0.76rem;
}

.custom-row-grid input {
  width: 100%;
  min-width: 120px;
}

.empty-editor-state {
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--muted);
}

.table-editor-footer {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.table-editor-footer > div,
.row-actions,
.csv-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 700px) {
  .column-definition {
    grid-template-columns: 1fr;
  }

  .table-editor-header,
  .editor-section-heading,
  .table-editor-footer {
    align-items: stretch;
    flex-direction: column;
  }
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  box-shadow: none;
}

button.secondary {
  background: rgba(15, 27, 38, 0.95);
}

#runQueryBtn {
  background: linear-gradient(135deg, rgba(88, 166, 255, 0.25), rgba(99, 230, 255, 0.2));
  border-color: rgba(88, 166, 255, 0.5);
}

#sqlEditor {
  width: 100%;
  min-height: 300px;
  resize: vertical;
  border: 0;
  outline: none;
  padding: 18px 18px 22px;
  background: linear-gradient(180deg, rgba(8, 16, 26, 0.96), rgba(11, 22, 34, 0.96));
  color: var(--text);
  font-family: "Consolas", "Monaco", monospace;
  font-size: 1rem;
  line-height: 1.7;
}

.execution-flow {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 10px 18px 18px;
}

.flow-card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 14px 12px;
  background: rgba(18, 29, 43, 0.82);
  transition: all 0.2s ease;
}

.flow-card::after {
  content: "";
  position: absolute;
  left: 24px;
  bottom: -15px;
  width: 2px;
  height: 15px;
  background: rgba(99, 230, 255, 0.25);
}

.flow-card:last-child::after {
  display: none;
}

.flow-card.active {
  border-color: rgba(99, 230, 255, 0.75);
  background: linear-gradient(135deg, rgba(88, 166, 255, 0.14), rgba(99, 230, 255, 0.08));
  box-shadow: 0 10px 20px rgba(88, 166, 255, 0.12);
}

.flow-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.flow-step {
  color: var(--cyan);
  font-size: 0.75rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.flow-label {
  font-weight: 700;
}

.flow-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.88rem;
}

.visualization-panel {
  margin-top: 20px;
  padding-bottom: 18px;
}

.tab-row {
  display: flex;
  gap: 10px;
  padding: 18px 18px 0;
}

.tab {
  padding: 10px 18px;
  border: 1px solid var(--border);
  background: rgba(15, 27, 38, 0.8);
  color: var(--muted);
}

.tab.active {
  background: linear-gradient(135deg, rgba(88, 166, 255, 0.2), rgba(99, 230, 255, 0.15));
  color: var(--text);
  border-color: rgba(99, 230, 255, 0.55);
}

.bottom-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px;
  flex-wrap: wrap;
}

#stepCounter {
  margin-left: auto;
  color: var(--muted);
  font-weight: 600;
}

.stage-description {
  padding: 0 18px 12px;
  color: var(--muted);
  font-size: 0.96rem;
  min-height: 24px;
}

.table-container,
.result-container,
.plan-container {
  padding: 0 18px 14px;
  overflow-x: auto;
}

.plan-help {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.5;
}

.plan-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.copy-status {
  color: var(--green);
  font-size: 0.8rem;
}

.relational-algebra-expression {
  margin: 0;
  padding: 20px;
  overflow-x: auto;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: rgba(7, 15, 25, 0.85);
  color: var(--text);
  font-family: "Consolas", "Monaco", monospace;
  font-size: 1rem;
  line-height: 1.65;
  white-space: pre;
}

.operator-legend {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.operator-legend > div {
  display: flex;
  gap: 7px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.8rem;
}

.operator-symbol {
  color: var(--cyan);
  font-weight: 800;
}

.query-tree {
  min-width: max-content;
  padding: 12px 8px 24px;
  overflow-x: auto;
  text-align: center;
}

.query-tree-branch {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.query-tree-node {
  display: grid;
  gap: 4px;
  min-width: 180px;
  max-width: 280px;
  padding: 11px 14px;
  border-color: var(--border-strong);
  background: rgba(17, 28, 45, 0.96);
  text-align: center;
}

.query-tree-node.active {
  border-color: var(--cyan);
  background: linear-gradient(135deg, rgba(88, 166, 255, 0.24), rgba(99, 230, 255, 0.14));
  box-shadow: 0 0 20px rgba(99, 230, 255, 0.14);
}

.query-tree-node.informational {
  opacity: 0.8;
}

.tree-operation {
  color: var(--cyan);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.tree-clause {
  overflow-wrap: anywhere;
  color: var(--text);
}

.tree-stats {
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.4;
}

.query-tree-children {
  position: relative;
  display: flex;
  justify-content: center;
  gap: 32px;
  padding-top: 26px;
}

.query-tree-children::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 2px;
  height: 22px;
  background: rgba(99, 230, 255, 0.4);
}

.query-tree-children.multiple::after {
  content: "";
  position: absolute;
  top: 21px;
  left: 25%;
  right: 25%;
  height: 2px;
  background: rgba(99, 230, 255, 0.4);
}

.hidden {
  display: none;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(7, 15, 25, 0.75);
}

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

.data-table th {
  background: rgba(16, 28, 40, 0.95);
  color: var(--cyan);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.data-table td {
  font-family: "Consolas", "Monaco", monospace;
}

.data-table .grouped-rows-cell {
  min-width: 320px;
  color: var(--muted);
  white-space: normal;
  line-height: 1.45;
}

.join-visualization {
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  background: rgba(10, 20, 32, 0.72);
}

.join-inputs {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
}

.join-input-card {
  min-width: 0;
  overflow-x: auto;
}

.join-input-card h3 {
  margin: 4px 0 10px;
  color: var(--cyan);
}

.join-card-label,
.join-output-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.join-condition {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--orange);
  font-family: "Consolas", "Monaco", monospace;
  text-align: center;
}

.join-arrow {
  color: var(--cyan);
  font-size: 1.5rem;
}

.join-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 14px 0;
}

.join-stats span {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(23, 35, 56, 0.95);
  color: var(--muted);
  font-size: 0.8rem;
}

@media (max-width: 850px) {
  .join-inputs {
    grid-template-columns: 1fr;
  }
}

.data-table tbody tr:hover {
  background: rgba(88, 166, 255, 0.06);
}

.empty-state {
  padding: 24px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  font-style: italic;
}

.explanation-container {
  padding: 18px;
}

.explanation-intro {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-left: 3px solid var(--cyan);
  border-radius: 0 10px 10px 0;
  background: rgba(99, 230, 255, 0.07);
  color: var(--muted);
  line-height: 1.55;
}

.explanation-list {
  display: grid;
  gap: 12px;
}

.explanation-card {
  display: block;
  width: 100%;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(10, 20, 32, 0.78);
  color: var(--text);
  text-align: left;
  line-height: 1.5;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.explanation-card:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  background: rgba(17, 34, 52, 0.92);
}

.explanation-card.active {
  border-color: var(--cyan);
  background: linear-gradient(135deg, rgba(88, 166, 255, 0.16), rgba(99, 230, 255, 0.08));
  box-shadow: 0 0 0 2px rgba(99, 230, 255, 0.12);
}

.explanation-card h3,
.explanation-card h4,
.explanation-card p {
  margin-top: 0;
}

.explanation-card h3 {
  margin-bottom: 8px;
  color: var(--cyan);
}

.explanation-card h4 {
  margin-bottom: 3px;
  color: var(--orange);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.explanation-card p {
  margin-bottom: 12px;
  color: var(--text);
}

.explanation-clause {
  display: inline-block;
  max-width: 100%;
  margin-bottom: 14px;
  padding: 5px 8px;
  overflow-wrap: anywhere;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: rgba(4, 11, 19, 0.72);
  color: #b7cfff;
}

.explanation-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.explanation-stats span {
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(23, 35, 56, 0.9);
  font-size: 0.75rem;
}

.explanation-summary {
  margin-top: 16px;
  padding: 17px 19px;
  border: 1px solid rgba(99, 230, 255, 0.38);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(99, 230, 255, 0.1), rgba(88, 166, 255, 0.08));
}

.explanation-summary h3 { margin: 0 0 7px; color: var(--cyan); }
.explanation-summary p { margin: 0; line-height: 1.6; }

body.presentation-mode .explanation-container { font-size: 1.08rem; }
body.presentation-mode .explanation-card { padding: 20px 22px; }

@media (max-width: 560px) {
  .explanation-container { padding: 10px; }
  .explanation-card { padding: 13px; }
}

.error-box {
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 122, 122, 0.4);
  background: rgba(58, 17, 17, 0.5);
  color: #ffd7d7;
  margin: 0 18px 16px;
}

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

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

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

  .toolbar-actions {
    width: 100%;
  }

  #exampleQueries {
    flex: 1;
    min-width: 0;
  }
}

/* Academic submission views and day theme */
[data-theme="light"] {
  --bg: #edf4fb; --bg-strong: #f8fbff; --panel: rgba(255, 255, 255, 0.97); --panel-alt: rgba(243, 248, 255, 0.98);
  --panel-soft: rgba(229, 239, 251, 0.98); --border: rgba(37, 75, 122, 0.2); --border-strong: rgba(20, 105, 168, 0.48);
  --text: #11243b; --muted: #526a84; --blue: #1168b5; --cyan: #006d87; --green: #087a50; --orange: #9a4d00; --danger: #b42318;
  --shadow: 0 12px 30px rgba(26, 57, 91, 0.14);
}
[data-theme="light"] body { background: radial-gradient(circle at top, rgba(74, 144, 226, 0.14), transparent 38%), linear-gradient(180deg, var(--bg-strong), var(--bg)); }
[data-theme="light"] .topbar, [data-theme="light"] .data-table th, [data-theme="light"] .help-popover { background: #f7fbff; color: var(--text); }
[data-theme="light"] textarea, [data-theme="light"] input, [data-theme="light"] select, [data-theme="light"] .data-table, [data-theme="light"] .explanation-card, [data-theme="light"] .join-visualization { background: rgba(255,255,255,.94); color: var(--text); }
[data-theme="light"] .explanation-clause, [data-theme="light"] pre, [data-theme="light"] code { background: #eef5fc; color: #194f82; }
[data-theme="light"] .error-box { background: #fff1f0; color: #8f1d16; }
[data-theme="light"] .badge, [data-theme="light"] .table-button, [data-theme="light"] .table-preview,
[data-theme="light"] .editor-toolbar, [data-theme="light"] button, [data-theme="light"] button.secondary,
[data-theme="light"] .flow-card, [data-theme="light"] .tab, [data-theme="light"] .timeline-item,
[data-theme="light"] .transaction-summary-grid > div, [data-theme="light"] .relational-algebra-expression,
[data-theme="light"] .query-tree-node, [data-theme="light"] .join-input-card,
[data-theme="light"] .explanation-stats span, [data-theme="light"] .join-stats span {
  background: var(--panel-alt);
  color: var(--text);
}
[data-theme="light"] .flow-card.active, [data-theme="light"] .tab.active,
[data-theme="light"] .table-button.active, [data-theme="light"] .query-tree-node.active {
  background: linear-gradient(135deg, rgba(17, 104, 181, 0.13), rgba(0, 109, 135, 0.08));
  color: var(--text);
}
[data-theme="light"] .toast, [data-theme="light"] .join-condition,
[data-theme="light"] .explanation-card:hover { background: var(--panel-alt); color: var(--text); }
[data-theme="light"] .data-table td { color: var(--text); }

.academic-nav { display: flex; flex-wrap: wrap; gap: 7px; }
.academic-modal, .report-modal { width: min(1120px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow: auto; padding: 24px; border: 1px solid var(--border-strong); border-radius: 18px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.academic-header { position: sticky; top: -24px; z-index: 2; display: flex; justify-content: space-between; align-items: center; gap: 16px; margin: -24px -24px 20px; padding: 20px 24px; border-bottom: 1px solid var(--border); background: var(--panel); }
.academic-header h2 { margin: 3px 0 0; }
.academic-section > h3 { margin-top: 28px; color: var(--cyan); }
.academic-section > h3:first-child { margin-top: 0; }
.learn-grid, .help-grid, .module-grid, .people-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.learn-card, .help-grid section, .module-grid section, .person-card, .video-placeholder, .academic-facts > div { padding: 16px; border: 1px solid var(--border); border-radius: 13px; background: var(--panel-alt); }
.learn-card { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.learn-card h4, .learn-card p, .help-grid h4, .help-grid p, .module-grid h4, .module-grid p { margin: 0; }
.learn-card code { display: block; width: 100%; padding: 9px; overflow-wrap: anywhere; border-radius: 8px; background: var(--bg-strong); color: var(--cyan); }
.video-placeholder { margin-top: 18px; min-height: 150px; display: grid; place-content: center; text-align: center; border-style: dashed; }
.workflow-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 0; counter-reset: workflow; list-style: none; }
.workflow-list li { padding: 12px; border-left: 3px solid var(--cyan); background: var(--panel-alt); border-radius: 8px; }
.academic-facts { display: grid; gap: 10px; }
.academic-facts dt { color: var(--cyan); font-weight: 700; }
.academic-facts dd { margin: 5px 0 0; }
.architecture-flow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 16px; border: 1px solid var(--border); border-radius: 13px; background: var(--panel-alt); }
.architecture-flow span { padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 8px; }
.architecture-flow span { overflow-wrap: anywhere; }
.architecture-flow b { color: var(--cyan); font-size: 1.2rem; }
.person-card { text-align: center; }
.person-card img, .guide-mark { width: 150px; height: 175px; margin: 0 auto 12px; object-fit: cover; border: 1px solid var(--border-strong); border-radius: 13px; }
.person-card img.guide-photo { object-fit: contain; background: #fff; }
.person-card img { object-position: 66% 40%; }
.person-card h4, .person-card p { overflow-wrap: anywhere; }
.guide-mark { display: grid; place-items: center; background: linear-gradient(135deg, rgba(88,166,255,.25), rgba(99,230,255,.12)); color: var(--cyan); font-weight: 800; }
.report-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.printable-report { padding: 30px; background: #fff; color: #17212b; border-radius: 10px; }
.printable-report h1 { letter-spacing: .05em; }
.printable-report h2 { margin-top: 28px; padding-bottom: 5px; border-bottom: 1px solid #b9c4cf; }
.printable-report pre, .printable-report code { white-space: pre-wrap; overflow-wrap: anywhere; color: #17212b; background: #f3f5f7; }
.printable-report pre { padding: 12px; }
.report-section { break-inside: avoid; padding: 10px 0; }
.report-table-wrap { overflow-x: auto; }
.report-table { width: 100%; border-collapse: collapse; }
.report-table th, .report-table td { padding: 7px 9px; border: 1px solid #aeb9c3; text-align: left; }
.report-table th, .report-table td { overflow-wrap: anywhere; }

@media (max-width: 800px) {
  .topbar, .topbar-actions { min-width: 0; }
  .topbar-actions { width: 100%; max-width: 100%; }
  .academic-nav { width: 100%; max-width: 100%; min-width: 0; overflow-x: auto; flex-wrap: nowrap; }
  .academic-nav button { white-space: nowrap; }
  .learn-grid, .help-grid, .module-grid, .people-grid, .workflow-list { grid-template-columns: 1fr; }
  .academic-modal, .report-modal { width: calc(100vw - 16px); padding: 16px; }
  .academic-header { top: -16px; margin: -16px -16px 16px; padding: 16px; }
  .tab-row { overflow-x: auto; white-space: nowrap; }
  .tab-row .tab { flex: 0 0 auto; }
  .academic-modal, .report-modal { overflow-x: hidden; }
}

@media print {
  body { padding: 0; background: #fff !important; color: #000 !important; }
  body > *:not(#reportModal), .no-print { display: none !important; }
  #reportModal { position: static; display: block !important; padding: 0; background: #fff; }
  .report-modal { width: 100%; max-height: none; overflow: visible; padding: 0; border: 0; box-shadow: none; }
  .printable-report { padding: 12mm; color: #000; }
  .report-table-wrap { overflow: visible; }
  .report-table { width: 100%; table-layout: fixed; font-size: 9pt; }
  .report-table thead { display: table-header-group; }
  .report-section, .report-table tr { break-inside: avoid; }
}

/* Interactive learning uses the existing SQLFlow palette and native controls. */
.simulation-panel, .join-video-lesson { margin: 18px 0; padding: 18px; border: 1px solid var(--border-strong); border-radius: 14px; background: var(--panel-alt); }
[data-theme="light"] #sqlEditor { background: var(--panel); color: var(--text); }
[data-theme="light"] .academic-header { background: #fff; }
[data-theme="dark"] .academic-header { background: #0e1827; }
.modal-backdrop { grid-template-columns: minmax(0, 1fr); }
.academic-modal, .report-modal { width: min(1120px, 100%); min-width: 0; }
@media (max-width: 800px) { .modal-backdrop { padding: 8px; } .academic-modal, .report-modal { width: 100%; } }
.simulation-controls, .quiz-navigation, .quiz-question-nav { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 0; }
.simulation-controls label { display: flex; align-items: center; gap: 6px; }
.simulation-relations { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 290px), 1fr)); gap: 16px; }
.simulation-relations > section, .help-manual > *, .quiz-topic-grid > *, .quiz-settings > * { min-width: 0; }
.learning-table-wrap { max-width: 100%; overflow-x: auto; border-radius: 8px; }
.simulation-accepted td { background: color-mix(in srgb, var(--green) 18%, var(--panel)); }
.simulation-rejected td { background: color-mix(in srgb, var(--danger) 18%, var(--panel)); }
.simulation-key { box-shadow: inset 0 -3px var(--cyan); }
.simulation-message, .simulation-status, .quiz-prompt { overflow-wrap: anywhere; }
.simulation-operation { font-weight: 700; color: var(--cyan); overflow-wrap: anywhere; padding: 12px; background: var(--panel); border-radius: 9px; }
.simulation-current { margin: 14px 0; padding: 12px; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--panel); }
.simulation-evidence-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,250px),1fr)); gap: 12px; }
.simulation-evidence-grid > section { min-width: 0; }
.simulation-output-contribution { grid-column: 1 / -1; }
.flow-card { width: 100%; text-align: left; }
.flow-description { display: block; margin-top: 10px; color: var(--muted); font-size: .82rem; line-height: 1.5; font-weight: 400; }
.simulation-evidence-detail { line-height: 1.6; overflow-wrap: anywhere; }
.simulation-relations .learning-table-wrap { max-height: 260px; min-height: 100px; overflow: auto; }
.simulation-relations > section { min-height: 180px; }
.simulation-current { min-height: 150px; }
.simulation-relations .data-table thead th { position: sticky; top: 0; z-index: 1; }
.simulation-row-state { font-weight: 700; white-space: nowrap; }
.simulation-processing td { background: color-mix(in srgb,var(--orange) 18%,var(--panel)); }
.simulation-decision { margin: 0 0 10px; }
.simulation-presenter-note { display: none; }
.presentation-mode .simulation-presenter-note { display: block; color: var(--muted); line-height: 1.5; }
.simulation-pair-note { color: var(--muted); font-size: .85rem; }
.simulation-order-map .learning-table-wrap { max-height: 240px; overflow: auto; }
.simulation-enter { animation: simulation-arrival 180ms ease-out; }
@keyframes simulation-arrival { from { opacity: .55; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
.presentation-mode .simulation-panel h3 { font-size: 1.7rem; }
.presentation-mode #sqlEditor { min-height: 200px; max-height: 260px; }
.presentation-mode #executionFlow { max-height: 300px; overflow: auto; }
.presentation-mode .simulation-operation { font-size: 1.15rem; }
.presentation-mode #simulationContainer .simulation-controls { position: sticky; top: 0; z-index: 3; padding: 10px; background: var(--panel); border-radius: 10px; }
.help-action-steps { line-height: 1.6; padding-left: 24px; }
.help-action-steps li { margin: 8px 0; }
.presentation-mode .simulation-relations .learning-table-wrap { max-height: 180px; }
.presentation-mode .simulation-evidence-grid { grid-template-columns: repeat(auto-fit,minmax(min(100%,260px),1fr)); }
.quiz-option small { color: var(--muted); white-space: nowrap; }
progress { width: 100%; height: 12px; accent-color: var(--blue); }
.help-manual { display: grid; grid-template-columns: minmax(180px, 260px) minmax(0, 1fr); gap: 20px; margin: 18px 0; }
.help-topic-nav { display: flex; flex-direction: column; gap: 7px; max-height: 65vh; overflow-y: auto; }
.help-topic-nav button { text-align: left; }
[aria-current="true"] { border-color: var(--cyan); box-shadow: inset 0 0 0 1px var(--cyan); }
#helpDetail p { line-height: 1.7; }
#helpDetail button, .quiz-feedback button, .quiz-topic-grid button { margin: 5px; }
.tutorial-cards button { margin: 5px; }
.responsive-video { aspect-ratio: 16 / 9; max-width: 900px; margin: 12px auto; }
.responsive-video iframe { display: block; width: 100%; height: 100%; border: 0; border-radius: 12px; }
.join-video-lesson { scroll-margin-top: 120px; }
.lesson-practice { display: inline-block; margin: 10px 12px 10px 0; color: var(--cyan); }
.quiz-settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); gap: 12px; }
.quiz-settings label, #interactiveHelp > label { display: grid; gap: 7px; }
.quiz-topic-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 14px; margin: 22px 0; }
.quiz-answer { margin: 16px 0; padding: 16px; border: 1px solid var(--border); border-radius: 12px; min-width: 0; }
.competitive-filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); gap: 12px; margin: 16px 0; }
.competitive-filters label { display: grid; gap: 6px; }
.competitive-filters input, .competitive-filters select { width: 100%; min-width: 0; }
.competitive-list, .references-list { display: grid; gap: 14px; }
.competitive-card { min-width: 0; overflow-wrap: anywhere; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel-alt); margin: 12px 0; }
.competitive-card h4 { margin: 8px 0; }
.competitive-meta { color: var(--muted); font-size: .9em; }
.competitive-choice { margin: 5px 0; }
.competitive-option { display: flex; gap: 9px; align-items: flex-start; padding: 8px; }
.competitive-option input { flex: 0 0 auto; }
.competitive-answer, .competitive-correct { font-weight: 700; color: var(--success, #15803d); }
.competitive-incorrect { font-weight: 700; color: var(--danger, #b42318); }
.competitive-card fieldset { min-width: 0; margin: 14px 0; }
.quiz-answer textarea { width: 100%; min-height: 130px; }
.quiz-answer input[type="text"], .quiz-answer input:not([type]) { width: 100%; }
.quiz-option { display: flex; align-items: baseline; gap: 12px; margin: 10px 0; padding: 12px; border-radius: 8px; background: var(--panel-alt); overflow-wrap: anywhere; }
.quiz-answer input[type="checkbox"], .quiz-answer input[type="radio"] { flex: 0 0 auto; width: 18px; height: 18px; accent-color: var(--blue); }
.quiz-answer fieldset { min-width: 0; border-color: var(--border); padding: 10px; }
.quiz-answer fieldset label { display: inline-flex; align-items: center; gap: 7px; margin-right: 16px; }
.quiz-answer li { margin: 10px 0; overflow-wrap: anywhere; }
.quiz-answer li button { margin: 4px; }
.quiz-code, #helpDetail pre, #quizSection pre { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 100%; padding: 12px; background: var(--panel-alt); color: var(--text); }
.quiz-feedback, .quiz-resume { margin: 18px 0; padding: 16px; border: 1px solid var(--border-strong); border-radius: 12px; background: var(--panel-alt); }
.quiz-feedback.correct { border-left: 5px solid var(--green); }
.quiz-feedback.incorrect { border-left: 5px solid var(--danger); }
.quiz-score { font-size: 1.35rem; color: var(--cyan); }
.sql-keyword { color: var(--cyan); font-weight: 700; }
.sql-string { color: var(--green); }
.sql-number { color: var(--orange); }
.walkthrough-card { position: fixed; z-index: 1000; bottom: 12px; left: 50%; transform: translateX(-50%); width: min(590px, calc(100% - 24px)); max-height: 38vh; overflow: auto; padding: 16px; border: 2px solid var(--cyan); border-radius: 14px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.walkthrough-card h3, .walkthrough-card p { margin: 7px 0; }
.walkthrough-target { outline: 4px solid var(--orange) !important; outline-offset: 4px; scroll-margin-bottom: 280px; }
@media (max-width: 800px) { .help-manual { grid-template-columns: 1fr; } .help-topic-nav { max-height: 200px; } .quiz-question-nav { max-height: 160px; overflow: auto; } }
@media (prefers-reduced-motion: reduce) { .simulation-panel *, .walkthrough-target { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }
@media print { .walkthrough-card { display: none !important; } }
