:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --ink: #10233a;
  --muted: #4f6178;
  --accent: #00796b;
  --accent-2: #0f4c81;
  --line: #ced8e5;
  --console-bg: #ffffff;
  --console-ink: #10233a;
  --editor: #ffffff;
  --editor-ink: #10233a;
  --error: #a61b1b;
  --ide-code-font-size: 0.95rem;
  --ide-console-font-size: 0.92rem;
  --ide-variables-font-size: 0.84rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, #dff6f2 0%, transparent 28%),
    radial-gradient(circle at 88% 5%, #e1eefb 0%, transparent 32%),
    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: linear-gradient(120deg, #0a6f63, #0d5f93);
  color: #f7fffe;
  border-radius: 16px;
  padding: 0.9rem 1rem;
  box-shadow: 0 10px 24px rgba(13, 95, 147, 0.24);
}

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

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

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.6rem;
  min-width: 2.6rem;
  padding: 0.55rem;
}

.icon-button svg {
  width: 1.1rem;
  height: 1.1rem;
  stroke: currentColor;
  stroke-width: 2.2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button[hidden] {
  display: none !important;
}

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

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

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

button:disabled {
  cursor: not-allowed;
  background: repeating-linear-gradient(
    -45deg,
    #8b95a5,
    #8b95a5 10px,
    #a3acba 10px,
    #a3acba 20px
  );
  color: #eef2f7;
  transform: none;
  filter: none;
  opacity: 1;
}

button.is-active {
  background: linear-gradient(180deg, #f59e0b, #d97706);
  color: #fffdf5;
  box-shadow: inset 0 0 0 2px rgba(255, 248, 220, 0.4), 0 0 0 2px rgba(245, 158, 11, 0.25);
}

button.is-active:hover {
  filter: brightness(1.03);
}

#runBtn {
  background: linear-gradient(135deg, #ffb703, #fb8500);
  padding: 0.74rem 1.28rem;
  font-weight: 800;
  color: #1f1300;
  box-shadow: 0 12px 24px rgba(251, 133, 0, 0.34);
  border: 1px solid rgba(140, 60, 0, 0.22);
}

#runBtn:hover {
  filter: brightness(1.04);
  transform: translateY(-2px);
}

#runBtn:focus-visible {
  outline: 3px solid rgba(255, 245, 214, 0.95);
  outline-offset: 2px;
}

#debugStartBtn,
#debugStepBtn,
#debugStopBtn {
  background: var(--error);
}

#debugStartBtn {
  margin-left: 0.85rem;
  position: relative;
}

#debugStartBtn::before {
  content: "";
  position: absolute;
  left: -0.48rem;
  top: 18%;
  width: 1px;
  height: 64%;
  background: rgba(247, 255, 254, 0.55);
  pointer-events: none;
}

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

#saveToCloudBtn {
  background: var(--accent-2);
}

#saveToCloudBtn:hover {
  filter: brightness(1.1);
}

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

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

body.popup-mode {
  overflow: hidden;
}

body.popup-mode .app-shell,
body.standalone-mode .app-shell {
  max-width: none;
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 1rem;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

body.popup-mode .workspace,
body.standalone-mode .workspace {
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, 0.9fr);
  align-items: stretch;
  min-height: 0;
}

body.popup-mode .panel,
body.standalone-mode .panel {
  min-height: 0;
  max-height: none;
  height: 100%;
}

body.popup-mode .reference,
body.standalone-mode .reference {
  max-width: none;
  min-height: 0;
  overflow: auto;
}

body.popup-mode .download-bar,
body.standalone-mode .download-bar {
  padding: 0.5rem 0 0;
  flex-wrap: wrap;
}

.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(180deg, #eef3f9, #e2ebf6);
}

.panel-title-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.text-size-controls {
  display: inline-flex;
  gap: 0.35rem;
}

.text-size-btn {
  min-width: 2rem;
  padding: 0.25rem 0.4rem;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid #c8d7e8;
  color: #29405d;
  font-weight: 700;
  box-shadow: none;
}

.text-size-btn:hover {
  background: #f8fbff;
}

.text-size-glyph {
  font-size: 0.95rem;
  line-height: 1;
}

.text-size-glyph.small {
  font-size: 0.8rem;
}

.text-size-mark {
  font-size: 0.7rem;
  vertical-align: super;
  margin-left: 0.05rem;
}

.editor-tabs {
  display: flex;
  gap: 0.15rem;
  padding: 0.45rem 0.55rem 0;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #f8fafc, #edf3fa);
  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 #ced8e5;
  border-bottom: 1px solid #9bb2cf;
  background: linear-gradient(180deg, #f5f9ff, #e7eef8);
  color: #29405d;
  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: #9bb2cf;
  border-bottom-color: #ffffff;
  background: #ffffff;
  color: #10233a;
  position: relative;
  z-index: 2;
}

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

.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 #ced8e5;
  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;
  overflow-x: auto;
  overflow-y: 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: var(--ide-code-font-size);
  line-height: 1.45;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  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: #ffffff;
}

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

.file-view {
  grid-column: 2;
  margin: 0;
  height: 100%;
  overflow: auto;
  overflow-x: auto;
  overflow-y: auto;
  padding: 0.9rem;
  border: 0;
  outline: none;
  resize: none;
  background: #ffffff;
  color: #111827;
  font-family: "JetBrains Mono", "Fira Code", "Menlo", monospace;
  font-size: var(--ide-code-font-size);
  line-height: 1.45;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  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 #d8e2f0;
  text-align: right;
  color: #7b91ae;
  background: #f1f6fc;
  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: #dff3ff;
  color: #0f4c81;
  border-right: 2px solid #0f4c81;
}

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

.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: var(--ide-code-font-size);
  line-height: 1.45;
}

.token-keyword {
  color: #0f4c81;
  font-weight: 600;
}

.token-builtin {
  color: #00796b;
}

.token-number {
  color: #9a5500;
}

.token-string {
  color: #0f7a43;
}

.token-comment {
  color: #7289a7;
  font-style: italic;
}

.token-operator {
  color: #10233a;
}

.autocomplete {
  position: absolute;
  z-index: 4;
  min-width: 180px;
  max-width: 320px;
  max-height: 220px;
  overflow: auto;
  border: 1px solid #ced8e5;
  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: #e5f3ff;
}

.autocomplete-item-variable {
  color: #0f4c81;
  font-weight: 650;
}

#console {
  margin: 0;
  padding: 0.9rem;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  background: var(--console-bg);
  color: var(--console-ink);
  border-top: 1px solid #eef3f8;
  font-family: "JetBrains Mono", "Fira Code", monospace;
  font-size: var(--ide-console-font-size);
  line-height: 1.45;
}

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

.variables-panel {
  border-top: 1px solid #d9e4ef;
  background: #f8fbfe;
  color: #10233a;
  min-height: 0;
}

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

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

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

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

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

.download-pdf-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 1px solid #0f4c81;
  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(15, 76, 129, 0.24);
  min-width: 180px;
  text-align: center;
}

.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: #eef5fc;
}

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

.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 #ced8e5;
  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: #0f6f8a;
  color: #f8fafc;
}

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

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

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