:root {
  color-scheme: dark;
  --ink: #1e1919;
  --paper: #f7f5f2;
  --blue: #0061fe;
  --blue-soft: rgba(0, 97, 254, 0.38);
  --lime: #b4dc19;
  --orange: #fa551e;
  --yellow: #fad24b;
  --cyan: #14c8eb;
  --pink: #ffafa5;
  --violet: #c8aff0;
  --muted: #736c64;
  --p1: #d99f59;
  --p2: #d99962;
  --p3: #a67153;
  --p4: #733f2d;
  --p5: #f2f2f2;
  --motion: cubic-bezier(0.65, 0, 0.45, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  color: var(--paper);
  font-family: "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  letter-spacing: 0;
}

button {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
}

.app-shell {
  height: 100svh;
  min-height: 0;
  overflow: hidden;
}

.brand-rail {
  position: fixed;
  z-index: 20;
  left: 0;
  top: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 60px;
  border-right: 1px solid var(--blue-soft);
  background: var(--ink);
}

.rail-title {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-top: 16px;
  writing-mode: vertical-rl;
}

.rail-title strong {
  font-size: 15px;
  font-weight: 700;
  text-transform: uppercase;
}

.rail-title span,
.rail-source,
.panel-index,
.field-title span,
.field-progress small,
.archive-title,
.palette-details dt {
  font-family: "Courier New", monospace;
  font-size: 9px;
  font-weight: 700;
  line-height: 1.1;
  text-transform: uppercase;
}

.rail-title span {
  color: #b4c8e1;
}

.rail-actions {
  display: grid;
  margin: auto 0;
  border-top: 1px solid var(--blue-soft);
}

.rail-button {
  position: relative;
  display: grid;
  place-items: center;
  width: 59px;
  height: 58px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--blue-soft);
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  transition: background 220ms var(--motion), color 220ms var(--motion);
}

.rail-button-primary {
  background: var(--blue);
}

.rail-button:hover,
.rail-button:focus-visible {
  background: var(--yellow);
  color: var(--ink);
}

.rail-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.rail-button-primary:hover svg {
  transform: rotate(90deg);
}

.rail-button-primary svg {
  transition: transform 280ms var(--motion);
}

.rail-button.is-off::after {
  content: "";
  position: absolute;
  width: 28px;
  height: 2px;
  background: currentColor;
  transform: rotate(-38deg);
}

.rail-source {
  margin-bottom: 16px;
  color: #b4c8e1;
  writing-mode: vertical-rl;
}

.experience {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 400px);
  min-height: 0;
  height: 100svh;
  margin-left: 60px;
}

.playfield {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background-color: var(--ink);
  background-image:
    linear-gradient(var(--blue-soft) 1px, transparent 1px),
    linear-gradient(90deg, var(--blue-soft) 1px, transparent 1px);
  background-position: -1px -1px;
  background-size: 188px 188px;
}

#bubbleCanvas {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.field-title {
  position: absolute;
  z-index: 4;
  left: 28px;
  top: 22px;
  display: grid;
  gap: 16px;
  color: var(--paper);
  pointer-events: none;
}

.field-title span {
  color: #b4c8e1;
}

.field-title strong {
  font-size: 82px;
  font-weight: 700;
  line-height: 0.76;
}

.field-progress {
  position: absolute;
  z-index: 5;
  right: 24px;
  top: 22px;
  display: grid;
  gap: 5px;
  min-width: 146px;
  padding: 15px 16px 13px;
  border-radius: 18px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 4px 4px 0 var(--blue);
  pointer-events: none;
}

.field-progress span {
  font-size: 15px;
  font-weight: 700;
}

.field-progress small {
  color: var(--muted);
}

.selection-tray {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: 24px;
  display: grid;
  grid-template-columns: repeat(5, 52px);
  gap: 8px;
  width: 324px;
  height: 84px;
  padding: 16px;
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 5px 5px 0 var(--blue);
  transform: translateX(-50%);
  pointer-events: auto;
}

.tray-slot,
.tray-bubble {
  width: 52px;
  height: 52px;
  border-radius: 50%;
}

.tray-slot {
  position: relative;
  border: 1px solid var(--ink);
  background: #dfdcd8;
  transition: border-color 220ms var(--motion), box-shadow 220ms var(--motion), transform 220ms var(--motion);
}

.tray-slot::after {
  content: attr(data-index);
  position: absolute;
  left: 50%;
  top: 50%;
  color: #8c8279;
  font-family: "Courier New", monospace;
  font-size: 9px;
  font-weight: 700;
  transform: translate(-50%, -50%);
}

.tray-slot.is-target {
  border: 3px solid var(--target);
  box-shadow: 0 0 0 2px var(--ink), 0 0 0 5px color-mix(in srgb, var(--target), transparent 40%);
  animation: target-breathe 1.8s var(--motion) infinite;
}

.tray-slot.is-target::after {
  color: var(--ink);
}

.tray-slot.is-miss {
  animation: slot-miss 420ms var(--motion);
}

.tray-bubble {
  position: relative;
  padding: 0;
  border: 2px solid var(--ink);
  background: var(--bubble);
  animation: arrive 280ms var(--motion);
}

button.tray-bubble {
  cursor: pointer;
}

.tray-bubble:not(.is-last) {
  pointer-events: none;
}

.tray-bubble::after {
  content: "";
  position: absolute;
  left: 12px;
  top: 10px;
  width: 14px;
  height: 8px;
  border-radius: 50%;
  background: rgba(247, 245, 242, 0.72);
  transform: rotate(-24deg);
}

.selection-tray.miss {
  animation: tray-miss 380ms var(--motion);
}

.selection-tray.pop {
  animation: tray-pop 500ms var(--motion);
}

.completion-overlay {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  visibility: hidden;
  pointer-events: none;
}

.completion-overlay.is-active {
  visibility: visible;
}

.completion-bands {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
}

.completion-band {
  position: relative;
  display: block;
  width: 104%;
  height: 112%;
  margin-left: -2%;
  border-radius: 50% 50% 0 0;
  background: var(--band);
  transform: translateY(110%) scaleX(0.14) rotate(var(--tilt));
  transform-origin: 50% 100%;
}

.completion-overlay.is-active .completion-band {
  animation: rainbow-rise 1.35s var(--motion) both;
  animation-delay: var(--delay);
}

.completion-overlay.is-leaving .completion-band {
  animation: rainbow-leave 720ms var(--motion) both;
  animation-delay: var(--leave-delay);
}

.completion-label {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 8px;
  width: min(470px, calc(100vw - 40px));
  padding: 22px 24px 24px;
  border-radius: 24px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 7px 7px 0 var(--blue);
  opacity: 0;
  transform: translateY(24px) scale(0.92) rotate(-1deg);
}

.completion-label span {
  font-family: "Courier New", monospace;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.completion-label strong {
  overflow-wrap: anywhere;
  font-size: 52px;
  line-height: 0.88;
}

.completion-overlay.is-active .completion-label {
  animation: completion-label-in 520ms var(--motion) 1.05s forwards;
}

.completion-overlay.is-leaving .completion-label {
  animation: completion-label-out 320ms var(--motion) forwards;
}

.palette-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-left: 1px solid var(--blue-soft);
  background: var(--paper);
  color: var(--ink);
}

.panel-index {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 0 20px;
  border-bottom: 1px solid #d3cec9;
  color: var(--muted);
}

.palette-panel > h1 {
  min-height: 126px;
  margin: 0;
  padding: 20px 20px 14px;
  overflow-wrap: anywhere;
  font-size: 52px;
  font-weight: 700;
  line-height: 0.88;
}

.palette-panel > p {
  min-height: 68px;
  margin: 0;
  padding: 0 20px 16px;
  color: #4f4a46;
  font-size: 14px;
  line-height: 1.35;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  min-height: 186px;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}

.swatch {
  position: relative;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-right: 1px solid var(--ink);
  background: var(--swatch);
  color: var(--swatch-label);
  cursor: pointer;
}

.swatch:last-child {
  border-right: 0;
}

.swatch::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 38%;
  width: 34px;
  height: 34px;
  border: 2px solid currentColor;
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.5);
  transition: opacity 220ms var(--motion), transform 220ms var(--motion);
}

.swatch.is-observed::before {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.swatch::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 2px solid currentColor;
  opacity: 0;
  transform: scale(0.88);
  transition: opacity 220ms var(--motion), transform 220ms var(--motion);
}

.swatch.is-target::after {
  opacity: 1;
  transform: scale(1);
  animation: swatch-target 1.8s var(--motion) infinite;
}

.swatch span {
  position: absolute;
  left: 50%;
  bottom: 10px;
  font-family: "Courier New", monospace;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  transform: translateX(-50%) rotate(-90deg);
  white-space: nowrap;
}

.palette-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 74px;
  margin: 0;
  border-bottom: 1px solid #d3cec9;
}

.palette-details div {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 7px;
  min-width: 0;
  padding: 10px 20px;
}

.palette-details div + div {
  border-left: 1px solid #d3cec9;
}

.palette-details dt,
.archive-title {
  color: var(--muted);
}

.palette-details dd {
  margin: 0;
  overflow: hidden;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.archive {
  min-height: 0;
  padding: 18px 20px 20px;
}

.archive-title {
  margin-bottom: 8px;
}

.archive-list {
  display: grid;
  max-height: 118px;
  overflow: auto;
  border-top: 1px solid var(--ink);
}

.archive-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 104px;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 7px 0;
  border: 0;
  border-bottom: 1px solid var(--ink);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.archive-item strong {
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-swatches {
  display: flex;
  width: 104px;
  height: 26px;
  border: 1px solid var(--ink);
  border-right: 0;
}

.mini-swatches i {
  flex: 1;
  border-right: 1px solid var(--ink);
  background: var(--mini);
}

.toast {
  position: fixed;
  left: calc(50% + 30px);
  bottom: 20px;
  z-index: 30;
  max-width: calc(100vw - 100px);
  min-height: 44px;
  padding: 13px 17px;
  border-radius: 14px;
  background: var(--yellow);
  color: var(--ink);
  box-shadow: 4px 4px 0 var(--blue);
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 14px);
  transition: opacity 180ms var(--motion), transform 180ms var(--motion);
}

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

.rail-button:focus-visible,
.swatch:focus-visible,
.archive-item:focus-visible {
  outline: 3px solid var(--lime);
  outline-offset: -3px;
}

@keyframes arrive {
  from { opacity: 0; transform: scale(0.45) rotate(-8deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes tray-miss {
  0%, 100% { transform: translateX(-50%); }
  35% { transform: translateX(calc(-50% - 8px)) rotate(-1deg); }
  70% { transform: translateX(calc(-50% + 6px)) rotate(1deg); }
}

@keyframes tray-pop {
  0%, 100% { transform: translateX(-50%) scale(1); }
  45% { transform: translateX(-50%) scale(1.06) rotate(-1deg); }
}

@keyframes target-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.92); }
}

@keyframes slot-miss {
  0%, 100% { transform: scale(1); }
  35% { transform: scale(0.8) rotate(-5deg); }
  70% { transform: scale(1.06) rotate(3deg); }
}

@keyframes swatch-target {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

@keyframes rainbow-rise {
  0% {
    border-radius: 50% 50% 0 0;
    transform: translateY(110%) scaleX(0.14) rotate(var(--tilt));
  }
  58% {
    border-radius: 44% 44% 0 0;
    transform: translateY(0) scaleX(0.58) rotate(0deg);
  }
  100% {
    border-radius: 0;
    transform: translateY(-5%) scaleX(1.06) rotate(0deg);
  }
}

@keyframes rainbow-leave {
  from { transform: translateY(-5%) scaleX(1.06); }
  to { transform: translateY(-112%) scaleX(0.76); }
}

@keyframes completion-label-in {
  to { opacity: 1; transform: translateY(0) scale(1) rotate(0); }
}

@keyframes completion-label-out {
  to { opacity: 0; transform: translateY(-18px) scale(0.94); }
}

@media (max-width: 980px) {
  .experience {
    grid-template-columns: minmax(0, 1fr) 360px;
  }

  .field-title strong {
    font-size: 68px;
  }

  .palette-panel > h1 {
    font-size: 44px;
  }
}

@media (max-width: 760px) {
  .brand-rail {
    right: 0;
    bottom: auto;
    flex-direction: row;
    justify-content: space-between;
    width: auto;
    height: 58px;
    border-right: 0;
    border-bottom: 1px solid var(--blue-soft);
  }

  .rail-title {
    display: grid;
    gap: 2px;
    padding: 0 12px;
    writing-mode: horizontal-tb;
  }

  .rail-title strong {
    font-size: 15px;
  }

  .rail-title span {
    font-size: 8px;
  }

  .rail-actions {
    display: flex;
    margin: 0;
    border-top: 0;
    border-left: 1px solid var(--blue-soft);
  }

  .rail-button {
    width: 48px;
    height: 57px;
    border-right: 1px solid var(--blue-soft);
    border-bottom: 0;
  }

  .rail-source {
    display: none;
  }

  .experience {
    display: block;
    height: calc(100svh - 58px);
    margin-top: 58px;
    margin-left: 0;
  }

  .playfield {
    width: 100%;
    height: 100%;
    background-size: 112px 112px;
  }

  .field-title {
    left: 16px;
    top: 17px;
    gap: 10px;
  }

  .field-title strong {
    font-size: 44px;
  }

  .field-progress {
    right: 16px;
    top: 16px;
    min-width: 118px;
    padding: 11px 12px 10px;
    border-radius: 14px;
  }

  .field-progress span {
    font-size: 13px;
  }

  .selection-tray {
    bottom: 188px;
    grid-template-columns: repeat(5, 43px);
    gap: 5px;
    width: 259px;
    height: 67px;
    padding: 12px;
    border-radius: 18px;
  }

  .tray-slot,
  .tray-bubble {
    width: 43px;
    height: 43px;
  }

  .completion-label {
    padding: 18px 19px 20px;
    border-radius: 18px;
  }

  .completion-label strong {
    font-size: 38px;
  }

  .palette-panel {
    position: absolute;
    z-index: 8;
    left: 10px;
    right: 10px;
    bottom: 10px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 142px;
    grid-template-rows: 34px 126px;
    height: 160px;
    overflow: hidden;
    border: 0;
    border-radius: 18px;
    box-shadow: 5px 5px 0 var(--blue);
  }

  .panel-index {
    grid-column: 1 / -1;
    min-height: 34px;
    padding: 0 11px;
  }

  .palette-panel > h1 {
    grid-column: 1;
    grid-row: 2;
    min-height: 0;
    padding: 12px;
    overflow: hidden;
    border-right: 1px solid var(--ink);
    font-size: 31px;
    line-height: 0.9;
  }

  .palette-panel > p,
  .palette-details,
  .archive {
    display: none;
  }

  .swatches {
    grid-column: 2;
    grid-row: 2;
    min-height: 0;
    border: 0;
  }

  .swatch span {
    bottom: 9px;
    font-size: 8px;
  }

  .toast {
    left: 50%;
    bottom: 184px;
    max-width: calc(100vw - 32px);
  }
}

@media (max-width: 410px) {
  .rail-title span {
    display: none;
  }

  .rail-title {
    padding-inline: 10px;
  }

  .rail-button {
    width: 45px;
  }

  .field-title strong {
    font-size: 40px;
  }

  .palette-panel {
    grid-template-columns: minmax(0, 1fr) 132px;
  }

  .palette-panel > h1 {
    font-size: 28px;
  }
}

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