:root {
  --bg: #000000;
  --fg: #00ff00;
  --system: #00aa00;
  --error: #ff0000;
  --highlight: #00ff00;
  --trivia: #ffff66;
  --font: "Courier New", Courier, monospace;
  --input-bar-height: 3.25rem;
  --mobile-header-height: 2.5rem;
  --mobile-toggle-height: 2.75rem;
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
}

body {
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

#app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--system);
  flex-shrink: 0;
}

.header h1 {
  margin: 0;
  font-size: 1rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.header-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
}

.room-label {
  font-size: 0.7rem;
  color: var(--highlight);
  letter-spacing: 0.08em;
}

.status {
  font-size: 0.75rem;
  color: var(--system);
}

.mobile-pane-toggle {
  display: none;
}

.terminal-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 0;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  width: 100%;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  border-right: 1px solid var(--system);
}

.system-pane {
  border-right: none;
}

.pane-label {
  font-size: 0.65rem;
  letter-spacing: 0.2em;
  padding: 0.25rem 0.5rem;
  color: var(--system);
  border-bottom: 1px solid var(--system);
  flex-shrink: 0;
}

.chat-banner-wrap {
  flex-shrink: 0;
  width: 100%;
  overflow: hidden;
  border-bottom: 1px solid var(--system);
  background: var(--bg);
}

.chat-banner {
  margin: 0;
  padding: 0.35rem 0.5rem 0.25rem;
  font-family: var(--font);
  font-size: clamp(0.45rem, 1.1vw, 0.62rem);
  line-height: 1.08;
  color: var(--fg);
  background: var(--bg);
  overflow: hidden;
  white-space: pre;
  transform-origin: top left;
  display: inline-block;
  max-width: 100%;
}

.terminal-host {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0.25rem;
  overflow: hidden;
  width: 100%;
  touch-action: pan-y;
}

.terminal-host .xterm {
  height: 100% !important;
  width: 100% !important;
}

.terminal-host .xterm .xterm-scroll-area {
  overflow: hidden;
}

.terminal-host .xterm-viewport {
  overflow-y: scroll !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

.input-bar {
  padding: 0.5rem 1rem;
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--system);
  background: var(--bg);
  flex-shrink: 0;
}

.input-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
}

.prompt {
  color: var(--highlight);
  font-weight: bold;
  flex-shrink: 0;
}

#cmd-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--fg);
  font-family: var(--font);
  font-size: 0.9rem;
  outline: none;
}

.cmd-send {
  display: none;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2.35rem;
  height: 2.35rem;
  margin: 0;
  padding: 0;
  border: 1px solid var(--highlight);
  border-radius: 50%;
  background: var(--highlight);
  color: var(--bg);
  font-family: var(--font);
  font-size: 1.15rem;
  line-height: 1;
  font-weight: bold;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-appearance: none;
  appearance: none;
}

.cmd-send:disabled {
  opacity: 0.35;
  cursor: default;
}

html.is-mobile .cmd-send {
  display: flex;
}

#cmd-input::placeholder {
  color: var(--system);
  opacity: 0.6;
}

.pane-toggle {
  flex: 1;
  margin: 0;
  padding: 0.85rem 0.5rem;
  border: none;
  border-bottom: 1px solid var(--system);
  background: var(--bg);
  color: var(--system);
  font-family: var(--font);
  font-size: 0.8rem;
  letter-spacing: 0.2em;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(0, 255, 0, 0.2);
  user-select: none;
}

.pane-toggle.active {
  color: var(--fg);
  background: color-mix(in srgb, var(--system) 15%, var(--bg));
  box-shadow: inset 0 -2px 0 var(--highlight);
}

/* ── Mobile layout (class set by JS in <head> + app.js) ── */
html.is-mobile #app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  position: relative;
}

html.is-mobile .header {
  flex: 0 0 auto;
  padding-top: max(0.5rem, env(safe-area-inset-top, 0px));
  z-index: 100;
}

html.is-mobile .mobile-pane-toggle {
  display: flex !important;
  flex: 0 0 auto;
  z-index: 200;
  background: var(--bg);
  position: relative;
}

html.is-mobile .terminal-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: block !important;
  position: relative;
  overflow: hidden;
  width: 100%;
}

html.is-mobile #chat-pane,
html.is-mobile #system-pane {
  position: absolute !important;
  top: 0;
  left: 0;
  right: 0;
  bottom: var(--input-bar-height, 3.25rem);
  display: flex !important;
  flex-direction: column !important;
  min-height: 0 !important;
  height: auto !important;
  width: 100% !important;
  border: none !important;
  overflow: hidden;
  background: var(--bg);
}

/* Default mobile view: chat only */
html.is-mobile #system-pane {
  display: none !important;
}

html.is-mobile.show-system #chat-pane {
  display: none !important;
}

html.is-mobile.show-system #system-pane {
  display: flex !important;
}

html.is-mobile .chat-banner-wrap {
  flex: 0 0 auto;
  z-index: 2;
  background: var(--bg);
}

html.is-mobile .terminal-host {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

html.is-mobile .input-bar {
  position: fixed !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  z-index: 9999 !important;
  width: 100% !important;
  margin: 0 !important;
  min-height: var(--input-bar-height, 3.25rem);
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom, 0px));
}

html.is-mobile .header h1 {
  font-size: 0.85rem;
}

html.is-mobile #cmd-input {
  font-size: 16px;
}

html.is-mobile .chat-banner {
  font-size: 0.48rem;
}

html.brimley-mode {
  --brimley-scale: 1.35;
}

html.brimley-mode .header h1,
html.brimley-mode .room-label,
html.brimley-mode .status,
html.brimley-mode .pane-label,
html.brimley-mode .pane-toggle,
html.brimley-mode .prompt,
html.brimley-mode #cmd-input,
html.brimley-mode .cmd-send {
  font-weight: 700;
}

html.brimley-mode .header h1 {
  font-size: 1.15rem;
}

html.brimley-mode .room-label,
html.brimley-mode .status {
  font-size: 0.85rem;
}

html.brimley-mode .pane-toggle {
  font-size: 0.95rem;
}

html.brimley-mode #cmd-input {
  font-size: 18px;
}

html.brimley-mode.is-mobile #cmd-input {
  font-size: 22px;
}

html.brimley-mode .chat-banner {
  font-size: clamp(0.55rem, 1.4vw, 0.78rem);
  font-weight: 700;
}

html.brimley-mode:not(.is-mobile) .chat-banner {
  font-size: clamp(0.62rem, 1.35vw, 0.95rem);
}

html.brimley-mode .pane-label {
  font-size: 0.8rem;
}

/* Desktop brimley: keep 2:1 panes locked; xterm font metrics set in JS (not CSS bold). */
html.brimley-mode:not(.is-mobile) .terminal-grid {
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
}

html.brimley-mode:not(.is-mobile) .pane,
html.brimley-mode:not(.is-mobile) .terminal-host,
html.brimley-mode:not(.is-mobile) .terminal-host .xterm {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}
