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

:root {
  --ui-bg: #f5f5f5;
  --panel: #ffffff;
  --line: #dfdfdf;
  --muted: #8c8c8c;
  --text: #4d4d4d;
  --blue: #1188cd;
  --blue-deep: #0f78b4;
  --paint-shadow: 0 14px 40px rgba(0, 0, 0, 0.08);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #ffffff;
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
}

#app-shell {
  --right-rail-width: 196px;
  position: relative;
  display: grid;
  grid-template-columns: 66px 1fr var(--right-rail-width);
  width: 100%;
  height: 100%;
  background: #ffffff;
}

#app-shell.right-rail-collapsed {
  --right-rail-width: 34px;
}

#left-rail,
#right-rail {
  background: #ffffff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
}

#right-rail {
  border-right: 0;
  border-left: 1px solid var(--line);
  padding: 12px 10px 16px;
  gap: 14px;
  position: relative;
  overflow: hidden;
}

#left-rail {
  padding: 12px 0 18px;
  gap: 14px;
}

.tool-chip {
  width: 40px;
  height: 52px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: transparent;
  color: #a3a3a3;
  border: 1px solid transparent;
}

.tool-chip.active {
  background: var(--blue);
  color: #ffffff;
  box-shadow: 0 12px 22px rgba(17, 136, 205, 0.25);
}

.tool-chip.ghost {
  margin-top: auto;
}

.tool-icon {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.rail-slider-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.rail-track {
  position: relative;
  width: 34px;
  height: 190px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.vertical-slider {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.rail-track-shell {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 0;
  bottom: 0;
  border-radius: 4px;
  background: #dfdfdf;
}

.rail-track-fill {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 0;
  height: calc(var(--slider-progress, 0.2) * 100%);
  min-height: 0;
  border-radius: 0 0 4px 4px;
  background: var(--blue);
}

.rail-track-thumb {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: calc(var(--slider-progress, 0.2) * 100% - 8px);
  height: 18px;
  border-radius: 6px;
  background: #ffffff;
  border: 1px solid rgba(145, 145, 145, 0.35);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.95),
    0 2px 6px rgba(0, 0, 0, 0.12);
}

.rail-track-thumb::before {
  content: "";
  position: absolute;
  left: 6px;
  right: 6px;
  top: 5px;
  height: 6px;
  border-radius: 3px;
  background: rgba(214, 214, 214, 0.9);
}

.rail-value {
  font-size: 11px;
  color: var(--muted);
}

.corners-icon {
  position: relative;
  width: 18px;
  height: 18px;
  display: block;
}

.corners-icon::before,
.corners-icon::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border-color: currentColor;
  border-style: solid;
}

.corners-icon::before {
  left: 0;
  top: 0;
  border-width: 3px 0 0 3px;
}

.corners-icon::after {
  right: 0;
  bottom: 0;
  border-width: 0 3px 3px 0;
}

#workspace {
  position: relative;
  min-width: 0;
  background: #ffffff;
}

#topbar {
  position: absolute;
  top: 12px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
  z-index: 6;
}

.mode-switch {
  display: inline-flex;
  border-radius: 10px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
  pointer-events: auto;
}

.mode-btn {
  min-width: 136px;
  height: 50px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #8d8d8d;
  background: #ffffff;
  border: 1px solid #dadada;
}

.mode-btn + .mode-btn {
  border-left: 0;
}

.mode-btn.active {
  background: var(--blue);
  color: #ffffff;
  border-color: var(--blue);
}

#canvas-zone {
  position: absolute;
  inset: 0;
  background: #ffffff;
}

#stage-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

#canvas-corners {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  display: none;
}

.canvas-corner {
  position: absolute;
  width: 28px;
  height: 28px;
}

.canvas-corner::before,
.canvas-corner::after {
  content: "";
  position: absolute;
  background: var(--blue);
  border-radius: 999px;
}

.canvas-corner.tl::before,
.canvas-corner.tr::before,
.canvas-corner.bl::before,
.canvas-corner.br::before {
  width: 28px;
  height: 5px;
}

.canvas-corner.tl::after,
.canvas-corner.tr::after,
.canvas-corner.bl::after,
.canvas-corner.br::after {
  width: 5px;
  height: 28px;
}

.canvas-corner.tl { left: 0; top: 0; }
.canvas-corner.tl::before { left: 0; top: 0; }
.canvas-corner.tl::after { left: 0; top: 0; }

.canvas-corner.tr { right: 0; top: 0; }
.canvas-corner.tr::before { right: 0; top: 0; }
.canvas-corner.tr::after { right: 0; top: 0; }

.canvas-corner.bl { left: 0; bottom: 0; }
.canvas-corner.bl::before { left: 0; bottom: 0; }
.canvas-corner.bl::after { left: 0; bottom: 0; }

.canvas-corner.br { right: 0; bottom: 0; }
.canvas-corner.br::before { right: 0; bottom: 0; }
.canvas-corner.br::after { right: 0; bottom: 0; }

#display-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#bcursor {
  position: absolute;
  pointer-events: none;
  display: none;
  border-radius: 50%;
  border: 1px solid rgba(90, 90, 90, 0.55);
  transform: translate(-50%, -50%);
  z-index: 5;
}

.color-wheel-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.rail-collapse-toggle {
  position: absolute;
  left: -13px;
  top: 22px;
  width: 26px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.96);
  color: #8c8c8c;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.08);
  z-index: 2;
}

#right-rail-toggle-glyph {
  display: inline-block;
  font-size: 16px;
  line-height: 1;
  transform: translateX(2px);
}

#app-shell.right-rail-collapsed #right-rail-toggle-glyph {
  transform: translateX(-2px) rotate(180deg);
}

#app-shell.right-rail-collapsed #right-rail {
  padding-left: 0;
  padding-right: 0;
}

#app-shell.right-rail-collapsed #right-rail > :not(.rail-collapse-toggle) {
  opacity: 0;
  pointer-events: none;
}

.wheel-wrap {
  width: 170px;
  height: 170px;
  border-radius: 50%;
  background: conic-gradient(#ff0000, #ffcf00, #23ff00, #00e4ff, #2142ff, #b000ff, #ff0090, #ff0000);
  display: grid;
  place-items: center;
  position: relative;
}

.wheel-wrap::before {
  content: "";
  width: 126px;
  height: 126px;
  border-radius: 50%;
  background: #ffffff;
  position: absolute;
}

.wheel-wrap input[type="color"] {
  position: relative;
  z-index: 1;
  width: 92px;
  height: 92px;
  border: 0;
  background: none;
}

.wheel-wrap input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.wheel-wrap input[type="color"]::-webkit-color-swatch {
  border: 0;
}

.current-swatch {
  font-size: 12px;
  color: var(--muted);
}

.mix-strip {
  width: 170px;
  height: 46px;
  border-radius: 0;
  background: linear-gradient(90deg, #142047, #0f69b5, #ffffff);
}

.pigment-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 0 2px;
}

.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow:
    inset -6px -6px 8px rgba(255, 255, 255, 0.18),
    inset 6px 6px 10px rgba(0, 0, 0, 0.08),
    0 3px 5px rgba(0, 0, 0, 0.08);
}

.swatch.active {
  border-color: var(--blue);
}

.right-cta,
.right-ghost {
  width: 170px;
  min-height: 46px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.right-cta {
  background: var(--blue);
  color: #ffffff;
}

.right-ghost {
  background: #ffffff;
  color: #6e6e6e;
  border: 1px solid var(--line);
}

#bottom-drawer {
  position: absolute;
  left: 88px;
  right: calc(var(--right-rail-width) + 24px);
  bottom: 18px;
  background: rgba(255, 255, 255, 0.97);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--paint-shadow);
  z-index: 10;
  overflow: hidden;
}

#bottom-drawer.hidden {
  display: none;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #ededed;
}

.drawer-tabs {
  display: flex;
  gap: 8px;
}

.drawer-tab {
  padding: 8px 14px;
  border-radius: 999px;
  background: #f1f1f1;
  color: #7d7d7d;
  font-size: 12px;
  font-weight: 700;
}

.drawer-tab.active {
  background: var(--blue);
  color: #ffffff;
}

.drawer-close {
  color: #8e8e8e;
  font-size: 12px;
  font-weight: 700;
}

.drawer-body {
  padding: 16px;
}

.drawer-panel {
  display: none;
}

.drawer-panel.active {
  display: block;
}

.drawer-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.drawer-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field span {
  font-size: 12px;
  color: var(--muted);
}

.field input[type="text"],
.field input[type="number"],
.field input[type="file"],
.field select,
.field textarea,
.field input[type="range"] {
  width: 100%;
}

.field input[type="text"],
.field input[type="number"],
.field input[type="file"],
.field select,
.field textarea {
  min-height: 40px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #dfdfdf;
  background: #fafafa;
  color: #555555;
}

.field textarea {
  min-height: 68px;
  resize: vertical;
}

.field strong {
  font-size: 12px;
  color: var(--blue);
}

.field input[type="range"] {
  appearance: none;
  height: 14px;
  border-radius: 999px;
  background: #e1e1e1;
}

.field input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 26px;
  height: 14px;
  border-radius: 999px;
  background: #8e8e8e;
}

.drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.plain-btn {
  min-width: 96px;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid #dbdbdb;
  background: #ffffff;
  color: #757575;
  font-size: 12px;
  font-weight: 700;
}

.plain-btn.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #ffffff;
}

.plain-btn.accent {
  background: #ffffff;
  border-color: var(--blue);
  color: var(--blue);
}

#layers {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 240px;
  overflow-y: auto;
  margin-top: 8px;
}

.layer-item {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 10px;
  padding: 10px;
  border-radius: 12px;
  border: 1px solid #e1e1e1;
  background: #ffffff;
}

.layer-item.active {
  border-color: #9ccff1;
  box-shadow: inset 0 0 0 1px rgba(17, 136, 205, 0.16);
}

.layer-thumb {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  border: 1px solid #e6e6e6;
  background:
    linear-gradient(45deg, #efefef 25%, transparent 25%),
    linear-gradient(-45deg, #efefef 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #efefef 75%),
    linear-gradient(-45deg, transparent 75%, #efefef 75%);
  background-size: 12px 12px;
  background-position: 0 0, 0 6px, 6px -6px, -6px 0;
}

.layer-meta {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.layer-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.layer-name {
  font-size: 12px;
  font-weight: 700;
  color: #555555;
}

.eye-btn {
  min-width: 44px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid #e1e1e1;
  background: #fafafa;
  color: #868686;
  font-size: 11px;
}

#ai-window {
  position: absolute;
  top: 96px;
  right: 228px;
  width: 360px;
  min-height: 290px;
  border-radius: 18px;
  border: 1px solid #dfdfdf;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--paint-shadow);
  overflow: hidden;
  z-index: 14;
  touch-action: none;
}

#ai-window.hidden {
  display: none;
}

#ai-window-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: #f7f7f7;
  border-bottom: 1px solid #ececec;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: #7c7c7c;
  cursor: move;
}

#ai-render-state {
  color: var(--blue);
}

.ai-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px 16px;
  height: calc(100% - 52px);
  min-height: 0;
}

.mix-toggle-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.toggle-chip {
  min-width: 84px;
  min-height: 36px;
  border-radius: 999px;
  background: #ededed;
  color: #8c8c8c;
  font-size: 12px;
  font-weight: 700;
}

.toggle-chip.on {
  background: var(--blue);
  color: #ffffff;
}

.ai-preview-frame {
  position: relative;
  flex: 1 1 auto;
  min-height: 160px;
  border-radius: 14px;
  border: 1px solid #e5e5e5;
  background:
    linear-gradient(45deg, #f0f0f0 25%, transparent 25%),
    linear-gradient(-45deg, #f0f0f0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f0f0f0 75%),
    linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  overflow: hidden;
}

.ai-mini-actions {
  display: flex;
  gap: 10px;
}

.ai-mini-actions .plain-btn {
  flex: 1;
}

.expand-btn {
  width: 42px;
  min-width: 42px;
  min-height: 40px;
  border-radius: 10px;
  border: 1px solid #dbdbdb;
  background: #ffffff;
  color: #7b7b7b;
  font-size: 20px;
  display: grid;
  place-items: center;
}

#ai-expand-glyph {
  display: inline-block;
  transition: transform 0.18s ease;
}

#ai-window.expanded #ai-expand-glyph {
  transform: rotate(180deg);
}

#ai-timer {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 26px;
  color: #7c7c7c;
  font-size: 12px;
}

#ai-hourglass {
  display: inline-block;
  font-size: 16px;
  line-height: 1;
}

#ai-timer.running #ai-hourglass {
  animation: hourglass-spin 1s steps(2, end) infinite;
}

#ai-timer.running #ai-timer-text {
  color: var(--blue);
}

#ai-config-panel {
  display: none;
  flex-direction: column;
  gap: 12px;
  padding-top: 2px;
}

#ai-window.expanded #ai-config-panel {
  display: flex;
  flex: 0 0 auto;
}

@keyframes hourglass-spin {
  0% { transform: rotate(0deg); }
  50% { transform: rotate(180deg); }
  100% { transform: rotate(360deg); }
}

#ai-preview {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
}

#ai-preview-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #a0a0a0;
  font-size: 12px;
}

#ai-resize-handle {
  position: absolute;
  width: 18px;
  height: 18px;
  right: 2px;
  bottom: 2px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 0 42%, #cccccc 42% 56%, transparent 56% 100%);
}

#status-badge {
  position: absolute;
  left: 92px;
  top: 14px;
  z-index: 9;
  min-height: 34px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid #e3e3e3;
  color: #8c8c8c;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  max-width: 420px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
}

#status-badge.ok {
  color: #2f8d4f;
}

#status-badge.err {
  color: #cc5a4d;
}

@media (max-width: 1100px) {
  #app-shell {
    --right-rail-width: 168px;
    grid-template-columns: 58px 1fr var(--right-rail-width);
  }

  #right-rail {
    padding-inline: 6px;
  }

  .wheel-wrap {
    width: 140px;
    height: 140px;
  }

  .wheel-wrap::before {
    width: 104px;
    height: 104px;
  }

  .mix-strip,
  .right-cta,
  .right-ghost {
    width: 148px;
  }

  #bottom-drawer {
    left: 74px;
    right: calc(var(--right-rail-width) + 14px);
  }

}
