:root {
  --wb-blue: #0055aa;
  --wb-blue-deep: #003366;
  --wb-grey: #aaaaaa;
  --wb-grey-light: #dddddd;
  --wb-orange: #ff8800;
  --wb-ink: #111111;
  --panel: #c0c0c0;
  --editor-bg: #f4f4f0;
  --out-bg: #001133;
  --out-fg: #88ff88;
  --font-ui: "IBM Plex Sans", "Segoe UI", sans-serif;
  --font-code: "IBM Plex Mono", "Consolas", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: var(--font-ui);
  color: var(--wb-ink);
  background:
    linear-gradient(180deg, var(--wb-blue) 0%, var(--wb-blue-deep) 100%);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.65rem 1rem;
  background: var(--panel);
  border-bottom: 3px solid #666;
  box-shadow: inset 0 1px 0 #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: inherit;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 1.05rem;
}

.brand-logo {
  display: block;
  height: 2.4rem;
  width: auto;
  image-rendering: auto;
  flex-shrink: 0;
}

.brand-text {
  white-space: nowrap;
}

.brand-js {
  color: var(--wb-blue-deep);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}

label {
  font-size: 0.85rem;
}

select,
button {
  font-family: var(--font-ui);
  font-size: 0.9rem;
}

select {
  min-width: 16rem;
  padding: 0.25rem 0.4rem;
  border: 2px solid #444;
  background: #fff;
}

button {
  padding: 0.3rem 0.85rem;
  border: 2px solid #333;
  background: var(--wb-grey-light);
  cursor: pointer;
  box-shadow: inset 1px 1px 0 #fff, inset -1px -1px 0 #777;
}

button:active {
  box-shadow: inset 1px 1px 0 #777;
}

button.primary {
  background: var(--wb-orange);
  font-weight: 600;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.main {
  --split-editor: 48%;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0.6rem;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 2px solid #222;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-title {
  margin: 0;
  padding: 0.35rem 0.55rem;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--wb-blue);
  color: #fff;
  border-bottom: 2px solid #222;
}

.editor-panel {
  flex: 0 0 var(--split-editor);
  min-height: 8rem;
  max-height: calc(100% - 8rem - 0.45rem);
}

.output-panel {
  flex: 1 1 auto;
  min-height: 8rem;
}

/* INKEY$ / SLEEP key capture — real text field so iOS/Android open a soft keyboard. */
.inkey-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.55rem;
  background: #1a1a3a;
  border-top: 2px solid #222;
}

.inkey-bar[hidden] {
  display: none !important;
}

.inkey-label {
  flex: 0 0 auto;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--wb-orange, #ffaa00);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.inkey-capture {
  flex: 1 1 auto;
  min-width: 0;
  /* 16px avoids iOS focus zoom */
  font-size: 16px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  padding: 0.45rem 0.55rem;
  border: 2px solid #444;
  border-radius: 2px;
  background: #0d0d24;
  color: #f0f0ff;
}

.inkey-capture::placeholder {
  color: #8888aa;
  font-size: 0.85rem;
}

.inkey-capture:focus {
  outline: none;
  border-color: var(--wb-orange, #ffaa00);
  box-shadow: 0 0 0 1px var(--wb-orange, #ffaa00);
}

.splitter {
  flex: 0 0 0.45rem;
  position: relative;
  z-index: 2;
  margin: 0.1rem 0;
  border-radius: 2px;
  background:
    linear-gradient(180deg, #888 0%, var(--wb-grey) 45%, #666 100%);
  box-shadow: inset 0 1px 0 #ddd, inset 0 -1px 0 #444;
  cursor: row-resize;
  touch-action: none;
}

.splitter::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2.2rem;
  height: 0.15rem;
  transform: translate(-50%, -50%);
  background: #333;
  border-radius: 1px;
  box-shadow: 0 -3px 0 #333, 0 3px 0 #333;
  opacity: 0.55;
}

.splitter:hover,
.splitter:focus-visible,
body.split-dragging .splitter {
  background: var(--wb-orange);
  outline: none;
}

body.split-dragging {
  cursor: row-resize;
  user-select: none;
}

body.split-dragging * {
  cursor: row-resize !important;
}

#source {
  flex: 1;
  width: 100%;
  border: 0;
  resize: none;
  padding: 0.6rem 0.75rem;
  font-family: var(--font-code);
  font-size: 0.92rem;
  line-height: 1.4;
  background: var(--editor-bg);
  color: #111;
}

/* Intuition screens / windows (Phase 4) */
.screens {
  flex: 1;
  min-height: 12rem;
  overflow: auto;
  padding: 0.5rem;
  background:
    repeating-linear-gradient(
      45deg,
      #004488 0,
      #004488 8px,
      #003366 8px,
      #003366 16px
    );
  border-bottom: 2px solid #222;
}

.screens[hidden] {
  display: none !important;
}

.screens:focus {
  outline: none;
}

.screens:focus-visible {
  outline: 2px solid var(--amber, #ffaa00);
  outline-offset: -2px;
}

.ace-screen {
  position: relative;
  margin: 0 auto;
  border: 2px solid #111;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
  overflow: hidden;
  background: var(--wb-blue);
}

.ace-window {
  position: absolute;
  display: flex;
  flex-direction: column;
  min-width: 80px;
  min-height: 40px;
  background: var(--wb-grey-light);
  border: 2px solid #111;
  box-shadow: 1px 1px 0 #fff inset, -1px -1px 0 #666 inset;
  z-index: 2;
}

.ace-window.borderless {
  border: 0;
  box-shadow: none;
  background: transparent;
}

.ace-window.backdrop {
  z-index: 1;
  pointer-events: none;
}

.ace-titlebar {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  height: 18px;
  padding: 0 0.2rem;
  background: linear-gradient(180deg, #0066cc 0%, var(--wb-blue) 100%);
  border-bottom: 1px solid #001133;
  cursor: default;
  user-select: none;
}

.ace-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #fff;
  font-family: var(--font-code);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.ace-gadget {
  width: 16px;
  height: 16px;
  min-width: 16px;
  min-height: 16px;
  padding: 0;
  border: 1px solid #111;
  background: var(--wb-grey-light);
  box-shadow: inset 1px 1px 0 #fff, inset -1px -1px 0 #777;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  z-index: 3;
}

.ace-gadget:active {
  box-shadow: inset 1px 1px 0 #777;
}

.ace-close {
  background:
    linear-gradient(135deg, transparent 45%, #222 45%, #222 55%, transparent 55%),
    linear-gradient(45deg, transparent 45%, #222 45%, #222 55%, transparent 55%),
    var(--wb-grey-light);
  background-size: 100% 100%;
}

.ace-depth {
  background:
    linear-gradient(#222, #222) center/60% 2px no-repeat,
    var(--wb-grey-light);
}

.ace-window-body {
  flex: 1;
  position: relative;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ace-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
  z-index: 0;
}

.ace-content {
  flex: 1;
  margin: 0;
  padding: 0.25rem 0.35rem;
  overflow: auto;
  font-family: var(--font-code);
  font-size: 0.75rem;
  line-height: 1.25;
  color: #fff;
  background: transparent;
  white-space: pre-wrap;
  word-break: break-word;
  position: relative;
  z-index: 1;
}

.ace-committed {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100%;
  white-space: pre;
}

.ace-text-run {
  position: absolute;
  display: inline-block;
  font-family: var(--font-code);
  font-size: 8px;
  line-height: 8px;
  white-space: pre;
  pointer-events: none;
}

/* Live INPUT draft positioned at the window text pen (inline after prompt). */
.ace-committed .live-input.ace-inline-draft,
.ace-committed .caret.ace-inline-draft {
  position: absolute;
  display: inline-block;
  font-family: var(--font-code);
  font-size: 8px;
  line-height: 8px;
  white-space: pre;
  margin: 0;
  z-index: 2;
}

.ace-committed .live-input.ace-inline-draft {
  color: #fff;
  background: transparent;
}

.ace-committed .caret.ace-inline-draft {
  width: 8px;
  height: 8px;
  margin-left: 0;
  vertical-align: top;
  background: #fff;
}

.ace-content .live-input {
  color: inherit;
}

.ace-content .caret {
  background: currentColor;
}

.ace-content.awaiting-input {
  cursor: text;
  box-shadow: inset 0 0 0 2px var(--wb-orange);
}

.ace-window.borderless .ace-content {
  background: transparent;
  color: #fff;
  pointer-events: none;
}

/* INPUT needs hit-testing so click-to-focus reaches the draft chrome. */
.ace-window.borderless .ace-content.awaiting-input {
  pointer-events: auto;
}

.ace-window.borderless .ace-content .live-input {
  color: #fff;
}

.ace-window.borderless .ace-content .caret {
  background: #fff;
}

.output-panel.intui-active .console {
  max-height: 30%;
}

/* While INPUT is mounted in a window, tuck the empty CLI console away. */
.output-panel.input-in-window .console {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
  border: 0;
  flex: 0;
}

/* Single shell surface: PRINT output + in-place INPUT (Amiga CLI feel). */
.console {
  position: relative;
  flex: 1;
  margin: 0;
  padding: 0.6rem 0.75rem;
  overflow: auto;
  font-family: var(--font-code);
  font-size: 0.9rem;
  line-height: 1.35;
  background: var(--out-bg);
  color: var(--out-fg);
  cursor: text;
}

.console:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--wb-orange);
}

.console.awaiting-input:focus,
.console.awaiting-input:focus-within {
  box-shadow: inset 0 0 0 2px var(--wb-orange);
}

.console-output {
  display: inline;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  white-space: pre-wrap;
  word-break: break-word;
}

.live-input {
  display: inline;
  color: #eeffee;
  white-space: pre-wrap;
}

.caret {
  display: inline-block;
  width: 0.55em;
  margin-left: 1px;
  background: var(--out-fg);
  vertical-align: text-bottom;
  height: 1.05em;
  animation: caret-blink 1s step-end infinite;
}

.caret[hidden] {
  display: none !important;
}

@keyframes caret-blink {
  50% {
    opacity: 0;
  }
}

/* Mirror field for IME / mobile; typed text is shown in .live-input. */
.console-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  margin: 0;
  clip: rect(0 0 0 0);
  overflow: hidden;
}

.status {
  padding: 0.35rem 1rem 0.55rem;
  font-size: 0.8rem;
  color: #e8e8ff;
}

.status[data-kind="error"] {
  color: #ffcc88;
}

@media (min-width: 900px) {
  .main {
    flex-direction: row;
  }

  .editor-panel {
    flex: 0 0 var(--split-editor);
    min-width: 12rem;
    max-width: calc(100% - 12rem - 0.45rem);
    min-height: 0;
    max-height: none;
  }

  .output-panel {
    flex: 1 1 auto;
    min-width: 12rem;
    min-height: 0;
  }

  .splitter {
    margin: 0 0.1rem;
    cursor: col-resize;
  }

  .splitter::after {
    width: 0.15rem;
    height: 2.2rem;
    box-shadow: -3px 0 0 #333, 3px 0 0 #333;
  }

  body.split-dragging {
    cursor: col-resize;
  }

  body.split-dragging * {
    cursor: col-resize !important;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: stretch;
  }

  .brand-text {
    display: none;
  }

  .brand-logo {
    height: 2.1rem;
  }

  .controls {
    width: 100%;
  }

  select {
    flex: 1;
    min-width: 0;
  }
}
