@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

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

html {
  overflow: hidden;
  position: fixed;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

:root {
  --bg: #1a1a2e;
  --panel-bg: #16213e;
  --cell-bg: #2a2a4a;
  --cell-border: #3a3a5a;
  --green: #538d4e;
  --yellow: #b59f3b;
  --gray: #3a3a3c;
  --text: #e0e0e0;
  --accent: #f5a623;
  --coin-gold: #ffd700;
  --red: #e74c3c;
  --purple: #9b59b6;
  --blue: #3498db;
  --font: 'Press Start 2P', monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-overflow-scrolling: auto;
  position: fixed;
}

#game-container {
  display: flex;
  flex-direction: column;
  max-width: 540px;
  width: 100%;
  height: 100%;
  padding: 0;
  position: relative;
  z-index: 10;
  overflow: hidden;
}

/* === TOP INFO BAR === */
#info-panel {
  background: var(--panel-bg);
  border-bottom: 2px solid var(--accent);
  flex-shrink: 0;
  z-index: 100;
}

.info-summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  flex-wrap: nowrap;
  overflow: hidden;
}

.info-chip {
  font-size: 10px;
  padding: 4px 10px;
  border-radius: 5px;
  background: rgba(255,255,255,0.08);
  white-space: nowrap;
  color: var(--text);
  letter-spacing: 0.5px;
}

.coins-chip { color: var(--coin-gold); font-size: 11px; }
.mult-chip { color: var(--accent); }
.score-chip { margin-left: auto; }

.boss-chip {
  font-size: 9px;
  padding: 3px 8px;
  border-radius: 5px;
  background: var(--red);
  color: #fff;
  animation: bossGlow 1s ease-in-out infinite alternate;
  white-space: nowrap;
}

@keyframes bossGlow {
  from { box-shadow: 0 0 4px var(--red); }
  to { box-shadow: 0 0 12px var(--red), 0 0 24px var(--red); }
}

.forfeit-btn {
  background: none;
  border: 1px solid #633;
  color: var(--red);
  font-size: 9px;
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s;
  line-height: 1;
}
.forfeit-btn:hover { background: var(--red); color: #fff; }

.info-toggle-btn {
  background: none;
  border: 1px solid #444;
  color: var(--text);
  font-family: var(--font);
  font-size: 8px;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.2s;
}

.info-toggle-btn:hover { border-color: var(--accent); }
.info-toggle-btn.open { transform: rotate(180deg); }

/* Expanded details */
.info-expanded {
  padding: 8px 12px 12px;
  border-top: 1px solid #333;
  animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.info-details {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 8px;
  padding: 3px 0;
  gap: 12px;
}

.label { color: #888; }
.value { color: var(--text); font-size: 10px; }

/* === RELIC BAR (Slay the Spire style) === */
.relic-bar {
  display: flex;
  gap: 6px;
  padding: 4px 12px 6px;
  flex-wrap: wrap;
  background: rgba(0,0,0,0.2);
  min-height: 0;
}

.relic-bar:empty { display: none; }

.relic {
  width: 32px;
  height: 32px;
  background: var(--panel-bg);
  border: 2px solid var(--purple);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  position: relative;
  transition: all 0.15s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.relic:hover, .relic.active {
  transform: scale(1.15);
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(155, 89, 182, 0.4);
  z-index: 10;
}

.relic-letter {
  border-color: var(--green);
  font-family: var(--font);
  font-size: 12px;
  color: var(--green);
  background: rgba(83, 141, 78, 0.15);
}

.relic-letter:hover, .relic-letter.active {
  border-color: var(--green);
  box-shadow: 0 0 10px rgba(83, 141, 78, 0.4);
}

.relic-tooltip {
  display: none;
  position: fixed;
  background: #1a1a2e;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 8px 12px;
  font-family: var(--font);
  font-size: 9px;
  color: var(--text);
  z-index: 200;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.7);
  line-height: 1.5;
  width: max-content;
  max-width: 220px;
  white-space: normal;
  text-align: center;
}

.relic-tooltip::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: var(--arrow-x, 50%);
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-bottom-color: var(--accent);
}

.relic:hover .relic-tooltip,
.relic.active .relic-tooltip {
  display: block;
  animation: tooltipIn 0.15s ease-out;
}

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

/* === PROGRESS MAP === */
.progress-map {
  background: rgba(0,0,0,0.4);
  border-top: 1px solid #333;
  padding: 10px 4px;
  margin-top: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
}

.progress-nodes {
  display: flex;
  align-items: center;
  gap: 0;
  min-width: max-content;
  padding: 4px 0;
}

.pnode {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 52px;
  position: relative;
}

.pnode-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-family: var(--font);
  border: 2px solid #444;
  background: var(--cell-bg);
  color: #666;
  transition: all 0.2s;
  position: relative;
  z-index: 1;
}

.pnode.completed .pnode-dot {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.pnode.boss .pnode-dot {
  border-color: var(--red);
  background: #3a1a1a;
  color: var(--red);
  font-size: 14px;
}

.pnode.boss.completed .pnode-dot {
  background: var(--red);
  color: #fff;
}

.pnode.current .pnode-dot {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 8px rgba(245, 166, 35, 0.4);
  animation: currentPulse 1.5s ease-in-out infinite alternate;
}

@keyframes currentPulse {
  from { box-shadow: 0 0 4px rgba(245, 166, 35, 0.2); }
  to { box-shadow: 0 0 12px rgba(245, 166, 35, 0.6); }
}

.pnode-word {
  font-size: 8px;
  color: #888;
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: var(--font);
  white-space: nowrap;
}

.pnode.completed .pnode-word { color: var(--green); }

.pnode-guesses {
  font-size: 7px;
  color: #666;
  font-family: var(--font);
}

.pnode-coins {
  font-size: 7px;
  color: var(--coin-gold);
  font-family: var(--font);
}

.pnode-line {
  width: 16px;
  height: 2px;
  background: #333;
  flex-shrink: 0;
  align-self: center;
  margin-bottom: 20px;
}

.pnode.completed + .pnode-line,
.pnode-line.done {
  background: var(--green);
}

/* Progress transition overlay */
.progress-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: rgba(10, 10, 30, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.4s ease-out;
}

.progress-overlay.fade-out {
  animation: fadeOut 0.3s ease-in forwards;
}

.progress-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 24px;
  max-width: 100vw;
  width: 100%;
}

.progress-header {
  font-family: var(--font);
  font-size: 22px;
  color: var(--accent);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 2px;
  animation: popIn 0.5s ease-out;
}

.progress-stats {
  display: flex;
  gap: 24px;
  justify-content: center;
  animation: popIn 0.5s ease-out 0.1s both;
}

.progress-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: var(--font);
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
  gap: 4px;
}

.progress-stat-val {
  font-size: 16px;
  color: #fff;
  letter-spacing: 1px;
}

.progress-overlay-nodes {
  display: flex;
  align-items: center;
  gap: 0;
  min-width: max-content;
  overflow-x: auto;
  max-width: 100%;
  padding: 16px 20px;
  animation: popIn 0.5s ease-out 0.2s both;
}

.progress-overlay-nodes .pnode {
  min-width: 56px;
}

.progress-overlay-nodes .pnode-dot {
  width: 36px;
  height: 36px;
  font-size: 13px;
}

.progress-overlay-nodes .pnode-word {
  font-size: 9px;
}

.progress-overlay-nodes .pnode-guesses,
.progress-overlay-nodes .pnode-coins {
  font-size: 8px;
}

.pnode.just-completed .pnode-dot {
  animation: justCompletedPop 0.6s ease-out 0.4s both;
}

@keyframes justCompletedPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.4); box-shadow: 0 0 20px var(--green); }
  100% { transform: scale(1); box-shadow: 0 0 8px var(--green); }
}

.progress-continue-btn {
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 28px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  animation: popIn 0.5s ease-out 0.5s both;
  transition: transform 0.15s, background 0.15s;
}

.progress-continue-btn:hover {
  transform: scale(1.05);
  background: #ffc04d;
}

@keyframes popIn {
  0% { opacity: 0; transform: translateY(15px) scale(0.95); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

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

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

.map-toggle {
  cursor: pointer;
  user-select: none;
}
.map-toggle:hover {
  color: var(--accent) !important;
}

/* === BOARD AREA === */
#board-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  min-height: 0;
  transition: all 0.5s;
}

/* Boss fight visuals */
#board-area.boss-fight {
  background: none;
}

#board-area.boss-fight .cell {
  border-color: #4a2020;
}

#board-area.boss-fight .cell.active {
  border-color: var(--red);
  box-shadow: 0 0 6px rgba(231,76,60,0.3);
}

#board-area.boss-fight .row-bonus {
  color: var(--red);
}

.boss-banner {
  font-family: var(--font);
  font-size: 10px;
  color: var(--red);
  text-align: center;
  padding: 6px 16px;
  background: rgba(180,30,30,0.15);
  border: 1px solid rgba(231,76,60,0.3);
  border-radius: 6px;
  margin-bottom: 4px;
  animation: bossBannerPulse 2s ease-in-out infinite alternate;
  flex-shrink: 0;
}

.boss-banner .boss-banner-name {
  font-size: 12px;
  display: block;
  margin-bottom: 2px;
}

.boss-banner .boss-banner-rule {
  font-size: 7px;
  color: #c0534a;
}

@keyframes bossBannerPulse {
  from { box-shadow: 0 0 5px rgba(231,76,60,0.1); }
  to { box-shadow: 0 0 15px rgba(231,76,60,0.3); }
}

/* Boss fire particles — behind all game content */
.fire-container {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

/* Base glow along bottom */
.fire-container::before {
  content: '';
  position: absolute;
  bottom: -20px;
  left: -10%;
  width: 120%;
  height: 120px;
  background: radial-gradient(ellipse at 50% 100%, rgba(255, 80, 0, 0.4) 0%, rgba(255, 40, 0, 0.2) 40%, transparent 70%);
  filter: blur(20px);
  animation: fireGlowPulse 1.5s ease-in-out infinite alternate;
}

@keyframes fireGlowPulse {
  0% { opacity: 0.6; transform: scaleY(0.9); }
  100% { opacity: 1; transform: scaleY(1.1); }
}

/* Main flame tongues */
.fire-particle {
  position: absolute;
  bottom: -10px;
  pointer-events: none;
  opacity: 0;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  animation: flameRise ease-out forwards;
}

@keyframes flameRise {
  0% {
    opacity: 0.9;
    transform: translateY(0) translateX(0) scaleX(1) scaleY(1) rotate(0deg);
    filter: blur(1px);
  }
  15% {
    opacity: 1;
    transform: translateY(calc(var(--rise) * 0.15)) translateX(var(--sway1)) scaleX(0.9) scaleY(1.2) rotate(var(--rot1));
    filter: blur(2px);
  }
  40% {
    opacity: 0.8;
    transform: translateY(calc(var(--rise) * 0.4)) translateX(var(--sway2)) scaleX(0.7) scaleY(1.4) rotate(var(--rot2));
    filter: blur(3px);
  }
  70% {
    opacity: 0.35;
    transform: translateY(calc(var(--rise) * 0.7)) translateX(var(--sway3)) scaleX(0.4) scaleY(1.1) rotate(var(--rot3));
    filter: blur(5px);
  }
  100% {
    opacity: 0;
    transform: translateY(var(--rise)) translateX(var(--sway4)) scaleX(0.1) scaleY(0.5) rotate(var(--rot4));
    filter: blur(8px);
  }
}

/* Embers — bright sparks that float up */
.ember {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  animation: emberFloat ease-out forwards;
}

@keyframes emberFloat {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  20% { opacity: 0.9; }
  60% { opacity: 0.5; transform: translate(var(--dx), calc(var(--rise) * 0.6)) scale(0.7); }
  100% { opacity: 0; transform: translate(calc(var(--dx) * 1.5), var(--rise)) scale(0); }
}

/* Smoke wisps */
.smoke-wisp {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle, rgba(80, 80, 80, 0.3), transparent);
  animation: smokeRise ease-out forwards;
}

@keyframes smokeRise {
  0% { opacity: 0; transform: translateY(0) translateX(0) scale(0.5); filter: blur(4px); }
  20% { opacity: 0.2; }
  50% { opacity: 0.15; transform: translateY(calc(var(--rise) * 0.5)) translateX(var(--dx)) scale(1.5); filter: blur(8px); }
  100% { opacity: 0; transform: translateY(var(--rise)) translateX(calc(var(--dx) * 2)) scale(3); filter: blur(15px); }
}

#grid-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  justify-content: center;
  /* Offset the bonus column so cells are visually centered */
  padding-right: clamp(40px, 11vw, 55px);
}

.grid-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.row-bonus {
  width: clamp(40px, 11vw, 55px);
  min-width: 40px;
  text-align: right;
  font-size: clamp(9px, 2.5vw, 12px);
  color: var(--coin-gold);
  padding-right: 8px;
  transition: all 0.3s;
  flex-shrink: 0;
}

.row-bonus.lost {
  color: var(--gray);
  text-decoration: line-through;
  opacity: 0.4;
}

.row-bonus.collected {
  color: var(--green);
  animation: bonusCollect 0.5s ease-out;
}

@keyframes bonusCollect {
  0% { transform: scale(1); }
  50% { transform: scale(1.5); color: var(--coin-gold); }
  100% { transform: scale(1); }
}

.cell {
  /* Dynamic sizing based on --word-length (set via JS) */
  --wl: var(--word-length, 5);
  width: clamp(34px, calc(60vw / var(--wl)), 62px);
  height: clamp(34px, calc(60vw / var(--wl)), 62px);
  border: 2px solid var(--cell-border);
  background: var(--cell-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(14px, calc(28vw / var(--wl)), 26px);
  font-family: var(--font);
  color: var(--text);
  text-transform: uppercase;
  border-radius: 4px;
  transition: border-color 0.1s;
  position: relative;
}

.cell.hint {
  color: rgba(255, 255, 255, 0.25);
  border-color: rgba(155, 89, 182, 0.3);
  font-style: italic;
}

.cell.active { border-color: var(--accent); }

.cell.filled {
  animation: cellPop 0.15s cubic-bezier(0.34, 1.56, 0.64, 1);
  border-color: #666;
}

@keyframes cellPop {
  0% { transform: scale(1) rotate(0deg); }
  30% { transform: scale(1.2) rotate(-2deg); }
  60% { transform: scale(0.95) rotate(1deg); }
  100% { transform: scale(1) rotate(0deg); }
}

.cell.reveal { animation: cellFlip 0.5s ease-in-out; }
.cell.reveal-green { animation: cellFlipGreen 0.6s cubic-bezier(0.34, 1.56, 0.64, 1); }
.cell.reveal-land { animation: cellLand 0.25s ease-out; }

@keyframes cellFlip {
  0% { transform: rotateX(0deg) scale(1); }
  45% { transform: rotateX(90deg) scale(0.9); }
  55% { transform: rotateX(90deg) scale(0.9); }
  100% { transform: rotateX(0deg) scale(1); }
}

@keyframes cellFlipGreen {
  0% { transform: rotateX(0deg) scale(1); }
  40% { transform: rotateX(90deg) scale(0.8); }
  60% { transform: rotateX(0deg) scale(1.2); }
  80% { transform: rotateX(0deg) scale(0.95); }
  100% { transform: rotateX(0deg) scale(1); }
}

@keyframes cellLand {
  0% { transform: scale(1.15); }
  50% { transform: scale(0.92); }
  100% { transform: scale(1); }
}

.cell.green { background: var(--green); border-color: var(--green); }
.cell.yellow { background: var(--yellow); border-color: var(--yellow); }
.cell.gray { background: var(--gray); border-color: var(--gray); }
.cell.green-glow { box-shadow: 0 0 12px var(--green), 0 0 24px var(--green); }

/* Row shake */
.grid-row.shake { animation: rowShake 0.4s ease-in-out; }

@keyframes rowShake {
  0%, 100% { transform: translateX(0); }
  10%, 50%, 90% { transform: translateX(-8px); }
  30%, 70% { transform: translateX(8px); }
}

/* === KEYBOARD === */
#keyboard-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-width: 520px;
  flex-shrink: 0;
  padding: 0 6px 8px;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.key {
  flex: 1;
  max-width: 44px;
  min-height: 52px;
  height: clamp(52px, 12vw, 58px);
  background: #818384;
  border: none;
  border-radius: 6px;
  color: #fff;
  font-family: var(--font);
  font-size: clamp(11px, 3vw, 14px);
  font-weight: bold;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  transition: all 0.1s;
  position: relative;
  padding: 0;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.key:hover { background: #999; }
.key:active { transform: scale(0.95); }

.key.wide { max-width: 65px; flex: 1.5; font-size: clamp(9px, 2.2vw, 12px); }
.key.delete, .key[data-key="⌫"] { font-size: clamp(18px, 5vw, 22px); font-weight: normal; }

.key.green { background: var(--green); color: #fff; }
.key.yellow { background: var(--yellow); color: #fff; }
.key.gray { background: #3a3a3c; color: #888; }

.key-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--accent);
  color: #000;
  font-size: 7px;
  padding: 2px 4px;
  border-radius: 4px;
  font-weight: bold;
  line-height: 1.2;
  z-index: 2;
}

/* === KEY TOOLTIP (long press / hover) === */
.key.tooltip-active {
  z-index: 20;
  transform: scale(1.1);
  border: 1px solid var(--accent);
}

.key-tooltip {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: #1a1a2e;
  border: 1px solid var(--green);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: var(--font);
  font-size: 8px;
  color: var(--text);
  white-space: nowrap;
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0,0,0,0.7);
  line-height: 1.5;
  animation: tooltipIn 0.15s ease-out;
}

.key-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--green);
}

.key-tip-line { color: var(--coin-gold); }
.key-tip-more { color: #888; font-style: italic; }

/* === SCORE POPUPS === */
#popup-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1000;
}

.score-popup {
  position: absolute;
  font-family: var(--font);
  font-size: 14px;
  color: var(--coin-gold);
  text-shadow: 0 0 8px var(--coin-gold), 2px 2px 0 #000;
  pointer-events: none;
  animation: popupFloat 1s ease-out forwards;
  z-index: 1001;
}

.score-popup.big {
  font-size: 20px;
  color: var(--accent);
  text-shadow: 0 0 15px var(--accent), 0 0 30px var(--accent);
}

.score-popup.mega {
  font-size: 28px;
  color: #ff4444;
  text-shadow: 0 0 20px #ff4444, 0 0 40px #ff4444;
}

@keyframes popupFloat {
  0% { opacity: 1; transform: translateY(0) scale(1); }
  20% { transform: translateY(-10px) scale(1.3); }
  100% { opacity: 0; transform: translateY(-60px) scale(0.8); }
}

/* === COIN BURST === */
.coin-particle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: var(--coin-gold);
  border-radius: 50%;
  pointer-events: none;
  animation: coinBurst 0.7s ease-out forwards;
}

@keyframes coinBurst {
  0% { opacity: 1; transform: translate(0, 0) scale(1); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0); }
}

/* === SCREEN SHAKE === */
.screen-shake { animation: screenShake 0.3s ease-in-out; }

@keyframes screenShake {
  0%, 100% { transform: translate(0, 0); }
  10% { transform: translate(-3px, -2px); }
  20% { transform: translate(4px, 1px); }
  30% { transform: translate(-2px, 3px); }
  40% { transform: translate(3px, -1px); }
  50% { transform: translate(-4px, 2px); }
  60% { transform: translate(2px, -3px); }
  70% { transform: translate(-1px, 4px); }
  80% { transform: translate(3px, -2px); }
  90% { transform: translate(-2px, 1px); }
}

/* === SHOP === */
#shop-overlay, #gameover-overlay, #forfeit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}

#leaderboard-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3500;
  padding: 16px;
}

#codex-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 3500;
}

#shop-panel, #gameover-panel {
  background: var(--panel-bg);
  border: 3px solid var(--accent);
  border-radius: 12px;
  padding: 24px 16px;
  text-align: center;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.shop-title, .gameover-title {
  font-size: 20px;
  color: var(--accent);
  margin-bottom: 8px;
  letter-spacing: 4px;
}

.shop-coins {
  font-size: 13px;
  color: var(--coin-gold);
  margin-bottom: 16px;
}

#shop-items {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.shop-card {
  background: var(--cell-bg);
  border: 2px solid #555;
  border-radius: 10px;
  padding: 14px 12px;
  width: 140px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.shop-card:hover {
  border-color: var(--accent);
  transform: scale(1.08);
  box-shadow: 0 0 20px rgba(245, 166, 35, 0.3);
}

.shop-card.sold { opacity: 0.3; pointer-events: none; }
.shop-card.cant-afford { opacity: 0.5; }

.card-icon { font-size: 28px; }
.card-name {
  font-size: 9px;
  color: var(--text);
  text-align: center;
  font-weight: bold;
}
.card-desc {
  font-size: 11px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  color: #aaa;
  text-align: center;
  line-height: 1.4;
}
.card-cost { font-size: 10px; color: var(--coin-gold); margin-top: 4px; }

.card-type {
  font-size: 7px;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

.card-type.letter { background: var(--green); color: #fff; }
.card-type.power { background: var(--purple); color: #fff; }
.card-type.booster { background: var(--blue); color: #fff; }

/* Rarity borders */
.shop-card.rarity-common { border-color: #555; }
.shop-card.rarity-uncommon { border-color: #4a9; }
.shop-card.rarity-rare { border-color: #59f; box-shadow: 0 0 8px rgba(85, 153, 255, 0.2); }
.shop-card.rarity-legendary { border-color: #f5a623; box-shadow: 0 0 12px rgba(245, 166, 35, 0.3); animation: legendaryPulse 2s ease-in-out infinite alternate; }

@keyframes legendaryPulse {
  from { box-shadow: 0 0 8px rgba(245, 166, 35, 0.2); }
  to { box-shadow: 0 0 20px rgba(245, 166, 35, 0.5); }
}

.shop-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
}

.reroll-btn {
  background: #444;
  color: var(--text);
  font-size: 9px;
  margin-right: 8px;
  padding: 8px 16px;
}
.reroll-btn:hover { background: #555; }
.reroll-btn.cant-afford { opacity: 0.4; pointer-events: none; }

.shop-btn {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 10px 24px;
  font-family: var(--font);
  font-size: 11px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.shop-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 20px var(--accent);
}

/* Game Over */
.gameover-word { font-size: 11px; color: var(--red); margin: 12px 0; }
.gameover-word span { color: var(--accent); font-size: 14px; }
.gameover-stats {
  font-size: 10px;
  margin: 12px 0;
  display: flex;
  gap: 24px;
  justify-content: center;
}
.gameover-stats div { color: var(--coin-gold); }

/* Shop enter animation */
.shop-enter {
  animation: shopEnter 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes shopEnter {
  0% { opacity: 0; transform: scale(0.4) translateY(60px) rotate(-3deg); }
  60% { opacity: 1; transform: scale(1.05) translateY(-5px) rotate(0.5deg); }
  80% { transform: scale(0.97) translateY(2px) rotate(0deg); }
  100% { transform: scale(1) translateY(0) rotate(0deg); }
}

/* Shop card slam-in */
.shop-card.card-slam {
  animation: cardSlam 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes cardSlam {
  0% { opacity: 0; transform: scale(0.3) translateY(-40px) rotate(-8deg); }
  50% { opacity: 1; transform: scale(1.1) translateY(4px) rotate(1deg); }
  70% { transform: scale(0.95) translateY(-2px) rotate(-0.5deg); }
  100% { transform: scale(1) translateY(0) rotate(0deg); }
}

/* Reroll dissolve/disintegrate */
.shop-card.card-disintegrate {
  animation: cardDissolve 0.6s ease-out forwards;
  pointer-events: none;
  position: relative;
  overflow: hidden;
}

.shop-card.card-disintegrate::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    135deg,
    transparent 0%,
    rgba(245, 166, 35, 0.4) 30%,
    rgba(245, 166, 35, 0.1) 60%,
    transparent 100%
  );
  animation: dissolveSweep 0.6s ease-out forwards;
}

@keyframes cardDissolve {
  0% {
    transform: scale(1);
    opacity: 1;
    filter: brightness(1) blur(0);
    clip-path: inset(0 0 0 0);
  }
  20% {
    transform: scale(1.03);
    opacity: 1;
    filter: brightness(1.6) blur(0);
  }
  40% {
    filter: brightness(1.2) blur(1px);
    clip-path: inset(0 0 0 0);
  }
  60% {
    filter: brightness(0.8) blur(2px);
    clip-path: polygon(
      0% 0%, 90% 0%, 100% 10%, 85% 30%, 100% 50%,
      80% 70%, 95% 90%, 70% 100%, 0% 100%
    );
    opacity: 0.6;
  }
  80% {
    filter: brightness(0.5) blur(4px);
    clip-path: polygon(
      5% 10%, 60% 0%, 70% 20%, 50% 40%, 65% 60%,
      40% 80%, 55% 100%, 10% 90%
    );
    opacity: 0.3;
    transform: scale(0.9);
  }
  100% {
    filter: brightness(0) blur(8px);
    clip-path: polygon(20% 30%, 40% 20%, 35% 50%, 50% 70%, 25% 60%);
    opacity: 0;
    transform: scale(0.7);
  }
}

@keyframes dissolveSweep {
  0% { opacity: 0; }
  20% { opacity: 1; }
  60% { opacity: 0.5; }
  100% { opacity: 0; }
}

/* Purchase burst — epic shake + explosion */
.shop-card.purchased {
  animation: purchaseBurst 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes purchaseBurst {
  0% { transform: scale(1) rotate(0deg); box-shadow: 0 0 0 transparent; }
  10% { transform: scale(1.3) rotate(-3deg); box-shadow: 0 0 40px var(--coin-gold); }
  20% { transform: scale(1.25) rotate(3deg); box-shadow: 0 0 50px var(--coin-gold), 0 0 80px rgba(245, 166, 35, 0.3); }
  30% { transform: scale(1.3) rotate(-2deg); }
  40% { transform: scale(1.2) rotate(1deg); }
  60% { transform: scale(0.9) rotate(0deg); opacity: 0.6; }
  100% { transform: scale(0.85) rotate(0deg); opacity: 0.2; }
}

/* Shop panel shake when buying */
.shop-shake {
  animation: shopShake 0.4s ease-in-out;
}

@keyframes shopShake {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  10% { transform: translate(-4px, -2px) rotate(-0.5deg); }
  20% { transform: translate(5px, 1px) rotate(0.5deg); }
  30% { transform: translate(-3px, 3px) rotate(-0.3deg); }
  40% { transform: translate(4px, -1px) rotate(0.3deg); }
  50% { transform: translate(-5px, 2px) rotate(-0.5deg); }
  60% { transform: translate(3px, -3px) rotate(0.2deg); }
  70% { transform: translate(-2px, 4px) rotate(-0.2deg); }
  80% { transform: translate(4px, -2px) rotate(0.1deg); }
  90% { transform: translate(-3px, 1px) rotate(0deg); }
}

/* Coins bump */
.coins-bump { animation: coinsBump 0.3s ease-out; }

@keyframes coinsBump {
  0% { transform: scale(1); }
  50% { transform: scale(1.4); color: #fff; }
  100% { transform: scale(1); }
}

/* Debug */
#debug-word {
  font-family: var(--font);
  font-size: 8px;
  color: #444;
  text-transform: uppercase;
  user-select: none;
  pointer-events: none;
}

/* === MENU SCREEN === */
#menu-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  animation: menuFadeIn 0.5s ease-out;
}

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

#menu-panel {
  text-align: center;
  max-width: 400px;
  padding: 30px;
}

.menu-title {
  font-size: 28px;
  color: var(--accent);
  letter-spacing: 4px;
  margin-bottom: 8px;
  text-shadow: 0 0 20px rgba(245, 166, 35, 0.4);
}

.menu-title-boxes {
  display: flex;
  gap: 5px;
  justify-content: center;
  margin-bottom: 10px;
}

.title-box {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font);
  font-size: 20px;
  font-weight: bold;
  color: #fff;
  border-radius: 4px;
  text-transform: uppercase;
  animation: titleBoxPop 0.4s ease-out both;
}

.title-box:nth-child(1) { animation-delay: 0.05s; }
.title-box:nth-child(2) { animation-delay: 0.1s; }
.title-box:nth-child(3) { animation-delay: 0.15s; }
.title-box:nth-child(4) { animation-delay: 0.2s; }
.title-box:nth-child(5) { animation-delay: 0.25s; }
.title-box:nth-child(6) { animation-delay: 0.3s; }
.title-box:nth-child(7) { animation-delay: 0.35s; }
.title-box:nth-child(8) { animation-delay: 0.4s; }

.title-box.green {
  background: var(--green);
  box-shadow: 0 2px 8px rgba(106, 170, 100, 0.5);
}

.title-box.yellow {
  background: var(--yellow);
  box-shadow: 0 2px 8px rgba(201, 180, 88, 0.5);
}

.title-box.dark {
  background: #3a3a4c;
  border: 2px solid #555;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

@keyframes titleBoxPop {
  0% { opacity: 0; transform: scale(0.3) rotateX(90deg); }
  60% { transform: scale(1.1) rotateX(0deg); }
  100% { opacity: 1; transform: scale(1) rotateX(0deg); }
}

@keyframes titlePulse {
  from { text-shadow: 0 0 10px rgba(245, 166, 35, 0.2); }
  to { text-shadow: 0 0 30px rgba(245, 166, 35, 0.6), 0 0 60px rgba(245, 166, 35, 0.2); }
}

.menu-subtitle {
  font-size: 10px;
  color: var(--purple);
  margin-bottom: 24px;
  letter-spacing: 2px;
}

.menu-desc {
  font-size: 8px;
  color: #888;
  margin-bottom: 32px;
  line-height: 2;
}

.menu-btn {
  background: var(--accent);
  color: #000;
  border: none;
  padding: 14px 40px;
  font-family: var(--font);
  font-size: 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 24px;
  display: inline-block;
}

.menu-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 0 30px var(--accent);
}

.menu-auth {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.menu-user {
  font-size: 8px;
  color: var(--coin-gold);
  min-height: 14px;
}

.auth-btn {
  background: none;
  border: 1px solid #555;
  color: var(--text);
  font-family: var(--font);
  font-size: 8px;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  width: 200px;
}

.auth-btn:hover { border-color: var(--accent); }

.google-btn { border-color: #4285f4; color: #4285f4; }
.google-btn:hover { background: rgba(66, 133, 244, 0.15); }

.anon-btn { border-color: #666; color: #888; }
.anon-btn:hover { background: rgba(255,255,255,0.05); }

.auth-btn.hidden { display: none; }

.menu-stats {
  font-size: 7px;
  color: #666;
  margin-bottom: 12px;
  display: flex;
  gap: 16px;
  justify-content: center;
}

.menu-stats .stat-item {
  text-align: center;
}

.menu-stats .stat-val {
  font-size: 11px;
  color: var(--coin-gold);
  display: block;
}

.menu-hint {
  font-size: 7px;
  color: #555;
  line-height: 2;
}

.menu-version {
  font-size: 7px;
  color: #444;
  margin-top: 12px;
  font-family: var(--font);
  letter-spacing: 1px;
  cursor: pointer;
  transition: color 0.2s;
}

.menu-version:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* Changelog */
#changelog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3500;
  padding: 16px;
  animation: fadeIn 0.3s ease-out;
}

.changelog-panel {
  max-height: 80vh;
  max-width: 480px;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.changelog-content {
  text-align: left;
  margin-bottom: 16px;
  overflow-y: auto;
  flex: 1;
  max-height: calc(80vh - 80px);
  padding-right: 8px;
}

.changelog-content::-webkit-scrollbar {
  width: 6px;
}
.changelog-content::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.05);
  border-radius: 3px;
}
.changelog-content::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 3px;
}

.changelog-release {
  margin-bottom: 20px;
}

.changelog-version-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.changelog-ver {
  font-family: var(--font);
  font-size: 13px;
  color: var(--accent);
}

.changelog-date {
  font-size: 9px;
  color: #555;
  font-family: var(--font);
}

.changelog-list {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.changelog-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 10px;
  color: #ccc;
  line-height: 1.4;
}

.changelog-badge {
  font-family: var(--font);
  font-size: 7px;
  padding: 2px 5px;
  border-radius: 3px;
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 1px;
}

.changelog-badge.new {
  background: rgba(106,170,100,0.2);
  color: var(--green);
}

.changelog-badge.fix {
  background: rgba(100,149,237,0.2);
  color: #6495ed;
}

.changelog-badge.change {
  background: rgba(201,180,88,0.2);
  color: var(--yellow);
}

.changelog-badge.remove {
  background: rgba(220,80,80,0.2);
  color: var(--red);
}

.changelog-text {
  font-family: sans-serif;
  font-size: 11px;
}

/* === SEED UI === */
.menu-seed-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
}
.menu-seed-toggle {
  background: none;
  border: 1px dashed #555;
  color: #aaa;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.menu-seed-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.menu-seed-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.menu-seed-input-wrap.hidden { display: none; }
.menu-seed-input {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  background: #1a1a2e;
  border: 2px solid var(--accent);
  color: var(--accent);
  padding: 12px 16px;
  border-radius: 8px;
  width: 180px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 3px;
}
.menu-seed-input::placeholder {
  color: #555;
  font-size: 9px;
  letter-spacing: 0;
}
.menu-seed-clear {
  background: none;
  border: none;
  color: #888;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
}
.menu-seed-clear:hover { color: #ff4444; }

/* Forfeit seed display */
.forfeit-seed {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 12px 0;
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
}
.seed-label { color: #888; }
.seed-value {
  color: var(--accent);
  background: #1a1a2e;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid #444;
  letter-spacing: 3px;
  font-size: 12px;
  min-width: 100px;
  text-align: center;
}
.seed-copy-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  padding: 4px;
}

/* Debug tools */
.debug-tools {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid #333;
}
.debug-btn {
  font-family: var(--font);
  font-size: 8px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid #444;
  background: rgba(255,255,255,0.05);
  color: #888;
  cursor: pointer;
  transition: all 0.2s;
}
.debug-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(255,255,255,0.1);
}

/* === GAME OVER SUMMARY === */
.gameover-summary {
  margin: 16px 0;
  text-align: left;
  max-height: 50vh;
  overflow-y: auto;
}

.summary-section {
  margin-bottom: 12px;
}

.summary-label {
  font-size: 8px;
  color: var(--accent);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

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

.summary-stat {
  text-align: center;
  padding: 8px 12px;
  background: rgba(255,255,255,0.05);
  border-radius: 6px;
  min-width: 80px;
}

.summary-stat-value {
  font-size: 16px;
  color: var(--coin-gold);
  display: block;
  margin-bottom: 4px;
}

.summary-stat-label {
  font-size: 6px;
  color: #888;
  text-transform: uppercase;
}

.summary-relics {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 6px;
}

.summary-relic {
  width: 28px;
  height: 28px;
  background: var(--panel-bg);
  border: 2px solid var(--purple);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.summary-letter-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(83, 141, 78, 0.2);
  border: 1px solid var(--green);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 8px;
  color: var(--green);
  font-family: var(--font);
}

/* Menu nav buttons */
.menu-nav {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-bottom: 12px;
}

.menu-nav-btn {
  background: none;
  border: 1px solid #444;
  color: #888;
  font-family: var(--font);
  font-size: 7px;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}
.menu-nav-btn:hover { border-color: var(--accent); color: var(--text); }

/* Overlay panels (leaderboard, codex) */
.overlay-panel {
  background: var(--panel-bg);
  border: 3px solid var(--accent);
  border-radius: 12px;
  padding: 24px 16px;
  text-align: center;
  max-width: 420px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
}
.panel-title { font-size: 16px; color: var(--accent); margin-bottom: 6px; letter-spacing: 2px; }
.panel-subtitle { font-size: 7px; color: #888; margin-bottom: 14px; }

/* Leaderboard */
.leaderboard-list {
  margin-bottom: 16px;
  text-align: left;
}

.lb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-bottom: 1px solid #2a2a4a;
  font-size: 8px;
}
.lb-row.lb-me { background: rgba(245, 166, 35, 0.1); border-color: var(--accent); }
.lb-rank { width: 20px; color: var(--accent); font-size: 10px; text-align: center; flex-shrink: 0; }
.lb-rank.gold { color: #ffd700; }
.lb-rank.silver { color: #c0c0c0; }
.lb-rank.bronze { color: #cd7f32; }
.lb-name { flex: 1; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { color: var(--coin-gold); font-size: 9px; flex-shrink: 0; }
.lb-round { color: #888; font-size: 7px; flex-shrink: 0; }
.lb-empty { color: #555; font-size: 8px; padding: 20px; text-align: center; }

/* Codex (Full-screen) */
#codex-fullscreen {
  width: 100%;
  height: 100%;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.codex-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 2px solid var(--accent);
  flex-shrink: 0;
}

.codex-title {
  font-size: 14px;
  color: var(--accent);
  letter-spacing: 2px;
}

.codex-close-btn {
  background: none;
  border: 1px solid #633;
  color: var(--red);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font);
}
.codex-close-btn:hover { background: var(--red); color: #fff; }

.codex-tabs {
  display: flex;
  gap: 0;
  flex-shrink: 0;
  border-bottom: 1px solid #333;
  overflow-x: auto;
}

.codex-tab {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: #666;
  font-family: var(--font);
  font-size: 8px;
  padding: 10px 8px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.codex-tab:hover { color: var(--text); }
.codex-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.codex-sections {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  text-align: left;
}

.codex-section {
  margin-bottom: 14px;
}

.codex-section-title {
  font-size: 9px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: 8px;
  padding-bottom: 4px;
  border-bottom: 1px solid #333;
}

.codex-section-count {
  font-size: 7px;
  color: #555;
  float: right;
  font-weight: normal;
}

.codex-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  margin-bottom: 4px;
  transition: all 0.15s;
}

.codex-row.discovered {
  background: rgba(255,255,255,0.03);
}
.codex-row.discovered:hover {
  background: rgba(255,255,255,0.07);
}

.codex-row.undiscovered {
  opacity: 0.25;
}

.codex-row-icon {
  font-size: 18px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--cell-bg);
  border: 2px solid #444;
  border-radius: 6px;
  flex-shrink: 0;
}

.codex-row.undiscovered .codex-row-icon {
  color: transparent;
}

.codex-row-info {
  flex: 1;
  min-width: 0;
}

.codex-row-name {
  font-size: 8px;
  color: var(--text);
  display: block;
}
.codex-row.undiscovered .codex-row-name {
  color: #444;
}
.codex-row.undiscovered .codex-row-name::before { content: '???'; }
.codex-row.undiscovered .codex-row-name > span { display: none; }

.codex-row-desc {
  font-size: 6px;
  color: #666;
  display: block;
  margin-top: 1px;
}
.codex-row.undiscovered .codex-row-desc { visibility: hidden; }

.codex-row-rarity {
  font-size: 5px;
  padding: 2px 5px;
  border-radius: 3px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.codex-row-rarity.common { background: #333; color: #888; }
.codex-row-rarity.uncommon { background: rgba(68,170,153,0.2); color: #4a9; }
.codex-row-rarity.rare { background: rgba(85,153,255,0.2); color: #59f; }
.codex-row-rarity.legendary { background: rgba(245,166,35,0.2); color: var(--accent); }

.codex-rarity-common .codex-row-icon { border-color: #555; }
.codex-rarity-uncommon .codex-row-icon { border-color: #4a9; }
.codex-rarity-rare .codex-row-icon { border-color: #59f; }
.codex-rarity-legendary .codex-row-icon { border-color: var(--accent); }

/* === BOSS INTRO (anime style) === */
#boss-intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 5000;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: bossIntroFadeIn 0.3s ease-out;
}

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

#boss-intro {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Diagonal slash effect */
.boss-intro-slash {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 40%, var(--red) 40%, var(--red) 42%, transparent 42%);
  opacity: 0;
  animation: slashReveal 0.4s 0.3s ease-out forwards;
}

@keyframes slashReveal {
  0% { opacity: 0; transform: translateX(-100%); }
  50% { opacity: 1; transform: translateX(0); }
  100% { opacity: 0.15; transform: translateX(0); }
}

/* Speed lines */
.boss-intro-lines {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.boss-line {
  position: absolute;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(231,76,60,0.6), transparent);
  animation: speedLine 0.6s ease-out forwards;
  opacity: 0;
}

.boss-line-1 { top: 20%; width: 100%; animation-delay: 0.2s; }
.boss-line-2 { top: 45%; width: 80%; left: 10%; animation-delay: 0.35s; }
.boss-line-3 { top: 65%; width: 90%; left: 5%; animation-delay: 0.25s; }
.boss-line-4 { top: 85%; width: 70%; left: 15%; animation-delay: 0.4s; }

@keyframes speedLine {
  0% { opacity: 0; transform: translateX(-100%) scaleX(0.5); }
  30% { opacity: 1; }
  100% { opacity: 0; transform: translateX(100%) scaleX(1); }
}

/* Content */
.boss-intro-content {
  position: relative;
  z-index: 2;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.boss-intro-icon {
  font-size: 60px;
  opacity: 0;
  animation: bossIconSlam 0.5s 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  filter: drop-shadow(0 0 20px rgba(231,76,60,0.8));
}

@keyframes bossIconSlam {
  0% { opacity: 0; transform: scale(3) rotate(-10deg); }
  60% { opacity: 1; transform: scale(0.9) rotate(2deg); }
  80% { transform: scale(1.05) rotate(-1deg); }
  100% { opacity: 1; transform: scale(1) rotate(0deg); }
}

.boss-intro-label {
  font-family: var(--font);
  font-size: 10px;
  color: var(--red);
  letter-spacing: 8px;
  text-transform: uppercase;
  opacity: 0;
  animation: bossTextSlide 0.4s 0.6s ease-out forwards;
}

.boss-intro-name {
  font-family: var(--font);
  font-size: 24px;
  color: #fff;
  text-shadow: 0 0 30px var(--red), 0 0 60px rgba(231,76,60,0.4);
  opacity: 0;
  animation: bossNameReveal 0.5s 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes bossNameReveal {
  0% { opacity: 0; transform: scale(0.5) translateY(20px); letter-spacing: 15px; }
  60% { opacity: 1; transform: scale(1.1) translateY(-5px); }
  100% { opacity: 1; transform: scale(1) translateY(0); letter-spacing: 3px; }
}

.boss-intro-rule {
  font-family: var(--font);
  font-size: 9px;
  color: #c0534a;
  max-width: 280px;
  line-height: 1.8;
  opacity: 0;
  animation: bossTextSlide 0.4s 1.1s ease-out forwards;
}

@keyframes bossTextSlide {
  0% { opacity: 0; transform: translateY(15px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* Background kanji */
.boss-intro-kanji {
  position: absolute;
  font-size: 200px;
  color: rgba(231,76,60,0.06);
  z-index: -1;
  animation: kanjiDrift 3s ease-in-out infinite alternate;
  user-select: none;
  pointer-events: none;
}

@keyframes kanjiDrift {
  from { transform: rotate(-5deg) scale(1); }
  to { transform: rotate(5deg) scale(1.1); }
}

/* Exit transition */
#boss-intro-overlay.boss-intro-exit {
  animation: bossIntroExit 0.6s ease-in forwards;
}

@keyframes bossIntroExit {
  0% { opacity: 1; transform: scale(1); }
  30% { transform: scale(1.02); }
  100% { opacity: 0; transform: scale(0.95) translateY(-20px); }
}

/* Forfeit dialog */
#forfeit-panel {
  background: var(--panel-bg);
  border: 2px solid var(--red);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  max-width: 300px;
}
.forfeit-title { font-size: 14px; color: var(--red); margin-bottom: 8px; }
.forfeit-desc { font-size: 8px; color: #888; margin-bottom: 16px; }
.forfeit-buttons { display: flex; gap: 10px; justify-content: center; }
.forfeit-cancel-btn { background: #444; color: var(--text); }
.forfeit-confirm-btn { background: var(--red); color: #fff; }

/* Player Profile */
#player-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3500;
  padding: 16px;
  animation: fadeIn 0.3s ease-out;
}

.player-panel {
  max-height: 85vh;
  overflow-y: auto;
  max-width: 480px;
  width: 100%;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
}

.player-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  flex-shrink: 0;
}

.player-avatar-placeholder {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid #555;
  background: #222;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.player-name-block {
  text-align: left;
}

.player-name {
  font-family: var(--font);
  font-size: 12px;
  color: #fff;
  margin-bottom: 4px;
}

.player-email {
  font-size: 9px;
  color: #888;
  font-family: monospace;
  word-break: break-all;
}

.player-badge {
  font-size: 8px;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font);
  display: inline-block;
  margin-top: 3px;
}

.player-badge.guest {
  background: #333;
  color: #aaa;
}

.player-badge.google {
  background: #1a472a;
  color: #4caf50;
}

.player-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.player-stat-card {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 10px 6px;
  text-align: center;
}

.player-stat-val {
  font-family: var(--font);
  font-size: 14px;
  color: var(--accent);
  display: block;
  margin-bottom: 4px;
}

.player-stat-label {
  font-size: 8px;
  color: #777;
  font-family: var(--font);
  text-transform: uppercase;
}

.player-section-title {
  font-family: var(--font);
  font-size: 11px;
  color: #aaa;
  margin-bottom: 10px;
  text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  padding-bottom: 6px;
}

.player-history {
  max-height: 250px;
  overflow-y: auto;
  margin-bottom: 16px;
}

.run-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.03);
  border-radius: 6px;
  margin-bottom: 4px;
  border-left: 3px solid var(--accent);
  transition: background 0.15s;
}

.run-entry:hover {
  background: rgba(255,255,255,0.07);
}

.run-rank {
  font-family: var(--font);
  font-size: 10px;
  color: #555;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.run-details {
  flex: 1;
  text-align: left;
  min-width: 0;
}

.run-words {
  font-size: 8px;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
  font-family: monospace;
}

.run-score {
  font-family: var(--font);
  font-size: 10px;
  color: var(--coin-gold);
  flex-shrink: 0;
}

.run-round {
  font-family: var(--font);
  font-size: 9px;
  color: var(--green);
  flex-shrink: 0;
}

.run-date {
  font-size: 8px;
  color: #555;
  flex-shrink: 0;
}

.run-powers {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.run-power-icon {
  font-size: 10px;
}

.player-empty {
  font-size: 9px;
  color: #555;
  padding: 20px;
  text-align: center;
  font-family: var(--font);
}

.player-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.player-logout-btn {
  background: var(--red) !important;
  color: #fff !important;
}

.hidden { display: none !important; }

/* ===========================
   MOBILE RESPONSIVE
   =========================== */
@media (max-width: 480px) {
  .info-chip { font-size: 8px; padding: 3px 6px; }
  .coins-chip { font-size: 9px; }
  .info-summary { gap: 6px; padding: 6px 10px; }

  .row-bonus { font-size: clamp(8px, 2.5vw, 11px); padding-right: 6px; }

  .shop-card { width: 130px; padding: 12px 10px; }
  .card-icon { font-size: 24px; }
  .card-desc { font-size: 10px; }
  .shop-title { font-size: 16px; }

  .score-popup { font-size: 12px; }
  .score-popup.big { font-size: 16px; }
  .score-popup.mega { font-size: 22px; }

  .key-badge { font-size: 6px; top: -5px; right: -4px; padding: 1px 3px; }
}
