:root {
  --bg: #15191c;
  --panel: #22282d;
  --panel-2: #2b3238;
  --panel-3: #343c43;
  --ink: #f4f7f9;
  --muted: #aeb9c1;
  --line: #46515a;
  --accent: #66c6d4;
  --accent-2: #ffd34f;
  --danger: #ff7777;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr) 232px;
  height: 100%;
  min-width: 0;
}

.tool-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 10px 8px;
  background: linear-gradient(180deg, #1f2529 0%, #171b1e 100%);
  border-right: 1px solid #303840;
  box-shadow: inset -1px 0 rgba(255, 255, 255, 0.03);
}

.color-stack {
  width: 50px;
  padding: 6px;
  border-radius: 7px;
  background: #111619;
  border: 1px solid #3a454d;
  display: grid;
  gap: 6px;
  cursor: pointer;
}

.color-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  text-align: center;
}

#colorPicker {
  width: 38px;
  height: 34px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.tool-btn,
.active-tool,
.icon-btn,
.small-btn,
.top-command,
.panel-btn {
  border: 1px solid #46515b;
  border-radius: 8px;
  background: linear-gradient(180deg, #313941 0%, #20272d 100%);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.08), 0 2px 0 rgba(0, 0, 0, 0.2);
  cursor: pointer;
  user-select: none;
}

.tool-btn {
  width: 50px;
  height: 46px;
  display: grid;
  place-items: center;
  font-size: 22px;
  position: relative;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.tool-btn:hover,
.icon-btn:hover,
.small-btn:hover,
.active-tool:hover,
.top-command:hover,
.panel-btn:hover {
  border-color: #72808a;
  background: linear-gradient(180deg, #3d474f 0%, #273038 100%);
}

.tool-btn.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, #354149 0%, #1f2b31 100%);
  box-shadow: 0 0 0 2px rgba(102, 198, 212, 0.22), inset 0 1px rgba(255, 255, 255, 0.14);
}

.pencil-btn {
  background: linear-gradient(180deg, #313941 0%, #20272d 100%);
  color: var(--ink);
}

.eraser-btn {
  color: #ffd7df;
}

.eraser-icon {
  width: 25px;
  height: 15px;
  display: block;
  border-radius: 4px 5px 5px 4px;
  background: linear-gradient(135deg, #ffd7df 0 45%, #f7fbff 45% 100%);
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: inset 0 -2px rgba(0, 0, 0, 0.12);
  transform: rotate(-11deg);
}

.active-tool .eraser-icon {
  width: 30px;
  height: 18px;
}

.hand-btn {
  color: #d9efff;
  font-size: 25px;
}

.studio-main {
  display: grid;
  grid-template-rows: 72px 1fr;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%) 0 0 / 48px 48px,
    linear-gradient(225deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%) 0 0 / 48px 48px,
    #1b2024;
  border-bottom: 1px solid #303840;
}

.current-tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.active-tool {
  width: 56px;
  height: 48px;
  font-size: 25px;
}

.top-command {
  height: 40px;
  padding: 0 13px;
  font-size: 14px;
  font-weight: 900;
  text-transform: uppercase;
}

.slider-row {
  display: grid;
  grid-template-columns: auto minmax(108px, 180px) 32px;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-size: 17px;
  font-weight: 800;
}

.slider-row span {
  color: var(--muted);
  font-size: 17px;
}

.slider-row strong {
  color: #d9e4ea;
  min-width: 30px;
}

input[type="range"] {
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: #1b2024;
  border: 2px solid #858d93;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  margin-top: -11px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}

.top-actions {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 8px;
}

.icon-btn {
  min-width: 42px;
  height: 40px;
  padding: 0 10px;
  font-size: 20px;
  font-weight: 800;
}

select,
input[type="number"] {
  width: 100%;
  min-width: 0;
  height: 34px;
  border-radius: 7px;
  border: 1px solid #46515b;
  background: #111619;
  color: var(--ink);
  padding: 0 10px;
}

.canvas-zone {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%) 0 0 / 48px 48px,
    linear-gradient(-45deg, rgba(255, 255, 255, 0.025) 25%, transparent 25%) 0 0 / 48px 48px,
    #111416;
}

.fullscreen-exit {
  position: fixed;
  right: 18px;
  top: 18px;
  z-index: 70;
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid #46515b;
  border-radius: 8px;
  background: rgba(17, 22, 25, 0.9);
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(12px);
}

.fullscreen-exit:hover {
  border-color: #72808a;
  background: rgba(39, 48, 56, 0.94);
}

body.drawing-fullscreen .app-shell {
  grid-template-columns: minmax(0, 1fr);
}

body.drawing-fullscreen .tool-rail,
body.drawing-fullscreen .side-panel,
body.drawing-fullscreen .topbar {
  display: none;
}

body.drawing-fullscreen .studio-main {
  grid-template-rows: 1fr;
  height: 100vh;
}

body.drawing-fullscreen .canvas-zone {
  position: fixed;
  inset: 0;
  z-index: 40;
}

body.drawing-fullscreen .fullscreen-exit {
  display: grid;
  place-items: center;
}

body.drawing-fullscreen .settings-panel {
  z-index: 80;
}

.canvas-wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3300px;
  height: 2550px;
  transform-origin: 0 0;
  background: white;
  box-shadow: var(--shadow);
}

.canvas-zone.is-hand,
.canvas-zone.is-space-pan {
  cursor: grab;
}

.canvas-zone.is-panning {
  cursor: grabbing;
}

.canvas-wrap > canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: auto;
  touch-action: none;
}

#previewCanvas {
  pointer-events: none;
}

.item-overlay {
  --ui-scale: 1;
  position: absolute;
  left: 0;
  top: 0;
  z-index: 5;
  border: calc(2px * var(--ui-scale)) solid rgba(102, 198, 212, 0.95);
  outline: calc(1px * var(--ui-scale)) solid rgba(14, 18, 21, 0.72);
  transform-origin: 50% 50%;
  cursor: move;
  pointer-events: auto;
  touch-action: none;
}

.item-overlay.hidden {
  display: none;
}

.item-handle {
  position: absolute;
  width: calc(13px * var(--ui-scale));
  height: calc(13px * var(--ui-scale));
  border-radius: 50%;
  border: calc(2px * var(--ui-scale)) solid #111619;
  background: var(--accent);
  box-shadow: 0 0 0 calc(1px * var(--ui-scale)) rgba(255, 255, 255, 0.82);
  cursor: nwse-resize;
}

.item-handle.nw {
  left: calc(-7px * var(--ui-scale));
  top: calc(-7px * var(--ui-scale));
}

.item-handle.ne {
  right: calc(-7px * var(--ui-scale));
  top: calc(-7px * var(--ui-scale));
  cursor: nesw-resize;
}

.item-handle.sw {
  left: calc(-7px * var(--ui-scale));
  bottom: calc(-7px * var(--ui-scale));
  cursor: nesw-resize;
}

.item-handle.se {
  right: calc(-7px * var(--ui-scale));
  bottom: calc(-7px * var(--ui-scale));
}

.item-rotate {
  position: absolute;
  left: 50%;
  top: calc(-42px * var(--ui-scale));
  width: calc(30px * var(--ui-scale));
  height: calc(30px * var(--ui-scale));
  border: calc(1px * var(--ui-scale)) solid #46515b;
  border-radius: 999px;
  background: #111619;
  color: var(--ink);
  font-size: calc(18px * var(--ui-scale));
  font-weight: 900;
  line-height: 1;
  transform: translateX(-50%);
  cursor: grab;
}

.item-opacity {
  position: absolute;
  left: 50%;
  bottom: calc(8px * var(--ui-scale));
  display: grid;
  grid-template-columns: auto minmax(calc(80px * var(--ui-scale)), calc(128px * var(--ui-scale))) calc(30px * var(--ui-scale));
  align-items: center;
  gap: calc(7px * var(--ui-scale));
  width: calc(212px * var(--ui-scale));
  max-width: calc(100% - calc(16px * var(--ui-scale)));
  min-width: calc(150px * var(--ui-scale));
  padding: calc(5px * var(--ui-scale)) calc(7px * var(--ui-scale));
  border-radius: calc(7px * var(--ui-scale));
  border: calc(1px * var(--ui-scale)) solid rgba(255, 255, 255, 0.24);
  background: rgba(17, 22, 25, 0.86);
  color: var(--ink);
  font-size: calc(12px * var(--ui-scale));
  font-weight: 900;
  transform: translateX(-50%);
  backdrop-filter: blur(8px);
  cursor: default;
}

.item-opacity span,
.item-opacity strong {
  font-size: calc(12px * var(--ui-scale));
}

.item-opacity input[type="range"] {
  height: calc(16px * var(--ui-scale));
}

.item-opacity input[type="range"]::-webkit-slider-thumb {
  width: calc(18px * var(--ui-scale));
  height: calc(18px * var(--ui-scale));
  margin-top: calc(-8px * var(--ui-scale));
}

.brush-cursor {
  position: fixed;
  display: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(20, 24, 27, 0.82);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.92);
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 20;
}

.side-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: linear-gradient(180deg, #252b31 0%, #1d2328 100%);
  border-left: 1px solid #303840;
  padding: 12px;
  overflow-x: hidden;
  overflow-y: hidden;
}

.panel-section {
  min-width: 0;
  flex: 0 0 auto;
  padding: 0 0 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid #3a434b;
}

.action-panel {
  padding-bottom: 12px;
  margin-bottom: 14px;
}

.panel-actions {
  display: grid;
  grid-template-columns: 44px 44px 1fr;
  gap: 8px;
}

.panel-actions .icon-btn {
  width: 100%;
}

.save-action {
  font-size: 18px;
}

.panel-section h2 {
  margin: 0 0 12px;
  font-size: 14px;
  letter-spacing: 0;
  text-transform: uppercase;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dim-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.dim-grid label,
.check-row {
  min-width: 0;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

.check-row {
  display: flex;
  align-items: center;
  margin-top: 12px;
}

.small-btn {
  min-width: 30px;
  height: 30px;
  font-size: 18px;
  font-weight: 800;
}

.layer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0 0 10px;
}

.panel-btn {
  height: 32px;
  min-width: 0;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.panel-btn:disabled {
  opacity: 0.42;
  cursor: default;
}

.layer-list {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-flow: row;
  gap: 8px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 2px;
}

.layers-panel {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-bottom: 0;
  border-bottom: 0;
}

.layer-item {
  display: grid;
  grid-template-columns: 26px 38px 1fr;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 6px;
  border-radius: 8px;
  border: 1px solid #3c4650;
  background: #171d21;
  cursor: pointer;
}

.layer-item.active {
  border-color: var(--accent);
}

.layer-thumb {
  position: static;
  inset: auto;
  display: block;
  width: 38px;
  height: 27px;
  border-radius: 4px;
  background: white;
  border: 1px solid #5a646c;
}

.layer-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 800;
}

.side-slider {
  flex: 0 0 auto;
  grid-template-columns: 1fr minmax(90px, 130px) 38px;
  margin-top: 14px;
  font-size: 15px;
}

.side-slider span,
.side-slider strong {
  font-size: 15px;
}

.tool-hint {
  position: fixed;
  z-index: 50;
  display: none;
  padding: 8px 10px;
  border-radius: 7px;
  background: #f8fbfc;
  color: #13171a;
  border: 1px solid rgba(0, 0, 0, 0.16);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
  font-size: 13px;
  font-weight: 800;
  pointer-events: none;
}

.settings-panel {
  position: fixed;
  z-index: 60;
  left: 96px;
  top: 120px;
  width: min(360px, calc(100vw - 96px));
  min-width: 288px;
  max-height: calc(100vh - 24px);
  background: rgba(38, 45, 51, 0.96);
  border: 1px solid #596670;
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
  backdrop-filter: blur(18px);
}

.settings-panel.hidden {
  display: none;
}

.settings-panel header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 40px;
  padding: 0 10px;
  background: #171c20;
  cursor: move;
}

.settings-panel h2 {
  margin: 0;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0;
}

#closeSettingsBtn {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-size: 24px;
  cursor: pointer;
}

.settings-body {
  display: grid;
  gap: 11px;
  padding: 12px;
  overflow: auto;
  max-height: calc(100vh - 86px);
}

.setting-row {
  display: grid;
  grid-template-columns: 78px 1fr 34px;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-weight: 800;
}

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

.segmented button {
  height: 32px;
  border-radius: 7px;
  border: 1px solid #48545e;
  background: #151a1e;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.segmented button.active {
  color: #121619;
  background: var(--accent-2);
  border-color: #ffe58c;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 64px minmax(0, 1fr);
  }

  .side-panel {
    display: none;
  }

  .topbar {
    grid-template-columns: auto auto;
    justify-content: space-between;
    gap: 9px;
  }

  .top-actions {
    display: flex;
  }

  .top-actions select {
    width: 76px;
  }

  .slider-row {
    grid-template-columns: auto minmax(68px, 1fr) 28px;
    gap: 7px;
  }
}

@media (max-width: 640px) {
  .topbar {
    grid-template-columns: 96px minmax(0, 1fr);
    padding: 9px 10px;
  }

  .active-tool {
    width: 52px;
  }

  .slider-row span,
  .slider-row strong {
    font-size: 15px;
  }
}
