
* {
  box-sizing: border-box;
}

:root {
  --lavender: #ffedf7;
  --lavender-deep: #8b7bea;
  --purple: #5c50c8;
  --purple-dark: #4034aa;
  --ink: #37328b;
  --muted: #7772c5;
  --panel: rgba(255, 255, 255, 0.88);
  --line: #dedcff;
  --soft: #f0efff;
  --pink: #f6b7cf;
  --shadow: 0 14px 38px rgba(76, 65, 164, 0.09);
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--lavender);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Nunito", system-ui, sans-serif;
  background: linear-gradient(
    120deg,
    #809bce,
    #95b8d1,
    #b8e0d4,
    #d6eadf,
    #eac4d5,
    #f5e2ea,
    #809bce
  );
  background-size: 400% 400%;
  animation: pastel-rgb-shift 30s ease-in-out infinite;
}

@keyframes pastel-rgb-shift {
  0% {
    background-position: 0% 50%;
  }

  25% {
    background-position: 100% 50%;
  }

  50% {
    background-position: 100% 100%;
  }

  75% {
    background-position: 0% 100%;
  }

  100% {
    background-position: 0% 50%;
  }
}

button {
  font: inherit;
  cursor: pointer;
}

button:focus-visible,
.pixel:focus-visible {
  outline: 3px solid #f18db5;
  outline-offset: 2px;
}

/* Main layout */

.app-shell {
  width: min(1800px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 0.86fr) minmax(0, 1.65fr) minmax(0, 0.7fr);
  gap: 16px;
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 17px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.gallery-panel,
.palette-panel {
  display: flex;
  flex-direction: column;
}

/* Gallery branding */

.brand {
  position: relative;
  padding: 24px 12px 18px;
  text-align: center;
  border-bottom: 1px solid #e8e6ff;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.5),
    rgba(246, 245, 255, 0.35)
  );
}

.brand-title {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 9px;
  color: #4d42b5;
  font-weight: 1000;
  font-size: clamp(23px, 2vw, 34px);
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.heart {
  color: #f3a6c5;
  font-size: 26px;
}

.brand p {
  margin: 3px 0 0;
  color: #7169c7;
  font-size: 18px;
  font-weight: 700;
}

/* Gallery filters */

.gallery-controls {
  padding: 18px 20px 10px;
}

.filter-tabs {
  display: flex;
  padding: 4px;
  gap: 4px;
  background: #efedff;
  border-radius: 12px;
}

.filter-tab {
  flex: 1;
  min-width: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  padding: 9px 6px;
  color: var(--purple);
  font-size: 15px;
  font-weight: 800;
  transition: background 0.18s, color 0.18s, transform 0.18s;
}

.filter-tab:hover {
  transform: translateY(-1px);
}

.filter-tab.active {
  color: white;
  background: var(--lavender-deep);
  box-shadow: 0 4px 12px #9184e94a;
}

/* Gallery grid */

.gallery-grid {
  flex: 1;
  min-height: 0;
  padding: 12px 20px 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 16px;
}

.art-card {
  position: relative;
  min-width: 0;
  aspect-ratio: 1 / 1.02;
  padding: 0;
  overflow: hidden;
  border: 2px solid #e4e0ff;
  border-radius: 10px;
  background: #f7f1ff;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}

.art-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 7px 15px #6b5dc426;
}

.art-card.selected {
  border: 4px solid var(--lavender-deep);
  box-shadow: 0 0 0 3px #a79cf12b;
}

.art-card canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.art-card .art-name {
  position: absolute;
  inset: auto 0 0;
  padding: 19px 4px 6px;
  color: white;
  font-size: 12px;
  font-weight: 900;
  text-align: center;
  background: linear-gradient(transparent, #2f2869a6);
  opacity: 0;
  transition: opacity 0.18s;
}

.art-card:hover .art-name,
.art-card.selected .art-name {
  opacity: 1;
}

.favorite-toggle {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 27px;
  height: 27px;
  border: 0;
  border-radius: 50%;
  color: #a09ad5;
  background: #ffffffdb;
  font-size: 17px;
  line-height: 1;
}

.favorite-toggle.is-favorite {
  color: #ee79aa;
}

/* Gallery pagination */

.gallery-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 28px;
  padding: 13px 16px 18px;
  border-top: 1px solid #e8e6ff;
  background: #faf9ff;
  font-size: 17px;
  font-weight: 800;
  color: #6257c7;
}

.page-arrow {
  border: 0;
  background: transparent;
  color: var(--purple);
  font-size: 34px;
  line-height: 1;
  padding: 0 8px;
}

.page-arrow:disabled {
  opacity: 0.25;
  cursor: default;
}

/* Coloring canvas */

.canvas-panel {
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
}

.canvas-header {
  min-height: 82px;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid #e9e7ff;
}

.puzzle-title-wrap {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.back-button {
  flex-shrink: 0;
  width: 39px;
  height: 39px;
  border: 0;
  border-radius: 12px;
  background: #f0efff;
  color: var(--purple);
  font-size: 34px;
  line-height: 1;
  padding: 0 0 4px;
}

h1 {
  margin: 0;
  font-size: 21px;
  line-height: 1.2;
  font-weight: 900;
  color: #3e35a5;
}

#puzzle-subtitle {
  margin: 3px 0 0;
  font-size: 12px;
  color: #9690d5;
  font-weight: 700;
}

/* Coloring progress */

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 190px;
}

#progress-label {
  white-space: nowrap;
  font-size: 17px;
  color: #5d51c7;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.progress-track {
  flex-shrink: 0;
  height: 13px;
  width: 115px;
  overflow: hidden;
  background: #e4e1fb;
  border-radius: 99px;
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #8a7be9, #e7a6d0);
  transition: width 0.2s;
}

/* Coloring grid */

.canvas-scroll {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: clamp(12px, 2vw, 28px);
  overflow: auto;
}

.pixel-grid,
#pixel-grid {
  width: min(100%, 576px);
  aspect-ratio: 1 / 1;
  height: auto;
  display: grid;
  grid-template-columns: repeat(24, minmax(0, 1fr));
  grid-template-rows: repeat(24, minmax(0, 1fr));
  gap: 0;
  padding: 0;
  border-top: 1px solid #aaa8c9;
  border-left: 1px solid #aaa8c9;
  background: #f2f1ff;
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
}

.pixel,
#pixel-grid .pixel {
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  aspect-ratio: 1 / 1;
  margin: 0;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 0;
  border-right: 1px solid #aaa8c9;
  border-bottom: 1px solid #aaa8c9;
  border-radius: 0;
  color: #38374e;
  font-size: clamp(7px, 0.9vw, 13px);
  font-weight: 700;
  line-height: 1;
  background: var(--pixel-bg, #f3f2ff);
  box-shadow: none;
  transform: none;
  transition: background-color 0.08s;
}

.pixel.colored {
  color: transparent;
}

.pixel.correct-flash {
  animation: correct 0.24s ease;
}

@keyframes correct {
  50% {
    filter: brightness(1.18);
  }
}

/* Canvas footer */

.canvas-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 24px 16px;
  color: #918bd0;
  font-size: 13px;
  font-weight: 700;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--purple);
  font-weight: 900;
  white-space: nowrap;
}

/* Completion banner */

.completion-banner {
  margin: 0 20px 18px;
  padding: 13px 16px;
  border-radius: 14px;
  background: #fce8f2;
  display: flex;
  align-items: center;
  gap: 12px;
  color: #6c429b;
  animation: pop-in 0.25s ease;
}

.completion-banner[hidden] {
  display: none;
}

.completion-icon {
  font-size: 28px;
  color: #e98ab6;
}

.completion-banner div {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.completion-banner strong {
  font-size: 15px;
}

.completion-banner span:not(.completion-icon) {
  font-size: 12px;
}

.completion-banner button {
  border: 0;
  border-radius: 9px;
  padding: 8px 13px;
  color: white;
  background: #8a79e8;
  font-weight: 900;
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Color palette */

.palette-panel {
  padding: 0 18px 17px;
}

.palette-heading {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 6px 6px;
}

.palette-icon {
  font-size: 29px;
  font-weight: 900;
}

h2 {
  margin: 0;
  font-size: 21px;
  font-weight: 900;
  color: #4037a5;
}

.palette-instruction {
  margin: 2px 6px 14px;
  font-size: 12px;
  color: #9690d5;
  font-weight: 700;
}

.palette-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.palette-item {
  display: grid;
  grid-template-columns: 26px 42px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  width: 100%;
  min-width: 0;
  min-height: 59px;
  padding: 7px 11px;
  border: 2px solid transparent;
  border-radius: 13px;
  background: #f7f6ff;
  text-align: left;
  color: #5e53c6;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.palette-item:hover {
  transform: translateX(-2px);
}

.palette-item.active {
  border-color: #8d7be9;
  background: #eeebff;
  box-shadow: 0 3px 10px #8d7be91a;
}

.palette-number {
  font-size: 20px;
  font-weight: 900;
  text-align: center;
}

.swatch {
  width: 40px;
  height: 40px;
  border: 1px solid #aaa7cb;
  border-radius: 9px;
  box-shadow: inset 0 0 0 1px #ffffff30;
}

.palette-name {
  min-width: 0;
  font-size: 15px;
  font-weight: 800;
}

.palette-count {
  display: block;
  font-size: 11px;
  color: #a29bdc;
  font-weight: 700;
  margin-top: 1px;
}

/* Coloring tools */

.tool-buttons {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: auto;
  padding-top: 22px;
}

.tool-button {
  min-width: 0;
  min-height: 52px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  border: 2px solid #d7d2ff;
  border-radius: 13px;
  color: #6457cf;
  background: transparent;
  font-size: 16px;
  font-weight: 900;
  transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
}

.tool-button:hover {
  transform: translateY(-1px);
  background: #f5f3ff;
}

.tool-button span {
  font-size: 23px;
  line-height: 1;
}

.tool-button.primary {
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, #8e7ceb, #8372e2);
  box-shadow: 0 5px 13px #8170e52e;
}

.tool-button.primary:hover {
  background: linear-gradient(135deg, #7e6bdd, #7563d5);
}

.tool-button.active-tool {
  border-color: #8a7be9;
  background: #eeebff;
}

/* Tips and save indicator */

.tip-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 13px 12px;
  margin-top: 17px;
  border-radius: 13px;
  background: #f5f3ff;
  color: #7167c9;
}

.tip-icon {
  font-size: 23px;
  line-height: 1.2;
}

.tip-card p {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  font-weight: 700;
}

.tip-card strong {
  color: #5146b8;
}

.save-note {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 7px;
  margin-top: 12px;
  color: #9c96d1;
  font-size: 11px;
  font-weight: 800;
}

.save-dot {
  width: 7px;
  height: 7px;
  background: #8bd8b2;
  border-radius: 50%;
  box-shadow: 0 0 0 3px #8bd8b225;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  padding: 11px 17px;
  border-radius: 12px;
  color: white;
  background: #4940a9;
  box-shadow: 0 8px 24px #342b7b38;
  font-size: 14px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Large screens */

@media (min-width: 1500px) {
  .gallery-grid {
    gap: 18px;
    padding-inline: 24px;
  }

  .palette-panel {
    padding-inline: 22px;
  }
}

/* Tablet and medium layouts */

@media (min-width: 701px) and (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 230px minmax(0, 1fr);
    gap: 12px;
    padding: 12px;
  }

  .palette-panel {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 12px 16px 16px;
    height: auto;
    min-height: 0;
  }

  .palette-heading {
    align-self: flex-start;
    padding: 4px 0;
  }

  .palette-instruction {
    display: none;
  }

  .palette-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    width: min(100%, 440px);
  }

  .palette-item {
    grid-template-columns: 20px 32px;
    justify-content: center;
    gap: 6px;
    min-height: 48px;
    padding: 5px;
  }

  .palette-number {
    font-size: 16px;
  }

  .swatch {
    width: 30px;
    height: 30px;
    border-radius: 7px;
  }

  .palette-name,
  .palette-count {
    display: none;
  }

  .tool-buttons {
    display: flex;
    flex-direction: row;
    justify-content: center;
    gap: 10px;
    width: min(100%, 440px);
    margin: 0;
    padding: 0;
  }

  .tool-button {
    flex: 1;
    min-width: 0;
    min-height: 48px;
    padding: 6px 8px;
    gap: 6px;
    font-size: 12px;
    white-space: normal;
    text-align: center;
  }

  .tool-button span {
    font-size: 20px;
  }

  .tip-card,
  .save-note {
    display: none;
  }

  .palette-item:hover,
  .tool-button:hover {
    transform: none;
  }
}

/* Compact tablet palette: 701px to 770px */

@media (min-width: 701px) and (max-width: 770px) {
  .app-shell {
    padding: 8px;
    gap: 8px;
    grid-template-columns: 230px minmax(0, 1fr);
  }

  .palette-panel {
    gap: 9px;
    padding: 10px 12px 14px;
  }

  .palette-list,
  .tool-buttons {
    width: min(100%, 360px);
  }

  .palette-list {
    gap: 5px;
  }

  .palette-item {
    grid-template-columns: 17px 25px;
    gap: 4px;
    min-height: 42px;
    padding: 4px;
  }

  .palette-number {
    font-size: 14px;
  }

  .swatch {
    width: 24px;
    height: 24px;
  }

  .tool-buttons {
    gap: 6px;
  }

  .tool-button {
    flex-direction: column;
    min-height: 55px;
    gap: 3px;
    padding: 5px 3px;
    font-size: 10px;
    line-height: 1.2;
  }

  .tool-button span {
    font-size: 18px;
  }
}

/* Hide color names on tablet-sized screens */

@media (min-width: 701px) and (max-width: 1030px) {
  .palette-name {
    display: none;
  }
}

/* Mobile screens */

@media (max-width: 700px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    padding: 9px;
    gap: 10px;
  }

  .gallery-panel {
    order: 1;
  }

  .canvas-panel {
    order: 2;
    min-height: 510px;
  }

  .palette-panel {
    order: 3;
    display: flex;
    padding: 10px 12px 14px;
  }

  .brand {
    padding: 15px 8px 10px;
  }

  .brand-title {
    font-size: 25px;
  }

  .brand p {
    font-size: 15px;
  }

  .gallery-controls {
    padding: 10px 12px 4px;
  }

  .gallery-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    padding: 8px 12px 12px;
  }

  .art-card {
    border-radius: 8px;
  }

  .art-card .art-name {
    display: none;
  }

  .favorite-toggle {
    top: 3px;
    right: 3px;
    width: 22px;
    height: 22px;
    font-size: 14px;
  }

  .gallery-footer {
    padding: 7px;
  }

  .canvas-header {
    min-height: 69px;
    padding: 12px;
    gap: 8px;
  }

  .back-button {
    width: 34px;
    height: 34px;
  }

  h1 {
    font-size: 18px;
  }

  #puzzle-subtitle {
    display: none;
  }

  .progress-wrap {
    min-width: 0;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
  }

  #progress-label {
    font-size: 13px;
  }

  .progress-track {
    width: 95px;
    height: 8px;
  }

  .canvas-scroll {
    padding: 12px;
    min-height: 0;
  }

  .pixel-grid,
  #pixel-grid {
    width: min(100%, 520px);
  }

  .pixel,
  #pixel-grid .pixel {
    font-size: clamp(5px, 1.7vw, 10px);
  }

  .canvas-bottom {
    padding: 8px 12px 12px;
    font-size: 11px;
  }

  .palette-heading {
    padding: 3px 2px 8px;
  }

  h2 {
    font-size: 19px;
  }

  .palette-instruction {
    display: block;
    margin-bottom: 9px;
  }

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

  .palette-item {
    grid-template-columns: 20px 32px minmax(0, 1fr);
    min-height: 49px;
    padding: 5px 7px;
  }

  .palette-name {
    display: block;
    font-size: 13px;
    overflow-wrap: normal;
  }

  .tool-buttons {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    padding-top: 12px;
  }

  .tool-button {
    min-height: 48px;
    flex-direction: column;
    gap: 1px;
    font-size: 11px;
    border-radius: 10px;
  }

  .tool-button span {
    font-size: 19px;
  }

  .tip-card {
    display: flex;
    margin-top: 11px;
  }

  .tip-card p {
    font-size: 11px;
  }

  .save-note {
    display: flex;
  }
}

/* PC performance and coloring cursor */

@media (min-width: 771px) {
  body {
    background-size: 400% 400%;
    animation: pastel-rgb-shift 30s ease-in-out infinite;
    background-position: 0% 50%;
  }

  #pixel-grid .pixel,
  .pixel-grid .pixel {
    cursor: crosshair;
    transition: none;
  }

  #pixel-grid .pixel:hover,
  .pixel-grid .pixel:hover {
    box-shadow: none;
  }

  .art-card,
  .palette-item,
  .tool-button,
  .filter-tab {
    transition: none;
  }

  .art-card:hover,
  .palette-item:hover,
  .tool-button:hover,
  .filter-tab:hover {
    transform: none;
  }
}

/* Reduced motion accessibility */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}