/* === Sweet Strategy - Donut Escape === */
/* Mobile-first, portrait-optimized, modern viewport units */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  font-family: "M PLUS Rounded 1c", sans-serif;
  background: #1a0a2e;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

/* ==========================================
   LAYOUT: flex column → canvas + controls
   Canvas fills all remaining space above controls.
   ========================================== */
#game-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 500px;
  margin: 0 auto;
  overflow: hidden;
}

#game-canvas {
  flex: 1 1 0;        /* grow to fill, shrink to fit */
  min-height: 0;      /* critical: allows flex child to shrink below content size */
  width: 100%;
  display: block;
  touch-action: none;
  image-rendering: auto;
}



/* === Controls Panel (in flex flow, bottom) === */
#controls-panel {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(26, 10, 46, 0.5), rgba(26, 10, 46, 0.95));
}

/* === D-Pad (Left Side) === */
#dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.dpad-mid {
  display: flex;
  align-items: center;
  gap: 2px;
}

.dpad-btn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffeedd;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.dpad-btn:active {
  background: rgba(255, 200, 100, 0.35);
  transform: scale(0.9);
  box-shadow: 0 0 14px rgba(255, 200, 100, 0.4);
}

.dpad-center {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
}

/* === Action Area (Right Side) === */
#action-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

#donut-count {
  font-size: 12px;
  font-weight: 700;
  color: #ffeedd;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* === Donut Button === */
.donut-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  border: 2px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
}

.donut-btn:active {
  transform: scale(0.9);
}

.donut-btn.selected {
  background: rgba(255, 200, 100, 0.3);
  border-color: #ffcc44;
  box-shadow: 0 0 24px rgba(255, 200, 100, 0.4);
}

.donut-btn.disabled {
  opacity: 0.35;
  pointer-events: none;
}

#donut-btn-canvas {
  width: 50px;
  height: 50px;
  display: block;
  pointer-events: none;
}

/* === Rank-In Animation List === */
#rank-animation-list {
  margin: 8px 0;
  max-height: 240px;
  overflow-y: auto;
}

.rank-entry {
  display: flex;
  align-items: center;
  padding: 5px 10px;
  margin: 3px 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
  font-family: "M PLUS Rounded 1c", sans-serif;
  color: rgba(255, 255, 255, 0.7);
  opacity: 0;
  transform: translateX(-30px);
  animation: rankSlideIn 0.3s ease forwards;
}

.rank-entry.is-player {
  background: linear-gradient(135deg, rgba(255, 200, 50, 0.25), rgba(255, 150, 30, 0.15));
  border: 1.5px solid rgba(255, 200, 80, 0.6);
  color: #FFD700;
  font-weight: bold;
  font-size: 14px;
  animation: rankSlideIn 0.3s ease forwards, rankGlow 1.2s ease-in-out infinite alternate;
}

.rank-entry .rank-num {
  width: 28px;
  font-weight: bold;
  flex-shrink: 0;
  text-align: center;
}

.rank-entry .rank-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin: 0 6px;
}

.rank-entry .rank-time {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

@keyframes rankSlideIn {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes rankGlow {
  from {
    box-shadow: 0 0 6px rgba(255, 200, 50, 0.3);
  }
  to {
    box-shadow: 0 0 18px rgba(255, 200, 50, 0.6);
  }
}

/* === Modals (fixed overlay) === */
#ranking-modal,
#ranking-list-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(6px);
}

.ranking-modal-content {
  background: linear-gradient(145deg, rgba(60, 20, 100, 0.95), rgba(30, 10, 60, 0.98));
  border: 2px solid rgba(255, 200, 100, 0.3);
  border-radius: 20px;
  padding: 24px 28px;
  text-align: center;
  max-width: 320px;
  width: 85%;
  box-shadow: 0 8px 40px rgba(0,0,0,0.5), 0 0 60px rgba(255, 200, 100, 0.1);
}

.ranking-list-content {
  max-height: 70vh;
  max-height: 70svh;
  overflow-y: auto;
}

.ranking-list-table {
  text-align: center;
  margin-top: 12px;
}

.ranking-list-row {
  padding: 8px 0;
  font-size: 15px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ranking-modal-title {
  font-size: 22px;
  font-weight: 900;
  color: #FFD700;
  margin-bottom: 10px;
  text-shadow: 0 2px 8px rgba(255, 200, 0, 0.3);
}

.ranking-modal-rank {
  font-size: 16px;
  color: #FF69B4;
  font-weight: 700;
  margin-bottom: 4px;
}

.ranking-modal-time {
  font-size: 24px;
  color: #FFFFFF;
  font-weight: 900;
  margin-bottom: 16px;
  font-variant-numeric: tabular-nums;
}

#rank-name-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 2px solid rgba(255, 200, 100, 0.3);
  background: rgba(255, 255, 255, 0.1);
  color: #FFFFFF;
  font-size: 16px;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  font-weight: 700;
  text-align: center;
  outline: none;
  margin-bottom: 14px;
  box-sizing: border-box;
}

#rank-name-input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

#rank-name-input:focus {
  border-color: #FFD700;
  box-shadow: 0 0 12px rgba(255, 200, 0, 0.3);
}

.ranking-modal-buttons {
  display: flex;
  gap: 10px;
}

.rank-btn {
  flex: 1;
  padding: 10px 8px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 900;
  font-family: 'M PLUS Rounded 1c', sans-serif;
  cursor: pointer;
  transition: all 0.2s;
}

.rank-btn:active {
  transform: scale(0.95);
}

.rank-btn-save {
  background: linear-gradient(135deg, #FFD700, #FFA500);
  color: #3C1464;
  box-shadow: 0 3px 12px rgba(255, 200, 0, 0.3);
}

.rank-btn-skip {
  background: rgba(255, 255, 255, 0.1);
  color: #CCBBDD;
  border: 1px solid rgba(255, 255, 255, 0.2);
}
