:root {
  --bg: #17181c;
  --surface: #24262c;
  --surface-2: #2f323a;
  --text: #f1f1f3;
  --text-dim: #9a9ca3;
  --accent: #e8b84b;
  --error: #e8654b;
  --paper: #f6efe0;
  --paper-text: #2a2620;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

#app {
  width: 100%;
  max-width: 420px;
}

.view {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
}

.view.hidden { display: none; }

h1 {
  font-size: 2.2rem;
  margin: 0;
  letter-spacing: 0.02em;
}

.subtitle {
  color: var(--text-dim);
  margin: 0 0 8px;
}

.bucket-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.bucket-card {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 14px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.bucket-card:hover,
.bucket-card:focus-visible {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.bucket-card:active {
  transform: translateY(0) scale(0.98);
}

.bucket-name {
  font-size: 1.1rem;
  font-weight: 600;
}

.bucket-hint {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.link-button {
  background: none;
  border: none;
  color: var(--text-dim);
  font: inherit;
  cursor: pointer;
  align-self: flex-start;
  padding: 4px 0;
}

.link-button:hover { color: var(--text); }

#stage {
  position: relative;
  width: 100%;
  height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.box {
  width: 140px;
  height: 140px;
  background: var(--surface);
  border: 2px solid var(--surface-2);
  border-radius: 12px;
  position: relative;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  transform-origin: 50% 90%;
}

.box:active { cursor: grabbing; }

.box-lid {
  position: absolute;
  top: -8px;
  left: -4px;
  right: -4px;
  height: 20px;
  background: var(--surface-2);
  border-radius: 8px;
}

.box.shaking {
  animation: box-shake 0.4s ease-in-out;
}

@keyframes box-shake {
  0%, 100% { transform: rotate(0deg) translateX(0); }
  15% { transform: rotate(-8deg) translateX(-4px); }
  30% { transform: rotate(7deg) translateX(4px); }
  45% { transform: rotate(-6deg) translateX(-3px); }
  60% { transform: rotate(6deg) translateX(3px); }
  75% { transform: rotate(-4deg) translateX(-2px); }
  90% { transform: rotate(3deg) translateX(1px); }
}

.paper {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 56px;
  background: var(--paper);
  border-radius: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  pointer-events: none; /* the box underneath stays shakeable even once a paper is showing */
}

.paper.hidden { display: none; }

.paper.fall {
  animation: paper-fall 0.45s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

@keyframes paper-fall {
  0% { opacity: 0; transform: translate(-50%, -80%) scale(0.25) rotate(-6deg); }
  60% { opacity: 1; transform: translate(-50%, -50%) scale(0.4) rotate(3deg); }
  100% { opacity: 1; transform: translate(-50%, -50%) scale(0.4) rotate(0deg); }
}

.paper.unfold {
  animation: paper-unfold 0.5s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

@keyframes paper-unfold {
  0% { opacity: 1; width: 44px; height: 56px; transform: translate(-50%, -50%) scale(0.4); }
  100% { opacity: 1; width: 260px; height: 180px; transform: translate(-50%, -50%) scale(1); }
}

.paper-text {
  font-size: 1.05rem;
  line-height: 1.4;
  color: var(--paper-text);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.paper-text.visible { opacity: 1; }

.motion-prompt {
  color: var(--accent);
  font-size: 0.9rem;
}

.motion-prompt.hidden { display: none; }

.instructions {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0;
}

.error {
  color: var(--error);
  font-size: 0.9rem;
}

.error.hidden { display: none; }
