*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #1e1e2e;
  color: #cdd6f4;
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: #181825;
  border-bottom: 1px solid #313244;
  height: 48px;
}

.toolbar-title {
  font-size: 16px;
  font-weight: 700;
  color: #cba6f7;
  letter-spacing: 0.5px;
}

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

.toolbar-actions button {
  padding: 6px 16px;
  border: 1px solid #45475a;
  border-radius: 6px;
  background: #313244;
  color: #cdd6f4;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.toolbar-actions button:hover {
  background: #45475a;
  border-color: #585b70;
}

.editor-layout {
  display: grid;
  grid-template-columns: 150px 1fr 1fr;
  height: calc(100vh - 48px - 32px);
  overflow: hidden;
}

.palette {
  background: #181825;
  border-right: 1px solid #313244;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
}

.palette h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #6c7086;
  margin-bottom: 4px;
}

.palette hr {
  border: none;
  border-top: 1px solid #313244;
  margin: 4px 0;
}

.palette button {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #313244;
  border-radius: 6px;
  background: #1e1e2e;
  color: #cdd6f4;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.palette button:hover {
  background: #313244;
  border-color: #585b70;
}

.palette-color-picker {
  margin-top: 4px;
}

.palette-color-picker label {
  font-size: 11px;
  color: #6c7086;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
  margin-bottom: 4px;
}

.color-swatches {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
}

.swatch {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 3px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: border-color 0.1s, transform 0.1s;
}

.swatch:hover {
  border-color: rgba(255, 255, 255, 0.4);
  transform: scale(1.1);
}

.swatch.active {
  border-color: #fff;
}

.editor-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid #313244;
  overflow: hidden;
}

.editor-container {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.line-numbers {
  width: 44px;
  background: #181825;
  color: #6c7086;
  font-family: 'Consolas', 'Fira Code', 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.6;
  padding: 10px 0;
  text-align: right;
  overflow: hidden;
  user-select: none;
  border-right: 1px solid #313244;
  flex-shrink: 0;
}

.line-numbers .line-num {
  padding-right: 8px;
  display: block;
  height: 22.4px;
}

.line-numbers .line-num.has-error {
  color: #f38ba8;
  background: rgba(243, 139, 168, 0.1);
}

#editor {
  flex: 1;
  resize: none;
  border: none;
  outline: none;
  background: #1e1e2e;
  color: #cdd6f4;
  font-family: 'Consolas', 'Fira Code', 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.6;
  padding: 10px 12px;
  tab-size: 4;
  white-space: pre;
  overflow-y: auto;
  overflow-x: auto;
}

#editor::placeholder {
  color: #585b70;
}

.error-panel {
  min-height: 0;
  max-height: 120px;
  overflow-y: auto;
  background: #181825;
  border-top: 1px solid #313244;
  padding: 0;
  font-size: 13px;
  font-family: 'Consolas', 'Fira Code', 'Courier New', monospace;
}

.error-panel:empty {
  display: none;
}

.error-panel .error-item {
  padding: 4px 12px;
  color: #f38ba8;
  cursor: pointer;
  border-bottom: 1px solid #313244;
}

.error-panel .error-item:hover {
  background: rgba(243, 139, 168, 0.08);
}

.error-panel .error-item .error-line {
  color: #fab387;
  font-weight: 600;
  margin-right: 8px;
}

.error-panel .warning-item {
  padding: 4px 12px;
  color: #f9e2af;
  cursor: pointer;
  border-bottom: 1px solid #313244;
}

.error-panel .warning-item:hover {
  background: rgba(249, 226, 175, 0.08);
}

.error-panel .warning-item .error-line {
  color: #fab387;
  font-weight: 600;
  margin-right: 8px;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #11111b;
}

.preview-panel > h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #6c7086;
  padding: 10px 16px 8px;
  flex-shrink: 0;
}

.preview-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: #11111b;
}

.cui-window {
  background: rgb(32, 32, 32);
  border: 1px solid rgba(40, 50, 40, 0.5);
  border-radius: 2px;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #ddd;
  overflow: hidden;
}

.cui-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.15);
}

.cui-titlebar-left {
  font-weight: 700;
  font-size: 18px;
  color: #fff;
}

.cui-titlebar-right {
  display: flex;
  align-items: center;
  gap: 2px;
}

.cui-version {
  font-size: 12px;
  color: #ccc;
  background: rgba(30, 35, 30, 0.9);
  padding: 3px 10px;
  border-radius: 2px;
  border: 1px solid rgba(70, 80, 70, 0.5);
  font-weight: 500;
}

.cui-resize-btn {
  width: 26px;
  height: 26px;
  background: rgba(30, 35, 30, 0.9);
  border: 1px solid rgba(70, 80, 70, 0.5);
  border-radius: 2px;
  color: #ccc;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}

.cui-close-btn {
  width: 26px;
  height: 26px;
  background: #c0291e;
  border: 1px solid #8b1e14;
  border-radius: 2px;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}

.cui-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cui-txt {
  font-size: 16px;
  line-height: 1.3;
  color: #ddd;
  word-wrap: break-word;
  padding: 2px 0;
}

.cui-ctxt {
  font-size: 16px;
  line-height: 1.3;
  color: #ddd;
  text-align: center;
  word-wrap: break-word;
  padding: 2px 0;
}

.cui-btn {
  display: block;
  width: 100%;
  padding: 8px 16px;
  border: 1px solid;
  border-radius: 3px;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  cursor: default;
  text-align: center;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
  background: linear-gradient(to bottom, rgba(255,255,255,0.08), transparent 40%, rgba(0,0,0,0.12)) var(--btn-bg);
}

.cui-btn-row {
  display: flex;
  gap: 12px;
}

.cui-btn-row .cui-btn {
  flex: 1;
}

.cui-img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 2px auto;
}

.cui-empty {
  color: #585b70;
  font-style: italic;
  text-align: center;
  padding: 40px 20px;
}

.status-bar {
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: #181825;
  border-top: 1px solid #313244;
  font-size: 12px;
  color: #6c7086;
}

.status-link {
  color: #6c7086;
  text-decoration: none;
}

.status-link:hover {
  color: #cdd6f4;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #45475a;
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: #585b70;
}
