@font-face {
  font-family: 'Instrument Sans';
  src: url('./assets/instrument-sans-latin.woff2') format('woff2');
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
}

:root {
  color-scheme: light;
  font-family: 'Instrument Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-synthesis: none;
  --canvas: #fdfdfc;
  --panel: #f7f7f5;
  --ink: #252522;
  --muted: #9b9b96;
  --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) 0; }
.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); }
.particle-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; cursor: pointer; opacity: 0; touch-action: manipulation; transition: opacity 150ms ease; }
.particle-canvas.is-transitioning { opacity: 1; }

.still-image {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  width: calc(var(--image-display-size, 0px) * var(--image-zoom, 1));
  height: calc(var(--image-display-size, 0px) * var(--image-zoom, 1));
  object-fit: contain;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: opacity 180ms ease, width 260ms var(--ease-out), height 260ms var(--ease-out);
}
.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;
  text-decoration: none;
  transition: color 180ms ease;
}
.wordmark:hover, .wordmark:focus-visible { color: var(--ink); }
.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;
}
.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;
}
.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,.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 { position: relative; aspect-ratio: 1; min-width: 0; transition: opacity 180ms ease, transform 260ms var(--ease-out); }
.image-card.is-entering { animation: card-arrive 510ms var(--ease-out) backwards; }
.image-card.is-removing { animation: card-leave 300ms var(--ease-out) both; pointer-events: none; }
.image-card.is-dragging { opacity: .25; }

.image-tile {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  overflow: hidden;
  border: 1px solid transparent;
  border-radius: 13px;
  background: transparent;
  cursor: grab;
  transition: border-color 180ms ease, background-color 180ms ease, transform 340ms var(--ease-spring);
}
.image-card:hover .image-tile, .image-card:focus-within .image-tile { background: rgba(30,30,25,.045); transform: scale(1.025); }
.image-card.is-active .image-tile { border-color: rgba(48,46,40,.1); background: rgba(255,255,255,.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,.96);
  color: #777771;
  box-shadow: 0 2px 9px rgba(25,25,20,.1);
  cursor: pointer;
  opacity: 0;
  transform: scale(.52) rotate(-35deg);
  transition: opacity 160ms ease, transform 310ms var(--ease-spring), color 160ms ease;
}
.image-card:hover .remove-button, .image-card:focus-within .remove-button { opacity: 1; transform: scale(1) rotate(0); }
.remove-button:hover { 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,.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; }
.library-clear:hover { color: var(--ink); }
.library-clear.is-confirming { color: #9e554a; }

.add-button {
  display: grid;
  width: 43px;
  height: 43px;
  place-items: center;
  border: 1px solid rgba(36,36,32,.04);
  border-radius: 50%;
  background: rgba(255,255,255,.9);
  color: #343430;
  box-shadow: 0 3px 13px rgba(31,31,27,.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,.105); transform: scale(1.09) 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-state p { margin: 0; color: #595852; font-size: 13px; }
.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); }
.text-button { padding: 4px 6px; border: 0; background: transparent; color: var(--muted); font-size: 11px; cursor: pointer; pointer-events: auto; }

.drop-indicator { position: fixed; inset: 0; z-index: 8; padding: 16px; background: rgba(253,253,252,.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,.48); border-radius: 16px; color: #64574d; font-size: 14px; }

.toast { position: fixed; z-index: 9; right: calc(var(--sidebar-width) + 24px); bottom: 22px; padding: 10px 14px; border: 1px solid rgba(30,30,26,.06); border-radius: 12px; background: rgba(255,255,255,.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); }

.touch-cursor { position: fixed; z-index: 20; top: -100px; left: -100px; width: 36px; height: 36px; border: 1px solid rgba(0,0,0,.1); border-radius: 50%; background: rgba(255,255,255,.5); box-shadow: 0 0 40px rgba(0,0,0,.15); opacity: 0; pointer-events: none; transform: translate(-50%,-50%); transition: opacity 125ms ease, transform 175ms var(--ease-out); }
.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(.9); }

@keyframes card-arrive { from { opacity: 0; transform: translateY(9px) scale(.89); } }
@keyframes card-leave { to { opacity: 0; transform: scale(.65) rotate(-7deg); filter: blur(4px); } }

@media (max-width: 699px) {
  :root { --canvas: #fff; --sidebar-width: 100vw; }
  .app { display: block; }
  .stage { width: 100%; height: 100%; }
  .library { position: absolute; z-index: 4; inset: 0 0 0 auto; width: 100%; min-width: 100%; border: 0; transition: transform 560ms var(--ease-out); }
  .sidebar-closed .library { transform: translateX(100%); }
  .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: 0 16px 16px 19px; }
  .image-card.is-active .remove-button { opacity: 1; transform: scale(1); }
  .toast { right: 18px; }
}

@media (hover: hover) and (pointer: fine) {
  .stage, .particle-canvas { cursor: none; }
}

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