:root {
  --bg-top: #1f3f57;
  --bg-bottom: #315c77;
  --panel: rgba(22, 45, 60, 0.72);
  --panel-border: #5d89a0;
  --ink: #e7f3f9;
  --muted: #c4dbe7;
  --accent: #94d877;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "Lucida Console", "Consolas", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 10%, rgba(118, 199, 138, 0.2), transparent 42%),
    radial-gradient(circle at 85% 0%, rgba(136, 191, 231, 0.24), transparent 34%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  overflow-x: hidden;
}

body {
  overscroll-behavior-y: contain;
}

#gameShell {
  max-width: 1040px;
  margin: 0 auto;
  padding: 18px 16px 20px;
  display: grid;
  gap: 12px;
  position: relative;
}

#hud {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 8px;
}

.hud-card {
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(39, 74, 95, 0.86), rgba(28, 56, 72, 0.86));
  border: 1px solid var(--panel-border);
  border-radius: 11px;
  padding: 8px 10px;
  font-weight: 700;
  display: grid;
  grid-template-columns: 16px 1fr auto;
  align-items: center;
  column-gap: 6px;
  color: #e7f3fa;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 8px 14px rgba(0, 0, 0, 0.18);
  letter-spacing: 0.2px;
  text-transform: uppercase;
  font-size: 12px;
  animation: hudFloat 4.8s ease-in-out infinite;
}

.hud-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.08), transparent 38%);
  pointer-events: none;
}

.hud-card::after {
  content: "";
  position: absolute;
  left: -30%;
  top: 0;
  width: 36%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.16), transparent);
  transform: skewX(-20deg);
  opacity: 0.45;
  animation: hudSweep 6.5s linear infinite;
}

.hud-card:nth-child(2) { animation-delay: 0.4s; }
.hud-card:nth-child(3) { animation-delay: 0.8s; }
.hud-card:nth-child(4) { animation-delay: 1.2s; }
.hud-card:nth-child(5) { animation-delay: 1.6s; }
.hud-card:nth-child(6) { animation-delay: 2s; }
.hud-card:nth-child(7) { animation-delay: 2.4s; }
.hud-card:nth-child(8) { animation-delay: 2.8s; }

.hud-label {
  color: #cce3ee;
}

.hud-icon {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  display: inline-block;
  border: 1px solid rgba(0, 0, 0, 0.25);
}

.hud-icon.score {
  background: linear-gradient(180deg, #ffd45f, #d89c2a);
}

.hud-icon.coin {
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff6c8, #f2bb2f 65%);
}

.hud-icon.life {
  background: linear-gradient(180deg, #ff8a7c, #d95a4f);
}

.hud-icon.time {
  background: linear-gradient(180deg, #9fe9ff, #5fb8d2);
}

.hud-icon.best {
  background: linear-gradient(180deg, #c4ff9e, #75c45f);
}

#muteBtn {
  position: static;
  justify-self: start;
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 12px;
}

#gameCanvas {
  width: 100%;
  height: auto;
  border: 2px solid #5e9abb;
  border-radius: 14px;
  background: linear-gradient(180deg, #84d2ff, #4da3cd 72%);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.28);
}

body.menu-open #gameCanvas,
body.final-open #gameCanvas {
  filter: saturate(0.82) blur(1px);
}

#controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

button {
  border: 1px solid #5b8ca5;
  background: linear-gradient(180deg, #4f84a0, #3f6f87);
  color: #e3eef2;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  letter-spacing: 0.2px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 4px 12px rgba(0, 0, 0, 0.2);
}

button:hover {
  background: linear-gradient(180deg, #5d94b0, #4a7b94);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 10px 18px rgba(0, 0, 0, 0.22);
  transform: translateY(-1px);
}

button:active {
  transform: translateY(1px);
}

#status {
  margin: 0;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-left: 4px solid var(--accent);
  border-radius: 9px;
  padding: 9px 11px;
  color: var(--muted);
  font-weight: 700;
}

#visualPanel {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(26, 50, 66, 0.78);
  font-size: 12px;
  font-weight: 700;
}

#visualPanel label {
  color: var(--muted);
}

#visualModeSelect {
  border: 1px solid #5b8ca5;
  background: #355f76;
  color: #e3eef2;
  border-radius: 7px;
  padding: 4px 6px;
  font-weight: 700;
}

#dinoScaleRange {
  width: 120px;
}

#dinoScaleValue {
  min-width: 42px;
  color: #dff3ff;
}

#touchPad {
  display: none;
  grid-template-columns: repeat(4, minmax(0, 74px));
  justify-content: center;
  gap: 8px;
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(calc(100vw - 20px), 360px);
  padding: 10px;
  border-radius: 18px;
  border: 1px solid rgba(123, 168, 196, 0.32);
  background: linear-gradient(180deg, rgba(8, 21, 33, 0.82), rgba(7, 18, 28, 0.92));
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(10px);
  z-index: 18;
  pointer-events: none;
}

#touchPad button {
  min-height: 58px;
  pointer-events: auto;
  display: grid;
  place-items: center;
  gap: 3px;
  padding: 8px 6px 9px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  font-size: 22px;
  font-weight: 900;
  border-radius: 14px;
}

.touch-icon,
.touch-text {
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-icon {
  font-size: 21px;
  line-height: 1;
}

.touch-text {
  font-size: 11px;
  line-height: 1;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: #d9edf8;
  opacity: 0.92;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 22;
  display: grid;
  place-items: center;
  background: rgba(6, 17, 27, 0.64);
  padding: 16px;
  overflow: hidden;
}

.overlay::before {
  content: "";
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(circle at 20% 25%, rgba(146, 216, 255, 0.12), transparent 24%),
    radial-gradient(circle at 76% 18%, rgba(153, 232, 137, 0.12), transparent 28%),
    radial-gradient(circle at 50% 72%, rgba(255, 223, 138, 0.1), transparent 26%);
  animation: overlayDrift 12s linear infinite;
  pointer-events: none;
}

.overlay-card {
  position: relative;
  overflow: hidden;
  width: min(560px, 100%);
  border-radius: 16px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(180deg, rgba(22, 45, 60, 0.94), rgba(15, 35, 47, 0.94));
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.34);
  padding: 20px 18px;
  text-align: center;
  animation: cardRise 0.55s ease, cardFloat 5.8s ease-in-out infinite;
}

.overlay-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.06), transparent 42%);
  pointer-events: none;
}

.menu-card {
  background:
    radial-gradient(circle at 14% 18%, rgba(149, 233, 176, 0.12), transparent 32%),
    linear-gradient(180deg, rgba(22, 45, 60, 0.96), rgba(15, 35, 47, 0.96));
}

.final-card {
  background:
    radial-gradient(circle at 82% 14%, rgba(255, 224, 149, 0.14), transparent 28%),
    linear-gradient(180deg, rgba(24, 47, 62, 0.97), rgba(15, 35, 47, 0.97));
}

.overlay-card h1,
.overlay-card h2 {
  margin: 0 0 10px;
  letter-spacing: 0.3px;
  text-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
}

.overlay-kicker {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  font-size: 11px;
  color: #bfe7ff;
}

.overlay-subtitle {
  margin: 0 0 14px;
  color: #cde1ec;
  font-size: 13px;
}

.menu-card {
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 210, 109, 0.12), transparent 24%),
    radial-gradient(circle at 80% 12%, rgba(143, 224, 255, 0.12), transparent 22%),
    linear-gradient(180deg, rgba(20, 44, 60, 0.96), rgba(9, 23, 34, 0.98));
}

.menu-emblem {
  width: 64px;
  height: 64px;
  position: absolute;
  right: 18px;
  top: 18px;
  border-radius: 20px;
  border: 1px solid rgba(147, 216, 255, 0.32);
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 213, 112, 0.36), transparent 28%),
    linear-gradient(180deg, rgba(29, 60, 82, 0.88), rgba(15, 31, 46, 0.94));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 14px 24px rgba(0, 0, 0, 0.2);
}

.menu-emblem span {
  position: absolute;
  display: block;
  border-radius: 999px;
}

.menu-emblem span:nth-child(1) {
  inset: 18px;
  border: 3px solid rgba(153, 230, 255, 0.88);
}

.menu-emblem span:nth-child(2) {
  left: 22px;
  right: 22px;
  top: 40px;
  height: 6px;
  background: linear-gradient(90deg, #ffd46f, #9fe5ff);
}

.menu-emblem span:nth-child(3) {
  width: 14px;
  height: 14px;
  left: 25px;
  top: 18px;
  background: #c9ff8d;
  box-shadow: 0 0 0 5px rgba(201, 255, 141, 0.14);
}

.menu-kicker {
  margin: 0 0 8px;
  color: #ffd67a;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1.8px;
  text-transform: uppercase;
}

.menu-subtitle {
  max-width: 42ch;
  margin: 0 auto 12px;
  color: #d7e8f5;
  line-height: 1.55;
}

.menu-badge-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 14px;
}

.menu-badge,
.menu-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 800;
}

.menu-badge {
  color: #fff0c1;
  border: 1px solid rgba(255, 218, 130, 0.38);
  background: linear-gradient(180deg, rgba(135, 95, 34, 0.84), rgba(101, 66, 23, 0.92));
}

.menu-chip {
  color: #d8efff;
  border: 1px solid rgba(139, 205, 235, 0.32);
  background: linear-gradient(180deg, rgba(46, 79, 108, 0.8), rgba(25, 48, 67, 0.92));
}

.menu-thanks {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(138, 189, 224, 0.24);
  background: rgba(18, 38, 53, 0.58);
  color: #cfe5f3;
  line-height: 1.5;
}

.menu-actions button:first-child,
#startBtn {
  background: linear-gradient(180deg, #69a65e, #4b7f44);
  border-color: rgba(193, 242, 176, 0.4);
}

.menu-actions button:first-child:hover,
#startBtn:hover {
  background: linear-gradient(180deg, #75b16a, #568f4e);
}

#resetBtn {
  background: linear-gradient(180deg, #926347, #73472f);
  border-color: rgba(240, 198, 144, 0.36);
}

#pauseBtn,
#menuHowBtn {
  background: linear-gradient(180deg, #547f9b, #395d75);
}

#howToText {
  border: 1px solid rgba(140, 195, 221, 0.34);
  border-radius: 12px;
  background: rgba(17, 39, 51, 0.58);
  padding: 10px 12px;
  color: #d1eaf6;
}

.final-card {
  width: min(620px, 100%);
  position: relative;
  border-color: rgba(255, 220, 145, 0.52);
  background:
    radial-gradient(circle at top center, rgba(255, 212, 112, 0.05), transparent 28%),
    radial-gradient(circle at 20% 22%, rgba(160, 233, 255, 0.05), transparent 20%),
    linear-gradient(180deg, rgba(33, 32, 54, 0.97), rgba(12, 17, 31, 0.98));
}

.final-card::before {
  background: linear-gradient(90deg, rgba(255, 223, 129, 0.58), rgba(163, 229, 255, 0.54), rgba(154, 219, 121, 0.48));
}

.final-kicker {
  margin: 0 0 10px;
  color: #ffe2a0;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1.9px;
  text-transform: uppercase;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.42);
}

.final-burst {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.final-burst span {
  position: absolute;
  width: 10px;
  height: 26px;
  border-radius: 999px;
  opacity: 0.28;
  filter: blur(0.8px);
  animation: finalFloat 3.8s ease-in-out infinite;
}

.final-burst span:nth-child(1) { left: 11%; top: 18%; background: #ffd26d; animation-delay: 0s; }
.final-burst span:nth-child(2) { left: 22%; top: 8%; background: #8fe0ff; animation-delay: -0.8s; }
.final-burst span:nth-child(3) { left: 78%; top: 12%; background: #c2ff8f; animation-delay: -1.4s; }
.final-burst span:nth-child(4) { left: 88%; top: 24%; background: #ffd26d; animation-delay: -2.2s; }
.final-burst span:nth-child(5) { left: 14%; top: 48%; background: #9bd8ff; animation-delay: -1.1s; }
.final-burst span:nth-child(6) { left: 84%; top: 56%; background: #fff0b3; animation-delay: -2.8s; }

.final-badge-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 10px;
}

.final-badge,
.final-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.final-badge {
  color: #fff3cf;
  border: 1px solid rgba(255, 220, 135, 0.4);
  background: linear-gradient(180deg, rgba(116, 79, 27, 0.9), rgba(78, 48, 16, 0.94));
}

.final-chip {
  color: #e3f3ff;
  border: 1px solid rgba(142, 208, 235, 0.32);
  background: linear-gradient(180deg, rgba(36, 64, 94, 0.88), rgba(19, 35, 58, 0.94));
}

.final-summary {
  max-width: 44ch;
  margin: 0 auto 16px;
  color: #f1f6fb;
  line-height: 1.55;
  text-shadow: 0 3px 14px rgba(0, 0, 0, 0.48);
}

.final-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0 20px;
}

.final-stat {
  padding: 14px 12px;
  border-radius: 16px;
  border: 1px solid rgba(129, 174, 217, 0.34);
  background: linear-gradient(180deg, rgba(24, 37, 61, 0.84), rgba(12, 18, 31, 0.94));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.final-stat strong {
  display: block;
  margin-top: 6px;
  color: #fff1c2;
  font-size: clamp(26px, 4vw, 34px);
  letter-spacing: 0.4px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.34);
}

.final-stat-label {
  display: block;
  color: #99bfdc;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.final-actions {
  margin-top: 2px;
}

.final-story {
  margin: 0 0 18px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(132, 183, 223, 0.28);
  background: linear-gradient(180deg, rgba(19, 31, 55, 0.88), rgba(10, 17, 30, 0.96));
}

.final-story-label {
  display: block;
  margin-bottom: 6px;
  color: #99c8ee;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.3px;
  text-transform: uppercase;
}

.final-story p {
  margin: 0;
  color: #e6f0f8;
  line-height: 1.5;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.32);
}

.final-actions button:first-child {
  background: linear-gradient(180deg, #d2a24c, #9e6d25);
  border-color: rgba(255, 224, 160, 0.5);
}

.final-actions button:first-child:hover {
  background: linear-gradient(180deg, #ddb15c, #ae7d31);
}

.final-actions button:last-child {
  background: linear-gradient(180deg, #5879a5, #37537a);
}

.menu-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.menu-select {
  display: grid;
  gap: 7px;
  justify-items: center;
  margin-bottom: 10px;
}

#difficultySelect {
  border: 1px solid #5b8ca5;
  background: #355f76;
  color: #e3eef2;
  border-radius: 7px;
  padding: 6px 10px;
  font-weight: 700;
  min-width: 130px;
}

.level-buttons {
  display: flex;
  gap: 8px;
}

.level-buttons button {
  min-width: 52px;
}

.overlay-card p {
  margin: 6px 0;
}

.achievement-panel {
  margin-top: 10px;
  border: 1px solid rgba(116, 163, 188, 0.45);
  border-radius: 10px;
  background: rgba(17, 37, 49, 0.58);
  padding: 10px;
  text-align: left;
}

.achievement-panel h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: #d6effc;
}

#achievementList {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 6px;
}

#achievementList li {
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 12px;
  border: 1px solid rgba(93, 138, 160, 0.4);
  background: rgba(29, 57, 74, 0.52);
  color: #cde6f2;
}

#achievementList li.done {
  border-color: rgba(139, 214, 150, 0.56);
  background: rgba(48, 85, 64, 0.54);
  color: #dff7e2;
}

.achievement-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: #b7d7e9;
  min-height: 16px;
}

.overlay-card small {
  display: block;
  margin-top: 12px;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

@keyframes hudFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

@keyframes hudSweep {
  0% { transform: translateX(-140%) skewX(-20deg); }
  100% { transform: translateX(360%) skewX(-20deg); }
}

@keyframes overlayDrift {
  0% { transform: translate3d(-1%, 0, 0) scale(1); }
  50% { transform: translate3d(1%, 1.5%, 0) scale(1.03); }
  100% { transform: translate3d(-1%, 0, 0) scale(1); }
}

@keyframes cardRise {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes cardFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

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

@media (max-width: 920px) {
  #hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #touchPad {
    display: grid;
  }

  body.touch-device #gameShell {
    padding-bottom: calc(126px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 680px) {
  body.touch-device #hud {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  body.touch-device .hud-card {
    grid-template-columns: 11px auto;
    justify-content: space-between;
    padding: 7px 8px;
    font-size: 11px;
    min-height: 34px;
  }

  body.touch-device .hud-label {
    display: none;
  }

  body.touch-device #muteBtn {
    justify-self: end;
    font-size: 11px;
    padding: 6px 9px;
  }

  #gameShell {
    padding: 12px 10px 18px;
    gap: 10px;
  }

  .overlay {
    padding: 10px;
  }

  .overlay-card {
    width: 100%;
    padding: 18px 14px 16px;
    border-radius: 16px;
  }

  .menu-emblem {
    width: 52px;
    height: 52px;
    right: 12px;
    top: 12px;
  }

  .menu-actions {
    gap: 8px;
  }

  .menu-actions button,
  .final-actions button {
    width: 100%;
  }

  .final-stats {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  #status {
    font-size: 12px;
    line-height: 1.35;
  }

  .final-stat strong {
    font-size: 28px;
  }

  #touchPad {
    width: min(calc(100vw - 16px), 340px);
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
    padding: 9px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  #touchPad button {
    min-height: 54px;
  }

  .touch-icon {
    font-size: 18px;
  }

  .touch-text {
    font-size: 10px;
  }
}

@media (max-width: 520px) {
  #gameShell {
    padding: 10px 8px 16px;
    gap: 8px;
  }

  #hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  body.touch-device #hud {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .hud-card {
    padding: 7px 8px;
    font-size: 11px;
  }

  #muteBtn {
    font-size: 11px;
    padding: 6px 9px;
  }

  #status {
    padding: 8px 9px;
    font-size: 11px;
  }

  #touchPad {
    width: calc(100vw - 12px);
    gap: 6px;
    padding: 8px;
  }

  #touchPad button {
    min-height: 50px;
    border-radius: 12px;
  }
}

@media (max-width: 680px) and (orientation: portrait) {
  body.touch-device #gameShell {
    padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px));
  }

  body.touch-device #gameCanvas {
    border-radius: 12px;
  }
}

@media (hover: none) and (pointer: coarse) {
  #touchPad {
    display: grid;
  }
}

body.touch-device #touchPad {
  display: grid;
}
