* {
  box-sizing: border-box;
}

:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-soft: #f1f4f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #f97316;
  --accent-strong: #ea580c;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
  --mono: "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace;
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.floating-back {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 1200;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-weight: 600;
}

.floating-back:hover {
  background: var(--surface-soft);
}

.sagecell-bridge {
  position: fixed;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  left: -100vw;
  top: -100vh;
}

.app {
  max-width: 100%;
  margin: 0 auto;
  padding: 56px 24px 28px;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.eyebrow {
  letter-spacing: 0.2em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--accent-strong);
  font-weight: 700;
  margin: 0 0 8px;
}

.topbar h1 {
  margin: 0;
  font-size: 34px;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
}

.status-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 18px;
  min-width: 200px;
  display: grid;
  gap: 6px;
  box-shadow: var(--shadow);
  text-align: right;
}

.status-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 16px;
}

.icon-link:hover {
  background: var(--surface);
}

.status-card .label {
  font-size: 12px;
  color: var(--muted);
}

.status-card strong {
  font-size: 18px;
  color: var(--text);
}

.status-meta {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
}

.status-card .hint {
  font-size: 12px;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 20px;
  align-items: stretch;
  min-height: calc(100vh - 150px);
}

.editor,
.output {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-header h2 {
  margin: 0;
  font-size: 18px;
}

.panel-hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.status-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress {
  position: relative;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  overflow: hidden;
  display: none;
}

.progress.show {
  display: block;
}

.progress-bar {
  position: absolute;
  top: 0;
  left: -40%;
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, var(--accent), var(--accent-strong));
  animation: progress-indeterminate 1.2s infinite ease-in-out;
}

@keyframes progress-indeterminate {
  0% {
    left: -40%;
  }
  100% {
    left: 100%;
  }
}

.run-status {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  padding: 6px 10px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.elapsed {
  font-size: 12px;
  color: var(--muted);
}

textarea {
  width: 100%;
  height: 360px;
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  font-family: var(--mono);
  font-size: 14px;
  resize: none;
  flex: 1;
}

.CodeMirror {
  height: 360px;
  font-family: var(--mono);
  font-size: 14px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  line-height: 1.4;
}

.CodeMirror-scroll {
  padding: 6px 0;
}

.CodeMirror-lines,
.CodeMirror-line {
  line-height: 1.4;
}

.helper {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.info-box {
  background: #fef3c7;
  border: 1px solid #fbbf24;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  color: #78350f;
  margin: 0;
  display: grid;
  gap: 6px;
}

.info-box strong {
  display: block;
  margin-bottom: 4px;
}

.info-box code {
  background: rgba(0, 0, 0, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 12px;
}

#tipText {
  display: block;
  min-height: 20px;
}

.validation {
  margin: 0;
  font-size: 12px;
  color: #b45309;
  min-height: 16px;
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.quick-search-wrap {
  position: relative;
}

.quick-search {
  display: grid;
  gap: 6px;
  margin-top: 2px;
}

.quick-search span {
  font-size: 12px;
  color: var(--muted);
}

.quick-search input {
  width: 100%;
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
}

.quick-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.2);
}

.quick-example-results {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 280px;
  overflow: auto;
  padding: 8px;
  gap: 8px;
}

.quick-example-results.show {
  display: grid;
}

.quick-example-item {
  width: 100%;
  text-align: left;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  box-shadow: none;
  color: var(--text);
  display: grid;
  gap: 3px;
}

.quick-example-item:hover {
  background: var(--bg);
  border-color: var(--accent);
}

.quick-example-item.active {
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.2);
}

.quick-example-item strong {
  font-size: 13px;
}

.quick-example-item span {
  font-size: 11px;
  color: var(--accent-strong);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.quick-example-item p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.quick-example-empty {
  padding: 10px;
  font-size: 12px;
  color: var(--muted);
}

.controls .select {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface-soft);
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.controls select {
  border: none;
  background: transparent;
  font-size: 12px;
  color: var(--text);
  outline: none;
}

button {
  background: linear-gradient(120deg, var(--accent), var(--accent-strong));
  border: none;
  color: white;
  padding: 10px 20px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(249, 115, 22, 0.25);
}

button:hover {
  filter: brightness(0.98);
}

button.secondary {
  background: #0f172a;
  box-shadow: none;
}

button.ghost {
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#status {
  font-size: 14px;
  color: var(--accent-strong);
}

.tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}

.tab {
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 6px 10px;
  border-radius: 8px;
  box-shadow: none;
  font-weight: 600;
}

.tab.active {
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--border);
}

.tab-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.tab-panels {
  display: grid;
  gap: 12px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}


.tab-panels pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface-soft);
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  min-height: 120px;
  max-height: none;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12px;
}

.CodeMirror pre {
  background: transparent;
  padding: 0;
  border: 0;
  border-radius: 0;
  min-height: auto;
  max-height: none;
  overflow: visible;
  font-family: inherit;
  font-size: inherit;
  line-height: 1.4;
}

pre.stderr {
  border-color: rgba(234, 88, 12, 0.35);
  color: #b45309;
}

.plot-area {
  background: var(--surface-soft);
  border: 1px dashed rgba(249, 115, 22, 0.4);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.plot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.plot-header h3 {
  margin: 0;
  font-size: 14px;
}

.plot-status {
  font-size: 12px;
  color: var(--muted);
}

.plot-actions {
  display: flex;
  justify-content: flex-end;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 10px;
}

.gallery button {
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: none;
}

.gallery img {
  width: 100%;
  height: 90px;
  object-fit: cover;
  display: block;
}



.files ul {
  padding-left: 16px;
  margin: 8px 0 0;
}

.files a {
  color: var(--accent-strong);
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.lightbox.show {
  display: flex;
}

.lightbox-content {
  background: var(--surface);
  border-radius: 16px;
  padding: 16px;
  max-width: 90vw;
  max-height: 90vh;
  display: grid;
  gap: 12px;
}

.lightbox-content img {
  max-width: 85vw;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 40;
}

.modal[aria-hidden="false"] {
  display: flex;
}

.session-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 60;
}

.session-overlay[aria-hidden="false"] {
  display: flex;
}

.session-overlay-card {
  width: min(520px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px;
  text-align: center;
  display: grid;
  gap: 10px;
}

.session-overlay-card h2 {
  margin: 0;
  font-size: 24px;
}

.session-overlay-card p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.modal-content {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  max-width: 900px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 20px;
}

.examples-list {
  display: grid;
  gap: 16px;
}

.examples-layout {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(0, 1fr);
  gap: 18px;
}

.examples-menu {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  height: fit-content;
  position: sticky;
  top: 0;
}

.examples-menu h3 {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.examples-menu-list {
  display: grid;
  gap: 8px;
}

.examples-menu-item {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.examples-menu-item.active {
  background: rgba(249, 115, 22, 0.15);
  border-color: var(--accent);
  color: var(--accent-strong);
}

.examples-content {
  min-width: 0;
}

.examples-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.examples-search {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.examples-search input {
  width: min(360px, 100%);
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.examples-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.2);
}

.example-item {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.example-item:hover {
  background: var(--bg);
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(249, 115, 22, 0.1);
}

.example-item h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--text);
}

.example-description {
  margin: 0 0 10px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.45;
}

.example-item code {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  max-height: 80px;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

.resources-list {
  display: grid;
  gap: 12px;
}

.resource-item {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
}

.resource-item a {
  color: var(--accent-strong);
  font-weight: 600;
  text-decoration: none;
}

.resource-item p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .grid {
    grid-template-columns: 1fr;
  }
  .status-card {
    text-align: left;
  }
  .controls {
    flex-wrap: wrap;
    justify-content: flex-start;
  }
}

@media (max-width: 900px) {
  .examples-layout {
    grid-template-columns: 1fr;
  }

  .examples-menu {
    position: static;
  }
}
