:root {
  --bg: #0e1014;
  --surface: #181b22;
  --line: #2a2e38;
  --text: #f5f6f8;
  --muted: #c2c6d0;
  --faint: #9aa0ad;
  --hover: #1e222b;
  --active: #262b36;
  --python: #e4bc3c;
  --js: #8eb8d0;
  --ok: #7fd4a4;
  --err: #f08b8b;
  --warn: #e0c075;
  --focus: #b4bccb;
  --mono: "Cascadia Code", "SF Mono", "JetBrains Mono", ui-monospace, Consolas, monospace;
  --sans: "Segoe UI Variable", "Segoe UI", ui-sans-serif, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

@media (min-width: 841px) {
  html,
  body {
    overflow: hidden;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  height: 100%;
  display: grid;
  grid-template-rows: 48px minmax(0, 1fr) minmax(300px, 0.85fr);
}

.topbar,
.pane-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  padding: 0 14px;
}

.topbar {
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding-right: 16px;
  border-right: 1px solid var(--line);
}

.logo {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.badge {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.picker {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 360px;
}

.picker select {
  width: 100%;
  appearance: none;
  background: var(--surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%237a7f8c' d='M1 1.5l5 5 5-5'/></svg>") no-repeat right 10px center;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 28px 6px 10px;
  font: inherit;
  outline: none;
}

.picker select:hover {
  background-color: var(--hover);
}

.picker select:focus-visible {
  border-color: var(--focus);
}

.actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
  font-size: 13px;
}

.status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
}

.status.ok::before {
  background: var(--ok);
}

.status.err::before {
  background: var(--err);
}

.status.ok {
  color: var(--ok);
}

.status.err {
  color: var(--err);
}

button {
  border: 0;
  border-radius: 8px;
  padding: 6px 12px;
  background: var(--text);
  color: var(--bg);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

button:hover {
  filter: brightness(0.94);
}

button:focus-visible,
.text-btn:focus-visible,
.file-tab:focus-visible {
  outline: 1px solid var(--focus);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
  filter: none;
}

kbd {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: #5c616c;
  background: transparent;
}

.text-btn,
.file-tab {
  background: transparent;
  color: var(--text);
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 6px;
}

.text-btn:hover,
.file-tab:hover {
  color: var(--text);
  background: var(--hover);
  filter: none;
}

.text-btn[aria-pressed="true"] {
  color: var(--text);
  background: var(--active);
}

.file-tab[aria-pressed="true"] {
  color: var(--text);
  background: transparent;
  box-shadow: inset 0 -1px 0 #c9cdd6;
}

.workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
}

.pane,
.console-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.pane-py {
  border-right: 1px solid var(--line);
}

.pane-head {
  border-bottom: 1px solid var(--line);
}

.pane-head h2,
.console-panel .pane-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--text);
}

.pane-py .pane-head h2 {
  color: var(--python);
}

.pane-js .pane-head h2 {
  color: var(--js);
}

.file-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  min-width: 0;
  flex: 1 1 auto;
}

.file-tab {
  font-family: var(--mono);
  font-size: 12px;
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta {
  margin-left: auto;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.pane-py .pane-head #runBtn {
  order: 5;
}

.pane-py .pane-head .meta {
  order: 4;
}

textarea,
.output,
.console,
.diagnostics {
  margin: 0;
  padding: 14px 16px;
  border: 0;
  resize: none;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  background: transparent;
  color: var(--text);
  font: 15px/1.65 var(--mono);
  outline: none;
  overflow: auto;
  white-space: pre;
  tab-size: 4;
}

textarea::selection,
.output::selection,
.console::selection {
  background: #2a3144;
}

.output {
  color: var(--text);
}

.output.placeholder,
.console.empty {
  color: var(--text);
  opacity: 0.8;
  white-space: pre-wrap;
}

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

.diagnostics {
  flex: 0 1 auto;
  max-height: 28%;
  padding: 0;
  border-top: 1px solid var(--line);
  background: #120f10;
}

.diag {
  display: grid;
  grid-template-columns: auto auto 1fr;
  gap: 10px;
  width: 100%;
  padding: 8px 16px;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font: 12px/1.45 var(--mono);
  font-weight: 400;
  text-align: left;
  cursor: pointer;
  white-space: normal;
}

.diag + .diag {
  border-top: 1px solid var(--line);
}

.diag:hover {
  background: var(--hover);
  filter: none;
}

.diag-sev {
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.diag.error .diag-sev {
  color: var(--err);
}

.diag.warning .diag-sev {
  color: var(--warn);
}

.diag-code,
.diag-where {
  color: var(--muted);
  font-size: 13px;
}

.diag-msg {
  grid-column: 1 / -1;
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

.console-panel {
  border-top: 1px solid var(--line);
  background: #161922;
}

.console {
  color: #f7f8fa;
  font-size: 15px;
}

@media (max-width: 840px) {
  .app {
    height: auto;
    min-height: 100%;
    grid-template-rows: auto auto auto;
  }

  .topbar {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "brand actions"
      "picker picker";
    height: auto;
    padding: 10px 12px;
    gap: 8px 12px;
  }

  .brand {
    grid-area: brand;
    padding-right: 0;
    border-right: 0;
  }

  .actions {
    grid-area: actions;
    margin-left: 0;
  }

  .picker {
    grid-area: picker;
    max-width: none;
  }

  #runHint,
  .meta {
    display: none;
  }

  .pane-py .pane-head #runBtn {
    order: 1;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .pane-py {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    min-height: 280px;
  }

  .pane-js {
    min-height: 220px;
  }

  .console-panel {
    min-height: 280px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
