@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;450;500;550;600&display=swap');

:root {
  color-scheme: light;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-optical-sizing: auto;
  font-synthesis: none;
  font-weight: 450;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

  --canvas: #fdfdfc;
  --panel: #f7f7f5;
  --ink: #252522;
  --muted: #9b9b96;
  --faint: #c3c3bd;
  --line: rgba(39, 39, 35, 0.055);
  --sidebar-width: clamp(300px, 24vw, 392px);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.45, 0.64, 1);
}

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

html,
body {
  width: 100%;
  height: 100%;
  min-width: 320px;
  margin: 0;
  overflow: hidden;
}

body {
  color: var(--ink);
  background: var(--canvas);
}

button {
  color: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
.particle-canvas:focus-visible {
  outline: 2px solid rgba(121, 104, 91, 0.48);
  outline-offset: 4px;
}

.app {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--sidebar-width);
  width: 100%;
  height: 100dvh;
  min-height: 380px;
  overflow: hidden;
  transition: grid-template-columns 680ms var(--ease-out);
}

.app.sidebar-closed,
.app.is-library-empty {
  grid-template-columns: minmax(0, 1fr) 0px;
}

.app.is-library-empty .library,
.app.is-library-empty .sidebar-reopen {
  visibility: hidden;
  pointer-events: none;
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--canvas);
}

.stage.has-touch-cursor,
.stage.has-touch-cursor * {
  cursor: none !important;
}

.touch-cursor {
  position: fixed;
  z-index: 20;
  top: -100px;
  left: -100px;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.15);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1);
  transform-origin: center;
  transition:
    opacity 125ms ease,
    transform 175ms var(--ease-out);
  will-change: opacity, transform;
}

.touch-cursor.is-visible {
  opacity: 1;
}

.touch-cursor.is-over-image {
  transform: translate(-50%, -50%) scale(1.15);
}

.touch-cursor.is-pressed {
  transform: translate(-50%, -50%) scale(0.9);
  transition-duration: 125ms, 105ms;
}

.touch-cursor.is-over-image.is-pressed {
  transform: translate(-50%, -50%) scale(1.035);
}

.particle-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
  opacity: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 150ms ease;
}

.particle-canvas.is-transitioning {
  opacity: 1;
}

.still-image {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: var(--image-display-size, 0px);
  height: var(--image-display-size, 0px);
  object-fit: contain;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: opacity 180ms ease;
}

.still-image.is-visible {
  opacity: 1;
}

.wordmark {
  position: absolute;
  z-index: 2;
  top: 35px;
  left: 37px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #5c5c5c;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: -0.012em;
  pointer-events: none;
}

.wordmark-mark {
  display: grid;
  grid-template-columns: repeat(2, 4px);
  grid-template-rows: repeat(2, 4px);
  gap: 3px;
}

.wordmark-mark i {
  display: block;
  border-radius: 50%;
  background: #707070;
}

.wordmark-mark i:nth-child(2),
.wordmark-mark i:nth-child(3) {
  opacity: 0.5;
  transform: scale(0.75);
}

.stage-hint,
.image-counter {
  position: absolute;
  z-index: 2;
  bottom: 28px;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.01em;
  pointer-events: none;
  transition: opacity 300ms ease;
}

.stage-hint {
  left: 38px;
}

.image-counter {
  right: 36px;
  font-variant-numeric: tabular-nums;
}

.library {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: var(--sidebar-width);
  min-height: 0;
  overflow: hidden;
  border-left: 1px solid var(--line);
  background: var(--panel);
  user-select: none;
  -webkit-user-select: none;
}

.library-header {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  min-height: 82px;
  padding: 0 23px 0 27px;
}

.library-title {
  display: flex;
  align-items: baseline;
  gap: 9px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: -0.015em;
}

.library-count {
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #777771;
  cursor: pointer;
  transition:
    color 180ms ease,
    background-color 180ms ease,
    transform 320ms var(--ease-spring),
    opacity 260ms ease;
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
  transform: scale(1.06);
}

.icon-button svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.35;
}

.sidebar-reopen {
  position: absolute;
  z-index: 3;
  top: 25px;
  right: 25px;
  opacity: 0;
  pointer-events: none;
  transform: translateX(8px);
}

.sidebar-closed .sidebar-reopen {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.image-grid {
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: start;
  gap: 15px 12px;
  min-height: 0;
  padding: 10px 20px 42px;
  overflow: auto;
  scrollbar-width: none;
}

.image-grid::-webkit-scrollbar {
  display: none;
}

.image-card {
  --sort-x: 0px;
  --sort-y: 0px;

  position: relative;
  aspect-ratio: 1;
  min-width: 0;
  transform: translate3d(var(--sort-x), var(--sort-y), 0);
  transition:
    opacity 160ms ease,
    transform 240ms var(--ease-out);
  will-change: transform;
}

.image-card.is-entering {
  animation: card-arrive 510ms var(--ease-out) backwards;
}

.image-card.is-dragging {
  opacity: 0.2;
}

.image-card.is-keyboard-dragging .image-tile {
  border-color: rgba(78, 78, 74, 0.5);
  box-shadow: 0 0 0 3px rgba(89, 89, 84, 0.1);
}

.drag-ghost {
  position: fixed;
  z-index: 20;
  margin: 0;
  animation: none;
  pointer-events: none;
  transform-origin: center;
  transition: none;
}

.drag-ghost .image-tile {
  border-color: rgba(48, 46, 40, 0.09);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 12px 34px rgba(29, 29, 25, 0.15);
  transform: none;
}

.drag-ghost .remove-button {
  display: none;
}

body.is-sorting-images {
  cursor: grabbing;
  user-select: none;
}

.image-card.is-removing {
  z-index: 1;
  pointer-events: none;
  animation: card-leave 310ms var(--ease-out) both;
}

.image-tile {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 13px;
  background: transparent;
  cursor: grab;
  touch-action: none;
  -webkit-user-drag: none;
  transition:
    border-color 180ms ease,
    background-color 180ms ease,
    transform 340ms var(--ease-spring);
}

.image-grid.is-reordering .image-tile {
  cursor: grabbing;
}

.image-card:hover .image-tile,
.image-card:focus-within .image-tile {
  background: rgba(30, 30, 25, 0.045);
  transform: scale(1.025);
}

.image-card.is-active .image-tile {
  border-color: rgba(48, 46, 40, 0.1);
  background: rgba(255, 255, 255, 0.72);
}

.image-tile img {
  display: block;
  width: 84%;
  height: 84%;
  object-fit: contain;
  pointer-events: none;
  transition: transform 380ms var(--ease-out);
}

.image-card:hover .image-tile img {
  transform: scale(1.045);
}

.remove-button {
  position: absolute;
  z-index: 2;
  top: -6px;
  right: -6px;
  display: grid;
  width: 23px;
  height: 23px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.96);
  color: #777771;
  box-shadow: 0 2px 9px rgba(25, 25, 20, 0.1);
  cursor: pointer;
  opacity: 0;
  transform: scale(0.52) rotate(-35deg);
  transition:
    background-color 160ms ease,
    color 160ms ease,
    opacity 160ms ease,
    transform 310ms var(--ease-spring);
}

.image-card:hover .remove-button,
.image-card:focus-within .remove-button {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

.remove-button:hover {
  background: #fff;
  color: #b05748;
  transform: scale(1.1) rotate(90deg) !important;
}

.remove-button svg {
  width: 12px;
  height: 12px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.6;
}

.library-footer {
  position: relative;
  z-index: 2;
  display: flex;
  flex: 0 0 65px;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 21px 21px 27px;
  background: var(--panel);
}

.library-footer::before {
  position: absolute;
  right: 0;
  bottom: 100%;
  left: 0;
  height: 43px;
  background: linear-gradient(to bottom, rgba(247, 247, 245, 0), rgba(247, 247, 245, 0.94));
  content: '';
  pointer-events: none;
}

.library-clear-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.library-clear-divider {
  color: var(--muted);
  font-size: 11px;
}

.library-clear {
  padding: 7px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  transition:
    color 170ms ease,
    opacity 170ms ease;
}

.library-clear:hover:not(:disabled) {
  color: var(--ink);
}

.library-clear.is-confirming {
  color: #9e554a;
}

.library-clear:disabled {
  cursor: default;
  opacity: 0.46;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  clip-path: inset(50%);
}

.add-button {
  display: grid;
  flex: 0 0 auto;
  width: 43px;
  height: 43px;
  place-items: center;
  border: 1px solid rgba(36, 36, 32, 0.04);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  color: #343430;
  box-shadow: 0 3px 13px rgba(31, 31, 27, 0.055);
  cursor: pointer;
  transition:
    box-shadow 220ms ease,
    transform 340ms var(--ease-spring);
}

.add-button:hover {
  box-shadow: 0 6px 18px rgba(31, 31, 27, 0.105);
  transform: scale(1.09) rotate(90deg);
}

.add-button:active {
  transform: scale(0.94) rotate(90deg);
}

.add-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.65;
}

.empty-state {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}

.empty-state[hidden] {
  display: none;
}

.empty-icon {
  position: relative;
  display: block;
  width: 33px;
  height: 33px;
  margin-bottom: 8px;
  color: #c9b8a7;
}

.empty-icon::before,
.empty-icon::after {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(currentColor, currentColor) center / 1.5px 100% no-repeat,
    linear-gradient(currentColor, currentColor) center / 100% 1.5px no-repeat;
  content: '';
}

.empty-icon::after {
  transform: rotate(45deg);
}

.empty-state.is-loading .empty-icon {
  animation: empty-icon-spin 920ms linear infinite;
}

.empty-state.is-loading .text-button {
  opacity: 0;
  pointer-events: none;
}

.empty-state p {
  margin: 0;
  color: #595852;
  font-size: 13px;
}

.text-button {
  padding: 4px 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  pointer-events: auto;
}

.text-button:hover {
  color: #835f4c;
}

.drop-indicator {
  position: fixed;
  inset: 0;
  z-index: 5;
  padding: 16px;
  background: rgba(253, 253, 252, 0.74);
  opacity: 0;
  pointer-events: none;
  transition: opacity 170ms ease;
  backdrop-filter: blur(6px);
}

.drop-indicator.is-visible {
  opacity: 1;
}

.drop-indicator-inner {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  border: 1px dashed rgba(112, 96, 80, 0.48);
  border-radius: 16px;
  color: #64574d;
  font-size: 14px;
}

.toast {
  position: fixed;
  z-index: 6;
  right: calc(var(--sidebar-width) + 24px);
  bottom: 22px;
  padding: 10px 14px;
  border: 1px solid rgba(30, 30, 26, 0.06);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  color: #57564f;
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition:
    opacity 180ms ease,
    transform 250ms var(--ease-out);
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@keyframes card-arrive {
  from {
    opacity: 0;
    transform: translateY(9px) scale(0.89);
  }

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

@keyframes empty-icon-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes card-leave {
  0% {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    filter: blur(0);
  }

  100% {
    opacity: 0;
    transform: scale(0.65) rotate(-7deg);
    filter: blur(4px);
  }
}

@media (max-width: 720px) {
  :root {
    --canvas: #ffffff;
    --sidebar-width: min(290px, 77vw);
  }

  .stage,
  .particle-canvas,
  img {
    dynamic-range-limit: standard;
  }

  .wordmark {
    top: 0;
    left: 20px;
    height: 72px;
  }

  .stage-hint {
    display: none;
  }

  .image-counter {
    right: 19px;
    bottom: 20px;
  }

  .library-header {
    min-height: 72px;
    padding: 0 13px 0 20px;
  }

  .sidebar-reopen {
    top: 19px;
    right: 13px;
  }

  .image-grid {
    gap: 10px;
    padding-right: 13px;
    padding-left: 13px;
  }

  .library-footer {
    flex-basis: 61px;
    padding-right: 16px;
    padding-bottom: 16px;
    padding-left: 19px;
  }

  .library-clear {
    padding: 4px 0;
  }
}

@media (max-width: 699px) {
  :root {
    --sidebar-width: 100vw;
  }

  .app {
    display: block;
  }

  .stage {
    width: 100%;
    height: 100%;
  }

  .library {
    position: absolute;
    z-index: 4;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    min-width: 100%;
    border-left: 0;
    transition: transform 560ms var(--ease-out);
  }

  .sidebar-closed .library {
    transform: translateX(100%);
  }

  .image-card.is-active .remove-button {
    opacity: 1;
    transform: scale(1) rotate(0deg);
  }

  .app:not(.sidebar-closed) .wordmark span:last-child,
  .app:not(.sidebar-closed) .stage-hint {
    opacity: 0;
  }

  .wordmark span:last-child {
    transition: opacity 200ms ease;
  }
}

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