:root {
  color-scheme: light dark;
  font-family: "Segoe UI", Helvetica, Arial, sans-serif;
  background-color: #0d1b2a;
  color: #e5eeff;

  /* Safe area insets for notched devices */
  --safe-area-inset-top: env(safe-area-inset-top);
  --safe-area-inset-right: env(safe-area-inset-right);
  --safe-area-inset-bottom: env(safe-area-inset-bottom);
  --safe-area-inset-left: env(safe-area-inset-left);
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, #4f83ff 0%, #17324f 55%, #0b1a2e 100%);
  overflow: hidden;
}

.game-shell {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  margin: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: clamp(0.75rem, 1.5vw, 1.5rem);
  padding: max(clamp(0.75rem, 1.5vw, 1.8rem), var(--safe-area-inset-top))
            max(clamp(0.75rem, 1.5vw, 1.8rem), var(--safe-area-inset-right))
            max(clamp(0.75rem, 1.5vw, 1.8rem), var(--safe-area-inset-bottom))
            max(clamp(0.75rem, 1.5vw, 1.8rem), var(--safe-area-inset-left));
  box-sizing: border-box;
  position: relative;
}

.hud {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  align-items: center;
  background: rgba(13, 33, 67, 0.88);
  padding: 0.85rem 1.2rem;
  border-radius: 0.9rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
}

.hud-group {
  display: flex;
  gap: 0.55rem;
  align-items: baseline;
  font-size: 1.05rem;
}

.hud-label {
  font-weight: 600;
  opacity: 0.85;
}

.status {
  margin-left: auto;
  font-style: italic;
  opacity: 0.8;
}

.playfield {
  position: relative;
  border-radius: 1.5rem;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  min-height: 0;
  touch-action: none; /* Prevent default touch behaviors on canvas */
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(#bde5ff 0%, #bde5ff 45%, #4ca4df 45%, #4ca4df 100%);
}

.controls {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.controls button {
  flex: 1 1 220px;
  padding: 0.9rem 1.1rem;
  min-height: 44px; /* Ensure minimum touch target size */
  border: none;
  border-radius: 0.9rem;
  font-size: 1.05rem;
  font-weight: 600;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #f1f5f9;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.controls button:disabled {
  background: #475569;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.controls button:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(37, 99, 235, 0.55);
}

.controls button:not(:disabled):active {
  transform: scale(0.97);
  opacity: 0.9;
}

.panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: clamp(300px, 60vw, 500px);
  max-height: 70vh;
  background: rgba(8, 20, 40, 0.95);
  border-radius: 1.25rem;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.6);
  padding: 1.35rem;
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(14px);
  z-index: 20;
}

.hidden {
  display: none !important;
}

.panel header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.85rem;
}

.panel h2 {
  margin: 0;
  font-size: 1.4rem;
}

.customize-section {
  margin-bottom: 1rem;
}

.customize-section h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}

.customize-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.customize-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(148, 163, 184, 0.12);
  padding: 0.6rem 0.75rem;
  border-radius: 0.65rem;
  gap: 0.75rem;
}

.customize-item-info {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.95rem;
}

.customize-item-actions {
  display: flex;
  gap: 0.5rem;
}

.customize-item button {
  padding: 0.65rem 1rem;
  min-height: 44px; /* Ensure touch target size */
  border: none;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.customize-item button.buy {
  background: rgba(22, 163, 74, 0.85);
  color: #ecfdf5;
}

.customize-item button.buy:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(22, 163, 74, 0.35);
}

.customize-item button.buy:disabled {
  background: rgba(71, 85, 105, 0.6);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.customize-item button.equip {
  background: rgba(59, 130, 246, 0.85);
  color: #e0f2fe;
}

.customize-item button.equip:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(59, 130, 246, 0.35);
}

.customize-item button.equip:disabled {
  background: rgba(71, 85, 105, 0.6);
  cursor: default;
  transform: none;
  box-shadow: none;
}

.customize-item .owned-tag {
  font-size: 0.78rem;
  font-weight: 600;
  color: #4ade80;
}

#close-collection-btn {
  background: transparent;
  border: none;
  color: inherit;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#collection-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* Smooth iOS scrolling */
}

#collection-list li {
  padding: 0.7rem 0.85rem;
  border-radius: 0.65rem;
  margin-bottom: 0.6rem;
  background: rgba(148, 163, 184, 0.15);
  display: flex;
  align-items: center;
  gap: 0.85rem;
  font-size: 0.95rem;
}

#collection-list li.collection-item {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#collection-list li.collection-item:hover {
  transform: translateY(-2px);
  background: rgba(148, 197, 255, 0.18);
  box-shadow: 0 8px 20px rgba(15, 118, 110, 0.15);
}

#collection-list li.collection-item:active {
  transform: scale(0.98);
  background: rgba(148, 197, 255, 0.25);
}

#collection-list li.collection-item:focus-visible {
  outline: 2px solid rgba(96, 165, 250, 0.9);
  outline-offset: 2px;
}

#collection-list li .fish-info {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

#collection-list li .fish-name {
  font-weight: 600;
}

#collection-list li .fish-meta {
  font-size: 0.8rem;
  opacity: 0.8;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

#collection-list li .fish-thumb {
  width: 64px;
  height: 38px;
  border-radius: 0.6rem;
  box-shadow: inset 0 0 0 2px rgba(148, 197, 255, 0.25);
}

#collection-list li .fish-count {
  font-weight: 700;
  background: rgba(15, 118, 110, 0.2);
  color: #5eead4;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  min-width: 2.5rem;
  text-align: center;
  margin-left: auto;
}

#collection-list li.empty {
  justify-content: center;
  color: rgba(248, 250, 252, 0.7);
  font-style: italic;
}

.rarity-Common {
  color: #e2e8f0;
}

.rarity-Uncommon {
  color: #86efac;
}

.rarity-Rare {
  color: #60a5fa;
}

.rarity-Epic {
  color: #c084fc;
}

.rarity-Legendary {
  color: #fbbf24;
}

.rarity-Mythic {
  color: #f87171;
  text-shadow: 0 0 10px rgba(248, 113, 113, 0.65);
}

.catch-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 12, 24, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1rem, var(--safe-area-inset-top))
            max(1rem, var(--safe-area-inset-right))
            max(1rem, var(--safe-area-inset-bottom))
            max(1rem, var(--safe-area-inset-left));
  z-index: 30;
}

.catch-card {
  display: flex;
  flex-direction: row;
  gap: 1.25rem;
  background: linear-gradient(160deg, rgba(15, 48, 80, 0.95), rgba(13, 33, 67, 0.9));
  border-radius: 1.5rem;
  padding: 1.6rem;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  max-width: 540px;
  width: 100%;
  color: #e2ecff;
}

.catch-image-frame {
  flex: 0 0 190px;
  background: rgba(15, 118, 110, 0.18);
  border-radius: 1.1rem;
  padding: 0.85rem;
  display: flex;
  justify-content: center;
  align-items: center;
}

.catch-image-frame img {
  width: 100%;
  height: auto;
  border-radius: 0.95rem;
  box-shadow: inset 0 0 0 2px rgba(148, 197, 255, 0.25);
}

.catch-text {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  justify-content: center;
}

.catch-text h3 {
  margin: 0;
  font-size: 1.5rem;
}

.catch-text p {
  margin: 0;
  line-height: 1.5;
  font-size: 0.98rem;
  color: rgba(226, 236, 255, 0.85);
}

.catch-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.close-catch-btn {
  align-self: flex-start;
  padding: 0.55rem 1.25rem;
  min-height: 44px;
  border: none;
  border-radius: 999px;
  font-weight: 600;
  background: rgba(59, 130, 246, 0.88);
  color: #e5eeff;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.close-catch-btn:active {
  transform: scale(0.95);
  opacity: 0.9;
}

.close-catch-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(59, 130, 246, 0.45);
}

.sell-catch-btn {
  padding: 0.55rem 1.25rem;
  min-height: 44px;
  border: none;
  border-radius: 999px;
  font-weight: 600;
  background: rgba(16, 185, 129, 0.85);
  color: #e5fdf4;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.sell-catch-btn:not(:disabled):active {
  transform: scale(0.95);
  opacity: 0.9;
}

.sell-catch-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(16, 185, 129, 0.45);
}

.sell-catch-btn:disabled {
  background: rgba(71, 85, 105, 0.6);
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

@media (max-width: 900px) {
  .hud {
    flex-direction: column;
    align-items: flex-start;
  }

  .status {
    margin-left: 0;
  }
}

/* QTE Overlay Styles */
.qte-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 12, 24, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1rem, var(--safe-area-inset-top))
            max(1rem, var(--safe-area-inset-right))
            max(1rem, var(--safe-area-inset-bottom))
            max(1rem, var(--safe-area-inset-left));
  z-index: 40;
  animation: fadeIn 0.2s ease;
  cursor: pointer;
  user-select: none;
}

.qte-content {
  background: linear-gradient(160deg, rgba(220, 38, 38, 0.95), rgba(185, 28, 28, 0.9));
  border-radius: 1.5rem;
  padding: 2rem 3rem;
  box-shadow: 0 20px 60px rgba(220, 38, 38, 0.5);
  text-align: center;
  animation: pulseQTE 0.6s ease-in-out infinite;
}

.qte-title {
  margin: 0 0 1.5rem 0;
  font-size: 3rem;
  font-weight: 900;
  color: #fef2f2;
  text-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  letter-spacing: 0.1em;
}

.qte-timer-container {
  background: rgba(15, 23, 42, 0.6);
  border-radius: 999px;
  height: 20px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.qte-timer-bar {
  background: linear-gradient(90deg, #10b981, #fbbf24, #ef4444);
  height: 100%;
  width: 100%;
  transition: width 0.1s linear;
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.6);
}

.qte-hint {
  margin: 0;
  font-size: 1.1rem;
  color: #fef2f2;
  opacity: 0.9;
}

@keyframes pulseQTE {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* Meter Mini-Game Overlay Styles */
.meter-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 12, 24, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(1rem, var(--safe-area-inset-top))
            max(1rem, var(--safe-area-inset-right))
            max(1rem, var(--safe-area-inset-bottom))
            max(1rem, var(--safe-area-inset-left));
  z-index: 40;
  animation: fadeIn 0.3s ease;
  cursor: pointer;
  user-select: none;
}

.meter-container {
  background: linear-gradient(160deg, rgba(15, 48, 80, 0.95), rgba(13, 33, 67, 0.9));
  border-radius: 1.5rem;
  padding: 2.5rem 3rem;
  box-shadow: 0 20px 60px rgba(37, 99, 235, 0.5);
  text-align: center;
  width: clamp(280px, 90vw, 600px);
  max-width: 500px;
}

.meter-title {
  margin: 0 0 2rem 0;
  font-size: 2rem;
  font-weight: 700;
  color: #e2ecff;
}

.meter-bar-container {
  margin-bottom: 1.5rem;
}

.meter-bar {
  position: relative;
  background: rgba(15, 23, 42, 0.8);
  border-radius: 12px;
  height: 50px;
  overflow: hidden;
  border: 3px solid rgba(148, 197, 255, 0.3);
}

.meter-target-zone {
  position: absolute;
  background: linear-gradient(90deg, rgba(16, 185, 129, 0.3), rgba(16, 185, 129, 0.5), rgba(16, 185, 129, 0.3));
  height: 100%;
  border-left: 3px solid #10b981;
  border-right: 3px solid #10b981;
  box-shadow: 0 0 20px rgba(16, 185, 129, 0.4);
}

.meter-indicator {
  position: absolute;
  background: linear-gradient(180deg, #60a5fa, #3b82f6);
  width: 8px;
  height: 100%;
  left: 0;
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.8);
  transition: left 0.05s linear;
}

.meter-hint {
  margin: 0;
  font-size: 1.1rem;
  color: #e2ecff;
  opacity: 0.9;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Success/Failure Flash Animations */
@keyframes flashSuccess {
  0%, 100% { background: transparent; }
  50% { background: rgba(16, 185, 129, 0.3); }
}

@keyframes flashFailure {
  0%, 100% { background: transparent; }
  50% { background: rgba(239, 68, 68, 0.3); }
}

.flash-success {
  animation: flashSuccess 0.5s ease;
}

.flash-failure {
  animation: flashFailure 0.5s ease;
}

@media (max-width: 700px) {
  .game-shell {
    padding: 1rem;
  }

  .controls button {
    flex-basis: 100%;
  }

  .catch-card {
    flex-direction: column;
    text-align: center;
    align-items: center;
  }

  .catch-image-frame {
    width: 100%;
  }

  .close-catch-btn {
    align-self: center;
  }

  .catch-actions {
    justify-content: center;
  }

  .qte-content {
    padding: 1.5rem 2rem;
  }

  .qte-title {
    font-size: 2rem;
  }

  .meter-container {
    width: clamp(260px, 95vw, 500px);
    padding: 1.5rem 1.5rem;
  }

  .meter-title {
    font-size: 1.5rem;
  }
}

/* Touch-specific styles */
@media (hover: none) and (pointer: coarse) {
  /* Remove hover effects on touch devices */
  .controls button:not(:disabled):hover {
    transform: none;
    box-shadow: none;
  }

  #collection-list li.collection-item:hover {
    transform: none;
    background: rgba(148, 163, 184, 0.15);
    box-shadow: none;
  }

  .close-catch-btn:hover,
  .sell-catch-btn:hover {
    transform: none;
    box-shadow: none;
  }
}

/* Tap ripple animation */
.tap-ripple {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  transform: translate(-50%, -50%);
  animation: ripple 0.6s ease-out;
  pointer-events: none;
  z-index: 10;
}

@keyframes ripple {
  to {
    transform: translate(-50%, -50%) scale(3);
    opacity: 0;
  }
}
