:root {
  --gap: 16px;
  --bg-0: #0f1220;
  --bg-1: #13172a;
  --panel: #161b31;
  --panel-elev: #1a2040;
  --panel-border: #27304f99;
  --ring: #5b7cfa;
  --ring-soft: #5b7cfa33;
  --text: #e7ecff;
  --muted: #9aa3c7;
  --hint: #6f7aa8;
  --accent: #6a7dff;
  --warn: #ff5d6c;

  --outer-pad: clamp(16px, 2vw, 32px);
  --panel-gap: 16px;
  --run-h: 48px;
  --run-gap: 16px;
}

* {
  box-sizing: border-box;
  scrollbar-color: #414a70 transparent;
  scrollbar-width: thin;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: var(--outer-pad);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", Arial;
  background:
    radial-gradient(1200px 700px at 10% -10%, #1b2040 0%, transparent 60%),
    radial-gradient(1000px 600px at 90% 0%, #251a42 0%, transparent 55%),
    linear-gradient(180deg, var(--bg-0), var(--bg-1));
  overflow: auto;
}

.run-button-container {
  width: 100%;
  height: var(--run-h);
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 0 var(--run-gap) 0;
}

.run-button {
  height: var(--run-h);
  width: 100px;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--accent), #3b56ff);
  box-shadow: 0 10px 20px rgba(59, 86, 255, .28);
  cursor: pointer;
  transition: transform .1s ease, filter .2s ease;
  z-index: 20;
}

.run-button:hover {
  filter: brightness(1.15);
}

.run-button:active {
  transform: translateY(2px);
}

main.layout {
  flex: 1;
  min-height: calc(100dvh - (var(--outer-pad) * 2) - var(--run-h) - var(--run-gap));
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: 1fr;
  gap: var(--panel-gap);
  max-width: none;
  margin: 0;
  align-content: stretch;
}

.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-elev));
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .03);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.panel>h2 {
  margin: 0 0 12px;
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--muted);
  border-bottom: 1px solid rgba(255, 255, 255, .05);
  padding-bottom: 10px;
}

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

.panel.editor {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, .05);
  padding-bottom: 10px;
}

.editor-header h2 {
  margin: 0;
  font-size: .95rem;
  font-weight: 700;
  color: var(--muted);
  border: 0;
  padding: 0;
}

.editor-header .actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  border: 1px solid rgba(255, 255, 255, .12);
  background: linear-gradient(180deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, .05));
  color: var(--text);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: filter .15s ease, transform .04s ease, box-shadow .2s ease;
}

.chip:hover {
  filter: brightness(1.07);
}

.chip:active {
  transform: translateY(1px);
}

.chip:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px var(--ring-soft), 0 0 0 1px var(--ring);
}

.editor-shell {
  flex: 1;
  border: 1px solid #2b3356;
  border-radius: 12px;
  background: #1e1e1e;
  overflow: hidden;
  min-height: 0;
}

#editor {
  height: 100%;
}

.editor-shell .monaco-editor,
.editor-shell .monaco-editor .overflow-guard,
.editor-shell .monaco-scrollable-element {
  border-radius: inherit;
}

#editor .minimap,
#editor .decorationsOverviewRuler {
  border-top-right-radius: inherit;
  border-bottom-right-radius: inherit;
  overflow: hidden;
}

.console-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel.console {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.console-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 0 0 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, .05);
  padding-bottom: 10px;
}

.console-header h2 {
  margin: 0;
  font-size: .95rem;
  font-weight: 700;
  letter-spacing: .02em;
  color: var(--muted);
  border: 0;
  padding: 0;
}

.btn.small {
  padding: 6px 10px;
  font-size: .8rem;
}

.term-frame {
  flex: 1;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: #000;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

.term-frame .xterm {
  width: 100% !important;
  height: 100% !important;
  padding: 10px;
  padding-right: 0;
  padding-bottom: 0;
}

.term-frame .xterm-screen {
  clip-path: inset(0 8px 0 0);
}

.term-frame .xterm-rows::after {
  content: "";
  display: block;
  height: 0;
}

.term-frame .xterm-viewport {
  pointer-events: auto;
  padding-bottom: 0 !important;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .04s ease, filter .15s ease, box-shadow .2s ease;
  outline: none;
}

.btn:focus-visible {
  box-shadow: 0 0 0 4px var(--ring-soft), 0 0 0 1px var(--ring);
}

.btn-ghost {
  color: var(--text);
  background: linear-gradient(180deg, rgba(255, 255, 255, .06), rgba(255, 255, 255, .04));
  border: 1px solid rgba(255, 255, 255, .08);
}

.btn-ghost:hover {
  filter: brightness(1.05);
}

.btn-ghost:active {
  transform: translateY(1px);
}

.btn-stop {
  color: #fff;
  background: linear-gradient(180deg, #ff4c4c, #c92424);
  box-shadow: 0 10px 20px rgba(255, 76, 76, .35);
}

.btn-stop:hover {
  filter: brightness(1.08);
}

.btn-stop:active {
  transform: translateY(1px);
}

*::-webkit-scrollbar {
  height: 10px;
  width: 10px;
}

*::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #3b4366, #323a5b);
  border-radius: 8px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-corner {
  background: transparent;
}

.console-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.console-tools .toggle {
  margin-right: 12px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  cursor: pointer;
  font-weight: 700;
  font-size: .8rem;
  color: var(--muted);
}

.toggle input {
  display: none;
}

.toggle .track {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  position: relative;
  padding: 2px;
  box-sizing: border-box;
  overflow: hidden;
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .12);
  background-clip: padding-box;
  transition: background .2s ease, border-color .2s ease;
}

.toggle .thumb {
  position: absolute;
  top: 50%;
  left: 0px;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  pointer-events: none;
  background: linear-gradient(180deg, #c5cbe9, #9aa3c7);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .35);
  transition: left .2s ease, right .2s ease, background .2s ease, box-shadow .2s ease;
}

.toggle input:checked+.track {
  background: #3b56ff;
  border-color: rgba(255, 255, 255, .20);
}

.toggle input:checked+.track .thumb {
  left: auto;
  right: 0px;
  background: #e7ecff;
}

@media (max-width:1200px) {
  :root {
    --outer-pad: clamp(12px, 3.5vw, 20px);
  }

  body {
    padding: var(--outer-pad);
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    overflow: auto;
  }

  .run-button-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: var(--run-h);
    margin: 0 0 var(--run-gap) 0;
  }

  main.layout {
    display: flex;
    flex-direction: column;
    gap: var(--panel-gap);
    height: calc(100dvh - (var(--outer-pad) * 2) - var(--run-h) - var(--run-gap));
    min-height: 0;
    margin: 0;
  }

  .editor-panel,
  .console-panel {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    min-width: 0;
  }

  .panel {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
  }

  .editor-header,
  .console-header {
    flex: 0 0 auto;
    margin: 0;
    padding-bottom: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, .05);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .editor-header .actions,
  .console-tools {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .editor-shell,
  .term-frame {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    border-radius: 12px;
  }

  #editor {
    height: 100%;
  }

  .term-frame .xterm {
    width: 100% !important;
    height: 100% !important;
  }

  .term-frame .xterm-viewport {
    height: auto !important;
    padding-bottom: 0 !important;
  }
}

.gh-btn {
  position: fixed;
  top: var(--outer-pad);
  right: var(--outer-pad);
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  color: var(--text);
  text-decoration: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, .04));
  border: 1px solid rgba(255, 255, 255, .12);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .06);
  transition: transform .06s ease, filter .15s ease, box-shadow .2s ease;
  z-index: 50;
}

.gh-btn:hover {
  filter: brightness(1.08);
}

.gh-btn:active {
  transform: translateY(1px);
}

.gh-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px var(--ring-soft), 0 0 0 1px var(--ring);
}

@media (max-width:1200px) {
  .gh-btn {
    top: var(--outer-pad);
    right: var(--outer-pad);
  }
}