:root {
  color-scheme: dark;
  --ink: #102542;
  --ink-soft: #243b59;
  --cream: #fff3d7;
  --cream-2: #f8e6bd;
  --turquoise: #45c3c8;
  --turquoise-dark: #249aa4;
  --yellow: #ffd56a;
  --coral: #ef7f73;
  --white: #fffdf7;
  --shadow: rgba(16, 37, 66, 0.28);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 10%, #27486f 0, #12243f 45%, #081425 100%);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  user-select: none;
  overscroll-behavior: none;
}

button,
a,
input {
  font: inherit;
}

button,
a {
  touch-action: manipulation;
}

.page-wrap {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.game-shell {
  position: relative;
  width: min(100vw, calc(100svh * 0.6), 480px);
  height: min(100svh, calc(100vw * 1.6666667), 800px);
  overflow: hidden;
  background: #9edfea;
  border-radius: 24px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  isolation: isolate;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.screen {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(180deg, rgba(16, 37, 66, 0.12), rgba(16, 37, 66, 0.34));
  backdrop-filter: blur(3px);
}

.screen--loading {
  background: linear-gradient(180deg, #95dce8, #ffe0aa 70%, #f2a888);
  text-align: center;
}

.screen--loading h1,
.menu-panel h1 {
  margin: 6px 0;
  color: var(--cream);
  font-size: clamp(42px, 11vw, 66px);
  line-height: 0.9;
  letter-spacing: -3px;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 7px 0 var(--turquoise-dark), 0 12px 20px var(--shadow);
}

.screen--loading p {
  margin: 14px 0 18px;
  color: var(--ink);
  font-weight: 800;
}

.logo-badge {
  width: 86px;
  height: 86px;
  display: grid;
  place-items: center;
  border: 4px solid var(--ink);
  border-radius: 28px;
  background: var(--cream);
  font-size: 46px;
  box-shadow: 0 8px 0 var(--ink-soft), 0 15px 30px var(--shadow);
  transform: rotate(-5deg);
}

.loading-track {
  width: min(290px, 80vw);
  height: 20px;
  padding: 3px;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--cream);
  box-shadow: 0 5px 0 var(--ink-soft);
}

.loading-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: repeating-linear-gradient(135deg, var(--turquoise) 0 16px, var(--yellow) 16px 32px);
  transition: width 0.12s linear;
}

#loadingPercent {
  display: block;
  margin-top: 11px;
  color: var(--ink);
}

.menu-panel,
.dialog-panel {
  width: min(100%, 390px);
  max-height: calc(100% - 24px);
  overflow: auto;
  padding: 28px 24px 24px;
  text-align: center;
  border: 4px solid var(--ink);
  border-radius: 30px;
  background: rgba(255, 243, 215, 0.96);
  box-shadow: 0 9px 0 var(--ink-soft), 0 22px 45px var(--shadow);
}

.menu-panel {
  background:
    radial-gradient(circle at 84% 8%, rgba(255, 213, 106, 0.65) 0 44px, transparent 45px),
    rgba(255, 243, 215, 0.96);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--turquoise-dark);
  font-size: 12px;
  font-weight: 1000;
  letter-spacing: 2px;
}

.subtitle {
  margin: 15px 0 18px;
  color: var(--ink-soft);
  font-weight: 800;
}

.character-card {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 18px;
  padding: 12px 14px;
  text-align: left;
  border: 3px solid var(--ink);
  border-radius: 20px;
  background: var(--white);
  box-shadow: 0 5px 0 var(--cream-2);
}

.character-preview {
  position: relative;
  flex: 0 0 70px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 24px 24px 20px 20px;
  background: var(--coral);
}

.cat-ear {
  position: absolute;
  z-index: -1;
  top: -14px;
  width: 25px;
  height: 28px;
  border: 3px solid var(--ink);
  background: var(--coral);
  transform: rotate(45deg);
}

.cat-ear--left { left: 7px; }
.cat-ear--right { right: 7px; }

.cat-face {
  color: var(--ink);
  font-size: 22px;
  font-weight: 1000;
}

.character-label {
  display: block;
  color: var(--turquoise-dark);
  font-size: 10px;
  font-weight: 1000;
  letter-spacing: 1.1px;
}

.character-card strong {
  font-size: 23px;
}

.primary-button,
.secondary-button,
.text-link {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 11px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  color: var(--ink);
  font-weight: 1000;
  letter-spacing: 0.4px;
  text-decoration: none;
  cursor: pointer;
}

.primary-button {
  background: var(--turquoise);
  box-shadow: 0 6px 0 var(--turquoise-dark);
}

.secondary-button {
  background: var(--yellow);
  box-shadow: 0 6px 0 #d9a93c;
}

.text-link {
  min-height: 40px;
  border-color: transparent;
  background: transparent;
  color: var(--ink-soft);
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 var(--ink-soft);
}

.menu-best {
  margin-top: 18px;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 800;
}

.controls-hint {
  margin: 9px 0 0;
  color: #52657c;
  font-size: 11px;
  font-weight: 700;
}

.dialog-panel h2 {
  margin: 4px 0 20px;
  font-size: 32px;
}

.range-row {
  display: flex;
  justify-content: space-between;
  margin-top: 18px;
  color: var(--ink);
  font-weight: 900;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--turquoise-dark);
}

.hud {
  position: absolute;
  z-index: 10;
  top: max(12px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.score-chip {
  min-width: 92px;
  padding: 7px 12px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: rgba(255, 243, 215, 0.9);
  box-shadow: 0 4px 0 rgba(16, 37, 66, 0.42);
}

.score-chip span {
  display: block;
  color: var(--turquoise-dark);
  font-size: 9px;
  font-weight: 1000;
  letter-spacing: 1px;
}

.score-chip strong {
  font-size: 20px;
}

.score-chip--best {
  min-width: 86px;
}

.icon-button {
  width: 48px;
  height: 48px;
  margin-left: auto;
  border: 3px solid var(--ink);
  border-radius: 15px;
  background: var(--yellow);
  color: var(--ink);
  font-size: 19px;
  font-weight: 1000;
  box-shadow: 0 4px 0 rgba(16, 37, 66, 0.42);
  cursor: pointer;
  pointer-events: auto;
}

.touch-controls {
  position: absolute;
  z-index: 8;
  inset: 0;
  display: flex;
  pointer-events: none;
}

.touch-zone {
  position: relative;
  width: 50%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: rgba(255, 255, 255, 0.56);
  font-size: 74px;
  font-weight: 300;
  pointer-events: auto;
  touch-action: none;
}

.touch-zone span {
  position: absolute;
  bottom: max(26px, env(safe-area-inset-bottom));
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border: 3px solid rgba(255, 255, 255, 0.33);
  border-radius: 50%;
  background: rgba(16, 37, 66, 0.14);
  line-height: 0.75;
}

.touch-zone--left span { left: 22px; }
.touch-zone--right span { right: 22px; }

.touch-zone.is-active span {
  background: rgba(69, 195, 200, 0.38);
  transform: scale(0.92);
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 10px;
}

.results-grid > div {
  padding: 12px;
  border: 3px solid var(--ink);
  border-radius: 17px;
  background: var(--white);
}

.results-grid span {
  display: block;
  color: var(--turquoise-dark);
  font-size: 10px;
  font-weight: 1000;
}

.results-grid strong {
  font-size: 28px;
}

.fall-icon {
  font-size: 48px;
  animation: wobble 1.4s ease-in-out infinite;
}

.new-record {
  margin: 10px 0;
  color: #c56a12;
  font-weight: 1000;
}

.is-hidden {
  display: none !important;
}

@keyframes wobble {
  0%, 100% { transform: rotate(-8deg) translateY(0); }
  50% { transform: rotate(8deg) translateY(-5px); }
}

@media (max-width: 520px), (pointer: coarse) {
  .game-shell {
    border-radius: 0;
    box-shadow: none;
  }

  .touch-controls:not(.is-hidden) {
    display: flex;
  }
}

@media (min-width: 521px) and (pointer: fine) {
  .touch-controls {
    display: none !important;
  }
}

@media (max-height: 680px) {
  .menu-panel,
  .dialog-panel {
    padding: 20px;
  }

  .menu-panel h1 {
    font-size: 46px;
  }

  .character-card {
    margin-bottom: 10px;
  }

  .controls-hint {
    display: none;
  }
}
