/* ============================================================
   MONSTER NOMICON — CSS
   Minesweeper-inspired tactical RPG puzzle.
   ============================================================ */

/* --- RESET & BASE --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', 'Consolas', monospace;
  background: #1a1a2e;
  color: #e0e0e0;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  padding: 4px 6px;
}

h1 {
  font-size: 2.8rem;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(180deg, #ffd700 0%, #e94560 60%, #9b59b6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-shadow: none;
  filter: drop-shadow(0 0 12px rgba(233, 69, 96, 0.6)) drop-shadow(0 2px 4px rgba(0,0,0,0.5));
  margin-bottom: 4px;
  letter-spacing: 6px;
}

/* --- CHARACTER SELECT SCREEN --- */
#char-select-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 20px;
}

#char-select-screen h2 {
  color: #ffd700;
  font-size: 1.8rem;
}

.char-cards {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

.char-card {
  background: #16213e;
  border: 2px solid #0f3460;
  border-radius: 14px;
  padding: 28px 24px;
  width: 240px;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
}

.char-card:hover {
  border-color: #e94560;
  transform: translateY(-4px);
  box-shadow: 0 8px 20px rgba(233, 69, 96, 0.3);
}

.char-card .icon { font-size: 3.2rem; margin-bottom: 10px; }
.char-card .name { font-size: 1.4rem; color: #ffd700; font-weight: bold; margin-bottom: 8px; }
.char-card .desc { font-size: 1rem; color: #aaa; line-height: 1.5; }

.char-select-toolbar { margin-top: 8px; }

/* --- GAME SCREEN --- */
#game-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0;
  width: 100%;
  max-width: 810px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* --- HUD --- */
.hud {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 6px 12px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.hud-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hud-bottom {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.hud-label { font-size: 0.95rem; color: #aaa; min-width: 50px; }
.hud-value { font-size: 1.05rem; font-weight: bold; color: #fff; }

/* HP hearts display */
.hp-hearts {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  flex: 1;
  align-items: center;
}
.heart {
  font-size: 1.25rem;
  line-height: 1;
}
.heart.empty {
  opacity: 0.3;
  filter: grayscale(1);
}
.heart-spacer {
  display: inline-block;
  width: 6px;
}

/* HP/EXP bars */
.bar-container {
  flex: 1;
  height: 20px;
  background: #0a0a1a;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  min-width: 100px;
}

.bar-fill {
  height: 100%;
  border-radius: 9px;
  transition: width 0.3s ease;
}

.bar-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.9rem;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 0 3px #000;
  white-space: nowrap;
}

.bar-exp .bar-fill { background: linear-gradient(90deg, #3498db, #2ecc71); }

/* --- BUTTONS --- */
.btn {
  padding: 7px 16px;
  border: 2px solid #0f3460;
  border-radius: 8px;
  background: #16213e;
  color: #e0e0e0;
  font-size: 1rem;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  border-color: #e94560;
  background: #1a1a3e;
}

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

.btn-skill.ready {
  border-color: #ffd700;
  animation: pulse-gold 1.5s infinite;
}

.btn-levelup {
  display: none;
}

.btn-levelup.available {
  display: inline-flex;
  border-color: #2ecc71;
  animation: pulse-green 1.5s infinite;
}

.btn-cancel { border-color: #e94560; color: #e94560; }

.btn-play {
  padding: 10px 30px;
  font-size: 1rem;
  background: #e94560;
  border-color: #e94560;
  color: #fff;
}
.btn-play:hover { background: #ff6b6b; }

@keyframes pulse-gold {
  0%, 100% { box-shadow: 0 0 5px rgba(255, 215, 0, 0.3); }
  50% { box-shadow: 0 0 15px rgba(255, 215, 0, 0.7); }
}

@keyframes pulse-green {
  0%, 100% { box-shadow: 0 0 5px rgba(46, 204, 113, 0.3); }
  50% { box-shadow: 0 0 15px rgba(46, 204, 113, 0.7); }
}

/* --- GRID --- */
.grid-wrapper {
  position: relative;
  padding-left: 24px;
  padding-top: 0;
  min-height: 0;
  display: flex;
  justify-content: center;
  width: 100%;
}

.grid {
  display: grid;
  gap: 2px;
  background: #0a0a1a;
  padding: 2px;
  border-radius: 8px 8px 0 0;
  border: 2px solid #0f3460;
  border-bottom: none;
  width: 100%;
  max-width: calc(100vh - 95px);
  max-width: calc(100dvh - 95px);
}

/* --- TILES --- */
.tile {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.25rem, 3.75vw, 2rem);
  font-weight: bold;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  border: none;
  outline: none;
  min-width: 0;
}

/* Closed tile */
.tile.closed {
  background: #2d3561;
  color: #8888aa;
  box-shadow: inset 0 -2px 0 #1a1a3e, inset 0 2px 0 #3d4571;
}
.tile.closed:hover { background: #3d4571; }

/* Revealed empty */
.tile.revealed {
  background: #16213e;
  cursor: default;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.3);
}

/* Number colors for adjacentHpSum */
.tile.revealed.sum-low { color: #3498db; }       /* 1-5 */
.tile.revealed.sum-mid { color: #2ecc71; }       /* 6-15 */
.tile.revealed.sum-high { color: #e67e22; }      /* 16-99 */
.tile.revealed.sum-extreme { color: #e74c3c; }   /* 100+ (mine adjacent) */

/* Monster (defeated) */
.tile.monster-dead {
  background: #1a1a2e;
  color: #666;
  cursor: default;
  flex-direction: column;
  line-height: 1;
}

/* Power number shown under entity icon */
.tile-power {
  display: block;
  font-size: clamp(0.75rem, 1.9vw, 1.15rem);
  color: #999;
  margin-top: -2px;
}

/* Monster (alive — revealed but not yet fought) */
.tile.monster-alive {
  background: #3d1a1a;
  color: #ff6b6b;
  cursor: pointer;
  flex-direction: column;
  line-height: 1;
  border: 1px solid #e94560;
}
.tile.monster-alive:hover { background: #5c2a2a; }

.tile-power.alive {
  display: block;
  font-size: clamp(0.8rem, 1.9vw, 1.15rem);
  color: #e94560;
  margin-top: -2px;
}

/* Monster (defeated, EXP pending collection) */
.tile.exp-pending {
  cursor: pointer !important;
  background: #1a2a1a !important;
  border: 1px solid #2ecc71;
}
.tile.exp-pending:hover { background: #2a3a2a !important; }

.tile-exp-pending {
  display: block;
  font-size: clamp(0.9rem, 2.25vw, 1.4rem);
  color: #2ecc71;
  font-weight: bold;
  margin-top: -2px;
  animation: pulse-exp 1s infinite;
}

/* Adjacent sum shown on defeated monster tiles */
.tile-sum-small {
  display: block;
  font-size: 0.7rem;
  color: #aaa;
  line-height: 1;
}

@keyframes pulse-exp {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

/* Mine (hit / game over) */
.tile.mine-hit {
  background: #5c1a1a;
  cursor: default;
  flex-direction: column;
  line-height: 1;
}

/* Mine (destroyed by skill) */
.tile.mine-destroyed {
  background: #2a2a1a;
  cursor: default;
}

/* Dragon tile (always visible) */
.tile.dragon {
  background: linear-gradient(135deg, #4a1a5e, #2a1040);
  border: 2px solid #9b59b6;
  cursor: pointer;
  font-size: clamp(1.75rem, 5vw, 2.75rem);
  flex-direction: column;
  line-height: 1;
}
.tile.dragon:hover { border-color: #e94560; }
.tile.dragon.defeated {
  background: linear-gradient(135deg, #1a5e2a, #104020);
  border-color: #2ecc71;
  cursor: default;
}

/* Item on tile */
.tile.has-item { cursor: pointer !important; }
.tile.has-item::after {
  content: '';
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: item-glow 1s infinite;
}
.tile.item-potion::after { background: #e74c3c; }
.tile.item-crystal::after { background: #3498db; }

@keyframes item-glow {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* --- MEMO OVERLAY ON TILES --- */
.tile .memo-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(1rem, 2.8vw, 1.5rem);
  font-weight: bold;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
  text-align: center;
}

.memo-overlay.memo-type-num   { color: #3498db; }
.memo-overlay.memo-type-danger { color: #e74c3c; }
.memo-overlay.memo-type-unknown { color: #3498db; }
.memo-overlay.memo-type-safe  { color: #2ecc71; }
.memo-overlay.memo-type-flag  { color: #ffd700; }

/* --- MEMO POPUP MENU --- */
.memo-popup {
  display: none;
  position: fixed;
  z-index: 200;
  background: #16213e;
  border: 2px solid #0f3460;
  border-radius: 10px;
  padding: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  min-width: 260px;
}

.memo-popup.active { display: block; }

.memo-title {
  font-size: 0.75rem;
  color: #aaa;
  text-align: center;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.memo-section { display: flex; flex-direction: column; gap: 5px; }
.memo-row { display: flex; gap: 4px; justify-content: center; }

.memo-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 2px solid #0f3460;
  border-radius: 6px;
  background: #1a1a3e;
  color: #e0e0e0;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.15s;
  font-weight: bold;
  padding: 0;
}
.memo-btn:hover { border-color: #e94560; background: #2a2a4e; }

.memo-danger { color: #e74c3c; border-color: #e74c3c44; }
.memo-danger:hover { border-color: #e74c3c; }
.memo-safe { color: #2ecc71; border-color: #2ecc7144; }
.memo-safe:hover { border-color: #2ecc71; }
.memo-unknown { color: #3498db; border-color: #3498db44; }
.memo-unknown:hover { border-color: #3498db; }
.memo-flag { color: #ffd700; border-color: #ffd70044; }
.memo-flag:hover { border-color: #ffd700; }
.memo-clear { color: #999; width: auto; padding: 0 16px; }

/* --- ROW BREAKER TARGETING INDICATORS --- */
.row-indicator, .col-indicator {
  position: absolute;
  background: rgba(255, 215, 0, 0.15);
  cursor: pointer;
  transition: background 0.15s;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: #ffd700;
  font-weight: bold;
  border-radius: 4px;
}
.row-indicator:hover, .col-indicator:hover {
  background: rgba(255, 215, 0, 0.4);
}
.row-indicator { width: 24px; }
.col-indicator { height: 24px; }

/* Targeting mode message */
.targeting-msg {
  display: none;
  text-align: center;
  color: #ffd700;
  font-size: 0.8rem;
  padding: 4px;
  background: rgba(255, 215, 0, 0.1);
  border-radius: 6px;
  border: 1px solid rgba(255, 215, 0, 0.3);
}
.targeting-msg.active { display: block; }

/* --- TOOLBAR --- */
.toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: auto;
}


/* --- MODALS --- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active { display: flex; }

.modal {
  background: #16213e;
  border: 2px solid #0f3460;
  border-radius: 16px;
  padding: 30px 40px;
  text-align: center;
  max-width: 400px;
  animation: modal-in 0.3s ease;
}

@keyframes modal-in {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal h2 { font-size: 1.6rem; margin-bottom: 12px; }
.modal .stats { font-size: 0.9rem; color: #aaa; margin-bottom: 16px; line-height: 1.8; }
.modal .stats span { color: #fff; font-weight: bold; }
.modal-hint { font-size: 0.75rem; color: #666; margin-top: 8px; }

.modal-victory h2 { color: #ffd700; }
.modal-defeat h2 { color: #e94560; }
.modal-levelup h2 { color: #2ecc71; }

/* --- HELP MODAL --- */
.modal-help {
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  text-align: left;
}
.modal-help h2 { text-align: center; color: #ffd700; }
.help-content h3 {
  color: #e94560;
  font-size: 0.95rem;
  margin: 14px 0 6px;
}
.help-content p, .help-content li {
  font-size: 0.8rem;
  color: #ccc;
  line-height: 1.6;
}
.help-content ul { padding-left: 20px; margin: 4px 0; }
.help-content strong { color: #fff; }

/* --- SETTINGS MODAL --- */
.modal-settings {
  max-width: 360px;
}
.modal-settings h2 {
  color: #ffd700;
}
.settings-content {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 16px 0;
}
.settings-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.settings-label {
  min-width: 60px;
  font-size: 0.95rem;
  color: #aaa;
  text-align: right;
}
.volume-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: #0a0a1a;
  border-radius: 3px;
  outline: none;
}
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #e94560;
  cursor: pointer;
  border: 2px solid #0f3460;
}
.volume-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #e94560;
  cursor: pointer;
  border: 2px solid #0f3460;
}
.volume-value {
  min-width: 28px;
  text-align: right;
  font-size: 0.85rem;
  color: #666;
}
.settings-row-mute {
  justify-content: center;
  margin-top: 4px;
}
#btn-mute-all {
  min-width: 120px;
}
#btn-mute-all.muted {
  border-color: #e94560;
  color: #e94560;
}

/* --- FLOATING TEXT ANIMATION --- */
@keyframes float-up {
  0% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -25px); }
}

/* --- VFX OVERLAY --- */
#vfx-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 50;
}

/* Damage flash (red) */
@keyframes vfx-damage-flash {
  0%   { background: rgba(233, 69, 96, 0.4); }
  100% { background: transparent; }
}
#vfx-overlay.damage-flash {
  animation: vfx-damage-flash 0.2s ease-out forwards;
}

/* Level up flash (green) */
@keyframes vfx-levelup-flash {
  0%   { background: rgba(46, 204, 113, 0.4); }
  100% { background: transparent; }
}
#vfx-overlay.levelup-flash {
  animation: vfx-levelup-flash 0.3s ease-out forwards;
}

/* Low HP warning vignette */
@keyframes vfx-low-hp-pulse {
  0%, 100% { box-shadow: inset 0 0 60px rgba(233, 69, 96, 0.15); }
  50%      { box-shadow: inset 0 0 100px rgba(233, 69, 96, 0.4); }
}
#vfx-overlay.low-hp-warning {
  animation: vfx-low-hp-pulse 2s ease-in-out infinite;
}

/* Heart pulse when HP low */
@keyframes vfx-heart-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.3); }
}
.hp-hearts.low-hp .heart.full {
  display: inline-block;
  animation: vfx-heart-pulse 0.6s ease-in-out infinite;
}

/* Screen shake */
@keyframes vfx-shake {
  0%, 100% { transform: translate(0, 0); }
  10%      { transform: translate(-6px, -3px); }
  20%      { transform: translate(5px, 2px); }
  30%      { transform: translate(-4px, 4px); }
  40%      { transform: translate(3px, -5px); }
  50%      { transform: translate(-5px, 3px); }
  60%      { transform: translate(4px, -2px); }
  70%      { transform: translate(-3px, 5px); }
  80%      { transform: translate(6px, -4px); }
  90%      { transform: translate(-2px, 2px); }
}
.grid-wrapper.shaking {
  animation: vfx-shake 0.3s ease-out;
}

/* Dragon celebration gold flash */
@keyframes vfx-dragon-celebrate {
  0%   { background: rgba(255, 215, 0, 0.5); }
  50%  { background: rgba(255, 215, 0, 0.15); }
  100% { background: transparent; }
}
#vfx-overlay.dragon-celebrate {
  animation: vfx-dragon-celebrate 0.6s ease-out forwards;
}

/* Confetti particle */
@keyframes vfx-confetti-fall {
  0%   { opacity: 1; transform: translateY(0) rotate(0deg) scale(1); }
  100% { opacity: 0; transform: translateY(100vh) rotate(720deg) scale(0.5); }
}
.confetti-particle {
  position: fixed;
  width: 8px;
  height: 8px;
  pointer-events: none;
  z-index: 55;
  border-radius: 2px;
  animation: vfx-confetti-fall var(--fall-duration, 2s) ease-in forwards;
  animation-delay: var(--fall-delay, 0s);
}

/* Tile flip on reveal */
@keyframes vfx-tile-flip {
  0%   { transform: scaleX(0); opacity: 0.5; }
  50%  { transform: scaleX(0.1); opacity: 0.7; }
  100% { transform: scaleX(1); opacity: 1; }
}
.tile.vfx-flip {
  animation: vfx-tile-flip 0.25s ease-out forwards;
  animation-delay: var(--flip-delay, 0s);
}

/* Combat hit flash on tile */
@keyframes vfx-combat-hit {
  0%   { background: rgba(255, 255, 255, 0.8); box-shadow: 0 0 12px rgba(255, 255, 255, 0.6); }
  100% { background: transparent; box-shadow: none; }
}
.tile.vfx-hit {
  animation: vfx-combat-hit 0.15s ease-out;
}

/* --- CHAR ICON IN HUD --- */
.hud-char-icon {
  font-size: 1.5rem;
  line-height: 1;
}

/* --- RESPONSIVE --- */
@media (max-width: 520px) {
  h1 { font-size: 2rem; letter-spacing: 4px; }
  .char-card { width: 200px; padding: 18px; }
  .hud { padding: 4px 8px; gap: 2px; }
  .grid-wrapper { padding-left: 20px; padding-top: 20px; }
}
