/* Main Styling for Jonigiri Food Drop */
:root {
  --color-border: #4d2f12;
  --color-bg-light: #fef9e7;
  --color-accent-orange: #ff9f1c;
  --color-accent-yellow: #ffd166;
  --color-btn-gradient-start: #ffb834;
  --color-btn-gradient-end: #f47a00;
  --color-text-dark: #4d2f12;
  --color-text-white: #ffffff;
  --font-family: "Fredoka", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-drag: none;
}

body {
  font-family: var(--font-family);
  background-color: #ffffff;
  background-image:
    linear-gradient(to right, #e8e8e8 1px, transparent 1px),
    linear-gradient(to bottom, #e8e8e8 1px, transparent 1px);
  background-size: 20px 20px;
  color: var(--color-text-dark);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  overflow: hidden;
  padding: 10px;
}

.game-wrapper {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 580px;
  height: 95vh;
  max-height: 870px;
}

/* Device frame container */
.device-frame {
  width: 100%;
  height: auto;
  max-height: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  border-radius: 18px;
  container-type: inline-size;
  /* Fix WebKit/Safari overflow-hidden border-radius bug */
  transform: translateZ(0);
  -webkit-mask-image: -webkit-radial-gradient(white, black);
}

.device-frame.ratio-tall {
  aspect-ratio: 1125 / 1238;
}

.device-frame.ratio-square {
  aspect-ratio: 1145 / 1138;
}

/* The main content area */
.device-screen {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background-color: transparent;
}

/* Screen base class with specific backgrounds */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: none;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 11% 5% 15% 5%;
  z-index: 5;
  animation: fadeIn 0.3s ease-out;
  background-size: 100% 100%;
  background-repeat: no-repeat;
  background-position: center bottom;
}

.screen.active {
  display: flex;
}

#screen-welcome {
  background-image: url('assets/backgrounds/home.png');
}

#screen-game {
  background-image: url('assets/backgrounds/playing.png');
}

#screen-gameover {
  background-image: url('assets/backgrounds/gameover.png');
}

#screen-leaderboard {
  background-image: url('assets/backgrounds/leaderboard.png');
  padding: 5% 5% 5% 5%;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.98);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Welcome Screen Styling */
.game-logo-img {
  width: 58cqw;
  height: auto;
  filter: drop-shadow(0 4px 6px rgba(77, 47, 18, 0.15));
}

.gameover-logo-img {
  width: 46cqw;
  height: auto;
  filter: drop-shadow(0 4px 6px rgba(77, 47, 18, 0.15));
}

.character-preview {
  position: absolute;
  bottom: 21%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
  width: 100%;
}

.character-preview img {
  width: 38cqw;
  filter: none;
}

.welcome-buttons {
  position: absolute;
  bottom: 9%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  justify-content: center;
}

/* Image Buttons Styles */
.btn-image-action {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  outline: none;
  transition: transform 0.1s ease;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.btn-image-action img {
  width: 35cqw;
  height: auto;
  display: block;
}

.btn-image-action:active {
  transform: translateY(4px);
}

.btn-image-action-small {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  outline: none;
  transition: transform 0.1s ease;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.btn-image-action-small img {
  max-width: 130px;
  height: auto;
  display: block;
}

.btn-image-action-small:active {
  transform: translateY(3px);
}

.btn-image-circle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  outline: none;
  transition: transform 0.1s ease;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.btn-image-circle img {
  width: 52px;
  height: 52px;
  display: block;
}

.btn-image-circle:active {
  transform: translateY(2px);
}

.btn-image-circle-small {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  outline: none;
  transition: transform 0.1s ease;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

.btn-image-circle-small img {
  width: 8.5cqw;
  height: 8.5cqw;
  display: block;
}

.btn-image-circle-small:active {
  transform: translateY(2px);
}

.animate-bounce {
  animation: miniBounce 1.5s ease infinite;
}

@keyframes miniBounce {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.06);
  }
}

/* Bottom Controls */
.bottom-controls {
  position: absolute;
  bottom: 3.5%;
  left: 2%;
  right: 2%;
  display: flex;
  justify-content: space-between;
  width: auto;
  padding: 0 6.5%;
}

/* Game Screen HUD */
.game-hud {
  position: absolute;
  top: 9.5%;
  left: 4%;
  right: 4%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
}

.score-display {
  background: url('assets/score-board.png') no-repeat center center;
  background-size: 100% 100%;
  border: none;
  box-shadow: none;
  width: 26cqw;
  height: 8.5cqw;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 4cqw;
  padding-bottom: 0.5cqw;
  font-weight: 800;
  font-size: 3.5cqw;
  color: #ffffff;
}

.star-icon {
  color: #ffa200;
  margin-right: 6px;
  font-size: 1.4rem;
}

/* Canvas Container */
.game-container-relative {
  position: absolute;
  top: 10.1%;
  bottom: 11.1%;
  left: 1.8%;
  right: 1.8%;
  display: flex;
  align-items: stretch;
}

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

/* Miss Gauge (Stamina Tank style) */
.miss-gauge-container {
  position: absolute;
  right: 6%;
  top: 34%;
  transform: translateY(-50%);
  width: 8.5cqw;
  display: flex;
  justify-content: center;
  z-index: 8;
  pointer-events: none;
}

.stamina-tank-wrapper {
  position: relative;
  width: 100%;
  height: auto;
  aspect-ratio: 142 / 403;
  display: flex;
  justify-content: center;
  align-items: flex-end;
}

.stamina-tank-img {
  width: 100%;
  height: auto;
  position: relative;
  z-index: 2;
}

.stamina-fill {
  position: absolute;
  left: 37%;
  width: 26%;
  bottom: 7.2%;
  height: 0%;
  background: linear-gradient(to top, #ff3c00, #ffaa00, #ffea00);
  z-index: 1;
  border-radius: 4px;
  transition: height 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#stamina-count-bubble {
  background: #fff;
  border: 3px solid var(--color-border);
  border-radius: 12px;
  padding: 2px 6px;
  font-weight: 800;
  font-size: 0.85rem;
  margin-bottom: 4px;
  color: var(--color-text-dark);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  text-align: center;
}

.miss-gauge-header {
  width: 32px;
  height: 32px;
  margin-bottom: 2px;
}

.gauge-head-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.miss-gauge-track {
  width: 18px;
  height: 200px;
  background: rgba(255, 255, 255, 0.8);
  border: 3px solid var(--color-border);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.miss-gauge-fill {
  width: 100%;
  background: linear-gradient(to top, #ff3c00, #ffaa00, #ffea00);
  border-radius: 6px;
  transition: height 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Game Over Screen */
.gameover-char-container {
  margin: 10px 0;
  display: flex;
  justify-content: center;
  align-items: center;
  position: absolute;
  bottom: 21%;
  left: 50%;
  transform: translateX(-50%);
}

.gameover-char-img {
  width: 40cqw;
  filter: none;
}

.gameover-message {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text-dark);
  background: rgba(255, 255, 255, 0.9);
  padding: 8px 18px;
  border-radius: 20px;
  border: 3px solid var(--color-border);
  text-align: center;
  margin-bottom: 10px;
}



/* Primary Button Style (fallback) */
.btn-primary {
  font-family: var(--font-family);
  font-weight: 800;
  font-size: 1.2rem;
  padding: 10px 24px;
  color: var(--color-text-white);
  background: linear-gradient(to bottom, var(--color-btn-gradient-start), var(--color-btn-gradient-end));
  border: 4px solid var(--color-border);
  border-radius: 50px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--color-border);
  transition: all 0.1s ease;
  outline: none;
  text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.25);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-primary:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--color-border);
}

.gameover-buttons {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 15px;
}

/* Leaderboard Screen */
.leaderboard-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 15px;
}

.leaderboard-icon {
  font-size: 2.2rem;
}

.leaderboard-header h2 {
  font-size: 2.2rem;
  color: #ff9f1c;
  -webkit-text-stroke: 2px var(--color-border);
  text-shadow: 0 3px 0 var(--color-border);
}

.leaderboard-list-wrapper {
  flex: 1;
  width: 100%;
  background: transparent;
  border: none;
  box-shadow: none;
  margin-top: 24.5%;
  margin-bottom: 15.5%;
  padding: 0 16%;
  overflow-y: auto;
}

#leaderboard-list {
  list-style: none;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.4cqw 2.4cqw;
  border-bottom: 2px dashed rgba(77, 47, 18, 0.15);
  font-weight: 700;
  font-size: 3.3cqw;
}

.leaderboard-item:last-child {
  border-bottom: none;
}

.leaderboard-rank-name {
  display: flex;
  align-items: center;
  gap: 12px;
}

.rank-badge {
  width: 5.4cqw;
  height: 5.4cqw;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 2px solid var(--color-border);
  font-size: 2.7cqw;
  font-weight: 800;
}

.rank-1 {
  background-color: #ffd700;
  color: #fff;
  text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.3);
}

.rank-2 {
  background-color: #c0c0c0;
  color: #fff;
  text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.3);
}

.rank-3 {
  background-color: #cd7f32;
  color: #fff;
  text-shadow: 1px 1px 0px rgba(0, 0, 0, 0.3);
}

.rank-other {
  background-color: #ede0c8;
  color: var(--color-text-dark);
}

.leaderboard-score {
  font-weight: 800;
  color: #e85d04;
}

.leaderboard-buttons {
  position: absolute;
  bottom: 8%;
  left: 2%;
  right: 2%;
  display: flex;
  justify-content: center;
  gap: 15px;
}

/* Modals & Overlays */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(77, 47, 18, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border-radius: 15px;
  z-index: 100;
  display: none;
  justify-content: center;
  align-items: center;
  padding: 24px;
}

.overlay.active {
  display: flex;
}

.overlay-card {
  background: #fffdf5;
  border: 5px solid var(--color-border);
  border-radius: 28px;
  padding: 24px;
  width: 100%;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.2);
  animation: popIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
  from {
    transform: scale(0.85);
    opacity: 0;
  }

  to {
    transform: scale(1);
    opacity: 1;
  }
}

.overlay-card h2 {
  font-size: 2.2rem;
  color: #ff9f1c;
  -webkit-text-stroke: 2px var(--color-border);
  text-shadow: 0 3px 0 var(--color-border);
  margin-bottom: 20px;
}

.overlay-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 15px;
  align-items: center;
}

/* Settings elements */
.settings-option {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-weight: 700;
  font-size: 1.1rem;
  width: 100%;
}

.settings-option select {
  font-family: var(--font-family);
  font-weight: 700;
  padding: 6px 12px;
  border: 3px solid var(--color-border);
  border-radius: 10px;
  background: #fff;
  outline: none;
}

/* Toggle Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  border: 3px solid var(--color-border);
  transition: .4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  border: 2px solid var(--color-border);
  transition: .4s;
  border-radius: 50%;
}

input:checked+.slider {
  background-color: #27c93f;
}

input:checked+.slider:before {
  transform: translateX(20px);
}

/* Pause Card Board */
.pause-card {
  background: url('assets/pause-board.png') no-repeat center center;
  background-size: 100% 100%;
  width: 75%;
  max-width: 250px;
  height: auto;
  aspect-ratio: 648 / 680;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8% 10%;
  position: relative;
  box-shadow: none;
  border: none;
  animation: popIn 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.pause-title {
  font-family: var(--font-family);
  font-size: 2.8rem;
  font-weight: 900;
  color: #ffb703;
  -webkit-text-stroke: 3px var(--color-border);
  text-shadow: 0 4px 0 var(--color-border);
  margin-top: -24%;
  margin-bottom: 12%;
}

.pause-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  align-items: center;
  margin-top: 42px;
}

.pause-buttons .btn-image-action img {
  width: 100%;
  max-width: 145px;
  height: auto;
  display: block;
}

/* GameOver Controls & Pill Input */
.gameover-spacer {
  height: 15%;
}

.gameover-controls {
  position: absolute;
  bottom: 8%;
  left: 2%;
  right: 2%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

.submit-score-container {
  background: url('assets/buttons/name-score.png') no-repeat center center;
  background-size: 100% 100%;
  width: 48cqw;
  height: 9.2cqw;
  display: flex;
  align-items: center;
  padding: 0 1cqw;
  position: relative;
  border: none;
}

#player-name {
  width: 63%;
  height: 80%;
  border: none !important;
  background: transparent !important;
  font-family: var(--font-family);
  font-size: 3.1cqw;
  font-weight: 700;
  color: var(--color-text-dark);
  padding: 0 1cqw 0 2.5cqw;
  outline: none !important;
  box-shadow: none !important;
}

.btn-save-score-transparent {
  width: 33%;
  height: 90%;
  border: none !important;
  background: transparent !important;
  cursor: pointer;
  outline: none !important;
}

.gameover-controls .btn-image-action {
  height: 9.2cqw;
  display: inline-flex;
  align-items: center;
}

.gameover-controls .btn-image-action img {
  height: 100%;
  width: auto;
  display: block;
}

.disclaimer-text {
  font-family: var(--font-family);
  font-size: 0.65rem;
  color: #7f6e5c;
  text-align: center;
  margin-top: 6px;
  font-weight: 700;
  text-shadow: 1px 1px 0 #ffffff;
  opacity: 0.55;
  z-index: 10;
}

.disclaimer-text a {
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* Responsive mobile styles to prevent horizontal cropping */
@media (max-width: 600px) {
  .game-wrapper {
    height: auto;
    min-height: 100vh;
    justify-content: center;
    padding: 28px 10px 15px 10px;
  }

  .device-frame {
    width: 100%;
    max-width: 100%;
    height: auto;
    margin-top: 10px;
  }

  #screen-leaderboard {
    padding: 5% 5% 5% 5%;
  }

  .leaderboard-list-wrapper {
    margin-top: 24.5%;
    margin-bottom: 15.5%;
    padding: 0 16%;
  }

  .gameover-char-container {
    bottom: 21%;
  }
}