:root {
  --gh: 100dvh;
}
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: var(--gh);
  background: #0a0a0a;
  font-family: sans-serif;
  overflow: hidden;
  touch-action: none;
}

#game-wrapper {
  flex-shrink: 0;
  box-sizing: border-box;
  background: linear-gradient(145deg, #d4a86a, #b8884a 40%, #a07038 60%, #b8884a);
  border-radius: 18px;
  padding: 6px;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.5),
    0 2px 8px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 220, 160, 0.5),
    inset 0 -1px 0 rgba(80, 40, 10, 0.4);
  border: 2px solid #8a6030;
  position: relative;
}

#game-wrapper::before {
  content: '';
  position: absolute;
  inset: 3px;
  border-radius: 14px;
  border: 1px solid rgba(255, 220, 160, 0.3);
  pointer-events: none;
  z-index: 50;
}

#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  background: url('../images/watermelon/background.png') top center / cover no-repeat;
  background-color: #fef9f2;
  overflow: hidden;
  border-radius: 12px 12px 0 0;
  box-sizing: border-box;
  box-shadow: inset 0 0 20px rgba(120, 80, 30, 0.12);
}

#legend-panel {
  background: linear-gradient(180deg, #f5e8d4, #eedcc0);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  flex-shrink: 0;
  padding: 0 8px 6px;
  gap: 0;
  border-radius: 0 0 12px 12px;
  border-top: 1px solid #d8c4a8;
}

.legend-title {
  color: #9a7a58;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  padding: 4px 0 3px;
  letter-spacing: 2px;
  flex-shrink: 0;
  width: 100%;
  border-bottom: 1px solid #e0cdb8;
}

#legend-list {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: auto auto;
  gap: 3px 0;
  padding: 4px 0;
  width: 100%;
}

.legend-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1px 1px;
  gap: 1px;
}

.legend-item canvas {
  display: block;
}

.legend-item .legend-label {
  color: #7a6048;
  font-size: 10px;
  text-align: center;
  white-space: nowrap;
  line-height: 1.2;
}

.legend-item .legend-num {
  color: #475569;
  font-size: 7px;
  line-height: 1;
}

.score-board {
  position: absolute;
  top: 20px;
  left: 20px;
  color: #5a3e20;
  font-size: 24px;
  font-weight: 800;
  z-index: 10;
  pointer-events: none;
}
.best-score {
  font-size: 13px;
  color: #9a7a58;
  font-weight: 600;
  margin-top: 2px;
}
#btn-panel {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  flex-shrink: 0;
  border-top: 1px solid #d8c4a8;
  background: linear-gradient(180deg, #f0dcc0, #e8d0b0);
}
#btn-panel button {
  background: #d4956a;
  border: none;
  border-radius: 20px;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 5px 18px;
  cursor: pointer;
  transition: opacity 0.2s;
  box-shadow: 0 2px 6px rgba(180, 120, 60, 0.35);
}
#btn-panel button:active {
  background: #c07a50;
}
#btn-panel button.active {
  background: #e85040;
  box-shadow: 0 2px 8px rgba(230, 60, 40, 0.4);
}
#btn-panel button.disabled {
  background: #c0b0a0;
  opacity: 0.5;
  pointer-events: none;
  box-shadow: none;
}
.deadline {
  position: absolute;
  top: 130px;
  width: 100%;
  height: 2px;
  background: #ef4444;
  border-top: 2px dashed #ef4444;
  z-index: 5;
  opacity: 0.6;
}

#warning-timer {
  position: absolute;
  top: 140px;
  left: 50%;
  transform: translateX(-50%);
  color: #ef4444;
  font-size: 40px;
  font-weight: 900;
  z-index: 20;
  display: none;
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}

#overlay {
  position: absolute;
  inset: 0;
  background: rgba(250, 240, 225, 0.92);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  color: #4a3020;
  text-align: center;
}
#overlay h2 {
  font-size: 48px;
  margin-bottom: 10px;
}
#overlay p {
  font-size: 20px;
  margin-bottom: 30px;
}
#overlay button {
  background: #d4956a;
  color: #fff;
  border: none;
  padding: 15px 40px;
  border-radius: 12px;
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Mobile */
@media (max-width: 540px) {
  #game-wrapper {
    border-radius: 12px;
    padding: 4px;
  }
  #game-wrapper::before {
    border-radius: 9px;
  }
  #game-container {
    border-radius: 8px 8px 0 0;
  }
  #legend-panel {
    border-radius: 0 0 8px 8px;
  }
}