/*
 * App shell: top bar, workspace, the code editor used by editor fields, the
 * stage, transport, and controls the editor reuses, and the shortcut sheet.
 * Only tokens from tokens.css are used here.
 */

.app {
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

/* Top bar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 0 var(--space-3) 0 var(--space-4);
  border-bottom: var(--hairline) solid var(--border);
  background: var(--bg);
  position: relative;
  z-index: var(--z-panel);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.topbar-left {
  gap: var(--space-5);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text);
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
  white-space: nowrap;
}

.wordmark:hover {
  text-decoration: none;
}

/* The Qubibyte mark, as the site's favicon. */
.wordmark-mark {
  width: calc(var(--space-5) + 2px);
  height: calc(var(--space-5) + 2px);
  object-fit: contain;
  flex: none;
}

/* White on the dark interface, as the site's navbar logo is. */
:root:not([data-ui-theme='light']) .wordmark-mark {
  filter: brightness(0) invert(1);
}

.topbar .btn-icon,
.btn .btn-icon {
  display: inline-flex;
}

.topbar-select select {
  max-width: var(--select-max-w);
}

/* Workspace and modes */

.workspace {
  min-height: 0;
  position: relative;
}

.mode {
  height: 100%;
  min-height: 0;
}

/* Code editor */

.ce {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  overflow: hidden;
  font-family: var(--font-code);
  font-size: var(--code-size);
  line-height: var(--code-line);
  background: var(--surface);
}

.ce-gutter {
  position: relative;
  overflow: hidden;
  padding: var(--space-3) 0;
  min-width: var(--space-10);
  color: var(--text-faint);
  text-align: right;
  user-select: none;
}

.ce-gutter-inner {
  padding: 0 var(--space-3) 0 var(--space-4);
  will-change: transform;
}

.ce-ln {
  height: var(--code-line);
  position: relative;
  font-variant-numeric: tabular-nums;
}

.ce-ln.is-active {
  color: var(--text-muted);
}

.ce-ln.has-error::before,
.ce-ln.has-warning::before {
  content: '';
  position: absolute;
  left: var(--space-1);
  top: 50%;
  width: var(--space-1);
  height: var(--space-1);
  margin-top: calc(-1 * var(--space-0));
  border-radius: var(--radius-full);
  background: var(--danger);
}

.ce-ln.has-warning::before {
  background: var(--warning);
}

.ce-main {
  position: relative;
  overflow: hidden;
}

.ce-layer {
  position: absolute;
  left: 0;
  top: 0;
  min-width: 100%;
  will-change: transform;
}

.ce-hl,
.ce-ta {
  margin: 0;
  padding: var(--space-3) var(--space-6) var(--space-12) var(--space-2);
  font-family: var(--font-code);
  font-size: var(--code-size);
  line-height: var(--code-line);
  letter-spacing: 0;
  tab-size: 2;
  white-space: pre;
  font-variant-ligatures: none;
}

.ce-hl {
  position: relative;
  color: var(--syn-plain);
  pointer-events: none;
}

.ce-active {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  background: var(--surface-hover);
  opacity: 0.6;
  pointer-events: none;
}

.ce-ta {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  resize: none;
  overflow: auto;
  background: transparent;
  color: transparent;
  caret-color: var(--text);
  outline: none;
}

.ce-ta:focus-visible {
  box-shadow: inset 0 0 0 var(--hairline) var(--accent-line);
}

.ce-ta::selection {
  background: var(--accent-wash);
  color: transparent;
}

.t-plain { color: var(--syn-plain); }
.t-keyword { color: var(--syn-keyword); }
.t-string { color: var(--syn-string); }
.t-number { color: var(--syn-number); }
.t-comment { color: var(--syn-comment); font-style: italic; }
.t-fn { color: var(--syn-fn); }
.t-api { color: var(--syn-fn); }
.t-type { color: var(--syn-plain); }
.t-gate { color: var(--syn-gate); }
.t-setting { color: var(--syn-setting); }
.t-punct { color: var(--syn-punct); }

.qm {
  display: inline-block;
  width: 0.525em;
  line-height: 1;
  font-family: var(--font-ui);
  font-style: normal;
  text-align: center;
}

.ce-diag {
  text-decoration: underline wavy var(--danger);
  text-decoration-skip-ink: none;
  text-underline-offset: var(--underline-offset);
}

.ce-diag.ce-warning {
  text-decoration-color: var(--warning);
}

.ce-pop {
  min-width: 0;
  width: var(--popover-w);
  max-height: var(--pop-max-h);
  overflow: auto;
  padding: var(--space-1);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  line-height: var(--leading-tight);
  border-radius: var(--radius-md);
}

.ce-item {
  display: grid;
  grid-template-columns: var(--space-4) auto minmax(0, 1fr);
  align-items: center;
  column-gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.ce-item.is-selected {
  background: var(--surface-active);
}

.ce-item-kind {
  display: inline-grid;
  place-items: center;
  width: var(--space-4);
  height: var(--space-4);
  border-radius: var(--radius-xs);
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
}

.ce-item-label {
  font-family: var(--font-code);
  color: var(--text);
}

.ce-item-detail {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-faint);
  font-family: var(--font-code);
  font-size: var(--text-xs);
  text-align: right;
}

.ce-item-doc {
  grid-column: 2 / -1;
  padding-top: var(--space-1);
  color: var(--text-muted);
  font-size: var(--text-xs);
  line-height: var(--leading-ui);
  white-space: normal;
}

.ce-tip {
  position: absolute;
  z-index: var(--z-popover);
  max-width: var(--popover-w);
  padding: var(--space-1) var(--space-2);
  border: var(--hairline) solid var(--border);
  border-left: var(--space-0) solid var(--danger);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  box-shadow: var(--shadow-popover);
  font-family: var(--font-ui);
  font-size: var(--text-sm);
  line-height: var(--leading-ui);
  pointer-events: none;
}

.ce-tip-warning {
  border-left-color: var(--warning);
}

/* Preview */

.preview-pane {
  background: var(--stage);
}

.stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  padding: var(--space-8);
  overflow: hidden;
}

.stage-frame {
  position: relative;
  width: 0;
  height: 0;
  box-shadow: 0 0 0 var(--hairline) var(--border);
}

.preview-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.caption-overlay {
  position: absolute;
  left: 50%;
  bottom: 6%;
  transform: translateX(-50%);
  max-width: 80%;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--scrim);
  color: var(--text);
  font-size: var(--text-lg);
  line-height: var(--leading-tight);
  text-align: center;
  pointer-events: none;
}

.caption-overlay:empty {
  display: none;
}

.pick-outline {
  position: absolute;
  border: var(--hairline) solid var(--accent);
  border-radius: var(--radius-xs);
  background: var(--accent-wash);
  pointer-events: none;
}

.stage-status {
  position: absolute;
  left: var(--space-4);
  top: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-muted);
  font-size: var(--text-xs);
  pointer-events: none;
}

.stage-status:empty {
  display: none;
}

.stage-status .pulse {
  width: var(--space-1);
  height: var(--space-1);
  border-radius: var(--radius-full);
  background: var(--accent);
  animation: pulse var(--dur-pulse) var(--ease-standard) infinite alternate;
}

@keyframes pulse {
  to {
    opacity: 0.25;
  }
}

.stage-error {
  position: absolute;
  left: var(--space-4);
  right: var(--space-4);
  bottom: var(--space-4);
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: var(--hairline) solid var(--border);
  border-left: var(--space-0) solid var(--danger);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  box-shadow: var(--shadow-popover);
  font-size: var(--text-sm);
  z-index: var(--z-overlay);
}

.stage-error .where {
  color: var(--danger);
  font-family: var(--font-code);
  font-size: var(--text-xs);
  white-space: nowrap;
  padding-top: var(--space-0);
}

.stage-error .msg {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Transport */

.transport {
  flex: none;
  padding: var(--space-2) var(--space-4) var(--space-3);
  border-top: var(--hairline) solid var(--border);
  background: var(--surface);
}

.transport-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--control-h);
}

.transport-buttons {
  display: flex;
  align-items: center;
  gap: var(--space-0);
}

.transport .play-btn {
  color: var(--text);
}

.time-readout {
  display: inline-flex;
  align-items: baseline;
  gap: var(--space-1);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.time-readout .total,
.time-readout .sep {
  color: var(--text-faint);
}

.frame-readout {
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
}

.transport .spacer {
  flex: 1;
}

.rate-badge {
  padding: 0 var(--space-1);
  border-radius: var(--radius-xs);
  background: var(--accent-wash);
  color: var(--accent-text);
  font-size: var(--text-2xs);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

/* Controls (sliders) */

.controls {
  flex: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--control-min-w), 1fr));
  gap: var(--space-2) var(--space-6);
  padding: 0 var(--space-4) var(--space-3);
  background: var(--surface);
}

.controls:empty {
  display: none;
}

.control {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr) var(--space-12);
  align-items: center;
  gap: var(--space-3);
}

.control .label {
  white-space: nowrap;
}

.control .value {
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  text-align: right;
}

/* Shortcut sheet */

.shortcuts-panel {
  top: calc(var(--topbar-h) + var(--space-2));
  right: var(--space-3);
  width: calc(var(--popover-w) * 1.6);
  max-height: calc(100vh - var(--topbar-h) - var(--space-8));
  overflow: auto;
  padding: var(--space-4) var(--space-5) var(--space-5);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.sheet-head h2 {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}

.shortcut-groups {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-5) var(--space-8);
}

.shortcut-group h3 {
  margin-bottom: var(--space-2);
}

.shortcut {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) 0;
  font-size: var(--text-sm);
  border-top: var(--hairline) solid var(--border);
}

.shortcut .keys {
  display: inline-flex;
  gap: var(--space-1);
}

/* Medium screens: give the preview more room */

@media (max-width: 1440px) {
  .stage {
    padding: var(--space-5);
  }
}

/* Narrow screens: stack the panes */

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
    grid-template-rows: auto auto;
  }

  .topbar-select select {
    max-width: none;
  }

  .topbar .divider-v {
    display: none;
  }

  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: var(--space-2) var(--space-3);
    row-gap: var(--space-2);
  }

  .topbar-right {
    flex-wrap: wrap;
  }

  .shortcut-groups {
    grid-template-columns: 1fr;
  }

  .shortcuts-panel {
    left: var(--space-3);
    width: auto;
  }
}

/* Modal dialogs (playground/modal.js) */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-popover) + 10);
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: var(--scrim);
  animation: pop-in var(--dur-base) var(--ease-standard);
}

.modal {
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  max-height: min(640px, calc(100vh - var(--space-8)));
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  box-shadow: var(--shadow-popover);
  color: var(--text);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4) var(--space-2) var(--space-5);
}

.modal-head h2 {
  font-size: var(--text-md);
  font-weight: var(--weight-semibold);
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-height: 0;
  padding: 0 var(--space-5) var(--space-5);
  overflow: auto;
}

/* Open a Qubi file (editor/ui/qubi-files.js) */

.qf-note,
.qf-empty,
.qf-computer p {
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: var(--leading-ui);
}

.qf-empty a,
.qf-note a {
  color: var(--accent, var(--brand));
}

.qf-tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: var(--hairline) solid var(--border);
}

.qf-tab {
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.qf-tab[aria-selected='true'] {
  border-bottom-color: var(--brand);
  color: var(--text);
}

.qf-list {
  display: grid;
  gap: var(--space-3);
  min-height: 160px;
}

.qf-group h3 {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-1);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.qf-sub {
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular, 400);
  white-space: nowrap;
}

.qf-file {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}

.qf-file:hover,
.qf-file:focus-visible {
  background: var(--surface-hover);
}

.qf-file .mono {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qf-file svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
}

.qf-load {
  grid-template-columns: 16px 1fr;
  color: var(--text-muted);
}

.qf-computer {
  display: grid;
  justify-items: start;
  gap: var(--space-3);
  padding-top: var(--space-2);
}

/* Sharing (playground/share.js) */

#share-btn.is-live {
  border-color: var(--accent-line);
  color: var(--accent-text);
}

.presence {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.presence[hidden] {
  display: none;
}

.presence-dot {
  width: 8px;
  height: 8px;
  margin-right: var(--space-1);
  border-radius: 50%;
  background: var(--text-muted);
}

.presence-dot.live {
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--success) 25%, transparent);
}

.presence-dot.offline,
.presence-dot.reconnecting {
  background: var(--warning);
}

.presence-face {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  overflow: hidden;
  border: 2px solid var(--face);
  border-radius: 50%;
  background: color-mix(in oklab, var(--face) 30%, var(--surface-raised));
  color: var(--text);
  font-size: 10px;
  font-weight: var(--weight-semibold);
  flex: none;
}

.presence .presence-face + .presence-face {
  margin-left: -6px;
}

.presence-face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.presence-more,
.presence-mode {
  margin-left: var(--space-1);
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.presence-mode {
  padding: 2px var(--space-2);
  border: var(--hairline) solid var(--border);
  border-radius: 999px;
}

.share-modal {
  width: min(600px, 100%);
}

.sh-block {
  display: grid;
  gap: var(--space-2);
}

.sh-block + .sh-block {
  padding-top: var(--space-4);
  border-top: var(--hairline) solid var(--border);
}

.sh-block h3 {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.sh-note {
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: var(--leading-ui);
}

.sh-note strong {
  color: var(--text);
}

.sh-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.sh-add {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: var(--space-2);
}

.sh-people {
  display: grid;
  gap: var(--space-1);
}

.sh-member {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
  font-size: var(--text-sm);
}

.sh-member:first-child {
  grid-template-columns: 24px minmax(0, 1fr) auto;
}

.sh-who {
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sh-general {
  display: grid;
  gap: var(--space-1);
}

.sh-linkrow .input {
  flex: 1;
  min-width: 0;
}

.sh-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: var(--text-xs);
}

.sh-foot-actions {
  display: inline-flex;
  gap: var(--space-3);
}

.linkish.danger {
  color: var(--danger);
}

.sh-here {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.sh-person {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2) 2px 2px;
  border: var(--hairline) solid var(--border);
  border-radius: 999px;
  color: var(--text);
  font-size: var(--text-xs);
  text-decoration: none;
}

a.sh-person:hover {
  background: var(--surface-hover);
  text-decoration: none;
}

/* The open document, at the top left (src/playground/cloud-docs.js) */

.docs-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  max-width: 340px;
  height: var(--control-h);
  padding: 0 var(--space-2);
  border: var(--hairline) solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

.docs-btn:hover,
.docs-btn:focus-visible {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.docs-btn .icon {
  flex: none;
  color: var(--text-muted);
}

.docs-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.docs-status {
  flex: none;
  color: var(--text-faint);
  font-size: var(--text-sm);
  font-weight: var(--weight-regular);
}

.docs-status[data-mode='offline'],
.docs-status[data-mode='full'],
.docs-status[data-mode='readonly'] {
  color: var(--warning, var(--danger));
}

.docs-modal {
  width: min(560px, 100vw - 32px);
}

.docs-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.docs-note {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: var(--leading-ui);
}

.docs-note a {
  color: var(--accent, var(--brand));
}

.docs-list ul {
  display: grid;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.docs-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: var(--hairline) solid var(--border);
  border-radius: var(--radius-sm);
}

.docs-row.is-open {
  border-color: var(--accent-line);
  background: var(--accent-wash);
}

.docs-row-main {
  display: grid;
  flex: 1 1 200px;
  min-width: 0;
}

.docs-row-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: var(--weight-medium);
}

.docs-row-meta {
  color: var(--text-faint);
  font-size: var(--text-sm);
}

.docs-row-actions {
  display: flex;
  gap: var(--space-1);
}

.docs-confirm {
  display: flex;
  flex-basis: 100%;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding-top: var(--space-2);
  border-top: var(--hairline) solid var(--border);
}

.docs-confirm p {
  margin: 0;
  font-size: var(--text-sm);
  line-height: var(--leading-ui);
}

.docs-confirm div {
  display: flex;
  gap: var(--space-1);
}

.btn.danger-solid {
  border-color: transparent;
  background: var(--danger);
  color: var(--on-accent);
}

@media (max-width: 760px) {
  .docs-status {
    display: none;
  }
}
