:root {
  --ink: #2E4057;
  --cream: #F2E4CE;
  --pine: #3F5C3D;
  --sage: #6E8F5A;
  --terracotta: #D9704A;
  --ochre: #E0A94C;
  --medalW: 160px;
  --medalH: 94px;
  --medalFont: 44px;
  --scoreTop: 22px;
  --ctrlTop: 20px;
  --ctrlRight: 22px;
  --ctrlGap: 8px;
  --tile: 52px;
  --cardW: 700px;
  --cardFont: 22px;
  --bigNum: 100px;
  --pauseTitle: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #F2E4CE;
  color: #2E4057;
  font-family: "Jost", "Trebuchet MS", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { position: fixed; inset: 0; }

#game, #ui { touch-action: manipulation; }

#game {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: #F2E4CE url("assets/sky_backdrop.webp") center / cover no-repeat;
}
#game canvas { display: block; }

#grain {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background-image: url("assets/grain.png");
  background-repeat: repeat;
  background-size: 256px 256px;
  opacity: 0.62;
  mix-blend-mode: multiply;
}

#ui {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

/* Painted score medallion */
#scoreWrap {
  position: absolute;
  left: 50%;
  top: var(--scoreTop);
  width: var(--medalW);
  height: var(--medalH);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#scoreWrap img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
}
#score {
  position: relative;
  display: block;
  font-family: "Jost", "Trebuchet MS", sans-serif;
  font-weight: 600;
  font-size: var(--medalFont);
  line-height: 1;
  letter-spacing: -0.01em;
  color: #2E4057;
  transform: translateY(0.015em);
}

/* Painted paper button tiles */
#controls {
  position: absolute;
  top: var(--ctrlTop);
  right: var(--ctrlRight);
  display: flex;
  gap: var(--ctrlGap);
  pointer-events: auto;
}
.tile {
  width: var(--tile);
  height: var(--tile);
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 160ms ease, transform 120ms ease;
  border-radius: 10px;
  -webkit-tap-highlight-color: transparent;
}
.tile img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.tile:hover,
.tile:focus-visible { opacity: 1; }
.tile:focus-visible { outline: 2px solid rgba(46, 64, 87, 0.55); outline-offset: 2px; }
.tile:active { transform: translateY(1px) scale(0.97); }

@media (hover: none) {
  .tile { opacity: 0.86; }
}

@media (max-width: 560px) {
  #controls { top: calc(var(--scoreTop) + var(--medalH) * 0.86); }
  .cardBody { line-height: 1.28; }
}

/* Tap hint beside the bird */
#hint {
  position: absolute;
  left: 0;
  top: 0;
  width: 90px;
  height: auto;
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
  will-change: transform, opacity;
}
#hint img { display: block; width: 100%; height: auto; }
#hint.show {
  opacity: 0.92;
  animation: hintRise 2.4s ease-in-out infinite;
}
@keyframes hintRise {
  0%, 100% { transform: translateY(0); opacity: 0.9; }
  50% { transform: translateY(-9px); opacity: 0.45; }
}

/* Torn paper card */
#cardWrap {
  position: absolute;
  left: 50%;
  top: 46%;
  width: 100%;
  height: 100%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 260ms ease;
}
#cardWrap.show { opacity: 1; }
#cardInner {
  position: relative;
  width: var(--cardW);
  transform: translateY(12px) rotate(-2.2deg);
  transition: transform 420ms cubic-bezier(0.18, 0.76, 0.28, 1);
  will-change: transform;
}
#cardWrap.show #cardInner { transform: translateY(0) rotate(-2.2deg); }
#cardImg {
  display: block;
  width: 100%;
  height: auto;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}
#cardContent {
  position: absolute;
  left: 7.5%;
  right: 7.5%;
  top: 9.5%;
  bottom: 9.5%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
#cardWrap.show #cardContent { pointer-events: auto; }

#cardTitle {
  display: block;
  width: 100%;
  height: auto;
  margin: 0 auto 1.2%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}
#cardTitle.hidden { display: none; }

.cardBody {
  width: 100%;
  color: #2E4057;
  font-family: "Jost", "Trebuchet MS", sans-serif;
  font-weight: 400;
  font-size: var(--cardFont);
  line-height: 1.32;
}
.cardBody.hidden { display: none; }
.cardBody p { margin: 0.28em 0; }
.cardBody .lead { font-weight: 500; font-size: 1.06em; }
.cardBody .sub {
  font-size: 0.78em;
  opacity: 0.82;
  margin-top: 0.55em;
}

/* End of run card */
.endLabel {
  font-size: 0.78em;
  letter-spacing: 0.05em;
  margin-top: 0.1em;
  opacity: 0.82;
}
.bigNum {
  font-family: "Jost", "Trebuchet MS", sans-serif;
  font-weight: 600;
  font-size: var(--bigNum);
  line-height: 0.98;
  margin: 0.04em 0 0.02em;
  color: #2E4057;
}
.bestLine {
  font-size: 0.86em;
  opacity: 0.9;
  margin: 0.08em 0 0.2em;
}
.bestLine span { font-weight: 600; }

/* Pause card */
.pauseGlyph {
  display: block;
  width: 16%;
  height: auto;
  margin: 0 auto 0.15em;
  opacity: 0.92;
  pointer-events: none;
}
.pauseTitle {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 700;
  font-size: var(--pauseTitle);
  line-height: 1;
  margin: 0.05em 0 0.18em;
  color: #2E4057;
}

/* Hand placed card buttons */
.cardBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.42em;
  margin: 0.34em 0 0;
  padding: 0.3em 0.62em;
  min-height: 44px;
  min-width: 44px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #2E4057;
  font-family: "Jost", "Trebuchet MS", sans-serif;
  font-weight: 500;
  font-size: 1em;
  line-height: 1.1;
  cursor: pointer;
  box-shadow: inset 0 -2px 0 rgba(46, 64, 87, 0.42);
  transition: background 140ms ease, box-shadow 140ms ease;
  -webkit-tap-highlight-color: transparent;
}
.cardBtn img {
  display: block;
  width: 1.9em;
  height: 1.9em;
  pointer-events: none;
}
.cardBtn:hover,
.cardBtn:focus-visible {
  background: rgba(46, 64, 87, 0.06);
  box-shadow: inset 0 -2px 0 rgba(46, 64, 87, 0.8);
}
.cardBtn:focus-visible { outline: 2px solid rgba(46, 64, 87, 0.5); outline-offset: 3px; }
.cardBtn:active { transform: translateY(1px); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  #hint.show { animation: none; opacity: 0.85; }
  #cardInner, #cardWrap, .tile, .cardBtn { transition-duration: 1ms; }
}
