* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #1a1a2e;
  font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#game-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
}

#game-canvas {
  height: 100vh;
  height: 100dvh;
  max-width: 100vw;
  aspect-ratio: 400 / 720;
  cursor: pointer;
}

#btn-settings {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 50;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.2s;
}

#btn-settings:active {
  background: rgba(0, 0, 0, 0.5);
}

#btn-mute {
  position: fixed;
  top: 10px;
  right: 56px;
  z-index: 50;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background 0.2s;
}

#btn-mute:active {
  background: rgba(0, 0, 0, 0.5);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: rgba(0, 0, 0, 0.8);
  z-index: 100;
  padding: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: #fff;
  border-radius: 0;
  padding: 20px 16px;
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  text-align: center;
}

.modal-content h2 {
  font-size: 24px;
  color: #333;
  margin-bottom: 4px;
}

.modal-desc {
  font-size: 13px;
  color: #666;
  margin-bottom: 16px;
}

/* Fruit Grid */
#fruit-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.fruit-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  border: 2px dashed #ddd;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
}

.fruit-slot:active {
  background: #f0f0f0;
}

.fruit-slot.has-image {
  border: 2px solid #4CAF50;
  background: #f8fff8;
}

.fruit-slot-preview {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  margin-bottom: 4px;
  overflow: hidden;
  position: relative;
}

.fruit-slot-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.fruit-slot-name {
  font-size: 10px;
  color: #666;
  white-space: nowrap;
}

.fruit-slot-check {
  font-size: 10px;
  color: #4CAF50;
  font-weight: bold;
}

.fruit-slot-size {
  font-size: 9px;
  color: #aaa;
}

.fruit-slot-plus {
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  background: #2196F3;
  color: #fff;
  border-radius: 50%;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  font-weight: bold;
}

/* Crop Overlay */
#crop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 200;
}

#crop-overlay.hidden {
  display: none;
}

#crop-box {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  max-width: 320px;
  width: 90%;
}

#crop-fruit-name {
  font-size: 16px;
  font-weight: bold;
  color: #333;
  margin-bottom: 12px;
}

#crop-canvas {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  border: 3px solid #eee;
  margin-bottom: 16px;
}

.crop-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.crop-buttons .btn {
  flex: 1;
  padding: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 14px 20px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn.hidden {
  display: none;
}

.btn-primary {
  background: #4CAF50;
  color: #fff;
}

.btn-default {
  background: #f5f5f5;
  color: #333;
  border: 2px solid #ddd;
}

.modal-bottom-buttons {
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-reset {
  background: transparent;
  color: #999;
  font-size: 14px;
  font-weight: 400;
  padding: 8px;
  text-decoration: underline;
}

.btn-start {
  background: linear-gradient(135deg, #FF6B6B, #FF8E53);
  color: #fff;
  font-size: 18px;
  width: 100%;
  padding: 16px;
  border-radius: 14px;
}

.btn-start:hover {
  opacity: 0.9;
}

.btn-cancel {
  background: #f5f5f5;
  color: #666;
  font-size: 16px;
  width: 100%;
  padding: 14px;
  border: 1px solid #ddd;
}

@media (min-width: 500px) {
  .modal-content {
    margin-top: 20px;
    border-radius: 20px;
    min-height: auto;
    max-height: 90vh;
    overflow-y: auto;
  }
}