:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-strong: #eef3f5;
  --ink: #172126;
  --muted: #64727a;
  --line: #d9e1e4;
  --accent: #0e8f83;
  --accent-strong: #08766d;
  --accent-soft: #d9f3ee;
  --warm: #f6b44b;
  --danger: #be4b49;
  --shadow: 0 18px 45px rgba(28, 39, 45, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    linear-gradient(180deg, #ffffff 0%, var(--bg) 45%, #edf2f3 100%);
  color: var(--ink);
}

button,
input,
label {
  font: inherit;
}

button,
label.button,
.empty-button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 82px;
  padding: 18px clamp(18px, 3vw, 42px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(16px);
}

h1 {
  margin: 0;
  font-size: clamp(22px, 2.6vw, 34px);
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: 0;
}

.status {
  min-height: 22px;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#fileInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.button,
.wide-button,
.icon-tool,
.segment,
.empty-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.button,
.wide-button,
.empty-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 750;
  text-decoration: none;
}

.button svg,
.wide-button svg,
.icon-tool svg {
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.button:hover:not(:disabled),
.wide-button:hover:not(:disabled),
.icon-tool:hover:not(:disabled),
.segment:hover,
.empty-button:hover {
  border-color: #b9c7cb;
  box-shadow: 0 10px 24px rgba(28, 39, 45, 0.1);
}

.button:active:not(:disabled),
.wide-button:active:not(:disabled),
.icon-tool:active:not(:disabled),
.segment:active,
.empty-button:active {
  transform: translateY(1px);
}

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

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

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(236px, 292px) 1fr;
  gap: clamp(14px, 2vw, 24px);
  padding: clamp(14px, 2.6vw, 30px);
  min-height: 0;
}

.controls {
  align-self: start;
  display: grid;
  gap: 14px;
}

.control-group {
  display: grid;
  gap: 12px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 26px rgba(28, 39, 45, 0.06);
}

.control-heading {
  color: #2f3d43;
  font-size: 13px;
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 38px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.segment {
  min-width: 0;
  border: 0;
  border-radius: 0;
  color: var(--muted);
  font-weight: 750;
}

.segment + .segment {
  border-left: 1px solid var(--line);
}

.segment.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.wide-button {
  width: 100%;
}

.wide-button.danger {
  color: var(--danger);
}

.swatch-row {
  display: grid;
  grid-template-columns: auto 32px 1fr;
  align-items: center;
  gap: 9px;
  min-height: 34px;
  color: var(--muted);
  font-size: 13px;
}

.swatch-label {
  font-weight: 750;
}

.swatch {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #d5dde0 25%, transparent 25%),
    linear-gradient(-45deg, #d5dde0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d5dde0 75%),
    linear-gradient(-45deg, transparent 75%, #d5dde0 75%);
  background-color: #fff;
  background-position:
    0 0,
    0 8px,
    8px -8px,
    -8px 0;
  background-size: 16px 16px;
}

.color-value {
  min-width: 0;
  overflow: hidden;
  color: #405058;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slider-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  color: #2f3d43;
  font-size: 13px;
  font-weight: 750;
}

output {
  min-width: 3ch;
  color: var(--accent-strong);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

.tool-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.icon-tool {
  display: inline-grid;
  place-items: center;
  min-height: 44px;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
}

.icon-tool.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.canvas-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
}

.drop-zone {
  position: relative;
  min-height: 420px;
  height: min(680px, max(420px, calc(100vh - 190px)));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(45deg, #dce4e7 25%, transparent 25%),
    linear-gradient(-45deg, #dce4e7 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dce4e7 75%),
    linear-gradient(-45deg, transparent 75%, #dce4e7 75%);
  background-color: #f8fbfb;
  background-position:
    0 0,
    0 13px,
    13px -13px,
    -13px 0;
  background-size: 26px 26px;
  box-shadow: var(--shadow);
}

.drop-zone.dragging {
  border-color: var(--accent);
  box-shadow:
    0 0 0 4px rgba(14, 143, 131, 0.16),
    var(--shadow);
}

#imageCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
}

.drop-zone.pick-mode #imageCanvas {
  cursor: crosshair;
}

.drop-zone.brush-mode #imageCanvas {
  cursor: none;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  pointer-events: none;
}

.empty-state.hidden {
  display: none;
}

.empty-button {
  border-color: var(--accent);
  background: #fff;
  color: var(--accent-strong);
  pointer-events: auto;
}

.brush-cursor {
  position: absolute;
  z-index: 3;
  width: 34px;
  height: 34px;
  border: 2px solid var(--warm);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.8);
  pointer-events: none;
  transform: translate(-50%, -50%);
  display: none;
}

.brush-cursor.visible {
  display: block;
}

@media (max-width: 820px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: stretch;
  }

  .top-actions .button,
  .top-actions label.button {
    flex: 1 1 150px;
  }

  .workbench {
    grid-template-columns: 1fr;
  }

  .controls {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch;
  }

  .drop-zone {
    height: 58vh;
    min-height: 380px;
  }
}

@media (max-width: 640px) {
  .controls {
    grid-template-columns: 1fr;
  }

  .button,
  .wide-button,
  .empty-button {
    min-height: 44px;
  }

  .drop-zone {
    height: 52vh;
    min-height: 340px;
  }
}
