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

:root {
  --bg: #1a0a2e;
  --bg-card: #2d1b4e;
  --accent: #ff6b9d;
  --accent-hot: #ff3d7f;
  --gold: #ffd166;
  --cream: #fff8f0;
  --muted: #c4b5d4;
  --success: #06d6a0;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --radius: 20px;
  --font: "Fredoka", system-ui, -apple-system, sans-serif;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

html {
  width: 100%;
  height: 100%;
  height: 100dvh;
  height: -webkit-fill-available;
}

body {
  width: 100%;
  min-height: 100%;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font);
  color: var(--cream);
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
}

#game-container {
  width: 100%;
  height: 100%;
  min-height: 100%;
  position: relative;
}

#game-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  margin: 0 auto;
  touch-action: none;
}

/* Loading */
#loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% 20%, rgba(255,107,157,.2), transparent 45%),
    radial-gradient(ellipse at 50% 30%, #3d1f6e 0%, #1a0a2e 70%);
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

#loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#loading-overlay p {
  font-size: clamp(0.95rem, 3.5vw, 1.1rem);
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-align: center;
}

.loader-donut {
  width: clamp(52px, 14vw, 64px);
  height: clamp(52px, 14vw, 64px);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, transparent 28%, #f4a261 28%, #f4a261 42%, #e76f51 42%, #e76f51 55%, #ff6b9d 55%, #ff6b9d 72%, transparent 72%),
    radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.35) 0%, transparent 40%);
  animation: spin-bounce 1.1s ease-in-out infinite;
  box-shadow: 0 0 0 4px #c45c26, 0 8px 24px rgba(255, 107, 157, 0.4);
}

@keyframes spin-bounce {
  0%, 100% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.08); }
}

/* Modal — full mobile friendly */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(12px, var(--sat))
    max(12px, var(--sar))
    max(12px, var(--sab))
    max(12px, var(--sal));
  background: rgba(10, 4, 20, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: opacity 0.25s ease, visibility 0.25s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.modal.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.modal-card {
  position: relative;
  width: min(420px, 100%);
  max-height: min(90dvh, 640px);
  overflow-y: auto;
  padding: 1.5rem 1.25rem 1.25rem;
  background: linear-gradient(165deg, #3a2260 0%, #2d1b4e 50%, #241540 100%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  touch-action: pan-y;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--cream);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
}

.modal-close:hover,
.modal-close:focus-visible {
  background: rgba(255, 255, 255, 0.16);
  outline: none;
}

.modal-card h2 {
  font-size: clamp(1.25rem, 5vw, 1.55rem);
  font-weight: 700;
  margin-bottom: 0.4rem;
  padding-right: 40px;
  background: linear-gradient(90deg, var(--gold), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.modal-sub {
  font-size: clamp(0.85rem, 3.5vw, 0.92rem);
  color: var(--muted);
  line-height: 1.45;
  margin-bottom: 1.1rem;
}

.upload-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 120px;
  padding: 1.1rem;
  border: 2px dashed rgba(255, 107, 157, 0.45);
  border-radius: 16px;
  background: rgba(255, 107, 157, 0.06);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  text-align: center;
}

.upload-zone:hover,
.upload-zone:focus-within {
  border-color: var(--accent);
  background: rgba(255, 107, 157, 0.12);
}

.upload-zone.dragover {
  border-color: var(--gold);
  background: rgba(255, 209, 102, 0.12);
  transform: scale(1.02);
}

.upload-icon {
  font-size: 2.2rem;
  line-height: 1;
}

.upload-zone span {
  font-weight: 600;
  font-size: 1rem;
}

.upload-zone small {
  color: var(--muted);
  font-size: 0.78rem;
}

.photo-preview-wrap {
  margin-top: 1rem;
  text-align: center;
}

.photo-preview-wrap.hidden {
  display: none;
}

#photo-preview {
  width: 100%;
  max-width: 280px;
  height: auto;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.12);
  background: #111;
}

#photo-status {
  margin-top: 0.6rem;
  font-size: 0.88rem;
  color: var(--success);
  font-weight: 500;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.2rem;
  justify-content: stretch;
}

.modal-actions .btn {
  flex: 1 1 120px;
  min-height: 48px;
}

.btn {
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.75rem 1.2rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  transition: transform 0.12s, opacity 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

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

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hot) 100%);
  color: #fff;
  box-shadow: 0 4px 16px rgba(255, 61, 127, 0.35);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--cream);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* Landscape phone */
@media (max-height: 480px) and (orientation: landscape) {
  .modal-card {
    max-height: 92dvh;
    padding: 1rem 1.15rem;
  }

  .upload-zone {
    min-height: 80px;
    flex-direction: row;
    gap: 1rem;
  }

  .modal-sub {
    margin-bottom: 0.6rem;
    font-size: 0.85rem;
  }
}

/* Very small phones */
@media (max-width: 360px) {
  .modal-card {
    padding: 1.15rem 1rem 1rem;
  }

  .btn {
    font-size: 0.9rem;
    padding: 0.7rem 1rem;
  }
}
