:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #d9dde2;
  color: #20242a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 312px 1fr;
  overflow: hidden;
}

.sidebar {
  height: 100vh;
  overflow: auto;
  background: #e9edf1;
  border-right: 1px solid #c8cdd3;
  padding: 10px;
  font-size: 13px;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 40px;
  padding: 2px 2px 8px;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.15;
}

.icon-button {
  width: 32px;
  min-width: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 50%;
  font-weight: 700;
}

.summary {
  color: #65707d;
  font-size: 12px;
  line-height: 1.28;
}

.tool-note {
  margin-top: 6px;
}

.sidebar section {
  --section-accent: #6d7885;
  --section-bg: #f5f7f9;
  margin-top: 8px;
  padding: 9px 9px 10px 10px;
  border: 1px solid #d2d8df;
  border-left: 4px solid var(--section-accent);
  border-radius: 8px;
  background: var(--section-bg);
}

.sidebar section:nth-of-type(1) {
  --section-accent: #0f6f78;
  --section-bg: #edf7f8;
}

.sidebar section:nth-of-type(2) {
  --section-accent: #496f9b;
  --section-bg: #f0f5fb;
}

.sidebar section:nth-of-type(3) {
  --section-accent: #7b5a88;
  --section-bg: #f7f1fa;
}

.sidebar section:nth-of-type(4) {
  --section-accent: #9a596b;
  --section-bg: #fbf1f4;
}

.sidebar section:nth-of-type(5) {
  --section-accent: #8a6a2d;
  --section-bg: #faf6ec;
}

.sidebar section:nth-of-type(6) {
  --section-accent: #668052;
  --section-bg: #f2f7ef;
}

.sidebar section:nth-of-type(7) {
  --section-accent: #5d728a;
  --section-bg: #f1f5f8;
}

.sidebar section:nth-of-type(8) {
  --section-accent: #596574;
  --section-bg: #f3f5f7;
}

h2 {
  margin: 0 0 7px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  color: #3f4853;
}

.section-toggle {
  width: 100%;
  min-height: 24px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 800;
  text-align: left;
  text-transform: uppercase;
}

.section-toggle:hover {
  border-color: transparent;
}

.section-toggle-icon {
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  border: 1px solid #b9c0c8;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.65);
  color: #56616e;
  font-size: 12px;
  line-height: 1;
}

.section-body {
  display: block;
}

.sidebar section.collapsed {
  padding-bottom: 8px;
}

.sidebar section.collapsed .section-body {
  display: none;
}

label {
  display: grid;
  gap: 4px;
  margin-bottom: 6px;
  font-size: 13px;
  color: #3e4650;
}

input,
select,
button,
.button {
  border: 1px solid #b9c0c8;
  border-radius: 6px;
  background: #fff;
  color: #20242a;
  font: inherit;
  font-size: 13px;
  min-height: 30px;
}

input,
select {
  width: 100%;
  padding: 4px 8px;
}

input[type="range"] {
  min-height: 30px;
  padding: 0;
  accent-color: #0f6f78;
}

button,
.button {
  padding: 5px 9px;
  cursor: pointer;
  text-align: center;
  user-select: none;
}

button:hover,
.button:hover {
  border-color: #7c8794;
}

.primary-button {
  background: #0f6f78;
  border-color: #0f6f78;
  color: #fff;
}

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

.button input {
  display: none;
}

.button-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.button-row > label {
  margin-bottom: 0;
}

.button-row + .slider-stack {
  margin-top: 8px;
}

.project-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: stretch;
}

.project-actions button,
.project-actions .button {
  width: 100%;
}

.image-tabs {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: 8px;
}

.image-tab {
  width: 100%;
  min-height: 30px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  padding: 4px 7px;
  border-color: #c9d2da;
  background: #ffffff;
  color: #35404c;
  text-align: left;
}

.image-tab.active {
  border-color: #0f6f78;
  background: #dff4f6;
  color: #123f45;
}

.image-tab-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-tab-state {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: transparent;
}

.image-tab.dirty .image-tab-state {
  background: #c7681b;
}

.background-actions button {
  flex: 1 1 calc(50% - 4px);
}

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

.check input {
  width: auto;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
  margin-bottom: 8px;
}

.segmented-control button {
  min-width: 0;
}

.segmented-control button.active {
  border-color: #0f6f78;
  background: #dceff1;
  color: #0c5961;
  font-weight: 700;
}

.slider-stack {
  display: grid;
  gap: 4px;
  margin-bottom: 8px;
}

.slider-field {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 64px;
  gap: 7px;
  align-items: center;
  min-height: 34px;
  margin-bottom: 4px;
}

.slider-field label {
  display: block;
  margin: 0;
  text-align: right;
  color: #3e4650;
}

.slider-field input[type="number"] {
  min-height: 28px;
  padding: 4px 6px;
  text-align: right;
}

.temp-slider input[type="range"] {
  background: linear-gradient(90deg, #536dff, #e6e06d);
  border-radius: 999px;
}

.tint-slider input[type="range"] {
  background: linear-gradient(90deg, #31b846, #cf4fc4);
  border-radius: 999px;
}

.color-grade-grid {
  display: grid;
  gap: 8px;
  margin-bottom: 8px;
}

.color-grade-control {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 7px 9px;
  align-items: center;
  padding: 7px;
  border: 1px solid #d0d6de;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
}

.color-grade-heading {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #3e4650;
  font-weight: 700;
}

.color-grade-heading button {
  min-height: 24px;
  padding: 2px 7px;
  font-size: 12px;
}

.color-wheel {
  --marker-x: 0%;
  --marker-y: 0%;
  --grade-color: hsl(0 100% 50%);
  position: relative;
  width: 88px;
  aspect-ratio: 1;
  border: 1px solid #9ba6b2;
  border-radius: 50%;
  background:
    radial-gradient(circle, #f4f6f8 0 13%, transparent 14%),
    radial-gradient(circle, transparent 0 54%, rgba(255, 255, 255, 0.88) 55% 62%, transparent 63%),
    conic-gradient(#f33, #ffbf00, #24d957, #18c7ef, #3158ff, #c822f2, #f33);
  box-shadow: inset 0 0 0 7px rgba(255, 255, 255, 0.8);
  cursor: crosshair;
  touch-action: none;
}

.color-wheel:focus-visible {
  outline: 2px solid #0f6f78;
  outline-offset: 2px;
}

.color-wheel::after {
  content: "";
  position: absolute;
  inset: 27%;
  border: 1px solid rgba(62, 70, 80, 0.36);
  border-radius: 50%;
  background: rgba(245, 247, 249, 0.55);
  pointer-events: none;
}

.color-wheel-marker {
  position: absolute;
  left: calc(50% + var(--marker-x));
  top: calc(50% + var(--marker-y));
  z-index: 1;
  width: 16px;
  height: 16px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--grade-color);
  box-shadow: 0 0 0 1px rgba(32, 36, 42, 0.78), 0 2px 5px rgba(32, 36, 42, 0.28);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.grade-amount {
  grid-template-columns: 62px minmax(0, 1fr) 52px;
  margin: 0;
}

.grade-amount label {
  text-align: left;
}

.workspace {
  min-width: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: 52px 1fr;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 9px 14px;
  background: #eceff2;
  border-bottom: 1px solid #c8cdd3;
}

#status {
  min-width: 0;
  flex: 1;
  color: #48525f;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.zoom-controls button {
  min-width: 34px;
  min-height: 30px;
  padding: 4px 9px;
}

.before-button {
  min-width: 68px;
}

.before-button.active {
  border-color: #0f6f78;
  background: #dceff1;
  color: #0c5961;
  font-weight: 700;
}

.zoom-level {
  min-width: 54px;
  min-height: 30px;
  display: grid;
  place-items: center;
  padding: 4px 8px;
  border: 1px solid #b9c0c8;
  border-radius: 6px;
  background: #fff;
  color: #303843;
  font-size: 13px;
}

.stage-wrap {
  position: relative;
  overflow: auto;
  padding: 32px 32px 104px;
}

.stage {
  position: relative;
  width: fit-content;
  height: fit-content;
  margin: 0 auto;
}

canvas {
  position: absolute;
  display: block;
  background-color: transparent;
  background-image:
    linear-gradient(45deg, #c5cad0 25%, transparent 25%),
    linear-gradient(-45deg, #c5cad0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #c5cad0 75%),
    linear-gradient(-45deg, transparent 75%, #c5cad0 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  box-shadow: 0 12px 32px rgba(24, 31, 40, 0.22);
  cursor: crosshair;
}

canvas.preview-white {
  background: #fff;
}

canvas.preview-gray {
  background: #bfc5cc;
}

canvas.preview-black {
  background: #11161d;
}

.empty-state {
  width: min(520px, calc(100vw - 390px));
  min-height: 280px;
  margin: 80px auto 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 16px;
  border: 1px dashed #a8b1bd;
  border-radius: 8px;
  background: #eef1f4;
  color: #4c5663;
}

.empty-state strong {
  font-size: 20px;
}

.brush-cursor {
  position: absolute;
  width: var(--brush-size, 42px);
  height: var(--brush-size, 42px);
  border: 2px solid rgba(15, 111, 120, 0.95);
  border-radius: 50%;
  box-shadow: 0 0 0 1px #fff;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 3;
}

.busy-overlay,
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(28, 34, 42, 0.48);
  z-index: 20;
}

.busy-card,
.modal-card {
  width: min(480px, calc(100vw - 48px));
  padding: 18px;
  border: 1px solid #c8cdd3;
  border-radius: 8px;
  background: #f8fafc;
  box-shadow: 0 20px 60px rgba(16, 24, 32, 0.28);
}

.busy-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: center;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid #cbd3dc;
  border-top-color: #0f6f78;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.modal-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.modal-heading h2 {
  margin: 0;
}

.modal-card p {
  margin: 0 0 10px;
  color: #3e4650;
  line-height: 1.45;
}

.hidden {
  display: none !important;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 860px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    overflow: auto;
  }

  .sidebar {
    height: auto;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid #c8cdd3;
  }

  .workspace {
    height: min(72vh, 760px);
  }

  .empty-state {
    width: min(520px, calc(100vw - 64px));
    margin-top: 32px;
  }
}
