:root {
  color-scheme: dark;
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  background: #082f49;
  color: #f8fafc;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

body {
  display: grid;
  align-items: start;
  justify-items: center;
  background:
    radial-gradient(circle at 18% 10%, rgba(254, 240, 138, 0.45), transparent 32%),
    radial-gradient(circle at 84% 18%, rgba(125, 211, 252, 0.34), transparent 34%),
    linear-gradient(180deg, #38bdf8 0%, #0ea5e9 42%, #14532d 100%);
}

button,
select,
a {
  font: inherit;
}

.dash-game {
  position: relative;
  display: grid;
  grid-template-rows: 68px 58px minmax(0, 1fr);
  gap: 10px;
  width: min(100vw, 520px);
  height: min(100svh, 920px);
  min-height: 100svh;
  padding: max(28px, calc(env(safe-area-inset-top) + 18px)) 12px calc(12px + env(safe-area-inset-bottom));
  overflow: hidden;
}

.topbar {
  position: relative;
  z-index: 25;
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr) minmax(132px, 148px);
  gap: 9px;
  align-items: center;
  min-width: 0;
}

.home-link,
.language-picker,
.hud div,
.panel,
.loading-card {
  border: 1px solid rgba(148, 163, 184, 0.42);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.82);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(12px);
}

.home-link {
  display: grid;
  place-items: center;
  min-height: 52px;
  height: 52px;
  color: #f8fafc;
  font-size: 28px;
  font-weight: 1000;
  text-decoration: none;
}

.topbar div {
  min-width: 0;
}

.topbar p,
.language-picker span,
.hud span {
  margin: 0;
  color: #93c5fd;
  font-size: 12px;
  font-weight: 1000;
}

.topbar h1 {
  overflow: hidden;
  margin: 2px 0 0;
  font-size: clamp(24px, 6vw, 34px);
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #f8fafc;
}

.language-picker {
  display: grid;
  gap: 4px;
  min-height: 52px;
  padding: 7px;
}

.language-picker select {
  width: 100%;
  min-height: 32px;
  border: 1px solid rgba(147, 197, 253, 0.55);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.95);
  color: #f8fafc;
  font-size: 13px;
  font-weight: 1000;
}

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

.hud div {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 7px 4px;
  border-color: rgba(34, 211, 238, 0.28);
}

.hud strong {
  font-size: clamp(18px, 5vw, 25px);
  line-height: 1;
  color: #facc15;
}

.score-pop {
  animation: dash-score-pop 0.26s ease;
}

.canvas-wrap {
  min-height: 0;
  overflow: hidden;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  background: #7dd3fc;
  box-shadow: 0 22px 50px rgba(8, 47, 73, 0.36);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.panel,
.loading-panel {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 13, 24, 0.82);
}

.panel {
  align-content: center;
  justify-items: center;
  gap: 13px;
  width: min(360px, calc(100% - 34px));
  height: auto;
  min-height: 250px;
  margin: auto;
  color: #f8fafc;
  text-align: center;
  animation: dash-panel-pop 0.42s cubic-bezier(0.17, 0.9, 0.28, 1.2);
}

.panel strong {
  font-size: clamp(28px, 8vw, 42px);
  line-height: 1;
}

.panel p {
  margin: 0;
  color: #cbd5e1;
  font-size: 16px;
  font-weight: 900;
  line-height: 1.35;
}

.panel button,
.panel a {
  display: grid;
  place-items: center;
  width: min(100%, 250px);
  min-height: 48px;
  border: 1px solid rgba(250, 204, 21, 0.7);
  border-radius: 8px;
  background: linear-gradient(135deg, #facc15, #fb923c);
  color: #111827;
  font-size: 18px;
  font-weight: 1000;
  text-decoration: none;
  box-shadow: 0 5px 0 rgba(124, 45, 18, 0.58);
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
}

.panel button:active,
.panel a:active {
  transform: translateY(3px) scale(0.98);
  box-shadow: 0 2px 0 rgba(124, 45, 18, 0.58);
  filter: brightness(1.07);
}

.leaderboard {
  display: grid;
  gap: 5px;
  width: min(100%, 260px);
}

.leaderboard div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 9px;
  border-radius: 8px;
  background: rgba(21, 80, 154, 0.12);
  font-weight: 1000;
  animation: dash-row-pop 0.3s ease both;
}

.loading-panel {
  background: rgba(8, 13, 24, 0.96);
}

.loading-card {
  display: grid;
  gap: 10px;
  width: min(100%, 320px);
  padding: 22px;
  text-align: center;
  animation: dash-panel-pop 0.36s ease;
}

.loading-card strong {
  font-size: 32px;
}

.loading-card div {
  height: 18px;
  padding: 3px;
  border: 1px solid rgba(147, 197, 253, 0.55);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.95);
}

.loading-card i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #22d3ee, #facc15, #fb923c);
  transition: width 0.2s ease;
}

.hidden {
  display: none !important;
}

.hud.hidden {
  display: grid !important;
  visibility: hidden;
  pointer-events: none;
}

@keyframes dash-panel-pop {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.93);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes dash-row-pop {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes dash-score-pop {
  0% {
    transform: scale(1);
  }
  55% {
    transform: scale(1.24);
    color: #facc15;
    text-shadow: 0 0 14px rgba(250, 204, 21, 0.75);
  }
  100% {
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .panel,
  .loading-card,
  .leaderboard div,
  .score-pop {
    animation: none;
  }
}

@media (max-width: 420px) {
  .dash-game {
    grid-template-rows: 62px 52px minmax(0, 1fr);
    gap: 8px;
    padding-top: max(30px, calc(env(safe-area-inset-top) + 20px));
    padding-right: 9px;
    padding-left: 9px;
  }

  .topbar {
    grid-template-columns: 48px minmax(0, 1fr) 126px;
  }

  .home-link {
    min-height: 48px;
    height: 48px;
  }

  .language-picker span {
    display: none;
  }

  .language-picker {
    min-height: 48px;
  }
}
html,
body,
button,
a,
canvas,
[role="button"] {
  -webkit-user-select: none;
  user-select: none;
}

input,
textarea,
select,
[contenteditable="true"] {
  -webkit-user-select: text;
  user-select: text;
}
