:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #5b6673;
  --line: #d8dee6;
  --active: #1664d9;
  --active-soft: #e8f0ff;
  --danger: #c43333;
  --shadow: 0 16px 44px rgba(26, 38, 54, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

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

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  font-size: 1.22rem;
  font-weight: 800;
  white-space: nowrap;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border: 2px solid var(--ink);
  border-radius: 7px;
  background:
    linear-gradient(135deg, transparent 48%, var(--ink) 49% 53%, transparent 54%),
    conic-gradient(from 90deg, #e53935, #fdd835, #43a047, #1e88e5, #8e24aa, #e53935);
  box-shadow: inset 0 0 0 5px #fff;
}

.quick-actions,
.tool-group,
.action-grid {
  display: flex;
  align-items: center;
  gap: 10px;
}

.workspace {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 0;
  height: 100%;
}

.toolbar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 20px;
  padding: 18px;
  background: #fbfcfe;
  border-right: 1px solid var(--line);
  border-bottom: none;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.tool-group {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 8px;
  min-width: 0;
}

.tool-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.color-controls {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}


.slider-group {
  min-width: 0;
  max-width: none;
  flex-grow: 0;
}

.group-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

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

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

.tool-button,
.text-button,
.icon-button,
select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  transition:
    border-color 160ms ease,
    background 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.tool-button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  font-weight: 700;
}

.tool-icon {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: #eef2f6;
  color: var(--muted);
  position: relative;
}

.brush-icon::before {
  content: "";
  position: absolute;
  width: 6px;
  height: 18px;
  border-radius: 999px 999px 3px 3px;
  background: currentColor;
  transform: rotate(35deg);
}

.brush-icon::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 4px;
  width: 9px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  transform: rotate(-20deg);
}

.eraser-icon::before {
  content: "";
  position: absolute;
  width: 17px;
  height: 11px;
  border-radius: 3px;
  background: currentColor;
  transform: rotate(-25deg);
}

.eraser-icon::after {
  content: "";
  position: absolute;
  left: 5px;
  bottom: 5px;
  width: 13px;
  height: 2px;
  border-radius: 999px;
  background: #ffffff;
  transform: rotate(-25deg);
}

.tool-button.active {
  border-color: var(--active);
  background: var(--active-soft);
  color: var(--active);
}

.tool-button.active .tool-icon {
  background: var(--active);
  color: white;
}

.text-button {
  padding: 0 14px;
  background: var(--active);
  border-color: var(--active);
  color: white;
  font-weight: 800;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 1.3rem;
  font-weight: 800;
}

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

.size-stepper {
  display: grid;
  grid-template-columns: 42px minmax(54px, 1fr) 42px;
  align-items: center;
  gap: 8px;
}

.size-button {
  font-size: 1.15rem;
}

.size-stepper output {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fb;
  color: var(--ink);
  font-weight: 800;
}

.size-slider {
  width: 100%;
  accent-color: var(--active);
}

.size-slider::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: #dbe4ef;
}

.size-slider::-webkit-slider-thumb {
  width: 22px;
  height: 22px;
  margin-top: -7px;
  border: 3px solid white;
  border-radius: 50%;
  background: var(--active);
  box-shadow: 0 1px 5px rgba(23, 33, 43, 0.25);
  appearance: none;
}

button:hover,
select:hover {
  border-color: #9aa8b6;
  transform: translateY(-1px);
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(22, 100, 217, 0.24);
  outline-offset: 2px;
}

.field-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--active);
}

#colorPicker {
  width: 100%;
  height: 42px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

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

.swatch {
  aspect-ratio: 1;
  min-height: 38px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--swatch);
  cursor: pointer;
  transition: all 150ms ease;
}

.swatch:hover {
  transform: scale(1.08);
}

.swatch.active {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 3px white;
}

select {
  width: 100%;
  padding: 0 12px;
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 18px,
    calc(100% - 13px) 18px;
  background-size:
    5px 5px,
    5px 5px;
  background-repeat: no-repeat;
}

.size-preview {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #f7f9fb;
  flex-shrink: 0;
}

#brushSizePreviewDot,
#eraserSizePreviewDot {
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: currentColor;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.canvas-panel {
  display: grid;
  grid-template-rows: 1fr auto;
  min-width: 0;
  min-height: 0;
  padding: 0;
  background: white;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  border: none;
  border-radius: 0;
  background: white;
  box-shadow: none;
  overflow: hidden;
}

#paintCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: white;
  touch-action: none;
}

.brush-cursor,
.eraser-cursor {
  position: absolute;
  left: 0;
  top: 0;
  display: none;
  width: 10px;
  height: 10px;
  pointer-events: none;
  transform: translate(-9999px, -9999px);
  z-index: 2;
}

.brush-cursor {
  border: 1px solid rgba(23, 33, 43, 0.55);
  border-radius: 50%;
  background: var(--brush-cursor-color, #111111);
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.9),
    0 2px 8px rgba(23, 33, 43, 0.2);
}

.eraser-cursor {
  border: 2px solid rgba(23, 33, 43, 0.85);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.8),
    0 2px 8px rgba(23, 33, 43, 0.25);
}

.canvas-wrap.brush-active #paintCanvas,
.canvas-wrap.eraser-active #paintCanvas {
  cursor: none;
}

.canvas-wrap.brush-active .brush-cursor.visible {
  display: block;
}


.canvas-wrap.eraser-active .eraser-cursor.visible {
  display: block;
}

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 40px;
  color: var(--muted);
  font-size: 0.86rem;
  padding: 0 18px;
  background: white;
  border-top: 1px solid var(--line);
}

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

  .topbar {
    min-height: 56px;
    padding: 8px 12px;
  }

  .brand span:last-child {
    display: none;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
    border-width: 1.5px;
    box-shadow: inset 0 0 0 3px #fff;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .toolbar {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px 14px;
    gap: 24px;
    align-items: flex-start;
    -webkit-overflow-scrolling: touch;
    height: 115px;
    border-right: none;
    border-bottom: 1px solid var(--line);
    background: #fbfcfe;
    scrollbar-width: none; /* Hide scrollbar for Firefox */
  }

  .toolbar::-webkit-scrollbar {
    display: none; /* Hide scrollbar for Chrome, Safari and Opera */
  }

  .tool-group {
    gap: 6px;
    height: 100%;
    justify-content: flex-start;
    flex-shrink: 0;
  }

  .tool-buttons {
    flex-direction: row;
    gap: 6px;
  }

  .color-controls {
    flex-direction: row;
    align-items: center;
    gap: 10px;
  }

  #colorPicker {
    width: 36px;
    height: 36px;
    padding: 2px;
    flex-shrink: 0;
  }

  .slider-group {
    min-width: 150px;
    max-width: 220px;
  }

  .brush-size-group {
    margin-left: 0;
  }

  .tool-button {
    min-height: 36px;
    padding: 0 10px;
    font-size: 0.88rem;
  }

  .tool-icon {
    width: 20px;
    height: 20px;
  }

  .swatches {
    display: flex;
    gap: 6px;
  }

  .swatch {
    width: 28px;
    height: 28px;
    min-height: auto;
    aspect-ratio: 1;
    border-radius: 6px;
  }

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

  .size-preview {
    width: 32px;
    height: 32px;
  }

  .toggle-row {
    min-height: 20px;
    margin-top: 2px;
    font-size: 0.8rem;
  }

  .toggle-row input {
    width: 14px;
    height: 14px;
  }

  .action-buttons {
    display: flex;
    gap: 6px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
    min-height: 36px;
    font-size: 1.1rem;
  }

  .canvas-panel {
    padding: 0;
    background: white;
  }

  .statusbar {
    font-size: 0.78rem;
    padding: 0 10px;
    background: white;
    border-top: 1px solid var(--line);
    min-height: 36px;
  }
}

@media (max-width: 520px) {
  .topbar {
    gap: 8px;
    padding: 8px 10px;
  }

  .quick-actions {
    gap: 6px;
  }

  .text-button {
    max-width: 110px;
    padding: 0 8px;
    font-size: 0.82rem;
    min-height: 36px;
  }
}
