:root {
  --ink: #19152a;
  --muted: #716a80;
  --purple: #4b2f8e;
  --deep: #1d113e;
  --line: #ddd6ea;
  --surface: #f5f2fb;
  --green: #167a4c;
  --red: #a22d3d;
  --console: #15121f;
  --editor: #1b1727;
  --editor-gutter: #15121f;
  --shadow: 0 16px 40px rgba(35, 22, 69, 0.12);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(circle at 10% -5%, rgba(120, 89, 198, 0.16), transparent 30rem),
    linear-gradient(#faf8fd, #f0edf7);
}
button, select, input, textarea { font: inherit; }

.skip-link {
  position: fixed;
  transform: translateY(-150%);
  z-index: 99;
  background: #fff;
  padding: 0.7rem;
  border-radius: 8px;
}
.skip-link:focus { transform: none; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 2.5vw, 2rem);
  color: #fff;
  background: linear-gradient(135deg, var(--deep), #56359d);
  box-shadow: 0 8px 28px rgba(29, 17, 62, 0.22);
}
.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 2px solid #ffffffa8;
  border-radius: 14px 14px 18px 10px;
  background: #ffffff1f;
  font: 800 1.25rem ui-monospace;
  transform: rotate(-2deg);
}
.brand-name { font-size: clamp(1.3rem, 2.5vw, 1.75rem); font-weight: 800; }
.brand-subtitle { font-size: 0.82rem; color: #ffffffc7; margin-top: 0.15rem; }

.examples { display: flex; align-items: end; gap: 0.5rem; }
.examples label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.7rem;
  font-weight: 750;
  text-transform: uppercase;
  color: #ffffffb8;
}
.examples select {
  min-height: 42px;
  min-width: 180px;
  border: 1px solid #ffffff40;
  border-radius: 10px;
  background: #ffffff20;
  color: #fff;
  padding: 0.5rem;
}
.examples option { color: #222; background: #fff; }

main { width: min(1800px, 100%); margin: auto; padding: clamp(0.75rem, 2vw, 1.4rem); }
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffffd9;
  box-shadow: 0 8px 24px #23164512;
}
.buttons { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.58rem 0.9rem;
  font-weight: 750;
  cursor: pointer;
}
.button:disabled { opacity: 0.45; cursor: not-allowed; }
.run { color: #fff; background: linear-gradient(135deg, #1c8c5a, var(--green)); }
.stop { color: var(--red); border-color: #f1bcc4; background: #ffe5e8; }
.secondary { color: #35216c; border-color: var(--line); background: #fff; }
.topbar .secondary { color: #fff; border-color: #ffffff40; background: #ffffff20; }
.input { color: #fff; background: var(--purple); }

.runtime { display: flex; align-items: center; gap: 0.55rem; color: var(--muted); font-size: 0.88rem; font-weight: 650; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #7859c6; box-shadow: 0 0 0 4px #7859c61c; }
.dot.loading, .dot.running { animation: pulse 1.2s infinite; }
.dot.ready { background: #1c8c5a; }
.dot.error { background: var(--red); }
@keyframes pulse { 50% { transform: scale(1.12); opacity: 0.65; } }

.workspace {
  display: grid;
  grid-template-columns: minmax(390px, 0.95fr) minmax(470px, 1.2fr);
  gap: 0.9rem;
  min-height: calc(100dvh - 205px);
}
.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
}
.panel > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 50px;
  padding: 0.55rem 0.8rem;
  border-bottom: 1px solid var(--line);
  color: #26184f;
}
.panel > header span { font-size: 0.78rem; color: var(--muted); text-align: right; }

.editor-shell {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  min-height: 440px;
  flex: 1;
  background: var(--editor);
  overflow: hidden;
}
.editor-stack { position: relative; min-width: 0; min-height: 440px; overflow: hidden; background: var(--editor); }
#lines, #highlight, #editor {
  margin: 0;
  border: 0;
  border-radius: 0;
  font: clamp(13.5px, 1.3vw, 16px) / 1.62 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  tab-size: 4;
  white-space: pre;
  font-variant-ligatures: none;
  letter-spacing: normal;
}
#lines {
  min-width: 3.2rem;
  overflow: hidden;
  padding: 1rem 0.75rem 2rem 0.5rem;
  background: var(--editor-gutter);
  color: #776f8b;
  text-align: right;
  user-select: none;
}
#highlight, #editor {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 1rem 1rem 2rem;
}
#highlight {
  z-index: 1;
  overflow: hidden;
  color: #f3eefc;
  background: var(--editor);
  pointer-events: none;
  user-select: none;
}
#editor {
  z-index: 2;
  resize: none;
  overflow: auto;
  outline: none;
  background: transparent;
  color: transparent;
  -webkit-text-fill-color: transparent;
  caret-color: #f8f5ff;
  text-shadow: none;
}
#editor::selection { background: rgba(143, 117, 209, 0.42); }
#editor:focus { box-shadow: inset 0 0 0 2px rgba(189, 168, 244, 0.18); }

.tok-keyword, .tok-operator { color: #ff79c6; }
.tok-string { color: #f1fa8c; }
.tok-number, .tok-constant { color: #bd93f9; }
.tok-comment { color: #7f8799; }
.tok-builtin { color: #8be9fd; }
.tok-function, .tok-class { color: #50fa7b; }
.tok-decorator, .tok-special { color: #ffb86c; }
.tok-special { color: #9fb6ff; font-style: italic; }

.editor-panel > footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem 0.8rem;
  padding: 0.45rem 0.8rem;
  background: var(--editor-gutter);
  color: #9d94b2;
  font-size: 0.72rem;
}
.editor-panel > footer code { color: #d6c8fa; font-family: ui-monospace, monospace; }

.outputs {
  display: grid;
  grid-template-rows: minmax(290px, 1.05fr) minmax(210px, 0.75fr);
  gap: 0.7rem;
  min-height: 0;
  flex: 1;
  padding: 0.7rem;
  background: var(--surface);
}
.turtle-card, .console-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  min-height: 38px;
  padding: 0.45rem 0.7rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.75rem;
  color: #26184f;
}
.subhead span { color: var(--muted); text-align: right; }
.canvas { min-height: 0; flex: 1; }
.canvas svg { display: block; width: 100%; height: 100%; min-height: 250px; }
.small-grid { fill: none; stroke: #eeeaf5; stroke-width: 0.7; }
.large-grid { fill: none; stroke: #ded7ec; stroke-width: 1; }
#cursor path {
  fill: var(--purple);
  stroke: #fff;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  filter: drop-shadow(0 2px 2px #1d113e55);
}

.console-card { background: var(--console); border-color: #2c263a; }
.console-card .subhead { background: #1d1928; border-color: #302a40; color: #e3dbf2; }
.console-card .subhead span { color: #938aa9; }
#console {
  min-height: 110px;
  flex: 1;
  overflow: auto;
  padding: 0.75rem 0.85rem 1.25rem;
  color: #ece8f7;
  background: var(--console);
  font: clamp(12.5px, 1.2vw, 14.5px) / 1.52 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.system { color: #aaa1bf; }
.error { color: #ff9aa7; }
.echo { color: #a9e7c5; }
.success { color: #92e1b7; }
#stdin {
  padding: 0.65rem 0.75rem 0.75rem;
  border-top: 1px solid #332c42;
  background: #1d1928;
  color: #d8d0e8;
  font-size: 0.8rem;
}
#stdin > div { display: grid; grid-template-columns: 1fr auto; gap: 0.45rem; margin-top: 0.4rem; }
#stdin input {
  min-width: 0;
  min-height: 42px;
  border: 1px solid #5d526f;
  border-radius: 9px;
  padding: 0.55rem 0.65rem;
  background: #12101a;
  color: #fff;
}

.page-footer {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 0.3rem 1.2rem;
  padding: 0 1rem calc(0.75rem + env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}
#toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 50;
  max-width: min(380px, calc(100vw - 2rem));
  border: 1px solid #dcd1f5;
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  background: #fff;
  color: #26184f;
  box-shadow: var(--shadow);
  font-weight: 650;
}

@media (max-width: 1050px) {
  .workspace { grid-template-columns: 1fr; min-height: auto; }
  .outputs { min-height: 620px; }
}

@media (max-width: 700px) {
  .topbar, .toolbar { align-items: flex-start; flex-direction: column; }
  .examples { width: 100%; }
  .examples label { flex: 1; }
  .examples select { width: 100%; min-width: 0; }
  .buttons { width: 100%; }
  .buttons .button { flex: 1; }
  .workspace { gap: 0.7rem; }
  .editor-shell, .editor-stack { min-height: 390px; }
  .editor-panel > footer { flex-direction: column; }
  .outputs { min-height: 590px; grid-template-rows: minmax(270px, 1fr) minmax(250px, 0.9fr); }
  .page-footer { flex-direction: column; }
}
