:root {
  --ff-hud-gap: 12px;
  --ff-panel-width: 320px;
}

* {
  box-sizing: border-box;
}

html, body {
  width: 100%;
  min-height: 100vh;
  margin: 0;
  padding: 0;
  background-color: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-body);
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

.game-container {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px;
  position: relative;
  z-index: 1;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.header h1 {
  font-family: var(--font-heading);
  font-size: 1.4rem;
  font-weight: 800;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--gold);
  text-shadow: 0 0 12px var(--gold-glow);
}

.game-icon-small {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  object-fit: cover;
}

.back-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-secondary);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-weight: 600;
  transition: var(--transition);
}

.back-btn:hover,
.back-btn:focus-visible {
  background: rgba(255, 255, 255, 0.16);
  color: var(--text-primary);
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.game-info {
  background: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.stats {
  display: flex;
  justify-content: space-between;
  gap: var(--ff-hud-gap);
  flex-wrap: wrap;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.stats span {
  white-space: nowrap;
}

#coinsText {
  color: var(--gold);
}

#speciesText {
  color: var(--cyan);
}

.xp-bar-container {
  position: relative;
  width: 100%;
  height: 14px;
  background: rgba(0, 0, 0, 0.35);
  border-radius: var(--radius-full);
  margin-top: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.xp-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--cyan), var(--cyan-light));
  border-radius: var(--radius-full);
  transition: width 0.25s ease-out;
  box-shadow: 0 0 12px var(--cyan-glow);
}

.xp-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-primary);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

.game-screen {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 16px;
  z-index: 2600;
}

#board {
  display: block;
  width: 100%;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  touch-action: manipulation;
  background: #000;
}

.event-toast {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: 0.95rem;
  color: #000;
  background: var(--gold);
  box-shadow: var(--shadow-glow-gold);
  z-index: 500;
  animation: toastIn 0.35s var(--ease-spring);
}

.event-toast.danger {
  background: var(--error);
  color: #fff;
  box-shadow: 0 0 24px hsla(0, 75%, 55%, 0.35);
}

.event-toast.golden {
  background: var(--gold-light);
  box-shadow: var(--shadow-glow-gold);
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, -20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.floating-text-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  border-radius: var(--radius-lg);
}

.floating-text {
  position: absolute;
  font-weight: 800;
  font-size: 1rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
  animation: floatUp 1s ease-out forwards;
  pointer-events: none;
}

.floating-text.coin {
  color: var(--gold);
}

.floating-text.xp {
  color: var(--cyan);
}

@keyframes floatUp {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-40px) scale(1.15); }
}

.game-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.control-btn {
  background: var(--bg-surface);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-weight: 700;
  cursor: pointer;
  transition: var(--transition);
  min-width: 110px;
}

.control-btn:hover,
.control-btn:focus-visible {
  background: var(--bg-surface-hover);
  border-color: var(--cyan);
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

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

.shop-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(var(--ff-panel-width), 100vw);
  height: 100vh;
  background: var(--bg-surface);
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow-lg);
  z-index: 2500;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  animation: slideIn 0.3s var(--ease-out);
}

@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.shop-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.shop-header h2 {
  margin: 0;
  font-family: var(--font-heading);
  color: var(--gold);
}

.close-shop-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  transition: var(--transition);
}

.close-shop-btn:hover,
.close-shop-btn:focus-visible {
  color: var(--text-primary);
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.shop-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

.upgrade-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

/* ── Shop Stats Header ── */
.shop-stats {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.shop-stat {
  flex: 1;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  text-align: center;
}

.shop-stat-value {
  display: block;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--gold);
  line-height: 1.2;
}

.shop-stat-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

/* ── Shop Cards ── */
.shop-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  transition: var(--transition);
}

.shop-card:hover {
  border-color: rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.3);
}

.shop-card.affordable {
  border-color: rgba(46, 204, 113, 0.2);
}

.shop-card.affordable:hover {
  border-color: rgba(46, 204, 113, 0.35);
}

.shop-card.maxed {
  opacity: 0.55;
}

.shop-card-icon {
  font-size: 1.6rem;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.shop-card-body {
  flex: 1;
  min-width: 0;
}

.shop-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.shop-card-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
}

.shop-card-level {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.shop-card-desc {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.35;
}

.shop-card-effect {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--cyan);
  margin-top: 4px;
}

.shop-card-progress {
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}

.shop-card-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--cyan), var(--cyan-light));
  border-radius: 2px;
  transition: width 0.3s ease;
}

.shop-card-buy {
  background: var(--success);
  color: #000;
  border: none;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
  min-width: 70px;
  text-align: center;
}

.shop-card-buy:hover:not(:disabled),
.shop-card-buy:focus-visible:not(:disabled) {
  filter: brightness(1.15);
  transform: scale(1.03);
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.shop-card-buy:active:not(:disabled) {
  transform: scale(0.97);
}

.shop-card-buy:disabled {
  background: var(--bg-surface-active);
  color: var(--text-muted);
  cursor: not-allowed;
}

.aquarium-section h3 {
  font-family: var(--font-heading);
  color: var(--cyan);
  margin: 0 0 12px;
}

.aquarium-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.aquarium-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: var(--transition);
}

.aquarium-card:hover:not(:disabled),
.aquarium-card:focus-visible:not(:disabled) {
  border-color: var(--cyan);
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.aquarium-card.active {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 1px var(--gold);
}

.aquarium-card.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.aquarium-info span {
  display: block;
}

.aquarium-name {
  font-weight: 700;
  color: var(--text-primary);
}

.aquarium-bonus {
  font-size: 0.8rem;
  color: var(--gold);
}

.aquarium-lock {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.modal {
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(2, 6, 18, 0.96);
  backdrop-filter: blur(16px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.modal-content {
  background: var(--bg-surface);
  padding: 32px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.06);
  min-width: 320px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.modal-content .game-logo {
  max-width: 100%;
  height: auto;
  margin-bottom: 16px;
  filter: drop-shadow(0 0 12px var(--cyan-glow));
}

.modal-content h2 {
  font-family: var(--font-heading);
  color: var(--text-primary);
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.input-group {
  margin-bottom: 20px;
  text-align: left;
}

.input-group label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  font-size: 1rem;
  background: rgba(0, 0, 0, 0.25);
  color: var(--text-primary);
  transition: var(--transition);
}

.input-group input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-glow);
  background: rgba(0, 0, 0, 0.35);
}

#startGame,
#playAgainBtn {
  background: var(--gold);
  color: #000;
  padding: 13px 28px;
  border-radius: var(--radius-md);
  border: none;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 8px 20px -4px var(--gold-glow);
  font-family: var(--font-heading);
  letter-spacing: 0.03em;
  text-transform: uppercase;
  width: 100%;
}

#startGame:hover,
#startGame:focus-visible,
#playAgainBtn:hover,
#playAgainBtn:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px -4px var(--gold-glow);
  filter: brightness(1.1);
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.summary-stats {
  background: rgba(0, 0, 0, 0.25);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 16px 0;
  text-align: left;
}

.summary-stats p {
  margin: 8px 0;
  color: var(--text-secondary);
}

.summary-stats span:last-child {
  color: var(--text-primary);
  font-weight: 700;
}

.bottom-ad {
  width: 100%;
}

@media (max-width: 640px) {
  :root {
    --ff-panel-width: 100vw;
  }

  .game-container {
    padding: 12px;
  }

  .header h1 {
    font-size: 1.15rem;
  }

  .stats {
    font-size: 0.85rem;
    justify-content: center;
  }

  .shop-panel {
    border-left: none;
  }

  .shop-content {
    padding: 16px;
  }
}

@media (max-width: 380px) {
  .stats {
    flex-direction: column;
    align-items: center;
    gap: 6px;
  }

  .control-btn {
    padding: 10px 14px;
    min-width: 90px;
    font-size: 0.9rem;
  }
}
