:root {
  color-scheme: dark;
  --bg: #0d1117;
  --panel: #161b22;
  --line: #2d333b;
  --text: #e6edf3;
  --muted: #9da7b3;
  --accent: #2f81f7;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top left, #151c2b, #0d1117 55%);
}

.app {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(340px, 420px) 1fr;
  gap: 20px;
  padding: 20px;
}

.controls {
  background: color-mix(in srgb, var(--panel) 90%, black);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
}

.brand {
  margin-bottom: 60px;
}

.brand-logo {
  width: 92px;
  height: auto;
  display: block;
  opacity: 0.92;
}

h1 {
  margin: 0;
  font-size: 1.4rem;
}

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

.subtitle,
.hint {
  color: var(--muted);
}

.subtitle {
  margin-top: 8px;
}

.panel {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

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

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.92rem;
}

input[type="number"],
input[type="text"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0e141b;
  color: var(--text);
  padding: 9px 10px;
}

.color-row input[type="text"] {
  font-family: ui-monospace, monospace;
  font-size: 0.88rem;
  width: 100%;
}

.colors-list {
  display: grid;
  gap: 10px;
}

.color-row {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 10px;
  align-items: center;
  background: #0f1620;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
}

.color-row.dragging {
  opacity: 0.55;
}

.color-row.drop-target {
  border-color: #6ba1ff;
}

.drag-handle {
  width: 18px;
  height: 26px;
  padding: 0;
  display: grid;
  gap: 3px;
  align-content: center;
  background: transparent;
  border: none;
  cursor: grab;
}

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

.drag-handle span {
  display: block;
  width: 12px;
  height: 2px;
  background: #98a4b2;
  border-radius: 2px;
}

input[type="color"] {
  width: 52px;
  height: 36px;
  border: 0;
  padding: 0;
  background: transparent;
}

.remove-btn {
  background: #2c1218;
  border: 1px solid #6e2638;
  color: #ffb5c4;
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
}

.remove-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn {
  border: 1px solid var(--line);
  background: #21262d;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 11px;
  cursor: pointer;
}

.btn.primary {
  border-color: #235eb7;
  background: var(--accent);
}

.btn.secondary {
  background: #1b2330;
}

.unit-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

.unit-toggle {
  display: flex;
  gap: 4px;
}

.unit-btn {
  border: 1px solid var(--line);
  background: #21262d;
  color: var(--muted);
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 0.85rem;
}

.unit-btn.active {
  background: var(--accent);
  border-color: #235eb7;
  color: var(--text);
}

.dpi-label {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  color: var(--muted);
}

.dpi-label input {
  width: 72px;
}

.actions {
  margin-top: 18px;
  display: flex;
  gap: 10px;
}

.controls-footer {
  margin-top: auto;
  padding-top: 16px;
  color: var(--muted);
  font-size: 0.82rem;
}

.preview-wrap {
  background: color-mix(in srgb, var(--panel) 65%, black);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
}

.preview-viewport {
  overflow: auto;
  max-width: 100%;
  max-height: calc(100vh - 120px);
  border-radius: 12px;
}

.preview-wrap.is-large-canvas .preview-viewport {
  max-width: min(100%, 1920px);
  max-height: min(calc(100vh - 120px), 1920px);
  border: 1px solid var(--line);
  background: rgb(0 0 0 / 0.12);
  padding: 10px;
}

.preview-meta {
  color: var(--muted);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.preview-status {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sync-badge {
  font-size: 0.76rem;
  color: #8be6a5;
  background: rgb(30 83 44 / 0.45);
  border: 1px solid rgb(74 170 101 / 0.6);
  border-radius: 999px;
  padding: 3px 8px;
  white-space: nowrap;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

#zoomLabel {
  min-width: 52px;
  text-align: center;
}

.preview {
  min-width: 240px;
  min-height: 200px;
  position: relative;
  border-radius: 12px;
  border: none;
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.35);
  background-color: #000;
  overflow: hidden;
  touch-action: none;
}

.preview-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.point-handle {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgb(255 255 255 / 0.95);
  box-shadow: 0 1px 12px rgb(0 0 0 / 0.4);
  transform: translate(-50%, -50%);
  cursor: grab;
}

.point-handle:active {
  cursor: grabbing;
}

@media (max-width: 1024px) {
  .app {
    flex: none;
    grid-template-columns: 1fr;
    align-content: start;
  }
}

@media (max-width: 768px) {
  .app {
    padding: 12px;
    gap: 12px;
  }

  .brand {
    margin-bottom: 28px;
  }

  .preview-meta {
    flex-wrap: wrap;
  }

  .unit-row {
    flex-wrap: wrap;
  }

  .preview-viewport {
    max-height: calc(60vh - 80px);
  }

  .point-handle {
    width: 28px;
    height: 28px;
  }
}

@media (max-width: 480px) {
  .app {
    padding: 8px;
    gap: 8px;
  }

  .brand {
    margin-bottom: 20px;
  }

  .controls {
    border-radius: 12px;
    padding: 14px;
  }

  .preview-wrap {
    border-radius: 12px;
    padding: 10px;
  }

  h1 {
    font-size: 1.2rem;
  }

  .btn {
    padding: 10px 12px;
    min-height: 40px;
  }

  .unit-btn {
    padding: 8px 14px;
    min-height: 36px;
  }

  .actions {
    flex-direction: column;
  }

  .actions .btn {
    width: 100%;
    text-align: center;
  }

  .remove-btn {
    font-size: 0;
    padding: 0 12px;
  }

  .remove-btn::after {
    content: "×";
    font-size: 1rem;
  }

  .preview-viewport {
    max-height: 50vh;
  }

  .point-handle {
    width: 32px;
    height: 32px;
  }
}
