:root {
  color-scheme: dark;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
  background: #0f1115;
  color: #e8eaed;
}

* {
  box-sizing: border-box;
}

html,
body,
#root {
  margin: 0;
  height: 100%;
}

.app {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto auto 1fr;
}

.conn-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  padding: 8px 14px;
  border-bottom: 1px solid #232833;
  background: #12161d;
}

.conn-modes {
  display: flex;
  gap: 6px;
}

.conn-btn {
  border: 1px solid #2f3640;
  background: transparent;
  color: #c7ced8;
  border-radius: 8px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
}

.conn-btn:hover:not(:disabled) {
  background: #1c2230;
}

.conn-btn.active {
  background: #243147;
  border-color: #3d7eff;
  color: #fff;
}

.conn-btn:disabled {
  opacity: 0.6;
  cursor: wait;
}

.conn-status {
  flex: 1;
  min-width: 180px;
  font-size: 12px;
}

.conn-ok {
  color: #7dcea0;
}

.conn-err {
  color: #ffb4b4;
}

.conn-room {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #9aa3af;
}

.conn-room select {
  max-width: 240px;
  border: 1px solid #2f3640;
  border-radius: 8px;
  background: #0c0e12;
  color: #e8eaed;
  padding: 5px 8px;
}

.token-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr)) auto;
  gap: 8px;
  padding: 8px 14px 10px;
  border-bottom: 1px solid #232833;
  background: #0f131a;
}

.token-form input {
  border: 1px solid #2f3640;
  border-radius: 8px;
  background: #0c0e12;
  color: #e8eaed;
  padding: 7px 10px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (max-width: 1100px) {
  .token-form {
    grid-template-columns: 1fr;
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid #232833;
  background: #141820;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.muted {
  color: #9aa3af;
  font-size: 13px;
}

.ghost {
  border: 1px solid #2f3640;
  background: transparent;
  color: #e8eaed;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

.ghost:hover {
  background: #1c2230;
}

.panes {
  display: grid;
  grid-template-columns: minmax(200px, 280px) 1.2fr 1fr;
  min-height: 0;
}

.pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  border-right: 1px solid #232833;
}

.pane:last-child {
  border-right: 0;
}

.pane-label {
  padding: 8px 12px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #8b949e;
  border-bottom: 1px solid #232833;
  background: #12161d;
}

.catalog-pane {
  grid-template-rows: auto auto 1fr;
  background: #10141b;
}

.filter {
  margin: 8px 10px;
  border: 1px solid #2f3640;
  border-radius: 8px;
  background: #0c0e12;
  color: #e8eaed;
  padding: 8px 10px;
  font-size: 13px;
}

.catalog-list {
  overflow: auto;
  padding: 4px 6px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.catalog-item {
  text-align: left;
  border: 0;
  background: transparent;
  color: #c7ced8;
  border-radius: 6px;
  padding: 7px 8px;
  font-size: 12px;
  cursor: pointer;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.catalog-item:hover {
  background: #1a2130;
}

.catalog-item.active {
  background: #243147;
  color: #fff;
}

.editor-pane {
  background: #1e1e1e;
  grid-template-rows: auto 1fr;
}

.editor-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: none;
  letter-spacing: 0;
}

.tab {
  border: 1px solid #2f3640;
  background: transparent;
  color: #9aa3af;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tab:hover:not(:disabled) {
  background: #1c2230;
  color: #e8eaed;
}

.tab.active {
  background: #243147;
  border-color: #3d7eff;
  color: #fff;
}

.tab:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tab-hint {
  margin-left: auto;
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 55%;
}

.editor-error {
  margin: 8px 12px;
  max-width: none;
}

.preview-pane {
  background: #0f1115;
}

.preview-body {
  overflow: auto;
  padding: 24px;
  display: grid;
  place-items: center;
}

.stage-wrap {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.stage-meta {
  font-size: 12px;
  color: #8b949e;
  font-variant-numeric: tabular-nums;
}

.stage {
  position: relative;
  background:
    linear-gradient(45deg, #161a22 25%, transparent 25%),
    linear-gradient(-45deg, #161a22 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #161a22 75%),
    linear-gradient(-45deg, transparent 75%, #161a22 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-color: #0c0e12;
  border: 1px solid #2a3140;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  /* Contain folds position:fixed overlays inside the stage. */
  transform: translateZ(0);
  overflow: hidden;
}

.stage-canvas {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: 12px;
  display: grid;
  place-items: stretch;
  align-content: stretch;
}

.preview-frame {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 200px;
  /* Nested containing block so Overlay fixed coords map to the frame. */
  transform: translateZ(0);
  overflow: hidden;
  border-radius: 8px;
}

.preview-portal {
  position: absolute;
  inset: 0;
  z-index: 30;
  pointer-events: none;
}

.preview-portal > * {
  pointer-events: auto;
}

.handle {
  position: absolute;
  padding: 0;
  border: 0;
  background: #3d7eff;
  opacity: 0.85;
}

.handle:hover {
  opacity: 1;
}

.handle-e {
  top: 12px;
  right: -4px;
  width: 8px;
  height: calc(100% - 24px);
  cursor: ew-resize;
  border-radius: 999px;
}

.handle-s {
  left: 12px;
  bottom: -4px;
  height: 8px;
  width: calc(100% - 24px);
  cursor: ns-resize;
  border-radius: 999px;
}

.handle-se {
  right: -5px;
  bottom: -5px;
  width: 12px;
  height: 12px;
  cursor: nwse-resize;
  border-radius: 3px;
}

.error-block {
  margin: 0;
  max-width: 560px;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 14px 16px;
  border-radius: 10px;
  background: #2a1215;
  border: 1px solid #5c1f28;
  color: #ffb4b4;
  font-size: 13px;
  line-height: 1.45;
}

@media (max-width: 1100px) {
  .panes {
    grid-template-columns: 1fr;
    grid-template-rows: 180px 1fr 1fr;
  }
}
