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

#viewport {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
}

body {
  background: #cbb994;
}

#plane {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
}

/* Every card is EXACTLY 200x80 — this must match ENTRY_WIDTH/ENTRY_HEIGHT
   in server/placement.js, since it's what makes the collision footprint
   exact. Cards show a 64px thumbnail + a 50-char snippet; full content
   lives in the detail overlay (interaction.js). */
/* No overflow:hidden on .entry itself — the [E] badge renders just above
   the card via ::after. Children are individually constrained instead. */
.entry {
  position: absolute;
  width: 200px;
  height: 80px;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: #fff8e7;
  border: 1px solid #8a7752;
  padding: 8px;
  box-sizing: border-box;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.2);
  font-family: sans-serif;
  font-size: 12px;
}

.entry img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  flex-shrink: 0;
  display: block;
}

.entry p {
  margin: 0;
  max-height: 64px;
  overflow: hidden;
}

/* Active target: highlighted + floating [E] badge (styled in Task 11,
   which adds the interaction layer that toggles this class). */
.entry.active {
  border-color: #d64545;
  box-shadow: 0 0 0 2px #d64545, 2px 2px 0 rgba(0, 0, 0, 0.2);
}

.entry.active::after {
  content: '[E]';
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  background: #2b2b2b;
  color: #fff;
  padding: 1px 6px;
  font-size: 11px;
  border-radius: 3px;
}

#avatar {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  background: #d64545;
  border: 2px solid #7a1f1f;
  z-index: 10;
}

#avatar.facing-up,
#avatar.facing-up-left,
#avatar.facing-up-right { border-radius: 4px 4px 12px 12px; }
#avatar.facing-down,
#avatar.facing-down-left,
#avatar.facing-down-right { border-radius: 12px 12px 4px 4px; }
#avatar.facing-left { border-radius: 12px 4px 4px 12px; }
#avatar.facing-right { border-radius: 4px 12px 12px 4px; }

#avatar:not(.sprited).walking {
  animation: corkboard-avatar-bob 0.3s infinite alternate;
}

@keyframes corkboard-avatar-bob {
  from { transform: scale(1); }
  to { transform: scale(0.85, 1.1); }
}

/* Sprite-sheet avatar convention: public/sprites/sprite_sheet.png is a 2-column x
   8-row grid, every cell the same size. Column 0 = frame A (also the idle
   frame), column 1 = frame B. Row order (counterclockwise from down):
   0=down, 1=down-left, 2=left, 3=up-left, 4=up, 5=up-right, 6=right,
   7=down-right. avatar.js probes for this file at load and adds the
   `sprited` class to #avatar if it loads; otherwise the plain red-box
   rules above are the fallback. */
#avatar.sprited {
  --cell-w: 32px;
  --cell-h: 48px;
  width: var(--cell-w);
  height: var(--cell-h);
  margin: calc(var(--cell-h) / -2) 0 0 calc(var(--cell-w) / -2);
  background: url('/sprites/sprite_sheet.png') no-repeat;
  background-size: calc(var(--cell-w) * 2) calc(var(--cell-h) * 8);
  background-position: 0 calc(var(--row, 0) * -1 * var(--cell-h));
  border: none;
  border-radius: 0;
  image-rendering: pixelated;
}
#avatar.sprited.facing-down { --row: 0; }
#avatar.sprited.facing-up { --row: 4; }
#avatar.sprited.facing-left { --row: 2; }
#avatar.sprited.facing-right { --row: 6; }
#avatar.sprited.facing-down-left { --row: 1; }
#avatar.sprited.facing-down-right { --row: 7; }
#avatar.sprited.facing-up-left { --row: 3; }
#avatar.sprited.facing-up-right { --row: 5; }
#avatar.sprited.walking {
  animation: sprite-walk 0.4s steps(2) infinite;
}
@keyframes sprite-walk {
  from { background-position-x: 0; }
  to { background-position-x: calc(var(--cell-w) * -2); }
}

#detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#detail-overlay[hidden] {
  display: none;
}

#detail-card {
  background: #fff8e7;
  border: 1px solid #8a7752;
  padding: 16px;
  max-width: min(640px, 90vw);
  max-height: 85vh;
  overflow-y: auto;
  font-family: sans-serif;
}

#detail-image {
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  display: block;
  margin: 0 auto 12px;
}

#detail-image[hidden] {
  display: none;
}

#detail-text {
  margin: 0;
  white-space: pre-wrap;
}

/* Hotbar: a Q-toggled modal slot bar (see hotbar.js). Sits above the plane
   but below the detail overlay (z-index 100). */
#hotbar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: row;
  gap: 6px;
  z-index: 50;
}

#hotbar[hidden] {
  display: none;
}

.hotbar-slot {
  width: 60px;
  height: 64px;
  background-image: url('/sprites/hotbar.png');
  background-size: 100% 100%;
  image-rendering: pixelated;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hotbar-slot.selected {
  box-shadow: 0 0 0 3px #f5d90a;
  transform: scale(1.08);
}

.hotbar-slot .item-icon {
  width: 36px;
  height: 40px;
  background-image: url('/sprites/eraser.png');
  background-size: 100% 100%;
  image-rendering: pixelated;
}

/* Equipped item floating above the avatar's head. */
#held-item {
  position: fixed;
  top: calc(50% - 64px);
  left: 50%;
  margin-left: -13px;
  width: 27px;
  height: 30px;
  background-image: url('/sprites/eraser.png');
  background-size: 100% 100%;
  image-rendering: pixelated;
  z-index: 10;
  animation: held-item-bob 1s ease-in-out infinite alternate;
}

#held-item[hidden] {
  display: none;
}

@keyframes held-item-bob {
  from { transform: translateY(0); }
  to { transform: translateY(-6px); }
}

/* Armed entry: about to be erased. Must visually coexist with .active
   (the [E] interaction highlight). */
.entry.armed {
  outline: 3px solid #d33;
  animation: armed-shake 0.25s infinite;
}

@keyframes armed-shake {
  0%, 100% { translate: 0 0; }
  25% { translate: -2px 0; }
  75% { translate: 2px 0; }
}
