:root {
  color-scheme: light;
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  background: #ffeaa3;
  color: #2d2513;
  --glass-border: rgba(127, 90, 35, 0.15);
}

* {
  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;
  place-items: center;
  background:
    radial-gradient(circle at 16% 16%, rgba(255, 112, 112, 0.28), transparent 20%),
    radial-gradient(circle at 82% 12%, rgba(84, 167, 255, 0.24), transparent 24%),
    linear-gradient(180deg, #fff0a8 0%, #ffd58f 100%);
}

button,
a {
  font: inherit;
}

/* Flexbox Layout Shell */
.lunch-game {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100vw, 520px);
  height: min(100dvh, 920px);
  padding: max(12px, env(safe-area-inset-top)) 14px calc(18px + env(safe-area-inset-bottom));
  overflow: hidden;
}

/* Header Topbar */
.topbar {
  display: grid;
  grid-template-columns: 50px 1fr auto;
  gap: 10px;
  align-items: center;
}

.home-link {
  display: grid;
  place-items: center;
  min-height: 50px;
  border: 3px solid #7f5a23;
  border-radius: 8px;
  background: #fff9dc;
  color: #3b2a13;
  text-decoration: none;
  box-shadow: 0 5px 0 #c99b44;
  font-size: 28px;
  font-weight: 1000;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.home-link:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #c99b44;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(22px, 6vw, 32px);
  line-height: 1.1;
  font-weight: 900;
}

#brandText {
  margin: 0;
  color: #d97706;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.header-right {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.language-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: #704f1f;
}

#languageLabel {
  display: none; /* Hide on small screens */
}

.language-picker select {
  background: #d97706;
  border: 3px solid #7f5a23;
  color: #ffffff;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 900;
  outline: none;
  cursor: pointer;
  box-shadow: 0 3px 0 #7f5a23;
}

.language-picker select option {
  background-color: #d97706;
  color: #ffffff;
}

/* Gameplay Stats HUD */
.game-hud {
  display: grid;
  grid-template-columns: 1.2fr 0.9fr 0.9fr;
  gap: 10px;
  padding: 8px 14px;
  border: 3px solid #7f5a23;
  border-radius: 8px;
  background: #fff9dc;
  box-shadow: 0 4px 0 #c99b44;
  align-items: center;
}

.hud-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hud-item span {
  font-size: 11px;
  font-weight: 900;
  color: #704f1f;
}

.hud-item div {
  width: 100%;
  height: 8px;
  background: #fff7d4;
  border: 2px solid #7f5a23;
  border-radius: 999px;
  overflow: hidden;
}

.hud-item i {
  display: block;
  height: 100%;
  background: #57b869;
  width: 0%;
  transition: width 0.25s ease;
}

.hud-item-score, .hud-item-round {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.hud-item-score span, .hud-item-round span {
  font-size: 11px;
  font-weight: 900;
  color: #704f1f;
}

.hud-item-score strong, .hud-item-round strong {
  font-size: 18px;
  font-weight: 1000;
  color: #3b2a13;
}

/* Stage / Level Selector */
.stage-select {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 16px 0;
  overflow-y: auto;
}

.stage-select h2 {
  font-size: 24px;
  font-weight: 1000;
  margin: 0 0 14px;
  color: #5e421b;
}

.stage-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  width: 100%;
  max-width: 360px;
}

.stage-card {
  background: #fffdf0;
  border: 4px solid #7f5a23;
  border-radius: 12px;
  padding: 14px;
  color: #2d2513;
  text-align: left;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  box-shadow: 0 6px 0 #c99b44;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  position: relative;
}

.stage-card.unlocked:active {
  transform: translateY(3px);
  box-shadow: 0 3px 0 #c99b44;
}

.stage-card.locked {
  opacity: 0.6;
  background: #e2e8f0;
  cursor: not-allowed;
  box-shadow: 0 6px 0 #94a3b8;
  border-color: #64748b;
}

.stage-card span {
  font-size: 11px;
  font-weight: 1000;
  text-transform: uppercase;
  color: #d97706;
  margin-bottom: 4px;
}

.stage-card.locked span {
  color: #64748b;
}

.stage-card strong {
  font-size: 18px;
  font-weight: 1000;
  margin-bottom: 4px;
}

.stage-card small {
  font-size: 13px;
  color: #704f1f;
  font-weight: 500;
  line-height: 1.4;
}

.stage-card-colors {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.stage-card-colors i {
  width: 26px;
  height: 26px;
  border: 3px solid rgba(63, 43, 22, 0.78);
  border-radius: 50%;
  box-shadow: inset 0 -4px rgba(0, 0, 0, 0.12), 0 3px 0 rgba(112, 75, 28, 0.24);
}

.stage-card-colors .red { background: #ff6b6b; }
.stage-card-colors .yellow { background: #ffd75e; }
.stage-card-colors .blue { background: #62b8ff; }
.stage-card-colors .green { background: #78d66c; }
.stage-card-colors .orange { background: #ff9a3d; }
.stage-card-colors .purple { background: #a78bfa; }
.stage-card-colors .white { background: #fffdf2; }
.stage-card-colors .brown { background: #b77948; }
.stage-card-colors .gray { background: #cbd5e1; }
.stage-card-colors .pink { background: #ff9ac7; }
.stage-card-colors .black { background: #2f2b35; }
.stage-card-colors .cyan { background: #67e8f9; }

.stage-card:disabled {
  color: #2d2513;
}

.stage-card.locked small {
  color: #64748b;
}

/* Game Play Content wrapper */
.game-play-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}

.lunchboxes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 10px;
}

.lunchbox {
  display: grid;
  place-items: center;
  min-height: 94px;
  border: 4px solid rgba(63, 43, 22, 0.86);
  border-radius: 8px;
  color: #271b0d;
  box-shadow: inset 0 -10px rgba(0, 0, 0, 0.12), 0 8px 0 rgba(112, 75, 28, 0.42);
  cursor: pointer;
}

.lunchbox span {
  width: 52px;
  height: 34px;
  border: 4px solid rgba(255, 255, 255, 0.72);
  border-radius: 999px 999px 14px 14px;
}

.lunchbox strong {
  font-size: clamp(16px, 4.4vw, 22px);
  text-shadow: 0 1px rgba(255, 255, 255, 0.55);
}

.lunchbox.red {
  background: #ff6b6b;
}

.lunchbox.yellow {
  background: #ffd75e;
}

.lunchbox.blue {
  background: #62b8ff;
}

.lunchbox.green {
  background: #78d66c;
}

.lunchbox.orange {
  background: #ff9a3d;
}

.lunchbox.purple {
  background: #a78bfa;
}

.lunchbox.white {
  background: #fffdf2;
}

.lunchbox.brown {
  background: #b77948;
}

.lunchbox.gray {
  background: #cbd5e1;
}

.lunchbox.pink {
  background: #ff9ac7;
}

.lunchbox.black {
  background: #2f2b35;
  color: #fff7dc;
}

.lunchbox.cyan {
  background: #67e8f9;
}

.lunchbox.hit {
  animation: box-hit 0.42s ease;
}

.lunchbox.miss {
  animation: box-miss 0.24s ease;
}

.food-stage {
  display: grid;
  place-items: center;
  min-height: 178px;
  flex: 1;
}

.food-card {
  display: grid;
  place-items: center;
  width: min(48vw, 190px);
  height: min(48vw, 190px);
  max-width: 190px;
  max-height: 190px;
  min-width: 142px;
  min-height: 142px;
  border: 4px solid #7f5a23;
  border-radius: 8px;
  background: #fffdf0;
  box-shadow: 0 12px 0 #c99b44, 0 18px 24px rgba(104, 66, 26, 0.28);
  cursor: grab;
  user-select: none;
  touch-action: none;
  transition: transform 0.12s ease;
}

.food-card.dragging {
  z-index: 10;
  opacity: 0.95;
  cursor: grabbing;
  transition: none;
}

.food-card img {
  width: 88px;
  height: 88px;
  object-fit: contain;
  pointer-events: none;
}

.food-card strong {
  font-size: 24px;
}

.feedback {
  display: grid;
  place-items: center;
  min-height: 52px;
  color: #573d18;
}

.feedback strong {
  padding: 10px 18px;
  border: 3px solid #7f5a23;
  border-radius: 999px;
  background: #fff9dc;
  font-size: 20px;
  text-align: center;
}

/* Results Overlay */
.result-panel {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(85, 55, 20, 0.34);
  backdrop-filter: blur(8px);
  animation: lunch-fade-in 0.24s ease;
}

.result-card {
  display: grid;
  gap: 12px;
  width: min(100%, 370px);
  padding: 24px;
  border: 4px solid #7f5a23;
  border-radius: 8px;
  background: #fff9dc;
  color: #382611;
  text-align: center;
  box-shadow: 0 12px 0 #c99b44;
  animation: lunch-panel-pop 0.42s cubic-bezier(0.17, 0.9, 0.28, 1.2);
}

.result-card h2 {
  font-size: 34px;
  font-weight: 1000;
  margin: 0;
}

.result-report {
  display: grid;
  gap: 10px;
  margin: 4px 0 8px;
  color: #704f1f;
}

.result-summary {
  font-size: 18px;
  font-weight: 1000;
}

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

.result-stats span {
  display: grid;
  place-items: center;
  min-height: 48px;
  padding: 6px;
  border: 2px solid #c99b44;
  border-radius: 8px;
  background: #fff3b6;
  color: #4d3515;
  font-size: 13px;
  font-weight: 1000;
  line-height: 1.2;
}

.skill-report {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 3px solid #7f5a23;
  border-radius: 8px;
  background: #fffdf0;
  text-align: left;
}

.skill-report > strong {
  color: #382611;
  font-size: 16px;
}

.skill-report-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #704f1f;
  font-size: 14px;
  font-weight: 900;
}

.skill-report-row b {
  color: #f2a71b;
  font-size: 15px;
  white-space: nowrap;
}

.progress-message {
  margin: 0;
  color: #5d421d;
  font-size: 15px;
  font-weight: 1000;
  line-height: 1.35;
}

.result-report small {
  color: #8a6a37;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
}

.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.result-actions button,
.result-actions a {
  width: 100%;
  min-height: 50px;
  border: 3px solid #7f5a23;
  border-radius: 8px;
  background: #ffcf63;
  color: #2d2513;
  font-size: 18px;
  font-weight: 1000;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 4px 0 #c99b44;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  display: grid;
  place-items: center;
}

.result-actions button:active,
.result-actions a:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #c99b44;
}

.result-actions a {
  background: #ffffff;
}

/* Loading Panel */
.loading-panel {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 112, 112, 0.28), transparent 22%),
    radial-gradient(circle at 80% 16%, rgba(84, 167, 255, 0.24), transparent 22%),
    rgba(255, 234, 163, 0.96);
}

.loading-card {
  display: grid;
  gap: 12px;
  width: min(100%, 300px);
  padding: 24px;
  border: 4px solid #7f5a23;
  border-radius: 8px;
  background: #fff9dc;
  color: #382611;
  text-align: center;
  box-shadow: 0 12px 0 #c99b44;
}

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

.loading-card span {
  font-size: 22px;
  font-weight: 1000;
}

.loading-card div {
  height: 18px;
  padding: 3px;
  border: 3px solid #7f5a23;
  border-radius: 999px;
  background: #fff7d4;
}

.loading-card i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: #57b869;
  transition: width 0.2s ease;
}

.hidden {
  display: none !important;
}

/* Sound Toggle Placement */
.sound-toggle {
  position: fixed;
  z-index: 30;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border: 3px solid #7f5a23;
  border-radius: 50%;
  background: #fff9dc;
  color: #2d2513;
  font-size: 22px;
  box-shadow: 0 5px 0 #c99b44;
  cursor: pointer;
  outline: none;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.sound-toggle:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #c99b44;
}

.sound-toggle.muted {
  opacity: 0.72;
}

/* Animations */
.food-card.pop {
  animation: food-pop 0.48s ease;
}

.food-card.shake {
  animation: food-shake 0.28s ease;
}

@keyframes box-hit {
  50% {
    transform: scale(1.06);
    filter: brightness(1.12);
  }
}

@keyframes box-miss {
  25% {
    transform: translateX(-6px);
  }
  75% {
    transform: translateX(6px);
  }
}

@keyframes food-pop {
  50% {
    transform: scale(1.12) rotate(4deg);
  }
}

@keyframes food-shake {
  25% {
    transform: translateX(-7px) rotate(-3deg);
  }
  75% {
    transform: translateX(7px) rotate(3deg);
  }
}

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

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

@media (prefers-reduced-motion: reduce) {
  .result-panel,
  .result-card,
  .food-card.pop,
  .food-card.shake {
    animation: none;
  }
}

/* Responsive Overrides */
@media (max-height: 700px) {
  .lunch-game {
    gap: 8px;
  }

  .lunchbox {
    min-height: 94px;
  }

  .food-stage {
    min-height: 142px;
  }

  .food-card {
    width: 138px;
    height: 138px;
    min-width: 132px;
    min-height: 132px;
  }
}
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;
}
