:root {
  --red-hi: #f0565c;
  --red: #d3222a;
  --red-deep: #8f1116;
  --cream: #f2ead6;
  --screen-base: #dde1cd;
  --ink: #2a2f26;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  background: #26241f;
  font-family: 'Nunito', 'Avenir Next', 'Segoe UI', sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.room {
  position: fixed;
  inset: 0;
}

.wall {
  position: absolute;
  inset: 0 0 54% 0;
  background:
    radial-gradient(90% 120% at 30% -10%, rgba(255, 236, 200, 0.14), transparent 55%),
    linear-gradient(180deg, #33312b 0%, #4a463d 62%, #5c564a 100%);
}

.wall::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(130% 100% at 50% 20%, transparent 52%, rgba(0, 0, 0, 0.42) 100%);
}

.table {
  position: absolute;
  inset: 46% 0 0 0;
  background:
    repeating-linear-gradient(
      93deg,
      rgba(58, 38, 18, 0.1) 0 2px,
      transparent 2px 7px,
      rgba(255, 226, 180, 0.05) 7px 9px,
      transparent 9px 16px
    ),
    repeating-linear-gradient(0deg, transparent 0 128px, rgba(0, 0, 0, 0.14) 128px 131px),
    linear-gradient(180deg, #a07c55 0%, #8a6845 34%, #745434 72%, #5f4429 100%);
  box-shadow: inset 0 2px 0 rgba(255, 240, 210, 0.1);
}

.table::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(58% 62% at 40% 6%, rgba(255, 240, 208, 0.3), transparent 68%);
  animation: breathe 11s ease-in-out infinite;
}

.table::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 55%, rgba(15, 8, 2, 0.42) 100%);
}

@keyframes breathe {
  0%,
  100% {
    opacity: 0.72;
  }
  50% {
    opacity: 1;
  }
}

.mote {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 244, 218, 0.55);
  filter: blur(1.6px);
  opacity: 0;
  animation: drift linear infinite;
  pointer-events: none;
}

.mote:nth-child(1) { left: 16%; top: 30%; animation-duration: 13s; animation-delay: 0s; }
.mote:nth-child(2) { left: 26%; top: 18%; animation-duration: 17s; animation-delay: 3s; transform: scale(0.7); }
.mote:nth-child(3) { left: 44%; top: 26%; animation-duration: 15s; animation-delay: 6s; }
.mote:nth-child(4) { left: 62%; top: 14%; animation-duration: 19s; animation-delay: 2s; transform: scale(1.3); }
.mote:nth-child(5) { left: 74%; top: 32%; animation-duration: 14s; animation-delay: 8s; transform: scale(0.8); }
.mote:nth-child(6) { left: 87%; top: 22%; animation-duration: 16s; animation-delay: 5s; }
.mote:nth-child(7) { left: 8%; top: 12%; animation-duration: 21s; animation-delay: 10s; transform: scale(0.6); }

@keyframes drift {
  0% { transform: translate(0, 0); opacity: 0; }
  12% { opacity: 0.7; }
  60% { opacity: 0.5; }
  100% { transform: translate(26px, -70px); opacity: 0; }
}

.brand {
  position: fixed;
  top: 18px;
  left: 22px;
  z-index: 40;
  transform: rotate(-1.4deg);
  pointer-events: none;
}

.brand .logo {
  font-family: 'Lilita One', 'Arial Rounded MT Bold', 'Chalkboard SE', sans-serif;
  font-size: 36px;
  letter-spacing: 0.5px;
  color: #f6efdd;
  text-shadow:
    0 2px 0 #7c1013,
    0 3px 0 rgba(60, 6, 8, 0.55),
    0 6px 14px rgba(0, 0, 0, 0.5);
}

.brand .logo sup {
  font-size: 12px;
  vertical-align: super;
}

.brand .tag {
  margin-top: 3px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 3.4px;
  text-transform: uppercase;
  color: rgba(246, 238, 220, 0.62);
}

.chips {
  position: fixed;
  top: 18px;
  right: 20px;
  z-index: 40;
  display: flex;
  gap: 9px;
}

.chip {
  appearance: none;
  border: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(28, 24, 18, 0.58);
  color: #f2e8d5;
  font: 700 12px/1 'Nunito', sans-serif;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.14);
  backdrop-filter: blur(5px);
  transition: transform 0.18s ease, background 0.18s ease;
}

.chip:hover {
  transform: translateY(-1.5px);
  background: rgba(48, 40, 30, 0.78);
}

.chip:active {
  transform: translateY(0.5px) scale(0.97);
}

.chip svg {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chip .ic-off { display: none; }
body.muted .chip .ic-on { display: none; }
body.muted .chip .ic-off { display: block; }

.hint {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  padding: 9px 18px;
  border-radius: 999px;
  background: rgba(28, 24, 18, 0.55);
  color: rgba(244, 234, 216, 0.92);
  font: 700 12px/1.2 'Nunito', sans-serif;
  letter-spacing: 0.6px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(5px);
  transition: opacity 1.4s ease;
  white-space: nowrap;
}

.hint b {
  color: #ffd75e;
  font-weight: 800;
}

.hint.gone {
  opacity: 0;
  pointer-events: none;
}

.credit {
  position: fixed;
  bottom: 16px;
  right: 20px;
  z-index: 40;
  font: 700 10px/1.4 'Nunito', sans-serif;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: rgba(244, 234, 216, 0.34);
  pointer-events: none;
}

.scene {
  position: absolute;
  left: 50%;
  top: 54%;
  width: 1240px;
  height: 800px;
  transform: translate(-50%, -50%) scale(var(--s, 1));
  perspective: 1700px;
  cursor: none;
}

.tilt {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
}

.boardShadow {
  position: absolute;
  left: 52px;
  top: 150px;
  width: 910px;
  height: 620px;
  background: radial-gradient(52% 52% at 50% 54%, rgba(16, 8, 2, 0.55), rgba(16, 8, 2, 0.3) 56%, transparent 76%);
  filter: blur(19px);
}

.flipper {
  position: absolute;
  left: 36px;
  top: 84px;
  width: 920px;
  height: 640px;
  transform-style: preserve-3d;
  transition: transform 0.8s cubic-bezier(0.65, -0.18, 0.28, 1.18);
}

.flipper.flipped {
  transform: rotateY(180deg);
}

.board {
  position: absolute;
  inset: 0;
  border-radius: 36px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.board.front {
  background: linear-gradient(155deg, #f2575d 0%, #d3222a 34%, #b0161c 72%, #931015 100%);
  box-shadow:
    inset 0 2px 2px rgba(255, 255, 255, 0.55),
    inset 0 -3px 6px rgba(0, 0, 0, 0.35),
    inset 3px 0 4px rgba(255, 255, 255, 0.16),
    inset -3px 0 5px rgba(0, 0, 0, 0.2),
    0 0 0 3px rgba(84, 7, 10, 0.6);
  transform: translateZ(8px);
}

.board.front::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(
    115deg,
    transparent 30%,
    rgba(255, 255, 255, 0.17) 43%,
    rgba(255, 255, 255, 0.03) 52%,
    transparent 62%
  );
  transform: translateX(var(--sheen, 0px));
  pointer-events: none;
}

.board.front.shake {
  animation: boardShake 0.5s linear;
}

@keyframes boardShake {
  0% { transform: translateZ(8px) translate(0, 0) rotate(0deg); }
  14% { transform: translateZ(8px) translate(-5px, 2px) rotate(-0.5deg); }
  28% { transform: translateZ(8px) translate(6px, -2px) rotate(0.55deg); }
  42% { transform: translateZ(8px) translate(-5px, -3px) rotate(-0.45deg); }
  58% { transform: translateZ(8px) translate(4px, 3px) rotate(0.4deg); }
  74% { transform: translateZ(8px) translate(-3px, 1px) rotate(-0.22deg); }
  100% { transform: translateZ(8px) translate(0, 0) rotate(0deg); }
}

.board.back {
  transform: rotateY(180deg) translateZ(8px);
  background:
    repeating-radial-gradient(circle at 50% 44%, rgba(0, 0, 0, 0.09) 0 3px, transparent 3px 30px),
    linear-gradient(155deg, #e04a50 0%, #b8181e 45%, #8f1116 100%);
  box-shadow:
    inset 0 2px 2px rgba(255, 255, 255, 0.4),
    inset 0 -3px 6px rgba(0, 0, 0, 0.35),
    0 0 0 3px rgba(84, 7, 10, 0.6);
}

.backBrand {
  position: absolute;
  top: 44%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Lilita One', sans-serif;
  font-size: 52px;
  letter-spacing: 2px;
  color: rgba(120, 10, 14, 0.75);
  text-shadow: 0 1px 1px rgba(255, 255, 255, 0.18);
  white-space: nowrap;
}

.backSticker {
  position: absolute;
  left: 52px;
  bottom: 54px;
  width: 220px;
  padding: 12px 14px;
  border-radius: 8px;
  background: linear-gradient(180deg, #f4efe2, #e2dac4);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(0, 0, 0, 0.06);
  color: #5c564a;
  font: 700 8.5px/1.7 'Nunito', sans-serif;
  letter-spacing: 1.1px;
  text-transform: uppercase;
}

.backSticker .bars {
  height: 20px;
  margin-top: 6px;
  background: repeating-linear-gradient(
    90deg,
    #3a362e 0 2px,
    transparent 2px 4px,
    #3a362e 4px 7px,
    transparent 7px 9px,
    #3a362e 9px 10px,
    transparent 10px 13px
  );
}

.backScrew {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #a8181d 0 30%, #6d0c10 75%);
  box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.6), 0 1px 1px rgba(255, 255, 255, 0.22);
}

.backScrew::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  width: 8px;
  height: 1.6px;
  margin: -0.8px 0 0 -4px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 1px;
  transform: rotate(35deg);
}

.backScrew.tl { left: 26px; top: 26px; }
.backScrew.tr { right: 26px; top: 26px; }
.backScrew.bl { left: 26px; bottom: 26px; }
.backScrew.br { right: 26px; bottom: 26px; }

.plate {
  position: absolute;
  top: 4px;
  left: 50%;
  transform: translateX(-50%) rotate(-0.5deg);
  padding: 2px 24px 3px;
  border-radius: 11px;
  background: linear-gradient(180deg, #f8f2e2, #e6dabb 62%, #d8caa6);
  box-shadow:
    0 2px 3px rgba(0, 0, 0, 0.32),
    inset 0 1px 1px rgba(255, 255, 255, 0.95),
    inset 0 -1px 2px rgba(122, 92, 42, 0.3);
  text-align: center;
}

.plate .name {
  font-family: 'Lilita One', sans-serif;
  font-size: 19px;
  letter-spacing: 0.5px;
  color: #c01d24;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.65);
  line-height: 1;
}

.plate .name sup {
  font-size: 7px;
}

.plate .sub {
  display: block;
  font: 800 6.5px/1 'Nunito', sans-serif;
  letter-spacing: 2.4px;
  text-transform: uppercase;
  color: #8a6f3f;
  margin-top: 2px;
}

.bevel {
  position: absolute;
  left: 41px;
  top: 41px;
  right: 41px;
  bottom: 89px;
  padding: 8px;
  border-radius: 22px;
  background: linear-gradient(180deg, #f6efdc, #ddd2b4 58%, #cfc2a0);
  box-shadow:
    0 2px 5px rgba(0, 0, 0, 0.38),
    inset 0 1px 2px rgba(255, 255, 255, 0.9),
    inset 0 -1px 2px rgba(0, 0, 0, 0.16);
}

.recess {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 15px;
  overflow: hidden;
  background: radial-gradient(115% 125% at 50% 36%, #e4e8d5 0%, #dde1cd 52%, #cbd0b8 100%);
  box-shadow:
    inset 0 4px 10px rgba(35, 40, 25, 0.42),
    inset 0 -2px 4px rgba(255, 255, 255, 0.55),
    inset 0 0 0 1.5px rgba(60, 66, 45, 0.2);
  transition: box-shadow 0.16s ease;
}

.recess.pulse {
  box-shadow:
    inset 0 7px 16px rgba(35, 40, 25, 0.55),
    inset 0 -2px 4px rgba(255, 255, 255, 0.5),
    inset 0 0 0 1.5px rgba(60, 66, 45, 0.24);
}

.recess canvas {
  position: absolute;
  left: 0;
  top: 0;
}

#inkCanvas { z-index: 1; }
#gridCanvas { z-index: 2; }

.magnetShadow {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 80px;
  z-index: 3;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(38, 44, 28, 0.09) 32%,
    rgba(38, 44, 28, 0.16) 50%,
    rgba(38, 44, 28, 0.09) 68%,
    transparent
  );
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
}

.magnetShadow.on {
  opacity: 1;
  transition: opacity 0.06s ease;
}

.sheen {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background:
    radial-gradient(
      95% 75% at var(--gx, 32%) var(--gy, 22%),
      rgba(255, 255, 255, 0.11),
      transparent 55%
    ),
    linear-gradient(112deg, rgba(255, 255, 255, 0.075), transparent 34%, transparent 66%, rgba(255, 255, 255, 0.05));
}

.stampGhost {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.14s ease;
  pointer-events: none;
}

.stampGhost svg {
  overflow: visible;
  position: absolute;
  left: 0;
  top: 0;
}

.stampGhost .g { display: none; }
.stampGhost[data-shape='circle'] .g-circle { display: block; }
.stampGhost[data-shape='square'] .g-square { display: block; }
.stampGhost[data-shape='triangle'] .g-triangle { display: block; }

.rail {
  position: absolute;
  left: 50%;
  bottom: 30px;
  width: 716px;
  height: 28px;
  transform: translateX(-50%);
  border-radius: 14px;
  background: linear-gradient(180deg, #6d0c10, #4c070a);
  box-shadow:
    inset 0 3px 7px rgba(0, 0, 0, 0.66),
    inset 0 -1px 1px rgba(255, 255, 255, 0.18),
    0 1px 1px rgba(255, 255, 255, 0.28);
}

.railLabel {
  position: absolute;
  left: 50%;
  bottom: 11px;
  transform: translateX(-50%);
  font: 800 8.5px/1 'Nunito', sans-serif;
  letter-spacing: 3.4px;
  text-transform: uppercase;
  color: rgba(255, 214, 208, 0.42);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

.knob {
  position: absolute;
  top: -9px;
  left: 0;
  width: 96px;
  height: 46px;
  border-radius: 13px;
  background: linear-gradient(180deg, #f4666b, #d3222a 46%, #a51217);
  box-shadow:
    0 5px 9px rgba(0, 0, 0, 0.48),
    inset 0 2px 2px rgba(255, 255, 255, 0.5),
    inset 0 -2px 3px rgba(0, 0, 0, 0.32);
  cursor: grab;
  touch-action: none;
  will-change: transform;
}

.knob:active {
  cursor: grabbing;
}

.knob::before {
  content: '';
  position: absolute;
  inset: 9px 24px;
  border-radius: 6px;
  background: repeating-linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.18) 0 3px,
    transparent 3px 9px
  );
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.25);
}

.knob:focus-visible {
  outline: 2px solid #ffd75e;
  outline-offset: 3px;
}

.anchorHole {
  position: absolute;
  right: 12px;
  top: 50%;
  width: 17px;
  height: 17px;
  margin-top: -8.5px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 30%, #170303 0 30%, #3d0709 62%, #5b0a0d);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.85), 0 1px 1px rgba(255, 255, 255, 0.35);
}

#stringLayer {
  position: absolute;
  inset: 0;
  z-index: 25;
  overflow: visible;
  pointer-events: none;
  transform: translateZ(14px);
  filter: drop-shadow(0 1.5px 1px rgba(10, 5, 0, 0.3));
}

#stringPath {
  fill: none;
  stroke: #ddd1b3;
  stroke-width: 2.6;
  stroke-linecap: round;
}

#pen {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  z-index: 30;
  pointer-events: none;
  transform-origin: 0 0;
  filter: drop-shadow(3px 7px 5px rgba(15, 8, 3, 0.4));
  transition: filter 0.18s ease;
}

#pen.writing {
  filter: drop-shadow(1px 2.5px 2px rgba(15, 8, 3, 0.52));
}

#pen.resting {
  filter: drop-shadow(2px 4px 3px rgba(15, 8, 3, 0.44));
}

#pen svg {
  overflow: visible;
  position: absolute;
  left: -20px;
  top: -140px;
  width: 160px;
  height: 170px;
}

.stamp {
  position: absolute;
  left: 0;
  top: 0;
  width: 88px;
  height: 88px;
  z-index: 20;
  cursor: pointer;
  touch-action: none;
  filter: drop-shadow(0 5px 5px rgba(12, 6, 1, 0.42));
  transition: filter 0.22s ease;
  will-change: transform;
}

.stamp:hover {
  filter: drop-shadow(0 8px 8px rgba(12, 6, 1, 0.48));
}

.stamp.lifted {
  filter: drop-shadow(0 18px 15px rgba(12, 6, 1, 0.45));
  cursor: none;
  pointer-events: none;
}

.stamp.returning {
  pointer-events: none;
  transition: transform 0.34s cubic-bezier(0.3, 1.4, 0.5, 1), filter 0.22s ease;
}

.stamp.pressing svg {
  transform: scale(0.86);
}

.stamp svg {
  width: 100%;
  height: 100%;
  transition: transform 0.1s ease;
  transform-origin: 50% 50%;
}

@media (prefers-reduced-motion: reduce) {
  .mote,
  .table::before {
    animation: none;
  }
  .flipper {
    transition-duration: 0.2s;
  }
}
