:root {
  --bg: #f2efe7;
  --panel: rgba(255, 251, 244, 0.92);
  --panel-strong: #fffdf8;
  --ink: #1f1a16;
  --muted: #685f57;
  --border: rgba(50, 34, 18, 0.14);
  --border-strong: rgba(36, 22, 10, 0.24);
  --accent: #3f6c52;
  --accent-strong: #264733;
  --accent-soft: rgba(63, 108, 82, 0.1);
  --stage: #ede7db;
  --drop: rgba(255, 251, 244, 0.82);
  --shadow: 0 24px 60px rgba(28, 21, 14, 0.12);
  --mobile-panel-height: 52vh;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110;
    --panel: rgba(22, 22, 20, 0.94);
    --panel-strong: #181715;
    --ink: #f1ece3;
    --muted: #aba093;
    --border: rgba(255, 245, 232, 0.08);
    --border-strong: rgba(255, 245, 232, 0.16);
    --accent: #9ed0ae;
    --accent-strong: #d6f2dc;
    --accent-soft: rgba(158, 208, 174, 0.1);
    --stage: #171614;
    --drop: rgba(24, 23, 21, 0.85);
    --shadow: 0 26px 70px rgba(0, 0, 0, 0.3);
  }
}

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

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(circle at top left, rgba(63, 108, 82, 0.12), transparent 32%),
    radial-gradient(circle at top right, rgba(199, 162, 97, 0.12), transparent 28%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.32), transparent 28%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.page-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-header {
  max-width: 1320px;
  margin: 0 auto;
  padding: 28px 24px 18px;
  width: 100%;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 0.82rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.page-header h1 {
  margin: 0;
  font-size: clamp(2rem, 4.4vw, 3.7rem);
  line-height: 0.98;
  letter-spacing: -0.04em;
}

.lede {
  margin: 14px 0 0;
  max-width: 58rem;
  line-height: 1.55;
  color: var(--muted);
}

.app-shell {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 24px 28px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  flex: 1;
}

.stage-panel,
.control-panel {
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.stage-panel {
  display: flex;
  flex-direction: column;
  min-height: 560px;
  padding: 18px;
}

.stage-topline,
.stage-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stage-topline {
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-strong);
  font-size: 0.87rem;
}

.pill.subtle {
  color: var(--muted);
}

.canvas-area {
  position: relative;
  flex: 1;
  min-height: 420px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background:
    linear-gradient(45deg, rgba(0, 0, 0, 0.03) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.03) 75%),
    linear-gradient(45deg, rgba(0, 0, 0, 0.03) 25%, transparent 25%, transparent 75%, rgba(0, 0, 0, 0.03) 75%),
    var(--stage);
  background-position: 0 0, 14px 14px, 0 0;
  background-size: 28px 28px;
  overflow: hidden;
}

.canvas-area.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -14px;
}

#previewCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  position: absolute;
  inset: 0;
  margin: auto;
  object-fit: contain;
  image-rendering: pixelated;
}

.drop-zone {
  position: absolute;
  inset: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  text-align: center;
  gap: 10px;
  border: 1px dashed var(--border-strong);
  border-radius: 18px;
  background: var(--drop);
  color: var(--muted);
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.drop-zone.hidden {
  opacity: 0;
  pointer-events: none;
}

.drop-zone-glyph {
  width: 60px;
  height: 60px;
  border-radius: 18px;
  border: 1px solid var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  color: var(--accent);
}

.drop-zone strong {
  color: var(--ink);
}

.drop-zone p {
  margin: 0;
  max-width: 24rem;
}

.stage-footer {
  margin-top: 14px;
  flex-wrap: wrap;
}

.stage-footer p {
  margin: 0;
}

#statusLine {
  color: var(--muted);
}

.privacy-note {
  font-size: 0.92rem;
}

.control-panel {
  position: relative;
  overflow: hidden;
}

.panel-handle {
  display: none;
}

.panel-scroll {
  padding: 18px;
  height: 100%;
  overflow: auto;
}

.panel-scroll::-webkit-scrollbar {
  width: 8px;
}

.panel-scroll::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

.control-section + .control-section {
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
}

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

.section-heading p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.button-stack {
  display: grid;
  gap: 10px;
}

.button-stack-attached {
  margin-top: 10px;
}

.button,
.chip {
  border-radius: 14px;
  border: 1px solid var(--border-strong);
  background: var(--panel-strong);
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.button:hover,
.chip:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}

.button.primary {
  background: var(--accent);
  color: #f7f4ee;
  border-color: var(--accent);
}

.button.primary:hover {
  background: var(--accent-strong);
}

.button.secondary {
  background: var(--panel-strong);
}

.button.ghost {
  background: transparent;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.divider span {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.field,
.range-field {
  display: grid;
  gap: 7px;
  margin-top: 14px;
}

.field span,
.range-field label {
  font-size: 0.92rem;
}

select,
input[type="text"] {
  width: 100%;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--panel-strong);
  color: inherit;
  padding: 10px 12px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.range-field output {
  color: var(--muted);
  font-size: 0.9rem;
}

.palette-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  max-height: 28rem;
  overflow: auto;
  padding-right: 4px;
}

.palette-list::-webkit-scrollbar {
  width: 8px;
}

.palette-list::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
}

.palette-entry {
  display: grid;
  grid-template-columns: 44px minmax(0, 90px) minmax(0, 1fr) 42px;
  gap: 8px;
  align-items: center;
}

.palette-color {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--panel-strong);
}

.palette-weight {
  margin: 0;
}

.palette-percent {
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.preset-row {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 9px 12px;
  font-size: 0.9rem;
}

.hidden {
  display: none !important;
}

.page-footer {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 24px 28px;
  color: var(--muted);
}

.page-footer a {
  color: inherit;
  text-decoration: none;
}

.page-footer a:hover {
  text-decoration: underline;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .stage-panel {
    min-height: 480px;
  }
}

@media (max-width: 800px) {
  body {
    overflow-x: hidden;
  }

  .page-header {
    padding: 20px 16px 14px;
  }

  .app-shell {
    padding: 0 16px 16px;
    display: block;
  }

  .stage-panel {
    min-height: calc(100vh - 160px);
    padding-bottom: calc(var(--mobile-panel-height) + 18px);
  }

  .control-panel {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    height: var(--mobile-panel-height);
    z-index: 10;
    border-radius: 22px;
  }

  .panel-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 12px 0 8px;
    border: 0;
    background: transparent;
    cursor: ns-resize;
    touch-action: none;
  }

  .panel-handle-bar {
    width: 52px;
    height: 5px;
    border-radius: 999px;
    background: var(--border-strong);
  }

  .panel-scroll {
    padding-top: 8px;
    height: calc(100% - 44px);
  }

  .page-footer {
    padding: 0 16px 16px;
  }
}

@media (max-width: 560px) {
  .palette-entry {
    grid-template-columns: 44px minmax(0, 84px) minmax(0, 1fr) 38px;
  }

  .canvas-area {
    min-height: 320px;
  }
}
