* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, sans-serif;
  background: #1a1a2e;
  color: #eee;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  padding-top: env(safe-area-inset-top);
}

/* --- Status strip (top: connection dot + node name + replay) --- */
#status-strip {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  background: #16213e;
  flex-shrink: 0;
  border-bottom: 1px solid #2a2a4a;
  position: relative;
  overflow: hidden;
}
#status-strip::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--replay-pct, 0%);
  background: rgba(90, 143, 221, 0.15);
  transition: width 0.3s ease;
  pointer-events: none;
}
#status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f44;
  transition: background 0.3s, box-shadow 0.3s;
  cursor: pointer;
  flex-shrink: 0;
}
#status-dot.connected { background: #4caf50; }
#status-dot.connected.fair { background: #ffb74d; }
#status-dot.connected.poor { background: #f44336; }
#status-dot.same-network { box-shadow: 0 0 0 2.5px #1a1a2e, 0 0 0 4px #4caf50; }
#status-dot.same-network.fair { box-shadow: 0 0 0 2.5px #1a1a2e, 0 0 0 4px #ffb74d; }
#status-dot.same-network.poor { box-shadow: 0 0 0 2.5px #1a1a2e, 0 0 0 4px #f44336; }
.latency-row { display: flex; align-items: center; gap: 8px; }
#latency-chart { display: block; width: 160px; height: 32px; flex-shrink: 0; }
#latency-indicator {
  font-size: 11px;
  font-family: monospace;
  color: rgba(255,255,255,0.7);
  opacity: 0;
  white-space: nowrap;
}
#latency-indicator.active { opacity: 1; }
#webrtc-debug {
  font-size: 11px;
  font-family: monospace;
  color: rgba(138, 180, 248, 0.7);
  white-space: nowrap;
}
#replay-progress {
  font-size: 10px;
  color: rgba(138, 180, 248, 0.9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 50%;
  opacity: 0;
  transition: opacity 0.3s;
}
#replay-progress.active { opacity: 1; }
#replay-progress.cancellable { cursor: pointer; padding: 2px 6px; border-radius: 4px; }
#replay-progress.cancellable:active { background: rgba(255, 255, 255, 0.1); }
.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #aaa;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: #1e2d50; }
.icon-btn.open { color: #eee; background: #12122a; }

/* --- PIN / start screen --- */
.start-logo {
  width: 80px;
  height: 80px;
  border-radius: 18px;
  margin-bottom: 8px;
}
#start-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
#pin-input {
  font-size: 32px;
  width: 140px;
  text-align: center;
  padding: 10px;
  border: 2px solid #444;
  border-radius: 10px;
  background: #16213e;
  color: #eee;
  letter-spacing: 8px;
  font-family: monospace;
}
#pin-input::placeholder { letter-spacing: 2px; font-size: 16px; color: #556; }
#pin-error { color: #f44; font-size: 13px; display: none; }
#start-btn {
  font-size: 24px;
  padding: 20px 60px;
  border: none;
  border-radius: 12px;
  background: #0f3460;
  color: #eee;
  cursor: pointer;
}
#start-btn:active { background: #1a5276; }

/* --- Main app container (visible after connect) --- */
#app {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* --- Toggle sections (shown/hidden via status bar icons) --- */
.toggle-section {
  display: none;
  flex-shrink: 0;
  background: #12122a;
}
.toggle-section.open {
  display: flex;
  flex-direction: column;
}

/* --- Screen section --- */
#screen-body {
  touch-action: none;
}
#screen-preview-wrap {
  position: relative;
  cursor: pointer;
}
#screen-preview-img {
  width: 100%;
  display: block;
  background: #000;
  min-height: 40px;
}
#screen-preview-img:not([src]) {
  display: none;
}
#screen-play-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
#screen-preview-wrap.show-indicator #screen-play-indicator { opacity: 1; }
#screen-play-indicator svg { width: 24px; height: 24px; }
.icon-btn.streaming { color: #4caf50; }

/* --- Mode pages --- */
#carousel-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* --- Bottom toolbar --- */
#bottom-bar {
  display: flex;
  align-items: flex-start;
  padding: 4px 8px;
  padding-bottom: env(safe-area-inset-bottom);
  background: #16213e;
  flex-shrink: 0;
  border-top: 1px solid #2a2a4a;
  gap: 2px;
  position: relative;
}
.bar-left, .bar-right { flex: 1; display: flex; gap: 2px; align-items: center; }
.bar-right { justify-content: flex-end; }
.bar-center { display: flex; gap: 2px; align-items: center; }
#carousel {
  flex: 1;
  min-height: 0;
}

.carousel-page {
  width: 100%;
  height: 100%;
  display: none;
}
.carousel-page.active {
  display: flex;
}

/* Pointer / Mouse / Gestures pages: LMB + Scroll + RMB */
.buttons-page {
  flex-direction: row;
  gap: 4px;
  padding: 4px;
}
.click-btn {
  flex: 1;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  font-weight: bold;
  color: #eee;
  background: #0f3460;
  cursor: pointer;
  touch-action: none;
}
.click-btn:active, .click-btn.pressed { background: #1a5276; }

.scroll-strip {
  width: 50px;
  border: none;
  border-radius: 8px;
  background: #1a1a3e;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  touch-action: none;
}
.scroll-strip .scroll-label {
  font-size: 10px;
  color: #556;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  pointer-events: none;
}
.scroll-strip .scroll-indicator {
  position: absolute;
  width: 24px;
  height: 4px;
  background: #556;
  border-radius: 2px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  transition: top 0.1s, background 0.1s;
  pointer-events: none;
}
.scroll-strip.active .scroll-indicator { background: #88a; }

/* Pad page */
.pad-page {
  align-items: center;
  justify-content: center;
  position: relative;
  touch-action: none;
  background: #1a1a3e;
  margin: 4px;
  border-radius: 8px;
}
.pad-page .touchpad-label {
  font-size: 14px;
  color: #334;
  pointer-events: none;
}
.pad-page.drag-active {
  background: #2a1a4e;
  box-shadow: inset 0 0 20px rgba(83, 52, 131, 0.4);
}

/* Agent page */
.agent-page {
  flex-direction: column;
  padding: 8px;
  gap: 8px;
  overflow: hidden;
  touch-action: auto;
}
.agent-btn {
  padding: 10px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
}
.agent-btn:disabled { opacity: 0.4; }
.agent-btn-start { background: #2e7d32; color: #fff; }
#agent-log {
  position: relative;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  background: #0a0a1a;
  border-radius: 6px;
  padding: 6px;
  font-size: 12px;
  line-height: 1.5;
  min-height: 0;
}
.agent-log-entry {
  padding: 4px 6px;
  border-bottom: 1px solid #1a1a2e;
}
.agent-log-entry .step { color: #888; margin-right: 6px; }
.agent-log-entry .action-type { font-weight: bold; margin-right: 6px; }
.agent-log-entry .action-type.click { color: #42a5f5; }
.agent-log-entry .action-type.type { color: #66bb6a; }
.agent-log-entry .action-type.scroll { color: #ffa726; }
.agent-log-entry .action-type.key_tap { color: #ab47bc; }
.agent-log-entry .action-type.done { color: #4caf50; }
.agent-log-entry .action-type.error { color: #ef5350; }
.agent-task-header {
  padding: 6px 8px;
  margin-bottom: 4px;
  background: #1a1a2e;
  border-radius: 4px;
  color: #90caf9;
  font-size: 12px;
  font-weight: bold;
  line-height: 1.4;
  position: sticky;
  top: 0;
  z-index: 1;
}
.agent-intent {
  margin-top: 2px;
  padding-left: 2px;
  color: #999;
  font-size: 11px;
  line-height: 1.3;
}
.agent-intent.expandable { cursor: pointer; }
.agent-intent.expandable .intent-full { display: none; }
.agent-intent.expandable.expanded .intent-short { display: none; }
.agent-intent.expandable.expanded .intent-full { display: inline; }

/* Terminal page */
.terminal-page {
  flex-direction: column;
  padding: 8px;
  gap: 8px;
  overflow: hidden;
  touch-action: auto;
}
#terminal-input-bar {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
#terminal-cmd {
  flex: 1;
  padding: 8px;
  border: 1px solid #2a2a4a;
  border-radius: 6px;
  background: #0a0a1a;
  color: #0f0;
  font-size: 14px;
  font-family: monospace;
}
#terminal-cmd::placeholder { color: #556; }
#terminal-output {
  flex: 1;
  overflow-y: auto;
  background: #0a0a1a;
  border-radius: 6px;
  padding: 6px;
  font-size: 12px;
  font-family: monospace;
  line-height: 1.4;
  min-height: 0;
  color: #ccc;
}
.terminal-entry { margin-bottom: 12px; }
.terminal-entry .term-prompt { color: #0f0; font-weight: bold; }
.terminal-entry .term-stdout { color: #ccc; white-space: pre-wrap; word-break: break-all; margin: 0; }
.terminal-entry .term-stderr { color: #f55; white-space: pre-wrap; word-break: break-all; margin: 0; }
.terminal-entry .term-exit { font-size: 11px; margin-top: 2px; }
.terminal-entry .term-exit.ok { color: #4caf50; }
.terminal-entry .term-exit.fail { color: #f44; }
.terminal-entry .term-error { color: #ffa726; font-style: italic; }
.setting-text-input {
  flex: 1;
  padding: 4px 6px;
  border: 1px solid #444;
  border-radius: 4px;
  background: #1a1a2e;
  color: #eee;
  font-size: 12px;
  font-family: monospace;
}

/* --- Desktop bar --- */
#desktop-bar {
  display: none;
  padding: 6px 8px;
  background: #12122a;
  flex-shrink: 0;
  border-bottom: 1px solid #2a2a4a;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
#desktop-spaces {
  display: flex;
  gap: 6px;
  min-width: min-content;
}
.desktop-space {
  flex: 0 0 auto;
  width: 44px;
  height: 28px;
  border-radius: 4px;
  background: #1a1a3e;
  border: 1px solid #333;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  color: #556;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.desktop-space:active { background: #2a2a5e; }
.desktop-space.active {
  background: #533483;
  border-color: #7b52a8;
  color: #eee;
}

/* --- Modifier bar --- */
#modifier-body {
  border-top: 1px solid #2a2a4a;
}
#modifier-bar {
  display: flex;
  padding: 6px 8px;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: space-between;
}
.mod-group:last-child {
  margin: 0 auto;
}
.mod-group {
  display: flex;
  gap: 4px;
}
.mod-btn {
  padding: 10px 14px;
  border: 1px solid #2a2a4a;
  border-radius: 6px;
  background: #16213e;
  color: #aaa;
  font-size: 16px;
  font-weight: bold;
  cursor: pointer;
  min-width: 44px;
  text-align: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
.mod-btn:active {
  background: #1e2d50;
}
.mod-btn.mod-active {
  background: #533483;
  color: #eee;
  border-color: #7b52a8;
}
.mod-btn[data-key="esc"] {
  font-size: 11px;
  letter-spacing: 0.5px;
}
.mod-btn[data-key="enter"] {
  min-width: 56px;
  padding: 10px 18px;
}
.mod-btn.mod-clipboard {
  background: #1a2744;
  border-color: #2a3d65;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mod-btn.mod-clipboard:active { background: #2a3d65; }

/* --- Keyboard section --- */
#keyboard-body {
  touch-action: auto;
  border-top: 1px solid #2a2a4a;
}
/* --- Keyboard mode drop-up --- */
#kb-mode-dropup {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  background: #16213e;
  border: 1px solid #2a2a4a;
  border-radius: 8px;
  z-index: 10;
  overflow: hidden;
  min-width: 120px;
  margin-bottom: 4px;
}
.dropup-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: #aaa;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  text-align: left;
}
.dropup-item:active { background: #1e2d50; }
.dropup-item.active { color: #eee; background: #533483; }

.kb-mode-content { display: flex; flex-direction: column; }
#text-input-bar {
  display: flex;
  gap: 6px;
  padding: 6px 8px;
  flex-shrink: 0;
}
#text-to-type {
  width: 100%;
  box-sizing: border-box;
  padding: 8px;
  padding-bottom: 38px;
  border: 1px solid #2a2a4a;
  border-radius: 6px;
  background: #1a1a2e;
  color: #eee;
  font-size: 14px;
  font-family: -apple-system, sans-serif;
  min-height: 48px;
  max-height: 100px;
  resize: none;
}
#text-input-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}
#text-input-actions {
  position: absolute;
  bottom: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
  z-index: 1;
}
#text-action-col {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: center;
}
#send-text-btn,
#agent-send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  color: #eee;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  transition: background 0.2s, box-shadow 0.2s;
}
#send-text-btn { background: #533483; }
#agent-send-btn { background: #1a5276; }
#send-text-btn:active { background: #6c43a0; }
#agent-send-btn:active { background: #2471a3; }
#agent-send-btn.running { background: #c62828; }
#agent-send-btn.running:active { background: #e53935; }
#send-text-btn.auto-send {
  box-shadow: 0 0 0 2px #7b52a8;
}
#agent-send-btn.auto-send {
  box-shadow: 0 0 0 2px #2471a3;
}
#send-text-btn.auto-send::after,
#agent-send-btn.auto-send::after {
  content: '';
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4caf50;
}
#keyboard-keys {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#keyboard-keys .simple-keyboard {
  background: #1a1a2e;
  border-radius: 0;
  padding: 4px 2px;
}
#keyboard-keys .hg-row {
  gap: 3px;
  margin-bottom: 3px;
  min-height: 36px;
}
#keyboard-keys .hg-button {
  background: #1a1a3e;
  color: #ddd;
  border: none;
  border-radius: 4px;
  border-bottom: none;
  box-shadow: none;
  font-size: 14px;
  height: auto;
  min-height: 0;
}
#keyboard-keys .hg-button:active,
#keyboard-keys .hg-button.hg-activeButton {
  background: #533483;
  color: #fff;
}
#keyboard-keys .hg-button.hg-button-mod-active {
  background: #533483;
  color: #fff;
}
#keyboard-keys .hg-button[data-skbtn="{space}"] {
  min-width: 30%;
}

/* --- Voice recording (inline in text mode) --- */
#voice-record-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: #c62828;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}
#voice-record-btn:active { background: #e53935; }
#voice-record-btn.recording {
  background: #e53935;
  animation: voice-pulse 1.5s infinite;
}
@keyframes voice-pulse {
  0% { box-shadow: 0 0 0 0 rgba(198,40,40,0.6); }
  70% { box-shadow: 0 0 0 14px rgba(198,40,40,0); }
  100% { box-shadow: 0 0 0 0 rgba(198,40,40,0); }
}
#voice-status {
  display: block;
  font-size: 11px;
  color: #777;
  padding: 0 8px 4px;
  min-height: 0;
}
#voice-status:empty { display: none; }

/* --- Media mode --- */
#media-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 16px 8px;
}
.media-row {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: center;
}
.media-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid #2a2a4a;
  background: #1a1a2e;
  color: #ccc;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.media-btn:active { background: #533483; color: #fff; }
.media-btn-large { width: 72px; height: 72px; }
.media-btn-large svg { width: 32px; height: 32px; }

/* --- Settings panel (full-screen slide-in from right) --- */
#settings-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  background: #12122a;
  z-index: 100;
  overflow-y: auto;
  touch-action: auto;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}
#settings-overlay.open { transform: translateX(0); }
#settings-header {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: #16213e;
  border-bottom: 1px solid #2a2a4a;
  flex-shrink: 0;
  gap: 8px;
}
#settings-header .settings-title {
  font-size: 15px;
  font-weight: bold;
  color: #eee;
  flex: 1;
}
#settings-back-btn {
  border: none;
  background: transparent;
  color: #aaa;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}
#settings-back-btn:active { color: #eee; }
#settings-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
#settings-tabs {
  display: flex;
  flex-direction: row;
  gap: 2px;
  margin-bottom: 12px;
}
.settings-tab {
  flex: 1;
  padding: 6px 4px;
  border: none;
  border-radius: 4px;
  font-size: 11px;
  font-weight: bold;
  color: #888;
  background: transparent;
  cursor: pointer;
  text-align: center;
}
.settings-tab:active { background: #1e2d50; }
.settings-tab.active { color: #eee; background: #533483; }
.settings-tab-content { display: none; }
.settings-tab-content.active { display: block; }
.setting-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.setting-label {
  font-size: 12px;
  color: #aaa;
  min-width: 70px;
}
.setting-row select, .setting-row input[type="range"] {
  flex: 1;
  padding: 4px 6px;
  border: 1px solid #444;
  border-radius: 4px;
  background: #1a1a2e;
  color: #eee;
  font-size: 12px;
}
.setting-value {
  font-size: 12px;
  color: #eee;
  min-width: 30px;
  text-align: right;
  font-family: monospace;
}
.toggle-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: bold;
  color: #eee;
  background: #533483;
  cursor: pointer;
  white-space: nowrap;
}
.toggle-btn:active { background: #6c43a0; }
.toggle-btn.active { background: #2e8b57; }
.setting-divider { border-top: 1px solid #333; margin: 6px 0; }

/* --- Debug panel --- */
#debug-panel {
  display: none;
  padding: 8px 12px;
  font-size: 11px;
  font-family: monospace;
  color: #888;
  white-space: pre;
  background: #0a0a1a;
  border-bottom: 1px solid #2a2a4a;
  flex-shrink: 0;
}
#camera-debug {
  display: none;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
#camera-preview {
  width: 80px;
  height: 80px;
  border: 1px solid #444;
  border-radius: 4px;
  image-rendering: pixelated;
  display: none;
}
#camera-debug-text {
  font-size: 11px;
  font-family: monospace;
  color: #888;
  white-space: pre;
}

/* --- Touchscreen mode --- */
#touchscreen-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #000;
  z-index: 90;
}

/* Orientation-agnostic touchscreen rules */
body.touchscreen-mode #touchscreen-overlay { display: flex; }
body.touchscreen-mode #carousel-section,
body.touchscreen-mode #screen-body,
body.touchscreen-mode #status-strip {
  display: none !important;
}
body.touchscreen-mode #display-toggle { display: none; }
body.touchscreen-mode #modifier-body {
  position: fixed;
  z-index: 96;
  background: #12122a;
}
body.touchscreen-mode #keyboard-body {
  position: fixed;
  z-index: 95;
  background: #12122a;
}

/* Screen wrap */
#ts-screen-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
#ts-screen-wrap img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: auto;
}

/* Play/pause button */
#ts-play-btn {
  display: none;
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 92;
  color: #aaa;
}
body.touchscreen-mode #ts-play-btn { display: flex; }
#ts-play-btn.streaming { color: #4f4; }

/* Tap ripple */
.ts-tap-ripple {
  position: absolute;
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.6);
  pointer-events: none;
  animation: ts-ripple 0.4s ease-out forwards;
}
@keyframes ts-ripple {
  0% { transform: translate(-50%,-50%) scale(0.5); opacity: 1; }
  100% { transform: translate(-50%,-50%) scale(2); opacity: 0; }
}

/* Rotate hint */
#ts-rotate-hint {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(255,255,255,0.5);
  font-size: 14px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 91;
}
#ts-rotate-hint.visible { opacity: 1; }

/* Lock button — only visible in touchscreen mode */
#ts-lock-btn { display: none; }
body.touchscreen-mode #ts-lock-btn { display: flex; }
#ts-lock-btn.ts-locked { color: #f90; background: rgba(255,153,0,0.15); }
#ts-lock-btn.ts-locked svg path#ts-lock-shackle {
  d: path("M7 11V7a5 5 0 0 1 10 0v4");
}

/* --- Touchscreen: Portrait layout --- */
@media (orientation: portrait) {
  /* Bottom bar stays horizontal at bottom (normal flow) */
  body.touchscreen-mode #bottom-bar {
    flex-direction: row;
    border-top: 1px solid #2a2a4a;
    border-right: none;
  }
  body.touchscreen-mode .bar-left,
  body.touchscreen-mode .bar-right,
  body.touchscreen-mode .bar-center {
    flex-direction: row; gap: 2px;
  }
  body.touchscreen-mode .bar-left,
  body.touchscreen-mode .bar-right { flex: 1; }
  body.touchscreen-mode .bar-center { flex: 0; }

  /* Overlay fills available space in flex flow (not fixed) */
  body.touchscreen-mode #touchscreen-overlay {
    position: relative;
    top: auto; left: auto; right: auto; bottom: auto;
    flex: 1;
    min-height: 0;
  }

  /* Panels — normal flow, stack above bottom bar */
  body.touchscreen-mode #modifier-body {
    position: static;
    z-index: auto;
  }
  body.touchscreen-mode #keyboard-body {
    position: static;
    z-index: auto;
  }
  body.touchscreen-mode #bottom-bar {
    position: static;
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Play button — in bar, reset absolute positioning */
  body.touchscreen-mode #ts-play-btn {
    position: static;
    left: auto; top: auto;
    z-index: auto;
  }
}

/* --- Touchscreen: Landscape layout --- */
@media (orientation: landscape) {
  /* Bottom bar → left sidebar with safe-area */
  body.touchscreen-mode #bottom-bar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    right: auto;
    width: calc(48px + env(safe-area-inset-left));
    flex-direction: column;
    align-items: center;
    z-index: 91;
    border-top: none;
    border-right: 1px solid #2a2a4a;
    padding: 8px 4px;
    padding-left: env(safe-area-inset-left);
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    gap: 8px;
    background: #0a0a1a;
  }
  body.touchscreen-mode .bar-left,
  body.touchscreen-mode .bar-right,
  body.touchscreen-mode .bar-center {
    flex-direction: column; gap: 8px;
  }
  body.touchscreen-mode .bar-left { flex: 0; }
  body.touchscreen-mode .bar-center {
    flex: 1;
    justify-content: center;
  }
  body.touchscreen-mode .bar-right { margin-top: auto; flex: 0; }

  /* Overlay offset for sidebar, left-aligned */
  body.touchscreen-mode #touchscreen-overlay {
    left: calc(48px + env(safe-area-inset-left));
  }
  body.touchscreen-mode #ts-screen-wrap {
    justify-content: flex-start;
  }

  /* Play button — hidden in landscape (moved into left bar via JS) */
  body.touchscreen-mode #ts-play-btn {
    position: static;
    left: auto; top: auto;
    z-index: auto;
  }

  /* Keyboard — bottom popup, offset for left sidebar */
  body.touchscreen-mode #keyboard-body {
    bottom: 0;
    left: calc(48px + env(safe-area-inset-left));
    right: 0;
    padding-bottom: 0;
  }

  /* Modifier — right-edge vertical panel, 2-column grid */
  body.touchscreen-mode #modifier-body {
    top: 0; bottom: 0; right: 0;
    left: auto;
    overflow-y: auto;
    justify-content: center;
    padding: 8px 4px;
    padding-right: 4px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    border-left: 1px solid #2a2a4a;
    border-top: none;
  }
  body.touchscreen-mode #modifier-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  body.touchscreen-mode .mod-group {
    display: contents;
  }
  body.touchscreen-mode .mod-btn {
    padding: 10px 8px;
    font-size: 14px;
    min-width: 0;
  }

  /* Hide rotate hint */
  #ts-rotate-hint { display: none; }
}

/* --- Node picker (on PIN screen) --- */
#node-list {
  width: 100%;
  max-width: 320px;
  max-height: 40vh;
  overflow-y: auto;
  margin-bottom: 8px;
}
.node-empty {
  text-align: center;
  color: #556;
  font-size: 13px;
  padding: 16px 0;
}
.node-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin: 6px 0;
  border-radius: 10px;
  background: #16213e;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.2s, opacity 0.2s;
}
.node-card:active { background: #1a2d50; }
.node-card.selected { border-color: #4caf50; }
.node-card.offline {
  opacity: 0.4;
  cursor: not-allowed;
}
.node-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.node-status-dot.online { background: #4caf50; }
.node-status-dot.offline { background: #666; }
.node-info { flex: 1; min-width: 0; }
.node-name {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.node-caps {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 3px;
}
.node-cap {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: #0f3460;
  color: #8ab4f8;
}

/* --- Node indicator (in status strip) --- */
#node-indicator {
  font-size: 10px;
  color: rgba(255,255,255,0.7);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

/* --- Drawer backdrop --- */
#drawer-backdrop {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 199;
  opacity: 0;
  transition: opacity 0.25s ease;
}
#drawer-backdrop.visible { display: block; }
#drawer-backdrop.open { opacity: 1; }

/* --- Drawer panel --- */
#drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  background: #12122a;
  z-index: 200;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  display: flex;
  flex-direction: column;
}
#drawer.open { transform: translateX(0); }
#drawer.dragging { transition: none; }

#drawer-content {
  flex: 1;
  padding: 16px 0;
  padding-top: max(16px, env(safe-area-inset-top));
}

/* Drawer sections */
.drawer-section { padding: 14px 16px; }
.drawer-section-label {
  font-size: 10px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #556;
  margin-bottom: 10px;
}
.drawer-divider {
  height: 1px;
  background: #2a2a4a;
  margin: 0 16px;
}

/* Drawer node cards */
.drawer-node {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid transparent;
}
.drawer-node + .drawer-node { margin-top: 6px; }
.drawer-node:active { background: #1e2d50; }
.drawer-node.connected {
  background: rgba(76, 175, 80, 0.1);
  border-color: #4caf50;
}
.drawer-node.offline { opacity: 0.4; cursor: not-allowed; }
.drawer-node .srv-name {
  font-size: 13px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.drawer-node .srv-platform {
  font-size: 12px;
  flex-shrink: 0;
}

/* Drawer desktop buttons */
#drawer-desktop-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
#drawer-desktop-list .desktop-space {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  font-size: 13px;
}

/* Drawer mode icon row */
.mode-icon-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}
.drawer-mode-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  color: #aaa;
  font-size: 18px;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.drawer-mode-icon:active { background: #1e2d50; }
.mode-more-btn { color: #667; font-size: 20px; letter-spacing: 2px; }
.drawer-mode-icon.active {
  color: #eee;
  background: #533483;
}
.drawer-mode-icon svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
}
/* Show more / less link for macros & clipboard */
.drawer-show-more {
  text-align: center;
  color: #668;
  font-size: 12px;
  padding: 6px 0;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.drawer-show-more:active {
  color: #99b;
}

/* Drawer empty state */
.drawer-empty {
  color: #556;
  font-size: 12px;
  padding: 12px 0;
  text-align: center;
  font-style: italic;
}

/* Drawer top bar (branding + settings) */
.drawer-top-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.drawer-brand-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
}
.drawer-top-bar .drawer-brand {
  flex: 1;
  font-size: 16px;
  font-weight: 700;
  color: #ccd;
  letter-spacing: 0.5px;
}
.drawer-settings-row {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  color: #778;
  flex-shrink: 0;
}
.drawer-settings-row:active { background: #1e2d50; }

/* Drawer action buttons & clipboard */
.drawer-action-btn {
  background: #1e2d50;
  border: 1px solid #334;
  border-radius: 6px;
  color: #ccc;
  font-size: 12px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.drawer-action-btn:active { background: #2a3d65; }
.drawer-workspace-btn {
  margin-top: 8px;
  padding: 10px 12px;
  font-size: 13px;
  text-align: center;
  width: 100%;
}

#drawer-clipboard { position: relative; }
#drawer-clipboard-input {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
}
#drawer-clipboard-input input {
  flex: 1;
  background: #111827;
  border: 1px solid #334;
  border-radius: 6px;
  color: #ddd;
  font-size: 13px;
  padding: 6px 8px;
  outline: none;
}
#drawer-clipboard-input input::placeholder { color: #556; }
#drawer-clipboard-input input:focus { border-color: #4a9eff; }

.clipboard-item {
  background: #111827;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
}
.clipboard-item + .clipboard-item { margin-top: 6px; }
.clipboard-item:active { background: #1e2d50; }
.clipboard-selected { border-left: 3px solid #9b59b6; background: #1a1533; }
.cb-preview {
  font-size: 13px;
  color: #ddd;
  word-break: break-word;
  line-height: 1.3;
}
.cb-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 10px;
  color: #556;
}
.cb-source { flex: 1; }

/* File clipboard items */
.cb-file-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 4px;
}
.cb-thumb {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  background: #1a1a2e;
}
.cb-file-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #556;
}
.cb-file-info {
  min-width: 0;
  flex: 1;
}
.cb-filename {
  font-size: 13px;
  color: #ddd;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cb-filesize {
  font-size: 10px;
  color: #556;
}
/* Clipboard context menu */
#clipboard-context-menu {
  position: absolute;
  z-index: 200;
  background: #1e2d50;
  border: 1px solid #334;
  border-radius: 8px;
  padding: 4px 0;
  min-width: 150px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.ctx-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: #ddd;
  font-size: 13px;
  padding: 10px 16px;
  text-align: left;
  cursor: pointer;
}
.ctx-item:active { background: #2a3d65; }

/* ===========================
   Action Log (right sidebar)
   =========================== */

#actionlog-backdrop {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 199;
  opacity: 0;
  transition: opacity 0.25s ease;
}
#actionlog-backdrop.visible { display: block; }
#actionlog-backdrop.open { opacity: 1; }

#actionlog {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 300px;
  background: #12122a;
  z-index: 200;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  display: flex;
  flex-direction: column;
}
#actionlog.open { transform: translateX(0); }
#actionlog.dragging { transition: none; }

#actionlog-content {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-top: max(8px, env(safe-area-inset-top));
}

.actionlog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #2a2a4a;
}
.actionlog-title {
  font-size: 15px;
  font-weight: 600;
  color: #dde;
}

#actionlog-filters {
  display: flex;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid #2a2a4a;
}
#actionlog-filters select {
  flex: 1;
  background: #1a1a3a;
  color: #aab;
  border: 1px solid #2a2a4a;
  border-radius: 4px;
  padding: 4px;
  font-size: 11px;
  font-family: inherit;
}

#actionlog-feed {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.actionlog-entry {
  padding: 7px 12px;
  border-bottom: 1px solid #1e1e3a;
}
.al-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 2px;
}
.al-time {
  color: #667;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.al-node {
  color: #5a8fdd;
  font-size: 10px;
}
.al-source {
  color: #7a7;
  font-size: 10px;
  margin-left: auto;
}
.al-summary {
  color: #ccd;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#actionlog-load-more {
  text-align: center;
  padding: 12px;
  color: #5a8fdd;
  font-size: 13px;
  cursor: pointer;
  border-top: 1px solid #2a2a4a;
}
#actionlog-load-more:active {
  background: #1e2d50;
}

/* --- Action context line --- */
.al-context {
  color: #889;
  font-size: 10px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.al-intent {
  color: #a9a;
  font-style: italic;
}

/* --- Annotation entries --- */
.actionlog-annotation {
  padding: 5px 12px;
  font-size: 11px;
  border-bottom: 1px solid #1e1e3a;
}
.actionlog-annotation .al-time {
  color: #667;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.al-ann-icon {
  margin: 0 4px;
}
.al-ann-label {
  font-weight: 600;
}
.al-ann-text {
  color: #bbc;
}

/* Flow start/end */
.annotation-flow_start {
  background: rgba(90, 143, 221, 0.1);
  border-left: 3px solid #5a8fdd;
  color: #7ab;
}
.annotation-flow_end {
  background: rgba(90, 143, 221, 0.06);
  border-left: 3px solid #5a8fdd;
  color: #788;
}

/* Bookmark */
.annotation-bookmark {
  background: rgba(221, 180, 90, 0.1);
  border-left: 3px solid #ddb45a;
  color: #cc9;
}

/* Comment */
.annotation-comment {
  background: rgba(120, 200, 120, 0.06);
  border-left: 3px solid #7a7;
  color: #abb;
}

/* Flow range highlight */
.actionlog-flow-range {
  border-left: 3px solid rgba(90, 143, 221, 0.35);
  background: rgba(90, 143, 221, 0.04);
}

/* --- Context menu --- */
.actionlog-context-menu {
  position: absolute;
  z-index: 1010;
  background: #1a1a35;
  border: 1px solid #333;
  border-radius: 8px;
  padding: 4px 0;
  min-width: 130px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.ctx-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  color: #ccd;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.ctx-menu-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.ctx-menu-icon svg { width: 16px; height: 16px; }
.ctx-menu-item:active {
  background: #2a2a50;
}

/* --- Flow view bar --- */
#actionlog-flow-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(90, 143, 221, 0.12);
  border-bottom: 1px solid rgba(90, 143, 221, 0.25);
}
#actionlog-flow-back,
#actionlog-flow-save {
  padding: 4px 10px;
  border: 1px solid rgba(90, 143, 221, 0.4);
  border-radius: 6px;
  background: rgba(90, 143, 221, 0.15);
  color: #aac;
  font-size: 12px;
  cursor: pointer;
}
#actionlog-flow-back:active,
#actionlog-flow-save:active {
  background: rgba(90, 143, 221, 0.3);
}
#actionlog-flow-label {
  flex: 1;
  font-size: 12px;
  color: #8af;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Record button & quick macro recording --- */
.actionlog-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.actionlog-rec-btn {
  position: relative;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rec-dot {
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e53935;
}
.actionlog-rec-btn.armed .rec-dot {
  animation: pulse-rec 1s ease-in-out infinite;
}
.actionlog-rec-btn.recording .rec-dot {
  border-radius: 2px;
  box-shadow: 0 0 6px #e53935;
}
.actionlog-rec-btn.disabled {
  opacity: 0.3;
  pointer-events: none;
}
@keyframes pulse-rec {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Recording indicator bar */
#actionlog-rec-indicator {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(229, 57, 53, 0.1);
  border-bottom: 1px solid rgba(229, 57, 53, 0.25);
  font-size: 11px;
  color: #e53935;
}
#actionlog-rec-indicator .rec-dot-sm {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #e53935;
  animation: pulse-rec 1s ease-in-out infinite;
}

/* Macro preview overlay */
#macro-preview-overlay {
  position: absolute;
  inset: 0;
  background: #12122a;
  z-index: 10;
  display: none;
  flex-direction: column;
}
#macro-preview-overlay.visible {
  display: flex;
}
.macro-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid #2a2a4a;
  font-size: 15px;
  font-weight: 600;
  color: #dde;
}
#macro-preview-count {
  font-size: 12px;
  font-weight: 400;
  color: #667;
}
#macro-preview-feed {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.macro-preview-footer {
  padding: 10px;
  border-top: 1px solid #2a2a4a;
}
#macro-preview-name {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  margin-bottom: 8px;
  background: #1a1a3a;
  color: #dde;
  border: 1px solid #2a2a4a;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
#macro-preview-name:focus {
  border-color: #5a8fdd;
}
.macro-preview-buttons {
  display: flex;
  gap: 8px;
}
.macro-preview-buttons button {
  flex: 1;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  border: none;
}
#macro-preview-discard {
  background: #2a2a4a;
  color: #aab;
}
#macro-preview-discard:active {
  background: #3a3a5a;
}
#macro-preview-save {
  background: rgba(229, 57, 53, 0.2);
  color: #e53935;
  border: 1px solid rgba(229, 57, 53, 0.4);
}
#macro-preview-save:active {
  background: rgba(229, 57, 53, 0.35);
}

/* --- Drawer macro items --- */
.drawer-macro-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  cursor: pointer;
}
.drawer-macro-item:not(:last-child) {
  border-bottom: 1px solid rgba(255,255,255,0.06);
}
.drawer-macro-item:active {
  background: rgba(90, 143, 221, 0.1);
}
.macro-name {
  color: #ccd;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.macro-count {
  color: #667;
  font-size: 12px;
  margin-left: 8px;
  white-space: nowrap;
}

/* ===========================
   Workspace Manager
   =========================== */

#workspace-manager,
#workspace-chat {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  background: #0f0f23;
  z-index: 10;
}

.wm-header,
.wc-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: #12122a;
  border-bottom: 1px solid #2a2a4a;
}
.wm-title {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  color: #dde;
}
#wc-name {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: #dde;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#wm-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 12px;
}

/* Workspace card */
.workspace-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 6px;
  border-radius: 8px;
  background: #16213e;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.workspace-card:active { background: #1a2d50; }
.workspace-card.active { border-color: #4caf50; }

.ws-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #556;
}
.ws-status-dot.idle { background: #556; }
.ws-status-dot.running { background: #4caf50; }
.ws-status-dot.completed { background: #2196f3; }
.ws-status-dot.failed { background: #f44336; }
.ws-status-dot.waiting { background: #ff9800; }

.ws-card-info { flex: 1; min-width: 0; }
.ws-card-name {
  font-size: 14px;
  color: #dde;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ws-card-desc {
  font-size: 11px;
  color: #667;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Registration form */
#wm-register-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  margin: 8px 12px;
  background: #12122a;
  border-radius: 8px;
  border: 1px solid #2a2a4a;
}
#wm-register-form select,
#wm-register-form input {
  background: #111827;
  border: 1px solid #334;
  border-radius: 6px;
  color: #ddd;
  font-size: 13px;
  padding: 8px 10px;
  outline: none;
  font-family: inherit;
}
#wm-register-form input::placeholder { color: #556; }
#wm-register-form input:focus { border-color: #4a9eff; }

/* ===========================
   Workspace Chat (WYNIWYG)
   =========================== */

#wc-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wc-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}
.wc-msg.user {
  align-self: flex-end;
  background: #1a3a5c;
  color: #dde;
  border-bottom-right-radius: 4px;
}
.wc-msg.assistant {
  align-self: flex-start;
  background: #1e1e3a;
  color: #ccd;
  border-bottom-left-radius: 4px;
}

.wc-tool-group {
  margin: 4px 0;
  border-left: 2px solid #444477;
  padding-left: 6px;
}
.wc-tool-summary {
  font-size: 0.8em;
  color: #8888bb;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.wc-tool-indicator {
  font-size: 0.8em;
  color: #8888bb;
  font-style: italic;
  padding: 1px 0;
}

.wc-input-bar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: #12122a;
  border-top: 1px solid #2a2a4a;
}
.wc-input-bar textarea {
  flex: 1;
  background: #111827;
  border: 1px solid #334;
  border-radius: 8px;
  color: #ddd;
  font-size: 14px;
  padding: 8px 10px;
  outline: none;
  resize: none;
  font-family: inherit;
}
.wc-input-bar textarea::placeholder { color: #556; }
.wc-input-bar textarea:focus { border-color: #4a9eff; }
.wc-input-bar button {
  align-self: flex-end;
  padding: 8px 16px;
  background: #533483;
  border: none;
  border-radius: 8px;
  color: #eee;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.wc-input-bar button:active { background: #6a44a0; }

/* --- Macro editor (full-screen slide-in from right) --- */
#macro-editor-overlay {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 100%;
  background: #12122a;
  z-index: 101;
  touch-action: auto;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
}
#macro-editor-overlay.open { transform: translateX(0); }

#macro-editor-header {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: #16213e;
  border-bottom: 1px solid #2a2a4a;
  flex-shrink: 0;
  gap: 8px;
}
#macro-editor-back {
  border: none;
  background: transparent;
  color: #aaa;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}
#macro-editor-back:active { color: #eee; }
#macro-editor-name {
  flex: 1;
  background: #1a1a3a;
  border: 1px solid #2a2a4a;
  border-radius: 6px;
  color: #eee;
  font-size: 14px;
  padding: 6px 10px;
  font-family: inherit;
  outline: none;
}
#macro-editor-name:focus { border-color: #5a8fdd; }
#macro-editor-save {
  background: rgba(90, 143, 221, 0.2);
  color: #5a8fdd;
  border: 1px solid rgba(90, 143, 221, 0.4);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.3s, color 0.3s, border-color 0.3s;
}
#macro-editor-save:active { background: rgba(90, 143, 221, 0.35); }
#macro-editor-save.save-ok {
  background: rgba(46, 125, 50, 0.25);
  color: #66bb6a;
  border-color: rgba(46, 125, 50, 0.4);
}
#macro-editor-save.save-err {
  background: rgba(229, 57, 53, 0.2);
  color: #e53935;
  border-color: rgba(229, 57, 53, 0.4);
}
#macro-editor-save.disabled {
  opacity: 0.4;
  pointer-events: none;
}

#macro-editor-toolbar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  gap: 8px;
  border-bottom: 1px solid #1e1e3a;
  flex-shrink: 0;
}
#macro-editor-replay {
  background: #2a2a4a;
  color: #aab;
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
}
#macro-editor-replay:active { background: #3a3a5a; }
#macro-editor-step-count {
  flex: 1;
  font-size: 12px;
  color: #667;
  text-align: center;
}
#macro-editor-add-step {
  background: #2a2a4a;
  color: #aab;
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
}
#macro-editor-add-step:active { background: #3a3a5a; }
#macro-editor-optimize {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  filter: saturate(1.2);
}
#macro-editor-optimize.loading {
  opacity: 0.4;
  pointer-events: none;
  animation: me-pulse 1.2s ease-in-out infinite;
}
@keyframes me-pulse { 0%,100% { opacity: 0.4; } 50% { opacity: 0.7; } }

#macro-optimizer-preview {
  padding: 10px 14px;
  background: #161636;
  border-bottom: 1px solid #223;
}
#macro-optimizer-summary {
  font-size: 13px;
  color: #ccd;
  margin-bottom: 6px;
}
#macro-optimizer-changes {
  margin: 0 0 10px 0;
  padding-left: 18px;
  font-size: 12px;
  color: #99a;
}
#macro-optimizer-changes li { margin-bottom: 3px; }
.me-optimizer-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.me-optimizer-actions button {
  border: none;
  border-radius: 6px;
  padding: 6px 16px;
  font-size: 13px;
  cursor: pointer;
}
#macro-optimizer-reject {
  background: #2a2a4a;
  color: #aab;
}
#macro-optimizer-reject:active { background: #3a3a5a; }
#macro-optimizer-accept {
  background: rgba(76, 175, 80, 0.25);
  color: #8f8;
}
#macro-optimizer-accept:active { background: rgba(76, 175, 80, 0.4); }

#macro-editor-steps {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px 0;
}

.me-step {
  padding: 8px 12px;
  border-bottom: 1px solid #1e1e3a;
  cursor: pointer;
}
.me-step:active { background: #1a1a3a; }
.me-step.expanded { background: #161636; }

.me-step-summary {
  display: flex;
  align-items: center;
  gap: 8px;
}
.me-drag-handle {
  color: #445;
  font-size: 14px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  padding: 4px 2px;
}
.me-drag-handle:active { cursor: grabbing; color: #88a; }
.me-drag-ghost {
  position: fixed;
  z-index: 200;
  opacity: 0.85;
  background: #1e1e40;
  border: 1px solid #4a4a7a;
  border-radius: 4px;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,.5);
  padding: 8px 12px;
}
.me-drag-placeholder {
  opacity: 0.3;
}
.me-step-num {
  font-size: 11px;
  color: #556;
  min-width: 18px;
  text-align: right;
}
.me-step-label {
  flex: 1;
  font-size: 13px;
  color: #dde;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.me-step-intent {
  display: block;
  font-size: 11px;
  color: #778;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.me-step-delay {
  font-size: 11px;
  color: #667;
  white-space: nowrap;
}
.me-step-actions {
  display: flex;
  gap: 6px;
}
.me-step-btn {
  border: none;
  background: #1e1e3a;
  color: #889;
  font-size: 16px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 6px;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.me-step-btn:active { background: #3a3a5a; color: #dde; }

.me-step-detail {
  padding: 8px 0 4px 26px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.me-step-detail .me-field {
  display: flex;
  align-items: center;
  gap: 8px;
}
.me-label {
  font-size: 11px;
  color: #667;
  min-width: 50px;
}
.me-input {
  flex: 1;
  background: #1a1a3a;
  border: 1px solid #2a2a4a;
  border-radius: 4px;
  color: #eee;
  font-size: 12px;
  padding: 4px 8px;
  font-family: inherit;
  outline: none;
}
.me-input:focus { border-color: #5a8fdd; }
.me-select {
  background: #1a1a3a;
  border: 1px solid #2a2a4a;
  border-radius: 4px;
  color: #eee;
  font-size: 12px;
  padding: 4px 8px;
  font-family: inherit;
  outline: none;
}

/* Add-step form */
#macro-editor-add-form {
  padding: 10px 12px;
  border-top: 1px solid #2a2a4a;
  background: #161636;
  flex-shrink: 0;
}
.me-add-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.me-add-row select {
  flex: 1;
  background: #1a1a3a;
  border: 1px solid #2a2a4a;
  border-radius: 4px;
  color: #eee;
  font-size: 13px;
  padding: 6px 8px;
  font-family: inherit;
  outline: none;
}
#macro-editor-action-params {
  margin-bottom: 8px;
}
#macro-editor-action-params .me-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
#macro-editor-add-delay {
  width: 80px;
  background: #1a1a3a;
  border: 1px solid #2a2a4a;
  border-radius: 4px;
  color: #eee;
  font-size: 12px;
  padding: 4px 8px;
  font-family: inherit;
  outline: none;
}
.me-add-buttons {
  display: flex;
  gap: 8px;
}
.me-add-buttons button {
  flex: 1;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
}
#macro-editor-add-cancel {
  background: #2a2a4a;
  color: #aab;
}
#macro-editor-add-cancel:active { background: #3a3a5a; }
#macro-editor-add-confirm {
  background: rgba(229, 57, 53, 0.2);
  color: #e53935;
  border: 1px solid rgba(229, 57, 53, 0.4);
}
#macro-editor-add-confirm:active { background: rgba(229, 57, 53, 0.35); }

.me-empty {
  text-align: center;
  color: #556;
  padding: 40px 20px;
  font-size: 13px;
}

/* ---- Parametrized macro modal ---- */
#macro-params-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
}
#macro-params-backdrop.open { display: block; }
#macro-params-modal {
  display: none;
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: #1a1a3a;
  border-radius: 12px;
  padding: 20px;
  width: 320px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  z-index: 201;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
#macro-params-modal.open { display: block; }
.mp-title {
  font-size: 15px;
  font-weight: 600;
  color: #e0e0e0;
  margin-bottom: 16px;
}
#macro-params-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.mp-field-label {
  font-size: 12px;
  color: #8899aa;
  margin-bottom: 4px;
}
.mp-field-input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #2a2a4a;
  background: #12122a;
  color: #e0e0e0;
  font-size: 14px;
  outline: none;
}
.mp-field-input:focus { border-color: #5a8fdd; }
.mp-buttons {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  justify-content: flex-end;
}
.mp-buttons button {
  padding: 8px 20px;
  border-radius: 6px;
  border: none;
  font-size: 13px;
  cursor: pointer;
}
#macro-params-cancel {
  background: #2a2a4a;
  color: #aaa;
}
#macro-params-run {
  background: #5a8fdd;
  color: #fff;
}
#macro-params-cancel:active { background: #3a3a5a; }
#macro-params-run:active { background: #4a7fcc; }

/* ---- Macro editor parameters section ---- */
#macro-editor-params {
  padding: 8px 10px;
  border-bottom: 1px solid #2a2a4a;
}
.me-params-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.me-section-title {
  font-size: 11px;
  color: #8899aa;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
#macro-editor-add-param {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid #2a2a4a;
  background: #1a1a3a;
  color: #8899aa;
  cursor: pointer;
}
#macro-editor-add-param:active { background: #2a2a4a; }
.me-param-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.me-param-row input {
  flex: 1;
  min-width: 0;
  padding: 5px 7px;
  border-radius: 4px;
  border: 1px solid #2a2a4a;
  background: #12122a;
  color: #e0e0e0;
  font-size: 12px;
  outline: none;
}
.me-param-row input:focus { border-color: #5a8fdd; }
.me-param-delete {
  background: none;
  border: none;
  color: #e53935;
  font-size: 16px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
#macro-editor-param-hints {
  font-size: 11px;
  color: #c89b3c;
  padding-top: 4px;
}

/* --- Cloud auth (Clerk sign-in on start screen) --- */
#clerk-auth-container {
  width: 100%;
  max-width: 380px;
  min-height: 200px;
  display: flex;
  justify-content: center;
}
.cloud-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: #16213e;
  border-radius: 10px;
}
.cloud-user-name {
  font-size: 14px;
  color: #cdd6f4;
}
.cloud-btn-small {
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid #444;
  border-radius: 6px;
  background: transparent;
  color: #aaa;
  cursor: pointer;
}
.cloud-btn-small:active { background: #2a2a4a; }
.cloud-btn-secondary {
  font-size: 16px;
  padding: 12px 32px;
  border: 2px solid #0f3460;
  border-radius: 10px;
  background: transparent;
  color: #5a8fdd;
  cursor: pointer;
}
.cloud-btn-secondary:active { background: #0f3460; color: #eee; }
.cloud-btn-primary {
  font-size: 20px;
  padding: 16px 48px;
  border: none;
  border-radius: 10px;
  background: #0f3460;
  color: #eee;
  cursor: pointer;
}
.cloud-btn-primary:active { background: #1a5276; }

/* --- Dashboard overlay --- */
#dashboard-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #12122a;
  z-index: 200;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  touch-action: auto;
}
.overlay-header {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: #16213e;
  border-bottom: 1px solid #2a2a4a;
  flex-shrink: 0;
  gap: 8px;
  font-size: 15px;
  font-weight: bold;
}
.back-btn {
  border: none;
  background: transparent;
  color: #aaa;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}
.dashboard-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.dashboard-section h3 {
  font-size: 16px;
  color: #cdd6f4;
  margin-bottom: 6px;
}
.dashboard-hint {
  font-size: 13px;
  color: #888;
  margin-bottom: 12px;
}
.api-key-list { display: flex; flex-direction: column; gap: 8px; }
.api-key-empty {
  font-size: 13px;
  color: #666;
  padding: 12px;
  text-align: center;
}
.api-key-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: #16213e;
  border-radius: 8px;
}
.api-key-info { display: flex; flex-direction: column; gap: 2px; }
.api-key-item-name { font-size: 14px; color: #cdd6f4; }
.api-key-date { font-size: 11px; color: #666; }
.api-key-revoke-btn {
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid #e53935;
  border-radius: 6px;
  background: transparent;
  color: #e53935;
  cursor: pointer;
}
.api-key-revoke-btn:active { background: #e53935; color: #fff; }
.api-key-create {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.api-key-create input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid #444;
  border-radius: 8px;
  background: #16213e;
  color: #eee;
  font-size: 14px;
}
.api-key-create input::placeholder { color: #556; }
.api-key-create button,
#api-key-copy-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  background: #0f3460;
  color: #eee;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}
.api-key-create button:active,
#api-key-copy-btn:active { background: #1a5276; }
.api-key-created {
  margin-top: 12px;
  padding: 12px;
  background: #1a3a2e;
  border: 1px solid #2e7d32;
  border-radius: 8px;
}
.api-key-created p {
  font-size: 13px;
  color: #a5d6a7;
  margin-bottom: 8px;
}
.api-key-created code {
  display: block;
  font-size: 12px;
  font-family: monospace;
  color: #eee;
  background: #0a1a0e;
  padding: 8px;
  border-radius: 4px;
  word-break: break-all;
  margin-bottom: 8px;
}
.download-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.download-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #16213e;
  border-radius: 8px;
  color: #5a8fdd;
  text-decoration: none;
  font-size: 14px;
}
.download-link:active { background: #1e2d4e; }
.download-icon { font-size: 20px; }
.setup-steps {
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
  color: #aaa;
}
.setup-steps li { line-height: 1.4; }

