:root {
  color-scheme: light;
  --surface: #f5f5f5;
  --surface-alt: #ffffff;
  --border: #c7c7c7;
  --overlay: rgba(0, 0, 0, 0.75);
  --accent: #4f6bed;
  --danger: #e74c3c;
  --text: #1e1e1e;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --surface: #1a1a1a;
  --surface-alt: #2a2a2a;
  --border: #444444;
  --overlay: rgba(0, 0, 0, 0.85);
  --accent: #6b8aff;
  --danger: #ff6b6b;
  --text: #e0e0e0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--surface);
  color: var(--text);
  min-height: 100vh;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.header-actions button,
.controls-panel button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.controls-panel button.danger {
  background: var(--danger);
}

.controls-panel button.danger.secondary,
.header-actions button.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
}

#add-div-element {
  width: 100%;
  margin-top: 0.5rem;
}

.header-actions button:hover,
.controls-panel button:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.controls-panel button:disabled,
.header-actions button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none;
  transform: none;
}

.app-main {
  display: flex;
  flex: 1;
  min-height: 0;
}

.controls-panel,
.layers-panel {
  width: 260px;
  background: var(--surface-alt);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  overflow-y: auto;
}

.controls-panel {
  border-right: 1px solid var(--border);
}

.layers-panel {
  border-left: 1px solid var(--border);
}

.layers-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.layer-item:hover {
  border-color: var(--accent);
  background: var(--surface-alt);
}

.layer-item.selected {
  border-color: var(--accent);
  background: rgba(107, 138, 255, 0.1);
}

.layer-item.dragging {
  opacity: 0.5;
}

.layer-drag-handle {
  width: 20px;
  height: 20px;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  opacity: 0.5;
  flex-shrink: 0;
}

.layer-drag-handle:active {
  cursor: grabbing;
}

.layer-drag-handle::before {
  content: '⋮⋮';
  font-size: 1rem;
  letter-spacing: -2px;
}

.layer-thumbnail {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  background: repeating-conic-gradient(#f5f5f5 0 25%, #fafafa 0 50%) 0 / 8px 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.layer-thumbnail img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.layer-thumbnail-icon {
  font-size: 1.25rem;
  opacity: 0.5;
}

.layer-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.layer-name {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.layer-type {
  font-size: 0.75rem;
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

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

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.control-group span {
  font-size: 0.9rem;
  color: inherit;
  opacity: 0.75;
}

.control-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.control-group textarea {
  min-height: 140px;
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  resize: vertical;
  font-family: 'JetBrains Mono', 'Fira Mono', monospace;
  font-size: 0.8rem;
  line-height: 1.45;
  background: var(--surface-alt);
  color: inherit;
}

.size-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.size-controls input[type="range"] {
  flex: 1;
}

.size-input {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}

.size-input input[type="number"] {
  width: 64px;
  border: none;
  background: transparent;
  color: inherit;
  font-size: 0.9rem;
}

.size-input input[type="number"]:focus {
  outline: none;
}

.size-input .suffix {
  font-size: 0.85rem;
  opacity: 0.7;
}

.control-hint {
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.4;
  opacity: 0.65;
}

#claude-css-prompt {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: inherit;
  font-size: 0.9rem;
  resize: vertical;
  margin-bottom: 0.5rem;
  font-family: inherit;
  line-height: 1.4;
}

#ask-claude-css {
  width: 100%;
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.css-advanced-section {
  margin-bottom: 0.75rem;
}

.css-button-group {
  display: flex;
  gap: 0.5rem;
}

.controls-panel button.ghost.small {
  font-size: 0.8rem;
  padding: 0.35rem 0.6rem;
  flex: 1;
}

.controls-panel button.ghost.small.danger {
  color: var(--danger);
  border-color: var(--danger);
}

.controls-panel button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.controls-panel button.ghost:hover {
  transform: none;
  box-shadow: none;
}

input[type="file"],
select,
input[type="range"] {
  width: 100%;
}

input[type="url"] {
  width: 100%;
}

.button-stack {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.button-file {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.button-file:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.button-file input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.layer-buttons {
  display: flex;
  gap: 0.5rem;
}

.layer-buttons button {
  flex: 1;
  padding: 0.4rem;
  font-size: 0.85rem;
}

#clone-element {
  width: 100%;
}

.canvas-container {
  flex: 1;
  position: relative;
  overflow: auto;
  padding: 0 1.5rem;
}

#canvas {
  width: 768px;
  min-height: 768px;
  height: auto;
  margin: 0 auto;
  background: transparent;
  border-radius: 12px;
  border: 2px dashed var(--border);
  position: relative;
  overflow: hidden;
}

.canvas-element {
  position: absolute;
  cursor: move;
  user-select: none;
  touch-action: none;
  transform-origin: center;
}

.canvas-element.selected {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
}

.hover-wrapper,
.anim-wrapper {
  display: inline-block;
  transform-origin: center;
}

.hover-wrapper {
  transition: transform 0.2s ease;
}

.anim-wrapper {
  display: inline-block;
}

.anim-wrapper img {
  display: block;
  max-width: none;
  border-radius: 8px;
  pointer-events: none;
}

.content-block {
  display: block;
  min-width: 200px;
  min-height: 120px;
  padding: 0;
  border-radius: 0;
  border: none;
  background: transparent;
  color: inherit;
  box-shadow: none;
  font-size: 1rem;
  line-height: 1.5;
  pointer-events: none;
}

.content-block * {
  pointer-events: none;
}

.canvas-element.selected .content-block {
  border: 1px dashed var(--accent);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* Hover effects */
.hover-wrapper.hover-rotate:hover {
  transform: rotate(12deg);
}

.hover-wrapper.hover-grow:hover {
  transform: scale(1.12);
}

.hover-wrapper.hover-rotate-grow:hover {
  transform: rotate(14deg) scale(1.18);
}

/* Animation loops */
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

@keyframes rotate-slow {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 0.9; }
  50% { transform: scale(1.17); opacity: 1; }
}

.anim-wrapper.anim-breathe {
  animation: breathe 4s ease-in-out infinite;
}

.anim-wrapper.anim-rotate {
  animation: rotate-slow 8s linear infinite;
}

.anim-wrapper.anim-pulse {
  animation: pulse 3s ease-in-out infinite;
}

dialog.app-dialog::backdrop {
  background: var(--overlay);
}

dialog.app-dialog {
  max-width: 720px;
  width: min(90vw, 760px);
  border: none;
  border-radius: 12px;
  padding: 0;
}

dialog.app-dialog form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.5rem;
}

#export-output {
  width: 100%;
  min-height: 320px;
  font-family: 'JetBrains Mono', 'Fira Mono', monospace;
  font-size: 0.85rem;
  resize: vertical;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.8rem;
}

.dialog-actions button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
}

.dialog-actions button:first-of-type {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.modal-row {
  display: flex;
  gap: 1rem;
}

.modal-row > .modal-group {
  flex: 1;
}

.modal-group {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 1rem;
  background: var(--surface-alt);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.modal-control {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.modal-control > span,
.modal-header > span {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
}

.modal-group input[type="text"],
.modal-group input[type="number"] {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  font-size: 0.95rem;
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.modal-group input[type="text"]:focus,
.modal-group input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(107, 138, 255, 0.1);
}

.modal-group input[type="text"]::placeholder {
  color: var(--text);
  opacity: 0.4;
}

.modal-group input[type="file"] {
  padding: 0.65rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  flex: 1;
  min-width: 0;
}

.modal-group input[type="file"]:hover {
  border-color: var(--accent);
  background: var(--surface-alt);
}

.file-preview-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.modal-group select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.modal-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(107, 138, 255, 0.1);
}

.preview-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  margin-top: 0.25rem;
}

.preview-hint {
  opacity: 0.65;
  font-size: 0.85rem;
  line-height: 1.5;
  margin: 0;
}

.favicon-preview {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.favicon-preview.empty {
  background: repeating-conic-gradient(#f5f5f5 0 25%, #fafafa 0 50%) 0 / 8px 8px;
  border-style: dashed;
}

.background-preview {
  width: 120px;
  height: 72px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background-size: cover;
  background-position: center;
  background-repeat: repeat;
  position: relative;
  overflow: hidden;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

.background-preview::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.15), transparent);
  pointer-events: none;
}

.background-preview.empty {
  background: repeating-conic-gradient(#f5f5f5 0 25%, #fafafa 0 50%) 0 / 12px 12px;
  border-style: dashed;
}

/* Deploy to GitHub Pages Modal */
.deploy-dialog {
  max-width: 680px;
}

.deploy-step {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  padding: 1rem;
  background: var(--surface-alt);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.deploy-step h3 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
}

.deploy-step p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.5;
}

.deploy-step a {
  color: var(--accent);
  text-decoration: underline;
}

.deploy-checklist {
  margin: 0;
  padding-left: 1.5rem;
  font-size: 0.9rem;
}

.deploy-checklist li {
  margin: 0.4rem 0;
}

.deploy-numbered {
  margin: 0;
  padding-left: 1.5rem;
  font-size: 0.9rem;
}

.deploy-numbered li {
  margin: 0.5rem 0;
}

.command-block {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  margin-top: 0.5rem;
}

.command-block pre {
  margin: 0;
  font-family: 'JetBrains Mono', 'Fira Mono', monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.command-block button {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
}

.deploy-hint {
  font-size: 0.8rem;
  opacity: 0.7;
  font-style: italic;
  margin-top: 0.5rem;
}

.deploy-success {
  background: rgba(76, 175, 80, 0.1);
  border: 1px solid rgba(76, 175, 80, 0.3);
  padding: 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
}

.deploy-success code {
  background: var(--surface);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-family: 'JetBrains Mono', 'Fira Mono', monospace;
  font-size: 0.85rem;
}

#download-deploy-html {
  width: 100%;
  margin-top: 0.5rem;
}

.deploy-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  border-bottom: 2px solid var(--border);
}

.deploy-tab {
  background: transparent;
  border: none;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  color: var(--text);
  opacity: 0.6;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s ease;
}

.deploy-tab:hover {
  opacity: 0.8;
}

.deploy-tab.active {
  opacity: 1;
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.deploy-tab-content {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.deploy-tab-content[hidden] {
  display: none;
}

.deploy-tab-content code {
  background: var(--surface);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  font-family: 'JetBrains Mono', 'Fira Mono', monospace;
  font-size: 0.85rem;
}

.deploy-dialog input[type="text"] {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.65rem 0.85rem;
  font-size: 0.95rem;
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.deploy-dialog input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(107, 138, 255, 0.1);
}

.deploy-dialog input[type="text"]::placeholder {
  color: var(--text);
  opacity: 0.4;
}

@media (max-width: 900px) {
  .app-main {
    flex-direction: column;
  }

  .controls-panel {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 1rem;
  }

  .panel-section {
    flex: 1 1 220px;
  }
}
