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

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(circle at 18% 8%, rgba(255, 216, 108, 0.2), transparent 28%),
    radial-gradient(circle at 82% 18%, rgba(91, 224, 156, 0.18), transparent 28%),
    linear-gradient(165deg, #111a2a 0%, #1d2a3f 56%, #111827 100%);
}

button,
a,
select {
  font: inherit;
}

.fruit-game {
  width: min(100%, 760px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px calc(16px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 10px;
}

.topbar {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) minmax(132px, 170px);
  gap: 10px;
  align-items: center;
}

.home-link,
.controls button,
.result-actions a,
.result-actions button,
#startBtn {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: #ffd35d;
  color: #182133;
  text-decoration: none;
  font-weight: 1000;
  box-shadow: inset 0 -4px rgba(0, 0, 0, 0.12), 0 10px 24px rgba(0, 0, 0, 0.22);
  touch-action: manipulation;
}

.home-link {
  display: grid;
  place-items: center;
  font-size: 26px;
}

.title-block {
  min-width: 0;
}

.title-block p {
  margin: 0 0 2px;
  color: #9eeaff;
  font-size: 12px;
  font-weight: 900;
}

.title-block h1 {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(22px, 6vw, 34px);
  line-height: 1.02;
}

.language-picker {
  display: grid;
  gap: 4px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.language-picker span {
  color: rgba(255, 255, 255, 0.68);
  font-size: 11px;
  font-weight: 900;
}

.language-picker select {
  width: 100%;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  background: rgba(10, 16, 26, 0.95);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

.scorebar {
  display: grid;
  grid-template-columns: 1fr 1fr 1.15fr;
  gap: 8px;
}

.scorebar div {
  min-width: 0;
  min-height: 72px;
  padding: 9px 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.scorebar span {
  display: block;
  color: rgba(255, 255, 255, 0.68);
  font-size: 12px;
  font-weight: 900;
}

.scorebar strong {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #ffd35d;
  font-size: clamp(18px, 5vw, 28px);
  line-height: 1.05;
}

#nextFruitText {
  width: 54px;
  height: 54px;
  margin-top: -2px;
  display: grid;
  place-items: center;
  overflow: visible;
  color: #9eeaff;
}

#nextFruitText svg {
  width: 54px;
  height: 54px;
  display: block;
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.24));
}

.board-shell {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
}

#gameCanvas {
  width: min(100%, calc((100svh - 196px) * 0.692));
  max-width: 720px;
  height: auto;
  max-height: calc(100svh - 196px);
  aspect-ratio: 720 / 1040;
  border: 4px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: #f8fbff;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.36);
  touch-action: none;
}

.controls {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 10px;
}

.controls button {
  width: 100%;
  font-size: 18px;
}

#restartBtn {
  background: rgba(255, 255, 255, 0.9);
}

.menu-panel,
.result-panel,
.loading-panel {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  background: rgba(9, 15, 25, 0.64);
  backdrop-filter: blur(8px);
}

.menu-panel.hidden,
.result-panel.hidden,
.loading-panel.hidden,
.toast.hidden {
  display: none;
}

.menu-panel > div,
.result-card,
.loading-card {
  width: min(92vw, 420px);
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: #fffdf1;
  color: #172033;
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.34);
  animation: fruit-pop 0.22s ease both;
}

.menu-panel {
  grid-template-rows: 1fr auto 1fr;
}

.menu-panel > div {
  grid-row: 2;
}

#startBtn {
  grid-row: 3;
  align-self: start;
  width: min(92vw, 420px);
}

.menu-panel h2,
.result-card h2 {
  margin: 0;
  font-size: clamp(28px, 8vw, 44px);
  line-height: 1;
}

.menu-panel p,
.result-card p {
  margin: 0;
  color: rgba(23, 32, 51, 0.72);
  font-size: 16px;
  font-weight: 800;
  line-height: 1.45;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.result-actions a,
.result-actions button {
  display: grid;
  place-items: center;
}

.loading-card div {
  height: 10px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(23, 32, 51, 0.12);
}

.loading-card i {
  display: block;
  width: 100%;
  height: 100%;
  background: #30c66d;
}

.toast {
  position: absolute;
  left: 50%;
  top: 42%;
  z-index: 10;
  min-width: 120px;
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(24, 33, 51, 0.86);
  color: #fff;
  font-weight: 1000;
  text-align: center;
  animation: fruit-toast 0.9s ease both;
}

@keyframes fruit-pop {
  from { transform: translateY(16px) scale(0.96); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes fruit-toast {
  0% { transform: translate(-50%, 18px) scale(0.92); opacity: 0; }
  20% { transform: translate(-50%, 0) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -30px) scale(1.04); opacity: 0; }
}

@media (max-width: 430px) {
  .fruit-game {
    gap: 8px;
    padding-inline: 8px;
  }

  .topbar {
    grid-template-columns: 40px minmax(0, 1fr) 122px;
    gap: 8px;
  }

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

  .scorebar div {
    min-height: 66px;
    padding: 8px;
  }

  #nextFruitText,
  #nextFruitText svg {
    width: 48px;
    height: 48px;
  }

  #gameCanvas {
    max-height: calc(100svh - 184px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .menu-panel > div,
  .result-card,
  .loading-card,
  .toast {
    animation-duration: 0.01ms !important;
  }
}
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;
}
