:root {
  --bg: #4e4c51;
  --ink: #fef6ff;
  --yoink-text: #7bf7d8;
  --panel: rgba(30, 28, 35, 0.92);
  --danger: #ff6b9d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: system-ui, "Segoe UI", sans-serif;
  background: radial-gradient(ellipse 120% 80% at 50% 20%, #5e5e5e 0%, var(--bg) 55%);
  color: var(--ink);
}

body.game-active {
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

body.game-active .landing .yoink-art {
  animation-play-state: paused;
}

#app {
  width: 100%;
  max-width: 52rem;
  padding: 1rem 1.5rem 2rem;
}

.landing {
  text-align: center;
}

.landing.hidden {
  display: none;
}

.landing h1 {
  margin: -1.5rem 0 0.75rem;
  font-family: "Titan One", "Impact", fantasy, sans-serif;
  font-size: clamp(2.5rem, 11vw, 3.75rem);
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--yoink-text);
  line-height: 1.2;
  -webkit-text-stroke: 7px #000000;
  paint-order: stroke fill;
}

.yoink-art {
  width: min(200px, 68vw);
  height: auto;
  margin: 0 auto;
  display: block;
  cursor: pointer;
  filter: drop-shadow(0 12px 28px rgba(0, 0, 0, 0.35));
  animation: yoink-bob 2.2s ease-in-out infinite;
  transform-origin: 50% 60%;
}

@keyframes yoink-bob {
  0%,
  100% {
    transform: translateY(0) rotate(-2deg);
  }
  50% {
    transform: translateY(-10px) rotate(2deg);
  }
}

.btn-play {
  margin-top: 0.5rem;
  padding: 0.65rem 1.75rem;
  font-family: "Titan One", "Impact", fantasy, sans-serif;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--yoink-text);
  border: 3px solid #1a1a1a;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: 4px 4px 0 #1a1a1a;
}

.btn-play:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 #1a1a1a;
}

.btn-play:focus-visible {
  outline: 3px solid var(--yoink-text);
  outline-offset: 4px;
}

.score-history {
  margin: 2.5rem auto 0;
  max-width: 18rem;
  text-align: left;
  background: var(--panel);
  border: 3px solid #1a1a1a;
  border-radius: 12px;
  box-shadow: 4px 4px 0 #1a1a1a;
}

.score-history summary {
  padding: 0.55rem 0.85rem;
  font-family: "Titan One", "Impact", fantasy, sans-serif;
  font-size: 0.95rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--yoink-text);
  cursor: pointer;
  list-style: none;
}

.score-history summary::-webkit-details-marker {
  display: none;
}

.score-history summary::after {
  content: "+";
  float: right;
  font-family: system-ui, sans-serif;
  font-size: 1rem;
  line-height: 1.2;
  opacity: 0.75;
}

.score-history[open] summary::after {
  content: "−";
}

.score-history summary:focus-visible {
  outline: 3px solid var(--yoink-text);
  outline-offset: 2px;
}

.score-history-list {
  margin: 0;
  padding: 0 0.85rem 0.75rem;
  list-style: none;
  border-top: 2px solid rgba(255, 255, 255, 0.08);
}

.score-history-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.45rem 0;
  font-size: 0.9rem;
  line-height: 1.35;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.score-history-list li:last-child {
  border-bottom: none;
}

.score-history-list .score {
  font-family: "Titan One", "Impact", fantasy, sans-serif;
  color: var(--yoink-text);
}

.score-history-list .date {
  font-size: 0.78rem;
  opacity: 0.72;
  white-space: nowrap;
}

.game-screen {
  display: none;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
}

.game-screen.visible {
  display: flex;
}

.game-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.25rem;
  font-family: "Titan One", "Impact", fantasy, sans-serif;
  font-size: 1rem;
  letter-spacing: 0.04em;
  color: var(--yoink-text);
}

.game-hud button {
  font-family: system-ui, sans-serif;
  font-size: 0.8rem;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  border: 2px solid #1a1a1a;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.canvas-wrap {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  border: 4px solid #1a1a1a;
  border-radius: 12px;
  overflow: hidden;
  background: #6b8cae;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

#game {
  display: block;
  width: 100%;
  height: auto;
  touch-action: manipulation;
  cursor: pointer;
}

.hint {
  text-align: center;
  font-size: 0.8rem;
  opacity: 0.75;
  margin: 0.25rem 0 0;
}

.game-over {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  z-index: 20;
  padding: 1rem;
}

.game-over.visible {
  display: flex;
}

.game-over-card {
  max-width: 22rem;
  width: 100%;
  padding: 1.75rem 1.5rem;
  background: var(--panel);
  border: 4px solid #1a1a1a;
  border-radius: 16px;
  text-align: center;
  box-shadow: 8px 8px 0 #1a1a1a;
}

.game-over-summary {
  min-width: 0;
}

.game-over-card h2 {
  margin: 0 0 0.75rem;
  font-family: "Titan One", "Impact", fantasy, sans-serif;
  font-size: clamp(1.75rem, 8vw, 2.25rem);
  font-weight: 400;
  color: var(--danger);
  letter-spacing: 0.06em;
}

.game-over-card .scores {
  margin: 0.75rem 0 1.25rem;
  font-size: 1.05rem;
  line-height: 1.6;
}

.game-over-card .scores strong {
  color: var(--yoink-text);
  font-family: "Titan One", fantasy, sans-serif;
}

.game-over-top-scores {
  margin: 0 0 1.1rem;
  padding: 0.75rem 0.85rem;
  text-align: left;
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
}

.game-over-top-scores-title {
  margin: 0 0 0.55rem;
  font-family: "Titan One", "Impact", fantasy, sans-serif;
  font-size: 0.9rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--yoink-text);
}

.game-over-top-scores-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.game-over-top-scores-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.4rem 0.45rem;
  font-size: 0.92rem;
  line-height: 1.35;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.game-over-top-scores-list li:last-child {
  border-bottom: none;
}

.game-over-top-scores-list .score {
  font-family: "Titan One", "Impact", fantasy, sans-serif;
  color: var(--yoink-text);
}

.game-over-top-scores-list .date {
  font-size: 0.78rem;
  opacity: 0.72;
  white-space: nowrap;
}

.game-over-top-scores-list .score-run-current {
  color: var(--yoink-text);
  background: rgba(123, 247, 216, 0.16);
  border-radius: 8px;
}

.game-over-top-scores-list .score-run-current.best-new {
  animation: best-flash-end-highlight 0.6s ease-in-out 3 forwards;
}

.game-over-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.game-over-actions button {
  padding: 0.55rem 1.1rem;
  font-size: 0.95rem;
  border-radius: 10px;
  border: 3px solid #1a1a1a;
  cursor: pointer;
  font-weight: 600;
}

.game-over-actions .btn-retry {
  background: var(--yoink-text);
  color: var(--bg);
}

.game-over-actions .btn-home {
  background: transparent;
  color: var(--ink);
}

@media (max-height: 520px) and (orientation: landscape) {
  .game-over {
    padding: 0.5rem;
    align-items: center;
  }

  /* Wide two-column layout only when top scores are shown */
  .game-over-card:has(#goTopScores:not([hidden])) {
    max-width: min(44rem, 96vw);
    max-height: calc(100dvh - 1rem);
    padding: 0.9rem 1rem;
    overflow: auto;
    display: grid;
    grid-template-columns: minmax(8.5rem, 1fr) minmax(11rem, 1.35fr);
    grid-template-areas:
      "summary topscores"
      "actions actions";
    column-gap: 0.85rem;
    row-gap: 0.65rem;
  }

  .game-over-card:has(#goTopScores:not([hidden])) .game-over-summary {
    grid-area: summary;
    align-self: center;
  }

  .game-over-card:has(#goTopScores:not([hidden])) h2 {
    /* 
    margin: 0 0 0.35rem;
    font-size: clamp(1.35rem, 5.5vw, 1.85rem);
    */
  }

  .game-over-card:has(#goTopScores:not([hidden])) .scores {
    margin: 0;
   /*font-size: 0.95rem;*/
    line-height: 1.45;
  }

  .game-over-card:has(#goTopScores:not([hidden])) .game-over-top-scores {
    grid-area: topscores;
    margin: 0;
    padding: 0.55rem 0.7rem;
  }

  .game-over-card:has(#goTopScores:not([hidden])) .game-over-top-scores-title {
    margin-bottom: 0.35rem;
    font-size: 0.82rem;
  }

  .game-over-card:has(#goTopScores:not([hidden])) .game-over-top-scores-list li {
    padding: 0.28rem 0.35rem;
    font-size: 0.84rem;
  }

  .game-over-card:has(#goTopScores:not([hidden])) .game-over-top-scores-list .date {
    font-size: 0.72rem;
  }

  .game-over-card:has(#goTopScores:not([hidden])) .game-over-actions {
    grid-area: actions;
    align-self: center;
    justify-content: center;
    margin: 0;
  }

  .game-over-card:has(#goTopScores:not([hidden])) .game-over-actions button {
    padding: 0.45rem 0.85rem;
    font-size: 0.88rem;
  }
}

.best-new {
  animation: best-flash 0.6s ease-in-out 3;
}

@keyframes best-flash {
  0%,
  100% {
    color: var(--yoink-text);
  }
  50% {
    color: #fff;
  }
}

@keyframes best-flash-end-highlight {
  0%,
  100% {
    color: var(--yoink-text);
    background: rgba(123, 247, 216, 0.16);
  }
  50% {
    color: #fff;
    background: rgba(123, 247, 216, 0.34);
  }
}
