:root {
  --bg: #0c0e14;
  --surface: #151922;
  --surface-2: #1c2230;
  --surface-3: #242b3d;
  --border: #2d3548;
  --text: #eef1f8;
  --muted: #8b95ad;
  --accent: #5b8def;
  --accent-hover: #7aa3f5;
  --accent-dim: rgba(91, 141, 239, 0.15);
  --success: #3ecf8e;
  --danger: #f07178;
  --radius: 12px;
  --font: "DM Sans", system-ui, sans-serif;
  --tools-width: 340px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.app {
  max-width: 1680px;
  margin: 0 auto;
  padding: 1.5rem 2rem 2.5rem;
}

.header {
  margin-bottom: 1.25rem;
}

.header-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
}

.brand-icon {
  font-size: 1.75rem;
  color: var(--accent);
  line-height: 1;
  margin-top: 0.15rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.version-line {
  font-size: 0.8rem;
  color: var(--muted);
  padding: 0.35rem 0.65rem;
  background: var(--surface-2);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.workspace {
  display: grid;
  grid-template-columns: var(--tools-width) 1fr;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

.tools-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  overflow-y: auto;
}

.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.tool-card[hidden] {
  display: none;
}

.tool-card-title {
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.badge-live {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--success);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-left: 0.35rem;
}

.tabs {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.tab {
  flex: 1;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.tab-panel[hidden] {
  display: none;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  padding: 1.25rem;
  border: 2px dashed var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: center;
}

.dropzone-compact {
  min-height: 72px;
  padding: 0.85rem;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.dropzone-text {
  font-weight: 600;
  font-size: 0.9rem;
}

.dropzone-hint {
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.7rem;
}

.field.compact {
  margin-bottom: 0.55rem;
}

.field-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input[type="text"],
input[type="url"],
input[type="number"],
select {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

input:focus,
select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.checkbox {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
  margin-bottom: 0.65rem;
  line-height: 1.35;
}

.hint-card {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.hint-inline {
  font-size: 0.75rem;
  color: var(--muted);
}

.color-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

#export-bg-color {
  width: 2.5rem;
  height: 2rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.btn {
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:not(:disabled):hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:not(:disabled):hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:not(:disabled):hover {
  color: var(--text);
  border-color: var(--muted);
}

.btn-tool {
  flex: 1;
  min-width: 2.5rem;
  padding: 0.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 1.1rem;
}

.btn-tool:not(:disabled):hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.btn-tool.is-active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent-hover);
}

#app-tooltip {
  position: fixed;
  z-index: 10000;
  padding: 0.4rem 0.6rem;
  font-size: 0.72rem;
  font-weight: 500;
  line-height: 1.35;
  max-width: 240px;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.12s ease;
}

#app-tooltip.is-visible {
  opacity: 1;
  visibility: visible;
}

.btn-row-wrap .btn-tool {
  flex: 0 1 auto;
  min-width: 2.25rem;
}

.btn-sm {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.65rem;
}

.btn-row.stack {
  flex-direction: column;
  margin-top: 0.5rem;
}

.select-mode-toggle {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 0.65rem;
}

.select-mode-btn {
  flex: 1;
  padding: 0.45rem 0.5rem;
  border: none;
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.select-mode-btn:hover {
  color: var(--text);
}

.select-mode-btn.active {
  background: var(--accent);
  color: #fff;
}

.status {
  min-height: 1.25rem;
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.status.error {
  color: var(--danger);
}

.status.success {
  color: var(--success);
}

.canvas-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  min-height: 480px;
}

.canvas-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 420px;
  color: var(--muted);
  text-align: center;
  padding: 2rem;
}

.canvas-empty p {
  margin: 0;
  max-width: 28rem;
}

.dual-view {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 900px) {
  .dual-view {
    grid-template-columns: 1fr;
  }
}

.view-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.view-pane-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.view-pane-head h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.view-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.live-indicator {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 600;
  margin-left: auto;
}

.view-frame {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  max-height: min(72vh, 640px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.view-frame-original {
  background: var(--surface-3);
}

.view-frame-edited,
.preview-transparency-bg {
  background-color: #d4d4d4;
  background-image: repeating-conic-gradient(#a8a8a8 0% 25%, #d4d4d4 0% 50%) 50% / 16px 16px;
}

.view-frame img {
  max-width: 100%;
  max-height: min(72vh, 640px);
  width: auto;
  height: auto;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  object-fit: contain;
}

.view-pane-edited .view-frame {
  position: relative;
}

.meta {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.edits-meta {
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}

.footer {
  margin-top: 2rem;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Selection overlay (edited pane only) */
.select-overlay {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  cursor: crosshair;
  touch-action: none;
}

.select-shade {
  position: absolute;
  background: rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.select-box {
  position: absolute;
  border: 2px solid var(--accent);
  box-sizing: border-box;
  pointer-events: none;
  display: none;
}

.select-box.visible {
  display: block;
}

.select-box.mode-resize {
  border-color: var(--success);
}

.select-size {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: rgba(15, 17, 23, 0.85);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  z-index: 1;
}

.handle {
  position: absolute;
  width: 10px;
  height: 10px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 2px;
  box-sizing: border-box;
  pointer-events: none;
  z-index: 2;
}

.select-box.mode-resize .handle {
  border-color: var(--success);
}

.handle-n { left: 50%; top: -6px; transform: translateX(-50%); }
.handle-s { left: 50%; bottom: -6px; transform: translateX(-50%); }
.handle-e { right: -6px; top: 50%; transform: translateY(-50%); }
.handle-w { left: -6px; top: 50%; transform: translateY(-50%); }
.handle-nw { left: -6px; top: -6px; }
.handle-ne { right: -6px; top: -6px; }
.handle-sw { left: -6px; bottom: -6px; }
.handle-se { right: -6px; bottom: -6px; }

.select-overlay.cursor-move { cursor: move; }
.select-overlay.cursor-ns { cursor: ns-resize; }
.select-overlay.cursor-ew { cursor: ew-resize; }
.select-overlay.cursor-nwse { cursor: nwse-resize; }
.select-overlay.cursor-nesw { cursor: nesw-resize; }
