* { box-sizing: border-box; font-family: sans-serif; }
body { margin: 0; background: #222; color: #eee; }
#hud { padding: 8px; background: #111; font-size: 1.1rem; }
#app { padding: 8px; }

.map-grid {
  display: grid;
  gap: 2px;
}
.map-tile {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  background: #333;
}

.shop-screen, .smith-screen, .start-screen, .quest-board-screen {
  max-width: min(90vw, 720px);
  margin: 0 auto;
}

.overlay-panel.battle-screen {
  max-width: min(92vw, 860px);
  margin: 0 auto;
  display: flex;
  gap: 16px;
  position: relative;
  overflow: hidden;
}
.battle-screen-forest {
  background: linear-gradient(to bottom, rgba(17, 17, 17, 0.97) 0%, rgba(17, 17, 17, 0.97) 62%, rgba(28, 48, 30, 0.9) 100%);
}
.battle-screen-cave {
  background: linear-gradient(to bottom, rgba(17, 17, 17, 0.97) 0%, rgba(17, 17, 17, 0.97) 62%, rgba(46, 42, 36, 0.9) 100%);
}
.battle-combatants-row {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.battle-decoration {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  font-size: 2.5rem;
  line-height: 1;
  opacity: 0.32;
  pointer-events: none;
  z-index: 0;
}
.battle-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  position: relative;
  z-index: 1;
}
.battle-combatant {
  text-align: center;
  position: relative;
}
.battle-emoji {
  font-size: 3rem;
  line-height: 1;
}
.battle-name {
  font-weight: 600;
  margin-top: 4px;
}
.battle-divider {
  font-size: 1.4rem;
  color: #555;
}
.battle-hp-bar {
  width: 200px;
  background: #333;
  border-radius: 4px;
  height: 10px;
  margin: 4px auto 0;
  overflow: hidden;
}
.battle-hp-fill {
  height: 100%;
  background: #c0392b;
  transition: width 0.2s;
}
.battle-hp-fill-hero {
  background: #27ae60;
}
.battle-hp-text {
  font-size: 0.75rem;
  color: #aaa;
  margin-top: 2px;
}
.battle-atb-bar {
  width: 200px;
  background: #222;
  border-radius: 4px;
  height: 6px;
  margin: 4px auto 0;
  overflow: hidden;
  position: relative;
}
.battle-atb-fill {
  height: 100%;
  background: #f1c40f;
  transition: width 0.3s linear;
}
.battle-parry-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 80%;
  width: 20%;
  background: rgba(231, 76, 60, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.battle-atb-bar-windup .battle-parry-zone {
  opacity: 1;
}
.battle-atb-bar-windup .battle-atb-fill {
  background: #e74c3c;
}
.battle-parry-hint {
  font-size: 0.75rem;
  color: #e74c3c;
  min-height: 1.1em;
  margin-top: 2px;
  cursor: pointer;
}
.battle-monster-row {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 18px;
  flex-wrap: wrap;
}
.battle-monster-slot {
  transition: transform 0.15s, opacity 0.15s;
  cursor: pointer;
}
.battle-monster-slot .battle-hp-bar,
.battle-monster-slot .battle-atb-bar {
  width: 110px;
}
.battle-monster-slot-selected {
  transform: scale(1.15);
}
.battle-monster-slot-dim {
  transform: scale(0.85);
  opacity: 0.55;
}
.battle-monster-slot-dead {
  display: none;
}
.battle-buff-indicator {
  font-size: 0.85rem;
  color: #f5b942;
  min-height: 1.2em;
  margin-top: 4px;
}
.battle-timing-meter {
  width: 280px;
  margin: 8px 0;
  opacity: 0.35;
  transition: opacity 0.15s;
}
.battle-timing-meter-active {
  opacity: 1;
}
.battle-timing-track {
  position: relative;
  height: 14px;
  background: #2a2a2a;
  border-radius: 7px;
  overflow: hidden;
}
.battle-timing-sweet-spot {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(74, 222, 128, 0.35);
}
.battle-timing-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 0%;
  background: #f5b942;
  cursor: pointer;
}
.battle-timing-hint {
  font-size: 0.8rem;
  color: #4ade80;
  text-align: center;
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.1s;
}
.battle-timing-hint-visible {
  opacity: 1;
}
.battle-sidebar {
  width: 180px;
  background: #161616;
  border-radius: 6px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
}
.battle-log-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: #888;
  margin-bottom: 6px;
  letter-spacing: 0.05em;
}
.battle-log {
  flex: 1;
  overflow-y: auto;
  font-size: 0.78rem;
  line-height: 1.5;
  color: #ccc;
  max-height: 320px;
}
button {
  margin: 4px;
  padding: 6px 14px;
  font-size: 0.92rem;
  font-family: inherit;
  color: #eee;
  background: #2a2a2a;
  border: 1px solid #555;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
button:hover:not(:disabled) {
  background: #383838;
  border-color: #777;
}
button:active:not(:disabled) {
  background: #202020;
}
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.battle-ability-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.battle-ability-button-combo {
  border-color: #f5b942;
  box-shadow: 0 0 8px rgba(245, 185, 66, 0.6);
}
.battle-ability-button-pressed {
  animation: battle-ability-press 220ms ease-out;
}
@keyframes battle-ability-press {
  0% { transform: scale(1); filter: brightness(1); }
  35% { transform: scale(1.14); filter: brightness(1.6); }
  100% { transform: scale(1); filter: brightness(1); }
}
button:focus-visible {
  outline: 2px solid #4ade80;
  outline-offset: 1px;
}
.shop-row, .smith-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; border-bottom: 1px solid #444;
  gap: 12px;
}
.shop-row-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
}
.slot-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid #444;
}
.slot-name { font-weight: 600; }
.slot-meta { font-size: 0.8rem; color: #aaa; }
.slot-ngplus-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 4px;
  background: #6c3fa1;
  font-size: 0.7rem;
}
.no-slots { color: #888; padding: 12px 0; }
.new-game-row { display: flex; gap: 8px; margin-top: 12px; }
.new-game-row input { flex: 1; padding: 6px; font-size: 1rem; }

.start-screen {
  position: relative;
  min-height: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 0;
  border-radius: 12px;
  overflow: hidden;
}
.start-scene {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  border-radius: 12px;
  background: linear-gradient(to bottom, #2b1f45 0%, #3a2a52 30%, #4a3560 55%, #33402d 78%, #1b2418 100%);
}
.start-scene-monster {
  position: absolute;
  display: inline-block;
  filter: brightness(0.85);
  animation-name: start-scene-float;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}
.start-scene-horizon {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  align-items: flex-end;
  font-size: 2.4rem;
  opacity: 0.55;
  filter: brightness(0.6);
  padding-bottom: 2px;
}
@keyframes start-scene-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.start-panel {
  position: relative;
  z-index: 1;
  width: min(92%, 480px);
  background: rgba(15, 15, 20, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  padding: 20px 24px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.start-title {
  text-align: center;
  margin: 0 0 16px;
  font-size: 2.1rem;
  letter-spacing: 1px;
  text-shadow: 0 1px 0 #6b5a8a, 0 2px 0 #55446f, 0 3px 0 #402f57, 0 5px 10px rgba(0, 0, 0, 0.6);
}

.inventory-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; border-bottom: 1px solid #444;
}
.inventory-empty { color: #888; padding: 6px 0; font-size: 0.85rem; }
.loot-source { color: #888; font-size: 0.8rem; text-align: right; }

.quest-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; border-bottom: 1px solid #444;
}

#overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.4);
}
#overlay.open {
  display: flex;
}

#app.dimmed {
  filter: brightness(0.6);
}

.overlay-panel {
  background: rgba(17, 17, 17, 0.97);
  border: 1px solid #444;
  border-radius: 8px;
  padding: 20px 24px;
  max-width: min(90vw, 720px);
  width: 90%;
}

.message-log-list {
  overflow-y: auto;
  max-height: 55vh;
}
.inventory-scroll-area {
  overflow-y: auto;
  max-height: 55vh;
}
.boss-tier-indicator {
  font-size: 1.3rem;
  letter-spacing: 4px;
  margin: 6px 0;
}
.message-log-entry {
  padding: 4px 0;
  border-bottom: 1px solid #333;
  font-size: 0.85rem;
  line-height: 1.4;
}

.map-tile.visited {
  background: #5c4a35;
}

.battle-monster-emoji {
  font-size: 4rem;
}

.stats-slot {
  padding: 4px 0;
  border-bottom: 1px solid #333;
}

.ngplus-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: #6c3fa1;
  font-size: 0.8rem;
  margin-bottom: 8px;
}

#hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.battle-hit-flash {
  filter: brightness(1.4) sepia(1) saturate(6) hue-rotate(-40deg);
}
@keyframes battle-shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
  100% { transform: translateX(0); }
}
.battle-hit-shake {
  animation: battle-shake 0.2s ease-in-out;
}
.battle-revive-glow {
  animation: battle-revive-pulse 1.1s ease-in-out;
}
@keyframes battle-revive-pulse {
  0% { filter: none; }
  40% { filter: drop-shadow(0 0 10px #4ade80) brightness(1.25); }
  100% { filter: none; }
}
.battle-flee-shrink {
  animation: battle-flee-shrink 0.9s ease-in forwards;
}
@keyframes battle-flee-shrink {
  0% { transform: scale(1) translateX(0); opacity: 1; }
  100% { transform: scale(0.2) translateX(60px); opacity: 0; }
}
.battle-death-spin {
  animation: battle-death-spin 0.9s ease-in forwards;
}
@keyframes battle-death-spin {
  0% { transform: rotate(0deg) scale(1); opacity: 1; }
  100% { transform: rotate(720deg) scale(0); opacity: 0; }
}
.battle-damage-number {
  position: fixed;
  font-size: 1.6rem;
  font-weight: 700;
  color: #ff5555;
  pointer-events: none;
  z-index: 30;
  animation: battle-float-up 1.4s ease-out forwards;
}
.battle-damage-number-crit {
  font-size: 2.6rem;
  color: #ffb020;
  text-shadow: 0 0 6px rgba(255, 176, 32, 0.85), 0 0 14px rgba(255, 120, 0, 0.6);
  animation-name: battle-float-up-crit;
}
@keyframes battle-float-up {
  0% { transform: translate(-50%, 0) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -90px) scale(1); opacity: 0; }
}
@keyframes battle-float-up-crit {
  0% { transform: translate(-50%, 0) scale(1.4); opacity: 1; }
  20% { transform: translate(-50%, -10px) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -110px) scale(1); opacity: 0; }
}
.battle-dialog-shake-crit {
  animation: battle-dialog-shake-crit 0.34s ease-in-out;
}
@keyframes battle-dialog-shake-crit {
  0% { transform: translateX(0); }
  15% { transform: translateX(-10px) rotate(-0.5deg); }
  35% { transform: translateX(9px) rotate(0.5deg); }
  55% { transform: translateX(-7px); }
  75% { transform: translateX(5px); }
  100% { transform: translateX(0); }
}
.battle-decoration-sway-crit {
  animation: battle-decoration-sway-crit 0.34s ease-in-out;
}
@keyframes battle-decoration-sway-crit {
  0% { transform: rotate(0deg); }
  25% { transform: rotate(-3deg); }
  50% { transform: rotate(2.5deg); }
  75% { transform: rotate(-1.5deg); }
  100% { transform: rotate(0deg); }
}

#flavor-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(17, 17, 17, 0.92);
  border: 1px solid #444;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 0.9rem;
  color: #ddd;
  max-width: 90%;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
  z-index: 20;
}
#flavor-banner.visible {
  opacity: 1;
}

#celebration-burst {
  position: fixed;
  top: 40%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-size: 5rem;
  opacity: 0;
  pointer-events: none;
  z-index: 25;
}
#celebration-burst.celebration-burst-play {
  animation: celebration-burst-pop 1.4s ease-out;
}
@keyframes celebration-burst-pop {
  0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
  15% { transform: translate(-50%, -50%) scale(1.3); opacity: 1; }
  30% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 0; }
}
