:root {
  --bg: #f4f1e8;
  --panel: #fffdf7;
  --ink: #1f1b18;
  --accent: #0f766e;
  --accent-2: #0ea5e9;
  --line: #dad2c5;
  --console-bg: #111827;
  --console-ink: #d1fae5;
  --error: #ef4444;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 20%, #fef3c7 0%, transparent 35%),
    radial-gradient(circle at 80% 85%, #cffafe 0%, transparent 30%),
    var(--bg);
}

.app-shell {
  max-width: 1300px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  gap: 0.9rem;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem 1rem;
}

.toolbar h1 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: 0.01em;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 0.55rem 0.85rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--accent);
  color: #ffffff;
  transition: transform 120ms ease, filter 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  background: #9ca3af;
  color: #e5e7eb;
  transform: none;
  filter: none;
}

#debugStartBtn,
#debugStepBtn,
#debugStopBtn {
  background: #b91c1c;
}

#debugStartBtn:hover,
#debugStepBtn:hover,
#debugStopBtn:hover {
  filter: brightness(1.08);
}

.workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9rem;
}

.panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 65vh;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: var(--panel);
}

.editor-panel {
  grid-template-rows: auto auto 1fr;
}

.panel-title {
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
  font-weight: 700;
  background: linear-gradient(90deg, #ffffff, #f8fafc);
}

.editor-tabs {
  display: flex;
  gap: 0.15rem;
  padding: 0.45rem 0.55rem 0;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #f8fafc, #eef2f7);
  overflow-x: auto;
  scrollbar-width: none;
}

.editor-tabs::-webkit-scrollbar {
  display: none;
}

.editor-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  border: 1px solid #cbd5e1;
  border-bottom: 1px solid #94a3b8;
  background: linear-gradient(180deg, #f8fafc, #e2e8f0);
  color: #334155;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  padding: 0.32rem 0.72rem;
  font-size: 0.8rem;
  font-weight: 650;
  white-space: nowrap;
  transform: none;
  filter: none;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
  margin-bottom: -1px;
}

.file-tab {
  padding: 0;
}

.editor-tab.active {
  border-color: #94a3b8;
  border-bottom-color: #fffefb;
  background: #fffefb;
  color: #0f172a;
  position: relative;
  z-index: 2;
}

.editor-tab:hover,
.editor-tab:active {
  transform: none;
  filter: none;
  background: linear-gradient(180deg, #ffffff, #e8eef5);
}

.file-tab-open,
.file-tab-close {
  border: 0;
  background: transparent;
  color: inherit;
  transform: none;
  filter: none;
  cursor: pointer;
  margin: 0;
}

.file-tab-open {
  padding: 0.32rem 0.45rem 0.32rem 0.72rem;
  font-size: 0.8rem;
  font-weight: 650;
}

.file-tab-close {
  padding: 0.2rem 0.5rem 0.2rem 0.4rem;
  font-size: 0.84rem;
  line-height: 1;
  border-left: 1px solid #cbd5e1;
  color: #64748b;
}

.file-tab-close:hover,
.file-tab-close:active {
  background: #fee2e2;
  color: #991b1b;
  transform: none;
  filter: none;
}

.editor-body {
  position: relative;
  min-height: 0;
}

#editor {
  grid-column: 2;
  overflow: auto;
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  resize: none;
  border: 0;
  outline: none;
  padding: 0.9rem;
  font-family: "JetBrains Mono", "Fira Code", "Menlo", monospace;
  font-size: 0.95rem;
  line-height: 1.45;
  background: transparent;
  color: transparent;
  caret-color: #111827;
  tab-size: 4;
}

.code-editor {
  position: relative;
  height: 100%;
  display: grid;
  grid-template-columns: 3.6rem 1fr;
  background: #fffefb;
}

.file-editor {
  height: 100%;
  display: grid;
  grid-template-columns: 3.6rem 1fr;
  background: #fffefb;
}

.file-view {
  grid-column: 2;
  margin: 0;
  height: 100%;
  overflow: auto;
  padding: 0.9rem;
  border: 0;
  outline: none;
  resize: none;
  background: #fffefb;
  color: #111827;
  font-family: "JetBrains Mono", "Fira Code", "Menlo", monospace;
  font-size: 0.95rem;
  line-height: 1.45;
  tab-size: 4;
}

.hidden {
  display: none;
}

.line-numbers {
  grid-column: 1;
  margin: 0;
  padding: 0.9rem 0.45rem 0.9rem 0;
  border-right: 1px solid #e5e7eb;
  text-align: right;
  color: #94a3b8;
  background: #f8fafc;
  overflow: hidden;
  user-select: none;
}

.line-number {
  display: block;
  padding-right: 0.05rem;
  cursor: pointer;
}

.line-number.breakpoint {
  background: #fee2e2;
  color: #991b1b;
  border-right: 2px solid #ef4444;
}

.line-number.current-debug {
  background: #dbeafe;
  color: #1d4ed8;
  border-right: 2px solid #2563eb;
}

.file-line-numbers {
  background: #f8fafc;
}

.highlight-layer {
  position: absolute;
  top: 0;
  left: 3.6rem;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 0.9rem;
  overflow: hidden;
  pointer-events: none;
  white-space: pre;
}

.line-numbers,
.highlight-layer {
  font-family: "JetBrains Mono", "Fira Code", "Menlo", monospace;
  font-size: 0.95rem;
  line-height: 1.45;
}

.token-keyword {
  color: #7c3aed;
  font-weight: 600;
}

.token-builtin {
  color: #0369a1;
}

.token-number {
  color: #b45309;
}

.token-string {
  color: #15803d;
}

.token-comment {
  color: #64748b;
  font-style: italic;
}

.token-operator {
  color: #1f2937;
}

.autocomplete {
  position: absolute;
  z-index: 4;
  min-width: 180px;
  max-width: 320px;
  max-height: 220px;
  overflow: auto;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 10px 25px rgba(2, 8, 23, 0.16);
}

.autocomplete-item {
  padding: 0.35rem 0.55rem;
  font-family: "JetBrains Mono", "Fira Code", "Menlo", monospace;
  font-size: 0.86rem;
  color: #0f172a;
  cursor: pointer;
  white-space: nowrap;
}

.autocomplete-item:hover,
.autocomplete-item.active {
  background: #e0f2fe;
}

#console {
  margin: 0;
  padding: 0.9rem;
  overflow: auto;
  background: var(--console-bg);
  color: var(--console-ink);
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 0.92rem;
  line-height: 1.45;
}

.console-stack {
  display: grid;
  grid-template-rows: 1fr 170px;
  min-height: 0;
}

.variables-panel {
  border-top: 1px solid #334155;
  background: #0b1220;
  color: #bfdbfe;
  min-height: 0;
}

.variables-title {
  padding: 0.35rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: #93c5fd;
  border-bottom: 1px solid #1e293b;
}

#variablesView {
  margin: 0;
  padding: 0.55rem 0.65rem;
  overflow: auto;
  height: calc(100% - 30px);
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: 0.84rem;
  line-height: 1.35;
}

.error {
  color: var(--error);
}

.reference {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffffd4;
  padding: 0.5rem 0.6rem;
  font-size: 0.9rem;
}

.download-bar {
  display: flex;
  justify-content: center;
  padding: 0.35rem 0 0.2rem;
}

.download-pdf-btn {
  background: linear-gradient(180deg, #dc2626, #b91c1c);
  border: 1px solid #7f1d1d;
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  padding: 0.75rem 1.35rem;
  border-radius: 12px;
  box-shadow: 0 8px 18px rgba(127, 29, 29, 0.28);
}

.download-pdf-btn:hover {
  filter: brightness(1.1);
}

.reference-collapsible > summary {
  cursor: pointer;
  list-style: none;
  font-weight: 700;
  padding: 0.35rem 0.45rem;
  border-radius: 8px;
}

.reference-collapsible > summary:hover {
  background: #f1f5f9;
}

.reference-collapsible[open] > summary {
  margin-bottom: 0.5rem;
  background: #ecfeff;
}

.ref-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.45rem 0 0.7rem;
  font-size: 0.84rem;
  table-layout: fixed;
}

.ref-table th,
.ref-table td {
  border: 1px solid #cbd5e1;
  padding: 0.35rem 0.45rem;
  vertical-align: top;
  text-align: left;
  overflow-wrap: anywhere;
}

.ref-table th:nth-child(1),
.ref-table td:nth-child(1) {
  width: 24%;
}

.ref-table th:nth-child(2),
.ref-table td:nth-child(2) {
  width: 31%;
}

.ref-table th:nth-child(3),
.ref-table td:nth-child(3) {
  width: 45%;
}

.ref-table th {
  background: #0f766e;
  color: #f8fafc;
}

.ref-table td code {
  font-size: 0.8rem;
}

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

  .panel {
    min-height: 48vh;
  }
}
