:root {
  color-scheme: dark light;
  font-family:
    'Inter',
    system-ui,
    -apple-system,
    sans-serif;
  line-height: 1.4;
  background: #0f1115;
  color: #e6e7eb;
}

* {
  box-sizing: border-box;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #0f1115 0%, #12141b 100%);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(16, 18, 24, 0.9);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}

.app-header h1 {
  margin: 0 0 6px;
  font-size: 1.4rem;
}

.brand-link {
  color: inherit;
  text-decoration: none;
}

.brand-link:hover {
  text-decoration: underline;
}

.app-header p {
  margin: 0;
  color: #9aa3b2;
  font-size: 0.95rem;
}

.status {
  font-size: 0.9rem;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #cdd4df;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(320px, 1fr));
  grid-template-areas:
    'component styles'
    'preview preview';
  gap: 18px;
  padding: 24px;
}

.component-panel {
  grid-area: component;
  max-height: min(64vh, 620px);
  min-height: 0;
}

.styles-panel {
  grid-area: styles;
  max-height: min(64vh, 620px);
  min-height: 0;
}

.preview-panel {
  grid-area: preview;
  position: relative;
}

@media (max-width: 900px) {
  .app-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      'component'
      'styles'
      'preview';
  }
}

.panel {
  background: rgba(18, 20, 28, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  min-height: 360px;
  overflow: hidden;
}

.panel.preview {
  min-height: 280px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(15, 17, 23, 0.9);
  position: relative;
  z-index: 2;
}

.panel-header h2 {
  margin: 0;
  font-size: 1rem;
}

.panel-header--stack {
  align-items: stretch;
  gap: 10px;
}

.panel-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header-row--actions {
  justify-content: flex-start;
}

.panel-header-row--quick-actions {
  justify-content: flex-start;
}

.controls {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 0.85rem;
  color: #b9c1cf;
  flex-wrap: wrap;
}

.controls--actions {
  justify-content: flex-start;
}

.controls--quick-actions {
  gap: 10px;
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.controls select {
  appearance: none;
  -webkit-appearance: none;
  background-color: rgba(255, 255, 255, 0.08);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%23d6def0' d='M1.2 0 5 3.8 8.8 0 10 1.2 5 6 0 1.2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  color: #f1f5ff;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 6px 30px 6px 10px;
  color-scheme: dark;
}

.controls select:focus-visible {
  outline: 2px solid rgba(122, 107, 255, 0.8);
  outline-offset: 1px;
}

.controls select option,
.controls select optgroup {
  background: #151a25;
  color: #eef3ff;
}

.controls select option:disabled {
  color: #95a1b9;
}

textarea {
  flex: 1;
  background: transparent;
  color: #e8ebf3;
  border: none;
  padding: 16px 18px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.9rem;
  resize: none;
}

textarea:focus {
  outline: none;
}

.source-textarea--hidden {
  display: none;
}

.editor-host {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.editor-host .cm-editor {
  height: 100%;
}

.editor-host .cm-scroller {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  overflow: auto;
}

@media (max-width: 900px) {
  .component-panel,
  .styles-panel {
    max-height: none;
    min-height: 360px;
  }
}

.panel-footer {
  padding: 10px 18px 16px;
  font-size: 0.85rem;
  color: #f6b56a;
}

.preview-host {
  flex: 0 1 auto;
  min-height: 180px;
  padding: 18px;
  overflow: auto;
  position: relative;
  background: #12141c;
  z-index: 1;
}

.preview-host[data-style-compiling='true']::before {
  content: 'Compiling styles…';
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  padding-top: 34px;
  background: rgba(10, 12, 18, 0.72);
  backdrop-filter: blur(2px);
  color: #d9e0ee;
  font-size: 0.88rem;
  letter-spacing: 0.01em;
  z-index: 2;
}

.preview-host[data-style-compiling='true']::after {
  content: '';
  position: absolute;
  left: 50%;
  top: calc(50% - 18px);
  width: 20px;
  height: 20px;
  margin-left: -10px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-top-color: #8f83ff;
  animation: preview-spin 0.7s linear infinite;
  z-index: 3;
}

@keyframes preview-spin {
  to {
    transform: rotate(360deg);
  }
}

.controls label.toggle {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.controls label.color-control {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.controls input[type='color'] {
  width: 34px;
  height: 24px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
}

.controls input[type='color']::-webkit-color-swatch-wrapper {
  padding: 0;
}

.controls input[type='color']::-webkit-color-swatch {
  border: none;
  border-radius: 6px;
}

.toggle input {
  accent-color: #7a6bff;
}

.hint-icon {
  display: inline-grid;
  place-content: center;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  color: #dbe5ff;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  opacity: 0.9;
  background: transparent;
}

.shadow-hint {
  position: relative;
  cursor: help;
  border-width: 1px;
  padding: 0;
}

.shadow-hint::before,
.shadow-hint::after {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 120ms ease,
    transform 120ms ease,
    visibility 120ms ease;
}

.shadow-hint::before {
  content: '';
  position: absolute;
  top: calc(100% + 4px);
  right: 4px;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 6px solid rgba(9, 12, 20, 0.96);
  transform: translateY(-4px);
  z-index: 31;
}

.shadow-hint::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(320px, calc(100vw - 36px));
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(9, 12, 20, 0.96);
  color: #dfe6f7;
  font-size: 0.78rem;
  font-weight: 500;
  line-height: 1.35;
  text-align: left;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.45);
  transform: translateY(-4px);
  z-index: 30;
}

.shadow-hint:hover::before,
.shadow-hint:hover::after,
.shadow-hint:focus-visible::before,
.shadow-hint:focus-visible::after {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.shadow-hint:focus-visible {
  outline: 2px solid rgba(122, 107, 255, 0.9);
  outline-offset: 2px;
}

.render-button {
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(122, 107, 255, 0.2);
  color: #f1f5ff;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}

.render-button:hover {
  background: rgba(122, 107, 255, 0.35);
}

.icon-button {
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: #d8e0ef;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 999px;
  cursor: pointer;
  display: inline-grid;
  place-content: center;
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.13);
}

.icon-button:focus-visible {
  outline: 2px solid rgba(122, 107, 255, 0.8);
  outline-offset: 1px;
}

.icon-button svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (max-width: 900px) {
  .panel-header-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-header-row--actions,
  .controls--actions {
    justify-content: flex-start;
  }
}

.app-footer {
  padding: 12px 24px 24px;
  color: #9aa3b2;
  font-size: 0.85rem;
}

.cdn-loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(7, 10, 16, 0.82);
  backdrop-filter: blur(6px);
  transition: opacity 160ms ease;
}

.cdn-loading[hidden] {
  opacity: 0;
  pointer-events: none;
}

.cdn-loading-card {
  width: min(560px, calc(100% - 40px));
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(13, 16, 24, 0.96);
  box-shadow: 0 20px 42px rgba(0, 0, 0, 0.35);
  padding: 22px 20px;
  text-align: center;
}

.cdn-loading-spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 12px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.24);
  border-top-color: #8f83ff;
  animation: preview-spin 0.7s linear infinite;
}

.cdn-loading-title {
  margin: 0;
  font-size: 1rem;
  color: #edf1ff;
  font-weight: 700;
}

.cdn-loading-copy {
  margin: 8px 0 0;
  font-size: 0.9rem;
  color: #b7c1d4;
}
