/* ===== RESET & BASE ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0a0a1a;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #e0e0e0;
}

#root {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== SCREENS ===== */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.screen.active {
  display: flex;
}

/* ===== TITLE SCREEN ===== */
#title-screen {
  background: radial-gradient(ellipse at center, #1a1a3e 0%, #0a0a1a 70%);
  position: relative;
  overflow: hidden;
}

.title-particles {
  position: absolute;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.particle {
  position: absolute;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #7c5cbf;
  animation: float-particle linear infinite;
  opacity: 0;
}

@keyframes float-particle {
  0%   { transform: translateY(100vh) translateX(0); opacity: 0; }
  10%  { opacity: 0.8; }
  90%  { opacity: 0.6; }
  100% { transform: translateY(-10vh) translateX(30px); opacity: 0; }
}

.title-content {
  z-index: 1;
  text-align: center;
  padding: 20px;
}

.game-title {
  font-size: clamp(2.5rem, 8vw, 4.5rem);
  font-weight: 900;
  letter-spacing: 0.05em;
  background: linear-gradient(135deg, #a78bfa, #60a5fa, #34d399);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  margin-bottom: 6px;
  animation: title-glow 3s ease-in-out infinite;
}

@keyframes title-glow {
  0%, 100% { filter: brightness(1); }
  50%       { filter: brightness(1.3); }
}

.game-subtitle {
  font-size: clamp(0.85rem, 2.5vw, 1.1rem);
  color: #8892b0;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-bottom: 50px;
}

.btn-primary {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  color: white;
  border: none;
  padding: 16px 48px;
  font-size: 1.2rem;
  font-weight: 700;
  border-radius: 50px;
  cursor: pointer;
  letter-spacing: 0.08em;
  transition: all 0.2s;
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.5);
  position: relative;
  overflow: hidden;
}

.btn-primary::before {
  content: '';
  position: absolute;
  top: 0; left: -100%;
  width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.4s;
}

.btn-primary:hover::before { left: 100%; }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 30px rgba(124, 58, 237, 0.7); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: transparent;
  color: #8892b0;
  border: 1px solid #334155;
  padding: 10px 32px;
  font-size: 0.9rem;
  border-radius: 50px;
  cursor: pointer;
  margin-top: 12px;
  transition: all 0.2s;
}
.btn-secondary:hover { color: #e0e0e0; border-color: #7c5cbf; }

.high-score-display {
  margin-top: 30px;
  font-size: 0.85rem;
  color: #64748b;
}
.high-score-display span {
  color: #f59e0b;
  font-weight: 700;
}

.title-preview {
  display: flex;
  gap: 8px;
  margin-bottom: 40px;
  font-size: 1.8rem;
}
.title-tile {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  animation: tile-bounce 1.5s ease-in-out infinite;
}
.title-tile:nth-child(2) { animation-delay: 0.1s; }
.title-tile:nth-child(3) { animation-delay: 0.2s; }
.title-tile:nth-child(4) { animation-delay: 0.3s; }
.title-tile:nth-child(5) { animation-delay: 0.4s; }

@keyframes tile-bounce {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}

/* ===== GAME SCREEN ===== */
#game-screen {
  background: #0a0a1a;
  flex-direction: column;
  gap: 0;
  padding: 0;
}

/* HUD */
.hud {
  width: 100%;
  max-width: 480px;
  padding: 10px 16px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,0.5);
  border-bottom: 1px solid #1e293b;
  flex-shrink: 0;
}

.hud-left { display: flex; flex-direction: column; gap: 4px; }
.hud-floor {
  font-size: 0.75rem;
  color: #64748b;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.hud-floor span { color: #a78bfa; font-weight: 700; font-size: 0.9rem; }

.hud-hp-bar-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}
.hud-hp-label { font-size: 0.7rem; color: #ef4444; }
.hud-hp-bar {
  width: 100px;
  height: 8px;
  background: #1e293b;
  border-radius: 4px;
  overflow: hidden;
}
.hud-hp-fill {
  height: 100%;
  background: linear-gradient(90deg, #ef4444, #f97316);
  border-radius: 4px;
  transition: width 0.3s ease;
}
.hud-hp-text {
  font-size: 0.75rem;
  color: #ef4444;
  font-weight: 700;
  min-width: 36px;
}

.hud-center { text-align: center; }
.hud-score {
  font-size: 1.4rem;
  font-weight: 900;
  color: #f59e0b;
  font-variant-numeric: tabular-nums;
}
.hud-score-label { font-size: 0.65rem; color: #64748b; text-transform: uppercase; }

.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.hud-items {
  display: flex;
  gap: 4px;
}
.item-slot {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: #1e293b;
  border: 1px solid #334155;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}
.item-slot:hover { border-color: #7c5cbf; background: #2d2060; }
.item-slot.empty { opacity: 0.3; }
.item-slot.active { border-color: #f59e0b; box-shadow: 0 0 8px rgba(245,158,11,0.5); }
.item-count {
  position: absolute;
  bottom: -2px;
  right: -2px;
  background: #7c3aed;
  color: white;
  font-size: 0.55rem;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.hud-turn {
  font-size: 0.7rem;
  color: #475569;
}

/* MAP AREA */
.map-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  width: 100%;
  max-width: 480px;
  position: relative;
}

#game-canvas {
  display: block;
  image-rendering: pixelated;
  touch-action: none;
}

/* Message overlay */
.message-overlay {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.85);
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 0.85rem;
  color: #e2e8f0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  white-space: nowrap;
  z-index: 10;
  max-width: 90%;
  text-align: center;
}
.message-overlay.show { opacity: 1; }

/* CONTROLS */
.controls {
  width: 100%;
  max-width: 480px;
  padding: 10px 16px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(0,0,0,0.3);
  border-top: 1px solid #1e293b;
  flex-shrink: 0;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 4px;
}

.dpad-btn {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid #334155;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.3rem;
  transition: all 0.1s;
  color: #94a3b8;
  -webkit-tap-highlight-color: transparent;
}
.dpad-btn:active, .dpad-btn.pressed {
  background: rgba(124, 58, 237, 0.4);
  border-color: #7c5cbf;
  transform: scale(0.92);
  color: #e2e8f0;
}
.dpad-btn.center {
  background: rgba(239, 68, 68, 0.15);
  border-color: #7f1d1d;
  font-size: 0.95rem;
  color: #ef4444;
}
.dpad-btn.center:active {
  background: rgba(239, 68, 68, 0.4);
}

.dpad-corner { background: transparent; border: none; pointer-events: none; }

.controls-hint {
  font-size: 0.65rem;
  color: #334155;
  text-align: center;
}

/* ===== RESULT SCREEN ===== */
#result-screen {
  background: radial-gradient(ellipse at center, #1a1a3e 0%, #0a0a1a 70%);
  padding: 30px 20px;
}

.result-content {
  text-align: center;
  max-width: 340px;
  width: 100%;
}

.result-icon {
  font-size: 4rem;
  margin-bottom: 12px;
  animation: result-pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes result-pop {
  0%   { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.result-title {
  font-size: 2rem;
  font-weight: 900;
  margin-bottom: 6px;
}
.result-title.win  { color: #34d399; }
.result-title.lose { color: #ef4444; }

.result-subtitle {
  color: #64748b;
  font-size: 0.9rem;
  margin-bottom: 30px;
}

.result-stats {
  background: rgba(255,255,255,0.04);
  border: 1px solid #1e293b;
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.stat-label { color: #64748b; font-size: 0.85rem; }
.stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: #e2e8f0;
}
.stat-value.highlight { color: #f59e0b; font-size: 1.2rem; }
.stat-value.new-record {
  color: #f59e0b;
  position: relative;
}
.stat-value.new-record::after {
  content: ' 🏆';
  font-size: 0.8rem;
}

.result-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ===== SKILL EFFECT ===== */
.skill-popup {
  position: fixed;
  pointer-events: none;
  font-weight: 900;
  font-size: 1.1rem;
  z-index: 100;
  animation: skill-float 1.2s ease-out forwards;
}

@keyframes skill-float {
  0%   { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(-60px) scale(1.3); opacity: 0; }
}

.skill-damage { color: #ef4444; }
.skill-heal   { color: #34d399; }
.skill-exp    { color: #f59e0b; }
.skill-item   { color: #a78bfa; }

/* ===== LOADING ===== */
.loading-screen {
  position: fixed;
  inset: 0;
  background: #0a0a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  flex-direction: column;
  gap: 20px;
  transition: opacity 0.5s;
}
.loading-screen.hidden { opacity: 0; pointer-events: none; }

.loader {
  width: 48px;
  height: 48px;
  border: 3px solid #1e293b;
  border-top-color: #7c3aed;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== FLOATING TEXT ===== */
@keyframes float-up {
  0%   { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-50px) scale(1.2); }
}

/* ===== RESPONSIVE ===== */
@media (max-height: 600px) {
  .hud { padding: 6px 12px; }
  .controls { padding: 6px 12px 8px; gap: 2px; }
  .dpad-btn { /* size handled by JS */ }
}

/* ===== ITEM TOOLTIP ===== */
.item-tooltip {
  position: absolute;
  background: rgba(10,10,26,0.97);
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.82rem;
  line-height: 1.5;
  z-index: 50;
  pointer-events: none;
  min-width: 160px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}
.item-tooltip .tooltip-name { font-weight: 700; color: #a78bfa; margin-bottom: 4px; }
.item-tooltip .tooltip-desc { color: #94a3b8; }

/* ===== STATUS BAR ===== */
.status-badges {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  max-width: 140px;
  justify-content: flex-end;
}
.status-badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
}
.status-badge.poison   { background: rgba(139,92,246,0.3); color: #a78bfa; border: 1px solid #7c3aed; }
.status-badge.strength { background: rgba(239,68,68,0.3);  color: #f87171; border: 1px solid #ef4444; }
.status-badge.shield   { background: rgba(96,165,250,0.3); color: #93c5fd; border: 1px solid #3b82f6; }
.status-badge.haste    { background: rgba(52,211,153,0.3); color: #6ee7b7; border: 1px solid #10b981; }

/* ===== FLOOR TRANSITION ===== */
.floor-transition {
  position: fixed;
  inset: 0;
  background: #0a0a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.floor-transition.show { opacity: 1; pointer-events: all; }
.floor-transition .floor-num {
  font-size: 3.5rem;
  font-weight: 900;
  background: linear-gradient(135deg, #a78bfa, #60a5fa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.floor-transition .floor-label {
  font-size: 0.85rem;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.2em;
}

/* ===== PWA INSTALL BUTTON ===== */
.btn-pwa {
  background: linear-gradient(135deg, #059669, #10b981);
  color: white;
  border: none;
  padding: 10px 28px;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: 50px;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4);
  animation: pulse-green 2s ease-in-out infinite;
}
.btn-pwa:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(16, 185, 129, 0.6);
}
.btn-pwa:active { transform: translateY(0); }

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 4px 16px rgba(16, 185, 129, 0.4); }
  50%       { box-shadow: 0 4px 24px rgba(16, 185, 129, 0.7); }
}

/* ===== iOS PWA HINT ===== */
.ios-hint {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10,10,26,0.96);
  border: 1px solid #334155;
  border-radius: 14px;
  padding: 14px 20px;
  font-size: 0.82rem;
  color: #e2e8f0;
  z-index: 300;
  text-align: center;
  max-width: 300px;
  line-height: 1.6;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6);
  animation: slide-up 0.4s ease-out;
}
@keyframes slide-up {
  from { transform: translateX(-50%) translateY(20px); opacity: 0; }
  to   { transform: translateX(-50%) translateY(0);    opacity: 1; }
}
.ios-hint-close {
  position: absolute;
  top: 8px; right: 12px;
  background: none; border: none;
  color: #64748b; font-size: 1.1rem; cursor: pointer;
}
.ios-hint .arrow { font-size: 1.4rem; display: block; margin-top: 6px; }
