:root {
  --bg: #08160f;
  --surface: rgba(13, 32, 22, 0.9);
  --surface-strong: #172619;
  --text: #fff7d9;
  --muted: #c2d7a4;
  --gold: #ffd56d;
  --pink: #ff7eb6;
  --green: #78d46d;
  --border: #ead994;
  --shadow: 0 30px 90px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(255, 126, 182, 0.18), transparent 28rem),
    radial-gradient(circle at bottom right, rgba(120, 212, 109, 0.16), transparent 30rem),
    linear-gradient(135deg, #07100b, #0c2115 46%, #10281c);
  font-family: "Trebuchet MS", "Lucida Grande", system-ui, sans-serif;
}

.shell {
  width: min(1200px, calc(100vw - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 0;
}

.game-card {
  border: 3px solid rgba(234, 217, 148, 0.72);
  background: var(--surface);
  box-shadow: var(--shadow);
  image-rendering: pixelated;
}

.game-card {
  border-radius: 22px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  background: linear-gradient(180deg, rgba(18, 42, 28, 0.98), rgba(12, 30, 20, 0.96));
  border-bottom: 3px solid rgba(234, 217, 148, 0.55);
}

.label {
  margin: 0 0 5px;
  color: var(--gold);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 3vw, 2.3rem);
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.45);
}

.progress {
  min-width: 150px;
  padding: 10px 12px;
  display: grid;
  gap: 3px;
  border: 2px solid rgba(234, 217, 148, 0.68);
  border-radius: 14px;
  background: rgba(4, 11, 8, 0.5);
  text-align: right;
  font-weight: 900;
  color: var(--gold);
}

#heartCounter {
  color: var(--pink);
  letter-spacing: 0.08em;
}

.canvas-wrap {
  position: relative;
  background: #05130c;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  image-rendering: pixelated;
  cursor: crosshair;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle, rgba(255, 213, 109, 0.18), rgba(3, 9, 6, 0.7) 65%),
    rgba(3, 9, 6, 0.48);
  text-align: center;
}

.overlay.is-visible {
  display: grid;
}

.panel {
  width: min(520px, 100%);
  padding: clamp(20px, 4vw, 36px);
  border: 4px solid var(--border);
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(33, 60, 33, 0.98), rgba(12, 28, 18, 0.98)),
    var(--surface-strong);
  box-shadow:
    0 0 0 5px rgba(0, 0, 0, 0.32),
    0 24px 70px rgba(0, 0, 0, 0.5);
}

.panel h2 {
  margin-bottom: 12px;
  font-size: clamp(1.6rem, 4vw, 3rem);
  line-height: 1;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5);
}

.panel p {
  color: var(--muted);
  line-height: 1.55;
}

.hint {
  margin-bottom: 0;
  font-size: 0.9rem;
}

button {
  border: 0;
  border-radius: 14px;
  padding: 12px 18px;
  color: #211108;
  background: linear-gradient(180deg, #ffe8a1, #ffb84d);
  box-shadow:
    inset 0 -4px rgba(117, 67, 12, 0.25),
    0 8px 0 rgba(0, 0, 0, 0.22);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
}

button:active {
  transform: translateY(4px);
  box-shadow:
    inset 0 -2px rgba(117, 67, 12, 0.25),
    0 4px 0 rgba(0, 0, 0, 0.22);
}

.clue-panel {
  border-color: #ffe384;
  animation: pop 260ms ease-out;
  overflow: hidden;
}

.note-opening {
  height: 112px;
  display: grid;
  place-items: center;
  perspective: 700px;
}

.note-sheet {
  position: relative;
  width: 104px;
  height: 78px;
  display: grid;
  place-items: center;
  border: 4px solid #7c431b;
  border-radius: 8px;
  color: #d94772;
  background:
    repeating-linear-gradient(0deg, transparent 0 12px, rgba(153, 91, 40, 0.16) 13px 15px),
    #fff0b3;
  box-shadow:
    inset 0 0 0 4px rgba(255, 255, 255, 0.35),
    0 10px 0 rgba(0, 0, 0, 0.22);
  transform-origin: 50% 100%;
}

.note-sheet::after {
  content: "";
  position: absolute;
  inset: 0;
  border-bottom: 4px solid #7c431b;
  background: #f1c36f;
  clip-path: polygon(0 0, 100% 0, 50% 72%);
  transform-origin: 50% 0;
}

.note-sheet span {
  position: relative;
  z-index: 1;
  font-size: 2.2rem;
  text-shadow: 2px 2px 0 #fff7d9;
}

.clue-panel.is-opening .note-sheet {
  animation: note-unfold 720ms cubic-bezier(0.18, 0.8, 0.2, 1) both;
}

.clue-panel.is-opening .note-sheet::after {
  animation: note-flap 620ms 110ms cubic-bezier(0.18, 0.8, 0.2, 1) both;
}

.clue-panel.is-opening .note-sheet span {
  animation: heart-reveal 420ms 420ms ease-out both;
}

.clue-panel.is-opening .clue-copy {
  animation: clue-copy-reveal 480ms 430ms ease-out both;
}

.victory {
  padding: 0;
  background: #050b06;
  overflow: hidden;
}

.victory img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
}

.victory::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    180deg,
    rgba(4, 10, 5, 0.55),
    rgba(4, 10, 5, 0.06) 36%,
    rgba(4, 10, 5, 0.2)
  );
}

.victory-copy {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 1;
  width: min(390px, calc(100% - 36px));
  padding: 14px 18px 16px;
  border: 3px solid rgba(255, 232, 161, 0.72);
  border-radius: 20px;
  background: rgba(8, 18, 10, 0.68);
  backdrop-filter: blur(3px);
  text-align: left;
}

.victory-copy h2 {
  margin-bottom: 6px;
  font-size: clamp(1.25rem, 2.3vw, 2rem);
  line-height: 1;
}

.victory-copy p {
  margin-bottom: 12px;
  font-size: 0.9rem;
  line-height: 1.35;
}

.controls {
  display: none;
  justify-items: center;
  gap: 8px;
  padding: 14px;
  background: rgba(5, 14, 9, 0.86);
  border-top: 3px solid rgba(234, 217, 148, 0.45);
}

.controls div {
  display: flex;
  gap: 8px;
}

.controls button {
  min-width: 58px;
  min-height: 48px;
  padding: 10px;
}

code {
  color: #ffe8a1;
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 5px;
  border-radius: 6px;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: scale(0.92) translateY(10px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes note-unfold {
  0% {
    opacity: 0;
    transform: translateY(28px) rotateX(78deg) scale(0.72);
  }

  55% {
    opacity: 1;
    transform: translateY(0) rotateX(-8deg) scale(1.06);
  }

  100% {
    opacity: 1;
    transform: translateY(0) rotateX(0) scale(1);
  }
}

@keyframes note-flap {
  from {
    transform: rotateX(0);
  }

  to {
    transform: rotateX(155deg);
  }
}

@keyframes heart-reveal {
  from {
    opacity: 0;
    transform: scale(0.4);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes clue-copy-reveal {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 720px), (pointer: coarse) {
  .shell {
    width: min(100vw - 16px, 1200px);
    padding: 8px 0;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .progress {
    width: 100%;
    text-align: left;
  }

  #startScreen {
    position: fixed;
    z-index: 20;
    padding: 16px;
  }

  #startScreen .panel {
    width: min(520px, 100%);
    max-height: calc(100dvh - 32px);
    padding: 18px;
    overflow-y: auto;
  }

  #clueModal {
    position: fixed;
    z-index: 20;
    padding: 16px;
  }

  #clueModal .clue-panel {
    width: min(520px, 100%);
    max-height: calc(100dvh - 32px);
    padding: 18px;
    overflow-y: auto;
  }

  #clueModal .note-opening {
    height: 96px;
  }

  #clueModal .clue-panel h2 {
    font-size: clamp(1.45rem, 7vw, 2rem);
    line-height: 1.08;
  }

  #winScreen {
    position: fixed;
    inset: 0;
    z-index: 30;
    padding:
      max(12px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
    overflow-y: auto;
    background:
      radial-gradient(circle at top, rgba(255, 213, 109, 0.16), transparent 45%),
      #07140d;
  }

  #winScreen.is-visible {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
  }

  #winScreen::after {
    display: none;
  }

  #winScreen img {
    position: relative;
    inset: auto;
    width: min(100%, 720px);
    height: auto;
    max-height: 52dvh;
    flex: 0 1 auto;
    object-fit: contain;
    border: 3px solid rgba(255, 232, 161, 0.72);
    border-radius: 18px;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
  }

  #winScreen .victory-copy {
    position: relative;
    top: auto;
    right: auto;
    width: min(100%, 520px);
    padding: 14px 16px;
    flex: 0 0 auto;
    text-align: center;
  }

  #winScreen .victory-copy h2 {
    margin-bottom: 6px;
    font-size: clamp(1.3rem, 6vw, 1.7rem);
    line-height: 1.05;
  }

  #winScreen .victory-copy p {
    margin-bottom: 10px;
    font-size: 0.9rem;
    line-height: 1.3;
  }

  #winScreen .victory-copy button {
    padding: 10px 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .clue-panel,
  .clue-panel.is-opening .note-sheet,
  .clue-panel.is-opening .note-sheet::after,
  .clue-panel.is-opening .note-sheet span,
  .clue-panel.is-opening .clue-copy {
    animation-duration: 1ms;
    animation-delay: 0ms;
  }
}
