.online-coloring-page {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255,255,255,.92), rgba(246,250,255,.96)),
    linear-gradient(135deg, rgba(255, 186, 24, .14), rgba(67, 201, 104, .1) 44%, rgba(47, 128, 237, .12));
}

.online-coloring-shell {
  padding: 18px 0 56px;
}

.coloring-editor-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.editor-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.editor-close {
  width: 48px;
  min-height: 48px;
  padding: 10px;
}

.editor-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  color: var(--primary);
  font-weight: 900;
}

.coloring-editor-head h1 {
  margin: 0;
  font-size: clamp(32px, 4vw, 56px);
  line-height: 1;
}

.coloring-editor-grid {
  display: grid;
  grid-template-columns: minmax(250px, 270px) minmax(0, 1fr) 210px;
  gap: 18px;
  align-items: start;
}

.coloring-toolbar,
.coloring-workspace,
.coloring-side-panel {
  border: 1px solid rgba(216, 224, 240, .95);
  border-radius: 16px;
  background: rgba(255,255,255,.96);
  box-shadow: 0 18px 48px rgba(18, 27, 74, .1);
}

.coloring-toolbar {
  position: sticky;
  top: 92px;
  display: grid;
  gap: 14px;
  padding: 14px;
  box-sizing: border-box;
  min-width: 0;
  overflow: hidden;
}

.tool-group {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.tool-mode-group,
.action-tools {
  grid-template-columns: 1fr 1fr;
}

.tool-mode-group {
  grid-template-columns: minmax(0, 1fr);
}

.photo-tools {
  grid-template-columns: 1fr;
}

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

.tool-history-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.zoom-tools .tool-button {
  min-height: 42px;
  padding-inline: 8px;
  font-size: 13px;
}

.action-tools .danger,
.export-tools [data-action="print"] {
  grid-column: 1 / -1;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid #dfe6f4;
  border-radius: 12px;
  background: #fff;
  color: #202849;
  cursor: pointer;
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(18, 27, 74, .05);
}

.tool-button span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-button:hover,
.tool-button.active {
  border-color: #8fc3ff;
  background: #eff8ff;
  color: #1455b8;
}

.tool-button.danger {
  color: #b42318;
  background: #fff8f6;
  border-color: #ffd2ca;
}

.tool-button.confirming {
  color: #be123c;
  background: #fff1f2;
  border-color: #fb7185;
}

.tool-button:disabled {
  cursor: not-allowed;
  opacity: .46;
  transform: none;
}

.tool-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.color-palette {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 9px;
}

.color-swatch {
  width: 100%;
  aspect-ratio: 1;
  min-height: 38px;
  border: 3px solid #fff;
  border-radius: 999px;
  background: var(--swatch);
  cursor: pointer;
  box-shadow: 0 0 0 1px #dbe3f1, 0 8px 14px rgba(18, 27, 74, .08);
}

.color-swatch.active {
  box-shadow: 0 0 0 3px #2f80ed, 0 10px 18px rgba(47, 128, 237, .18);
}

.custom-color-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid #dfe6f4;
  border-radius: 12px;
  background: #fff;
  color: #202849;
  cursor: pointer;
  font-weight: 900;
  box-shadow: 0 8px 18px rgba(18, 27, 74, .05);
}

.custom-color-picker span:not(.custom-color-chip) {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-color-picker.active {
  border-color: #8fc3ff;
  background: #eff8ff;
  color: #1455b8;
}

.custom-color-chip {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border: 3px solid #fff;
  border-radius: 999px;
  background: var(--custom-color);
  box-shadow: 0 0 0 1px #dbe3f1;
}

.custom-color-picker input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  opacity: 0;
}

.recent-colors {
  display: grid;
  gap: 8px;
}

.recent-color-list {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.recent-color-button {
  width: 100%;
  min-height: 30px;
  aspect-ratio: 1;
  border: 3px solid #fff;
  border-radius: 999px;
  background: var(--recent-color);
  cursor: pointer;
  box-shadow: 0 0 0 1px #dbe3f1, 0 8px 14px rgba(18, 27, 74, .08);
}

.recent-color-button.active {
  box-shadow: 0 0 0 3px #2f80ed, 0 10px 18px rgba(47, 128, 237, .18);
}

.brush-size-control,
.autosave-control {
  display: grid;
  gap: 9px;
  min-width: 0;
  max-width: 100%;
  padding: 12px;
  border: 1px solid #e5eaf4;
  border-radius: 12px;
  background: #fbfcff;
}

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

.brush-size-control span,
.autosave-control span {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  color: #202849;
}

.autosave-control span {
  flex: 1;
  gap: 8px;
  min-width: 0;
}

.autosave-control small {
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
}

.autosave-control input {
  position: relative;
  flex: 0 0 auto;
  width: 44px;
  height: 24px;
  margin: 0;
  appearance: none;
  border: 1px solid #d5def0;
  border-radius: 999px;
  background: #dfe6f4;
  cursor: pointer;
  transition: background-color .18s ease, border-color .18s ease;
}

.autosave-control input::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 2px 5px rgba(18, 27, 74, .22);
  transition: transform .18s ease;
}

.autosave-control input:checked {
  border-color: var(--primary);
  background: var(--primary);
}

.autosave-control input:checked::after {
  transform: translateX(20px);
}

.brush-size-control output {
  min-width: 36px;
  color: var(--primary);
  font-weight: 900;
  text-align: right;
}

.brush-size-control input {
  accent-color: var(--primary);
}

.export-tools .btn {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 48px;
  border-radius: 12px;
  gap: 7px;
  line-height: 1.15;
  text-align: center;
  white-space: normal;
}

.coloring-workspace {
  min-width: 0;
  padding: 18px;
}

.canvas-frame {
  display: grid;
  place-items: center;
  min-height: min(72vh, 780px);
  padding: clamp(12px, 2vw, 24px);
  border: 1px solid #e0e7f2;
  border-radius: 14px;
  background:
    linear-gradient(90deg, rgba(47,128,237,.05) 1px, transparent 1px),
    linear-gradient(rgba(47,128,237,.05) 1px, transparent 1px),
    #f8fbff;
  background-size: 28px 28px;
  overflow: hidden;
}

.canvas-stage {
  position: relative;
  width: min(100%, 720px);
  max-height: 72vh;
  display: grid;
  touch-action: none;
  user-select: none;
  transform-origin: center center;
  will-change: transform;
}

.canvas-stage img,
.canvas-stage canvas {
  grid-area: 1 / 1;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.canvas-stage img {
  z-index: 1;
  background: #fff;
  box-shadow: 0 16px 38px rgba(18, 27, 74, .13);
  pointer-events: none;
}

.canvas-stage [data-coloring-canvas] {
  z-index: 2;
  cursor: none;
  touch-action: none;
}

.canvas-stage [data-line-canvas] {
  z-index: 3;
  pointer-events: none;
}

.canvas-stage.move-mode [data-coloring-canvas] {
  cursor: grab;
}

.canvas-stage.move-mode.panning [data-coloring-canvas] {
  cursor: grabbing;
}

.brush-preview {
  position: absolute;
  z-index: 4;
  width: 18px;
  height: 18px;
  border: 2px solid #ef4444;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 2px rgba(255,255,255,.88), 0 8px 18px rgba(18, 27, 74, .16);
  transition: width .12s ease, height .12s ease, border-color .12s ease, background-color .12s ease, opacity .12s ease;
}

.brush-preview.visible {
  opacity: 1;
}

.brush-preview.eraser {
  border-style: dashed;
  box-shadow: 0 0 0 2px rgba(255,255,255,.95), 0 8px 18px rgba(18, 27, 74, .16);
}

.brush-preview.fill::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  transform: translate(-50%, -50%);
}

.brush-preview.picker::before,
.brush-preview.picker::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  background: currentColor;
  transform: translate(-50%, -50%);
}

.brush-preview.picker::before {
  width: 2px;
  height: 14px;
}

.brush-preview.picker::after {
  width: 14px;
  height: 2px;
}

.editor-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
}

.coloring-side-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.mini-page-card,
.mini-related,
.mini-saved {
  display: grid;
  gap: 10px;
}

.mini-page-card img {
  width: 100%;
  aspect-ratio: 1 / 1.18;
  object-fit: contain;
  border: 1px solid #e1e7f2;
  border-radius: 10px;
  background: #fff;
}

.mini-page-card h2,
.mini-related h2,
.mini-saved h2 {
  margin: 0;
  font-size: 16px;
}

.mini-page-card p,
.mini-saved p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.mini-related a {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 10px;
  align-items: center;
  min-height: 62px;
  padding: 7px;
  border: 1px solid #e4eaf4;
  border-radius: 10px;
  background: #fbfcff;
  font-size: 13px;
  font-weight: 900;
}

.mini-related img {
  width: 54px;
  height: 54px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}

.saved-list {
  display: grid;
  gap: 10px;
}

.saved-item {
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 10px;
  align-items: center;
  padding: 7px;
  border: 1px solid #e4eaf4;
  border-radius: 10px;
  background: #fbfcff;
}

.saved-item img {
  width: 62px;
  height: 62px;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}

.saved-item strong {
  display: block;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.2;
}

.saved-item small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.saved-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
}

.saved-actions button,
.saved-actions a {
  min-height: 30px;
  padding: 5px 8px;
  border: 1px solid #dfe6f4;
  border-radius: 8px;
  background: #fff;
  color: var(--primary);
  cursor: pointer;
  font-size: 11px;
  font-weight: 900;
}

.saved-actions .danger {
  color: #b42318;
  border-color: #ffd2ca;
  background: #fff8f6;
}

@media (max-width: 1120px) {
  .coloring-editor-grid {
    grid-template-columns: 1fr;
  }

  .coloring-toolbar {
    position: static;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: stretch;
  }

  .color-group,
  .photo-tools,
  .export-tools {
    grid-column: span 2;
  }

  .photo-tools {
    grid-template-columns: 1fr 1fr;
  }

  .coloring-side-panel {
    display: none;
  }
}

@media (max-width: 680px) {
  .online-coloring-shell {
    padding-bottom: 24px;
  }

  .coloring-editor-head {
    align-items: stretch;
    flex-direction: column;
  }

  .editor-head-actions {
    display: grid;
    grid-template-columns: 1fr auto;
    width: 100%;
  }

  .editor-head-actions .btn:not(.editor-close) {
    width: 100%;
  }

  .editor-close {
    width: 48px;
  }

  .coloring-toolbar {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }

  .coloring-toolbar > * {
    grid-column: 1 / -1;
    width: 100%;
  }

  .photo-tools {
    grid-template-columns: repeat(2, 1fr);
  }

  .photo-tools {
    grid-template-columns: 1fr 1fr;
  }

  .action-tools {
    grid-template-columns: repeat(2, 1fr);
  }

  .tool-mode-group .tool-button {
    min-height: 50px;
  }

  .action-tools .danger {
    grid-column: 1 / -1;
  }

  .tool-button {
    min-height: 46px;
    padding: 9px 8px;
    font-size: 13px;
  }

  .tool-button span {
    line-height: 1.15;
    white-space: normal;
  }

  .tool-button .icon,
  .btn .icon {
    width: 18px;
    height: 18px;
  }

  .color-group,
  .brush-size-control,
  .export-tools {
    grid-column: auto;
  }

  .color-palette {
    grid-template-columns: repeat(6, 1fr);
  }

  .color-swatch {
    min-height: 40px;
  }

  .export-tools {
    grid-template-columns: 1fr 1fr;
  }

  .export-tools .btn {
    min-height: 46px;
    padding-inline: 10px;
    font-size: 13px;
  }

  .coloring-workspace {
    padding: 10px;
  }

  .canvas-frame {
    min-height: 56vh;
    padding: 8px;
  }

  .canvas-stage {
    width: 100%;
    max-height: 66vh;
  }
}

@media print {
  .site-header,
  .site-footer,
  .breadcrumbs,
  .coloring-editor-head,
  .coloring-toolbar,
  .coloring-side-panel,
  .editor-note {
    display: none !important;
  }

  .online-coloring-page,
  .online-coloring-shell,
  .coloring-editor-grid,
  .coloring-workspace,
  .canvas-frame {
    padding: 0;
    margin: 0;
    border: 0;
    box-shadow: none;
    background: #fff;
  }
}
