/* Compiler workspace */

.compiler-section {
  padding: 0.5rem 0 1.5rem;
}

.compiler {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.compiler__toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.compiler__toolbar-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}

.compiler__toolbar-spacer {
  flex: 1;
  min-width: 0.5rem;
}

.compiler__shortcut {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.compiler__body {
  display: grid;
  grid-template-columns: 1fr;
  min-height: 520px;
}

.compiler__editors {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-bottom: 1px solid var(--border);
}

.editor-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  overflow-x: auto;
}

.editor-tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0.7rem 1rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.editor-tab[aria-selected="true"] {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: var(--surface);
}

.editor-panels {
  flex: 1;
  min-height: 280px;
  position: relative;
}

.editor-panel {
  display: none;
  height: 100%;
  min-height: 280px;
}

.editor-panel[data-active="true"] {
  display: flex;
}

.editor {
  display: grid;
  grid-template-columns: auto 1fr;
  width: 100%;
  height: 100%;
  min-height: 280px;
  background: var(--bg);
}

.editor__gutter {
  padding: 0.85rem 0.45rem 0.85rem 0.65rem;
  text-align: right;
  color: color-mix(in srgb, var(--muted) 70%, transparent);
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.55;
  user-select: none;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow: hidden;
}

.editor__input {
  width: 100%;
  height: 100%;
  min-height: 280px;
  border: 0;
  resize: none;
  padding: 0.85rem 0.85rem;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.55;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}

.editor__input.wrap {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.editor__input:focus {
  outline: none;
}

.compiler__preview {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 320px;
  background: var(--bg);
}

.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.preview-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  margin-right: 0.25rem;
}

.device-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}

.device-btn[aria-pressed="true"] {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.viewport-meta {
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--mono);
}

.preview-stage {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 0.75rem;
  background:
    linear-gradient(45deg, var(--surface-2) 25%, transparent 25%),
    linear-gradient(-45deg, var(--surface-2) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--surface-2) 75%),
    linear-gradient(-45deg, transparent 75%, var(--surface-2) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-color: var(--bg);
  overflow: auto;
}

.preview-frame-wrap {
  width: 100%;
  height: 100%;
  min-height: 280px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  transition: width 180ms ease;
  margin: 0 auto;
}

.preview-frame-wrap[data-device="tablet"] {
  width: min(100%, 768px);
}

.preview-frame-wrap[data-device="mobile"] {
  width: min(100%, 390px);
}

.preview-frame {
  width: 100%;
  height: 100%;
  min-height: 280px;
  border: 0;
  background: #fff;
}

.preview-empty {
  color: #64748b;
  font-size: 0.92rem;
  text-align: center;
  padding: 2rem 1rem;
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  background: #fff;
  z-index: 1;
}

.preview-empty[hidden] {
  display: none !important;
}

.preview-frame-wrap {
  position: relative;
}

.compiler__console {
  border-top: 1px solid var(--border);
  background: var(--surface);
  max-height: 220px;
  display: flex;
  flex-direction: column;
}

.console-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.console-head h3 {
  margin: 0;
  font-size: 0.85rem;
}

.console-body {
  overflow: auto;
  padding: 0.5rem 0.75rem;
  font-family: var(--mono);
  font-size: 0.8rem;
  min-height: 72px;
}

.console-line {
  display: grid;
  grid-template-columns: 72px 64px 1fr;
  gap: 0.5rem;
  padding: 0.2rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
}

.console-line[data-type="warn"] {
  color: var(--warn);
}

.console-line[data-type="error"] {
  color: var(--danger);
}

.console-line[data-type="info"] {
  color: var(--accent);
}

.console-empty {
  color: var(--muted);
}

.compiler-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  padding: 0.55rem 0.75rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
  background: var(--surface);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.toggle input {
  accent-color: var(--accent);
}

.settings-popover {
  position: relative;
}

.settings-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  width: min(260px, 80vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem;
  display: none;
  z-index: 50;
}

.settings-panel[data-open="true"] {
  display: grid;
  gap: 0.65rem;
}

.settings-panel label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.settings-panel input[type="range"] {
  width: 100%;
}

.compiler.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 200;
  border-radius: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.compiler.is-fullscreen .compiler__body {
  flex: 1;
  min-height: 0;
}

.compiler.is-fullscreen .editor-panels,
.compiler.is-fullscreen .editor-panel,
.compiler.is-fullscreen .editor,
.compiler.is-fullscreen .editor__input,
.compiler.is-fullscreen .compiler__preview,
.compiler.is-fullscreen .preview-frame-wrap,
.compiler.is-fullscreen .preview-frame {
  min-height: 0;
  height: 100%;
}

.error-banner {
  display: none;
  margin: 0;
  padding: 0.65rem 0.85rem;
  background: color-mix(in srgb, var(--danger) 15%, var(--surface));
  border-top: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border));
  color: var(--danger);
  font-size: 0.85rem;
}

.error-banner[data-visible="true"] {
  display: block;
}

@media (min-width: 960px) {
  .compiler__body {
    grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
    min-height: 620px;
  }

  .compiler__editors {
    border-bottom: 0;
    border-right: 1px solid var(--border);
  }

  .editor-panels,
  .editor-panel,
  .editor,
  .editor__input {
    min-height: 560px;
  }

  .preview-frame-wrap,
  .preview-frame {
    min-height: 480px;
  }
}
