:root {
  color-scheme: light;
  --ink: #152c42;
  --muted: #5d7790;
  --accent: #ffcf32;
  --accent-2: #ff8a2a;
  --blue: #1f6e9a;
  --danger: #e85f43;
  --glass-dark: rgba(16, 58, 88, 0.66);
  --panel: rgba(255, 255, 255, 0.93);
  --shadow: 0 22px 70px rgba(29, 76, 109, 0.28);
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #54bdf0;
  font-family: Inter, ui-rounded, "SF Pro Rounded", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  position: fixed;
  inset: 0;
}

button {
  font: inherit;
}

.game-shell {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  min-height: 420px;
  overflow: hidden;
  isolation: isolate;
  touch-action: none;
  user-select: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

.hud {
  position: absolute;
  z-index: 5;
  inset: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) auto max(12px, env(safe-area-inset-left));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.hud__stats,
.hud__actions {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.hud__actions {
  pointer-events: auto;
}

.score-card,
.icon-button {
  border: 2px solid rgba(255, 255, 255, 0.68);
  background: var(--glass-dark);
  color: #fff;
  box-shadow: 0 10px 28px rgba(21, 70, 104, 0.24);
  backdrop-filter: blur(13px);
  -webkit-backdrop-filter: blur(13px);
}

.score-card {
  min-width: 84px;
  padding: 8px 13px 9px;
  border-radius: 18px;
  text-align: center;
  line-height: 1;
  transition: transform 160ms ease, background 160ms ease;
}

.score-card--score {
  min-width: 92px;
}

.score-card--small {
  min-width: 76px;
}

.score-card--flash {
  transform: translateY(-2px) scale(1.06);
  background: rgba(255, 151, 35, 0.86);
}

.score-card__label {
  display: block;
  margin-bottom: 4px;
  font-size: 9px;
  font-weight: 950;
  letter-spacing: 0.16em;
  opacity: 0.82;
}

.score-card strong {
  font-size: clamp(23px, 4vw, 38px);
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
}

.icon-button {
  display: grid;
  width: 48px;
  height: 48px;
  padding: 0;
  place-items: center;
  border-radius: 16px;
  font-size: 21px;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease;
}

.icon-button:hover {
  transform: translateY(-2px);
  background: rgba(20, 67, 96, 0.82);
}

.icon-button:active {
  transform: translateY(1px) scale(0.95);
}

.overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  place-items: center;
  background: radial-gradient(circle at center, rgba(255,255,255,0.10), rgba(18, 63, 92, 0.30));
  opacity: 0;
  visibility: hidden;
  transform: scale(1.018);
  pointer-events: none;
  transition: opacity 220ms ease, visibility 220ms ease, transform 220ms ease;
}

.overlay--visible {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
  pointer-events: auto;
}

.panel {
  width: min(94vw, 530px);
  max-height: calc(100vh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  max-height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow: auto;
  padding: clamp(20px, 4.8vw, 36px);
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: clamp(26px, 5vw, 40px);
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
  text-align: center;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.panel::-webkit-scrollbar {
  width: 0;
}

.version-badge {
  display: inline-flex;
  margin-bottom: 13px;
  padding: 7px 13px;
  border-radius: 999px;
  background: #1f5576;
  color: #fff;
  font-size: 10px;
  font-weight: 950;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.version-badge--danger {
  background: var(--danger);
}

.version-badge--blue {
  background: var(--blue);
}

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

.panel h1 {
  margin-bottom: 12px;
  font-size: clamp(44px, 10vw, 76px);
  line-height: 0.84;
  letter-spacing: -0.075em;
  text-shadow: 0 6px 0 rgba(24, 50, 74, 0.08);
}

.panel h1 span {
  color: var(--accent-2);
}

.panel h2 {
  margin-bottom: 12px;
  font-size: clamp(28px, 6vw, 45px);
  line-height: 1.02;
  letter-spacing: -0.05em;
}

.lead,
.panel p {
  color: var(--muted);
  font-size: clamp(14px, 2.4vw, 17px);
  line-height: 1.45;
}

.lead {
  margin-bottom: 18px;
}

.menu-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 16px;
}

.menu-stats > div,
.result-grid > div {
  padding: 12px 8px;
  border-radius: 18px;
  background: #edf7fb;
  box-shadow: inset 0 0 0 1px rgba(54, 118, 151, 0.08);
}

.menu-stats span,
.result-grid span {
  display: block;
  margin-bottom: 4px;
  color: #6a8598;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.menu-stats strong,
.result-grid strong {
  display: block;
  font-size: clamp(24px, 6vw, 40px);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.button-row:has(.secondary-button:not([hidden])) {
  grid-template-columns: 1fr 0.72fr;
}

.button-row--result {
  grid-template-columns: 1fr 0.72fr;
}

.primary-button,
.secondary-button {
  width: 100%;
  min-height: 58px;
  border: 0;
  border-radius: 18px;
  font-size: 18px;
  font-weight: 950;
  cursor: pointer;
  transition: transform 150ms ease, filter 150ms ease, box-shadow 150ms ease;
}

.primary-button {
  border-bottom: 5px solid #d66b18;
  background: linear-gradient(180deg, #ffdf55, #ff982c);
  color: #50300c;
  box-shadow: 0 13px 28px rgba(238, 128, 22, 0.30);
}

.secondary-button {
  border-bottom: 5px solid #215a7b;
  background: linear-gradient(180deg, #3f9ed0, #257199);
  color: #fff;
  box-shadow: 0 13px 28px rgba(33, 106, 149, 0.25);
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-2px);
  filter: saturate(1.08);
}

.primary-button:active,
.secondary-button:active {
  transform: translateY(3px);
  border-bottom-width: 2px;
}

.how-to-play {
  margin-top: 12px;
  border-radius: 18px;
  background: #f2f8fb;
  color: var(--muted);
  text-align: left;
}

.how-to-play summary {
  padding: 12px 14px;
  color: var(--ink);
  font-weight: 950;
  cursor: pointer;
}

.how-to-play p {
  margin: 0;
  padding: 0 14px 14px;
  font-size: 13px;
}

.leaderboard-card {
  margin-top: 12px;
  padding: 13px;
  border-radius: 22px;
  background: rgba(239, 248, 252, 0.95);
  box-shadow: inset 0 0 0 1px rgba(54, 118, 151, 0.08);
  text-align: left;
}

.leaderboard-card--result {
  margin-bottom: 14px;
}

.leaderboard-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 950;
}

.leaderboard-card__head button {
  border: 0;
  background: transparent;
  color: #7892a6;
  font-size: 12px;
  font-weight: 850;
  cursor: pointer;
}

.leaderboard-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 24px;
  color: var(--ink);
}

.leaderboard-list li {
  padding: 7px 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.72);
  font-size: 13px;
}

.leaderboard-list li.empty {
  list-style: none;
  margin-left: -24px;
  color: #7d95a8;
  text-align: center;
}

.leaderboard-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.leaderboard-line strong {
  font-variant-numeric: tabular-nums;
}

.leaderboard-line small {
  color: #7892a6;
}

.controls-hint {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  margin-top: 14px;
  color: #698398;
  font-size: 12px;
  font-weight: 800;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 12px;
}

.meme-phrase {
  margin: 0 0 17px;
  padding: 13px 14px;
  border-radius: 18px;
  background: #fff6d7;
  color: #654617 !important;
  font-size: clamp(15px, 2.5vw, 18px) !important;
  font-weight: 900;
  line-height: 1.35 !important;
}

.panel .small-note {
  margin: 12px 0 -4px;
  font-size: 12px;
}

.tap-hint {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: max(32px, calc(env(safe-area-inset-bottom) + 22px));
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  box-shadow: 0 12px 30px rgba(33, 78, 109, 0.18);
  font-size: 13px;
  font-weight: 850;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 20px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.tap-hint--visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.tap-hint__icon {
  display: inline-block;
  animation: tap 900ms ease-in-out infinite;
}

.combo-toast {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: max(92px, calc(env(safe-area-inset-top) + 82px));
  min-width: 160px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  box-shadow: 0 12px 30px rgba(33, 78, 109, 0.18);
  font-size: 13px;
  font-weight: 950;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px) scale(0.96);
  transition: opacity 180ms ease, transform 180ms ease;
}

.combo-toast--visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

@keyframes tap {
  50% { transform: translateY(-5px) scale(1.08); }
}

@media (max-width: 720px) {
  .hud {
    align-items: stretch;
  }

  .hud__stats {
    gap: 6px;
  }

  .score-card--small {
    min-width: 63px;
    padding-inline: 9px;
  }

  .score-card--small .score-card__label {
    font-size: 8px;
    letter-spacing: 0.10em;
  }

  .hud__actions {
    gap: 6px;
  }

  .icon-button {
    width: 44px;
    height: 44px;
    border-radius: 14px;
  }
}

@media (max-width: 460px) {
  .hud {
    inset-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right));
  }

  .score-card--score {
    min-width: 74px;
  }

  .score-card {
    padding: 7px 8px 8px;
  }

  .score-card strong {
    font-size: 22px;
  }

  .score-card__label {
    font-size: 8px;
  }

  .hud__actions .icon-button {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  .panel {
    width: min(95vw, 530px);
    padding: 18px;
  }

  .menu-stats,
  .result-grid {
    gap: 6px;
  }

  .menu-stats span,
  .result-grid span {
    font-size: 8px;
  }

  .button-row:has(.secondary-button:not([hidden])),
  .button-row--result {
    grid-template-columns: 1fr;
  }
}

@media (max-height: 600px) and (orientation: landscape) {
  .panel {
    width: min(76vw, 620px);
    padding: 18px 24px;
  }

  .panel h1 {
    font-size: 44px;
  }

  .lead,
  .how-to-play,
  .controls-hint,
  .small-note {
    display: none;
  }

  .leaderboard-card {
    max-height: 116px;
    overflow: auto;
  }

  .primary-button,
  .secondary-button {
    min-height: 50px;
  }
}

@supports not selector(:has(*)) {
  .button-row {
    grid-template-columns: 1fr;
  }

  .button-row--result {
    grid-template-columns: 1fr 0.72fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

/* v2.0.4: mobile result-screen adaptive fixes */
:root {
  --app-height: 100dvh;
}

html {
  -webkit-text-size-adjust: 100%;
}

.overlay {
  min-height: var(--app-height, 100dvh);
  overflow: hidden;
}

.panel {
  max-height: calc(var(--app-height, 100dvh) - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}

.panel--result {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel--result .version-badge,
.panel--result h2,
.panel--result .meme-phrase,
.panel--result .result-grid,
.panel--result .button-row,
.panel--result .small-note {
  flex: 0 0 auto;
}

.panel--result h2 {
  overflow: visible;
}

.panel--result .leaderboard-card--result {
  min-height: 0;
}

@media (max-width: 540px) {
  .overlay {
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    place-items: start center;
    align-content: start;
  }

  .panel {
    width: min(96vw, 530px);
    max-height: calc(var(--app-height, 100dvh) - 20px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }

  .panel--result {
    padding: clamp(14px, 4vw, 18px);
    border-radius: clamp(24px, 7vw, 32px);
  }

  .panel--result .version-badge {
    margin-bottom: 8px;
    padding: 6px 11px;
    font-size: 9px;
    letter-spacing: 0.12em;
  }

  .panel--result h2 {
    margin-bottom: 8px;
    font-size: clamp(24px, 7.4vw, 34px);
    line-height: 1.04;
    letter-spacing: -0.045em;
  }

  .panel--result .meme-phrase {
    margin-bottom: 10px;
    padding: 10px 12px;
    border-radius: 16px;
    font-size: clamp(13px, 3.8vw, 16px) !important;
    line-height: 1.28 !important;
  }

  .panel--result .result-grid {
    gap: 7px;
    margin-bottom: 10px;
  }

  .panel--result .result-grid > div {
    padding: 9px 5px;
    border-radius: 16px;
  }

  .panel--result .result-grid span {
    margin-bottom: 3px;
    font-size: 8px;
    letter-spacing: 0.08em;
  }

  .panel--result .result-grid strong {
    font-size: clamp(27px, 8.2vw, 36px);
  }

  .panel--result .leaderboard-card--result {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    margin: 0 0 12px;
    padding: 10px;
    border-radius: 18px;
    overflow: hidden;
  }

  .panel--result .leaderboard-card__head {
    flex: 0 0 auto;
    margin-bottom: 7px;
  }

  .panel--result .leaderboard-list {
    flex: 1 1 auto;
    min-height: 0;
    max-height: min(34vh, 290px);
    max-height: min(34dvh, 290px);
    overflow-y: auto;
    padding-left: 22px;
    padding-right: 2px;
    scrollbar-width: none;
  }

  .panel--result .leaderboard-list::-webkit-scrollbar {
    width: 0;
    height: 0;
  }

  .panel--result .leaderboard-list li {
    padding: 6px 8px;
    border-radius: 11px;
    font-size: 12px;
  }

  .panel--result .leaderboard-line {
    gap: 8px;
  }

  .panel--result .leaderboard-line small {
    white-space: nowrap;
  }

  .panel--result .button-row--result {
    gap: 8px;
  }

  .panel--result .primary-button,
  .panel--result .secondary-button {
    min-height: 54px;
    border-radius: 17px;
    font-size: 17px;
  }

  .panel--result .small-note {
    margin-top: 9px;
    margin-bottom: 0;
  }
}

@media (max-width: 380px), (max-height: 740px) and (orientation: portrait) {
  .panel--result {
    padding: 12px;
    border-width: 2px;
  }

  .panel--result .version-badge {
    margin-bottom: 6px;
  }

  .panel--result h2 {
    margin-bottom: 6px;
    font-size: clamp(22px, 7vw, 29px);
  }

  .panel--result .meme-phrase {
    margin-bottom: 8px;
    padding: 9px 10px;
    font-size: clamp(12px, 3.55vw, 14px) !important;
  }

  .panel--result .result-grid {
    margin-bottom: 8px;
  }

  .panel--result .result-grid > div {
    padding: 8px 4px;
  }

  .panel--result .leaderboard-card--result {
    margin-bottom: 10px;
    padding: 9px;
  }

  .panel--result .leaderboard-list {
    gap: 5px;
    max-height: min(30vh, 214px);
    max-height: min(30dvh, 214px);
  }

  .panel--result .leaderboard-list li {
    padding: 5px 7px;
    font-size: 12px;
  }

  .panel--result .primary-button,
  .panel--result .secondary-button {
    min-height: 50px;
  }

  .panel--result .small-note {
    display: none;
  }
}

@media (max-width: 340px), (max-height: 620px) and (orientation: portrait) {
  .panel--result h2 {
    font-size: 22px;
  }

  .panel--result .meme-phrase {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .panel--result .leaderboard-card--result {
    max-height: 190px;
  }
}

/* Use measured mobile viewport height for the whole app as well. */
.game-shell {
  height: var(--app-height, 100dvh);
}
