*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f0f2f5;
  --surface: #fff;
  --border: #d8dee6;
  --text: #1a1a2e;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #e5e7eb;
  --error: #dc2626;
  --header-h: 56px;
  --banner-h: 40px;
}

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
}

.logo {
  color: var(--primary);
  font-size: 18px;
}

.tag {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #eff6ff;
  color: var(--primary);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.select-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.select-wrap select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  font-size: 13px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:not(:disabled):hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--secondary);
  color: var(--text);
}

.btn-secondary:hover {
  background: #d1d5db;
}

.upload-btn {
  cursor: pointer;
}

.load-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: var(--banner-h);
  background: #fef3c7;
  color: #92400e;
  font-size: 13px;
}

.load-banner.hidden {
  display: none;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #fcd34d;
  border-top-color: #92400e;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: calc(100vh - var(--header-h) - var(--banner-h) - 32px);
  gap: 0;
}

body.loaded .workspace {
  height: calc(100vh - var(--header-h) - 32px);
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
}

.editor-panel {
  border-right: 1px solid var(--border);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  flex-shrink: 0;
}

.hint {
  font-weight: 400;
  font-size: 12px;
}

.CodeMirror {
  flex: 1;
  height: auto !important;
  font-family: "Cascadia Code", "Consolas", "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
}

.output-area {
  flex: 1;
  overflow: auto;
  padding: 14px;
}

.stdout {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 13px;
  line-height: 1.55;
}

.stderr {
  margin: 12px 0 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Cascadia Code", "Consolas", monospace;
  font-size: 13px;
  color: var(--error);
  line-height: 1.55;
}

.stderr:empty {
  display: none;
}

.plots {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 12px;
}

.plots img {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
}

.btn-text {
  border: none;
  background: none;
  color: var(--primary);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
}

.btn-text:hover {
  text-decoration: underline;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 32px;
  padding: 0 16px;
  font-size: 12px;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.file-list {
  font-family: monospace;
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .editor-panel {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .toolbar {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
}
