:root {
  color-scheme: light;
  --ink: #08324f;
  --muted: #52758d;
  --ice: #dff7ff;
  --blue: #147eae;
  --deep-blue: #0a527f;
  --gold: #f7b733;
  --card: rgba(245, 252, 255, 0.92);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: #bfeafb;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background:
    radial-gradient(circle at 10% 12%, rgba(255, 255, 255, 0.92) 0 3px, transparent 4px),
    radial-gradient(circle at 84% 22%, rgba(255, 255, 255, 0.75) 0 2px, transparent 3px),
    linear-gradient(180deg, #8dd9f5 0%, #c9effc 43%, #eafaff 100%);
}

body::before,
body::after {
  content: "";
  position: fixed;
  z-index: 0;
  right: -8vw;
  bottom: -13vw;
  width: 56vw;
  height: 32vw;
  border-radius: 60% 0 0 0;
  background: linear-gradient(150deg, rgba(255,255,255,.92), rgba(187,230,246,.76));
  box-shadow: -34vw 7vw 0 rgba(237, 250, 255, 0.78);
  pointer-events: none;
}

body::after {
  left: -20vw;
  right: auto;
  bottom: -20vw;
  transform: rotate(8deg);
  opacity: 0.66;
}

.snow {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.52;
  background-image:
    radial-gradient(circle, #fff 0 2px, transparent 2.5px),
    radial-gradient(circle, #fff 0 1.4px, transparent 2px);
  background-size: 94px 94px, 137px 137px;
  background-position: 14px 18px, 63px 47px;
  animation: snowfall 18s linear infinite;
}

@keyframes snowfall {
  to { background-position: 14px 300px, 63px 480px; }
}

.game-shell {
  position: relative;
  z-index: 2;
  width: min(1080px, calc(100% - 28px));
  margin: 0 auto;
  padding: clamp(22px, 4vw, 48px) 0 34px;
}

.hero {
  margin-bottom: 18px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 5px;
  color: #176c93;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.22em;
}

h1 {
  margin: 0;
  color: #073d62;
  font-size: clamp(2rem, 5.5vw, 3.65rem);
  font-weight: 950;
  letter-spacing: -0.05em;
  line-height: 1.08;
  text-shadow: 0 2px 0 rgba(255,255,255,.8);
}

.subtitle {
  margin: 10px 0 0;
  color: #315f78;
  font-size: clamp(0.92rem, 2vw, 1.08rem);
  font-weight: 650;
}

.game-card {
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.88);
  border-radius: 26px;
  background: var(--card);
  box-shadow:
    0 25px 70px rgba(8, 58, 87, 0.2),
    inset 0 1px 0 #fff;
  backdrop-filter: blur(12px);
}

.info-bar,
.game-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 18px;
}

.mobile-controls {
  display: none;
  padding: 14px 12px 16px;
  border-top: 1px solid rgba(58, 136, 169, 0.16);
  text-align: center;
  background: rgba(225, 247, 255, 0.72);
}

.mobile-controls-label {
  margin: 0 0 8px;
  color: #52758d;
  font-size: .72rem;
  font-weight: 850;
  letter-spacing: .12em;
}

.direction-pad {
  display: grid;
  grid-template-columns: repeat(3, 58px);
  grid-template-rows: repeat(2, 58px);
  gap: 8px;
  justify-content: center;
}

.direction-button {
  display: grid;
  width: 58px;
  height: 58px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(9, 83, 121, .2);
  border-bottom-width: 4px;
  border-radius: 17px;
  color: #07527d;
  background: linear-gradient(160deg, #fff 0%, #dff6ff 100%);
  box-shadow: 0 6px 14px rgba(8, 76, 109, .16);
  font-size: 1.65rem;
  font-weight: 950;
  line-height: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .08s ease, box-shadow .08s ease, background .08s ease;
}

.direction-button:focus-visible {
  outline: 3px solid #f7b733;
  outline-offset: 2px;
}

.direction-button:active,
.direction-button.is-pressed {
  transform: translateY(3px) scale(.97);
  border-bottom-width: 1px;
  background: linear-gradient(160deg, #caeffd 0%, #a9ddf0 100%);
  box-shadow: 0 2px 6px rgba(8, 76, 109, .18);
}

.direction-up { grid-column: 2; grid-row: 1; }
.direction-left { grid-column: 1; grid-row: 2; }
.direction-down { grid-column: 2; grid-row: 2; }
.direction-right { grid-column: 3; grid-row: 2; }

.info-bar {
  justify-content: flex-start;
  border-bottom: 1px solid rgba(58, 136, 169, 0.16);
}

.stat {
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  min-width: 118px;
  column-gap: 8px;
}

.stat-icon {
  grid-row: 1 / span 2;
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 11px;
  color: #0f6d99;
  background: #d9f4ff;
  font-size: 1.16rem;
}

.stat-label {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.stat strong {
  font-size: 1.2rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.restart-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  margin-left: auto;
  padding: 8px 12px;
  border: 1px solid rgba(11, 89, 126, 0.14);
  border-radius: 13px;
  color: #0a527f;
  background: #fff;
  box-shadow: 0 5px 13px rgba(27, 100, 132, .1);
  font-weight: 850;
  transition: transform .15s ease, box-shadow .15s ease;
}

.restart-button:hover,
.restart-button:focus-visible,
.play-again-button:hover,
.play-again-button:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(12, 77, 109, .2);
}

.restart-button img {
  width: 19px;
  height: 19px;
}

kbd {
  display: inline-grid;
  min-width: 25px;
  height: 25px;
  padding: 0 5px;
  place-items: center;
  border: 1px solid #afd9e9;
  border-bottom-width: 3px;
  border-radius: 6px;
  color: #195978;
  background: #f9fdff;
  font-family: inherit;
  font-size: .72rem;
  font-weight: 900;
  line-height: 1;
}

.restart-button kbd {
  margin-left: 2px;
  min-width: 23px;
  height: 22px;
}

.canvas-frame {
  position: relative;
  width: 100%;
  overflow: hidden;
  background: #5bb6d9;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 19 / 13;
  outline: 0;
  touch-action: none;
}

canvas:focus-visible {
  box-shadow: inset 0 0 0 4px rgba(255, 212, 77, .95);
}

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #0b547c;
  background: rgba(221, 247, 255, .9);
  font-weight: 850;
  transition: opacity .25s ease;
}

.loading.is-hidden {
  visibility: hidden;
  opacity: 0;
}

.loading-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #1d8fbe;
  animation: pulse .8s ease-in-out infinite alternate;
}

@keyframes pulse {
  to { transform: scale(1.5); opacity: .4; }
}

.win-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 42, 68, .68);
  backdrop-filter: blur(4px);
  animation: fade-in .25s ease-out;
}

.win-overlay[hidden] {
  display: none;
}

@keyframes fade-in { from { opacity: 0; } }

.win-card {
  width: min(420px, 94%);
  padding: clamp(20px, 5vw, 34px);
  border: 2px solid rgba(255,255,255,.92);
  border-radius: 26px;
  text-align: center;
  background: linear-gradient(160deg, #fff 0%, #e8f9ff 100%);
  box-shadow: 0 25px 70px rgba(0, 24, 41, .35);
  animation: win-pop .35s cubic-bezier(.18,.89,.32,1.28);
}

@keyframes win-pop {
  from { opacity: 0; transform: scale(.8) translateY(20px); }
}

.win-fish {
  font-size: 2.7rem;
  filter: drop-shadow(0 5px 6px rgba(217, 140, 6, .24));
}

.win-kicker {
  margin: 5px 0 3px;
  color: #2085a9;
  font-size: .68rem;
  font-weight: 950;
  letter-spacing: .2em;
}

.win-card h2 {
  margin: 0;
  color: #083f65;
  font-size: clamp(1.65rem, 5vw, 2.35rem);
}

.win-card > p:not(.win-kicker) {
  margin: 8px 0 20px;
  color: var(--muted);
}

.win-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.win-stats div {
  padding: 12px;
  border-radius: 14px;
  background: #dff5fd;
}

.win-stats span,
.win-stats strong {
  display: block;
}

.win-stats span {
  color: #5b7b8d;
  font-size: .74rem;
  font-weight: 750;
}

.win-stats strong {
  margin-top: 2px;
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}

.play-again-button {
  width: 100%;
  min-height: 48px;
  border-radius: 14px;
  color: #fff;
  background: linear-gradient(135deg, #148abb, #086493);
  box-shadow: 0 6px 15px rgba(8, 99, 146, .25);
  font-weight: 900;
  transition: transform .15s ease, box-shadow .15s ease;
}

.game-footer {
  justify-content: space-between;
  border-top: 1px solid rgba(58, 136, 169, 0.16);
  color: #41677c;
  font-size: .78rem;
  font-weight: 750;
}

.route-hint,
.key-hint,
.key-hint span {
  display: flex;
  align-items: center;
  gap: 5px;
}

.key-hint b {
  margin: 0 3px;
  color: #7893a3;
  font-size: .7rem;
}

.start-dot,
.goal-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 0 4px rgba(68, 190, 224, .16);
  background: #25a9d5;
}

.goal-dot {
  box-shadow: 0 0 0 4px rgba(247, 183, 51, .2);
  background: var(--gold);
}

.tip {
  margin: 14px 0 0;
  text-align: center;
  color: #416b82;
  font-size: .8rem;
  font-weight: 650;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 660px) {
  .game-shell { width: min(100% - 14px, 1080px); padding-top: 16px; }
  .game-card { border-radius: 18px; }
  .info-bar { padding: 10px; gap: 8px; }
  .stat { min-width: 82px; column-gap: 5px; }
  .stat-icon { width: 30px; height: 30px; }
  .stat-label { font-size: .61rem; }
  .stat strong { font-size: 1rem; }
  .restart-button { min-height: 38px; padding: 7px 9px; font-size: .78rem; }
  .restart-button kbd, .restart-button img { display: none; }
  .game-footer { justify-content: center; padding: 10px; }
  .route-hint { display: none; }
  .key-hint kbd { min-width: 22px; height: 22px; font-size: .64rem; }
  .win-card { border-radius: 20px; }
}

@media (max-width: 760px), (hover: none) and (pointer: coarse) {
  .mobile-controls { display: block; }
}

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