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

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

body {
  background: #0a0a14;
  color: #e0e0e0;
  font-family: 'Press Start 2P', monospace;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  justify-content: center;
}

#game {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  position: fixed;
  top: 0; left: 0; right: 0;
  overflow: hidden;
  image-rendering: pixelated;
}

/* ========== START SCREEN ========== */
#start-screen {
  position: absolute; inset: 0;
  background: #0a0a14;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 30; gap: 8px; border: 4px solid #1a1a2e;
}
#start-screen.hidden { display: none; }
#start-screen h1 { font-size: 24px; color: #ff6b9d; margin-bottom: 4px; text-shadow: 2px 2px 0 #000; letter-spacing: 2px; }
#start-screen .subtitle { font-size: 10px; color: rgba(255,255,255,0.35); margin-bottom: 48px; letter-spacing: 1px; }
#start-screen .pick-text { font-size: 11px; color: rgba(255,255,255,0.6); margin-bottom: 24px; letter-spacing: 1px; }
#gender-buttons { display: flex; gap: 16px; }
.gender-btn {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 20px 36px; border: 3px solid #2a2a3e; background: #12121e;
  color: rgba(255,255,255,0.8); font-family: 'Press Start 2P', monospace;
  font-size: 12px; cursor: pointer; transition: all 0.15s;
}
.gender-btn:hover { border-color: #ff6b9d; background: rgba(255,107,157,0.08); transform: scale(1.03); }
.gender-avatar { width: 80px; height: 80px; object-fit: contain; }

/* ========== 18+ DISCLAIMER ========== */
#disclaimer-screen {
  position: absolute; inset: 0;
  background: #0a0a14;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 30;
}
#disclaimer-screen.hidden { display: none; }
#disclaimer-box {
  background: #12121e; border: 3px solid #2a2a3e;
  padding: 32px 28px; max-width: 320px; text-align: center;
  font-family: 'Press Start 2P', monospace;
}
.disclaimer-emoji { font-size: 28px; margin-bottom: 12px; }
#disclaimer-box h2 {
  font-size: 14px; color: #ff6b9d; margin-bottom: 16px;
  text-shadow: 1px 1px 0 #000; letter-spacing: 1px;
}
#disclaimer-box p {
  font-size: 9px; color: rgba(255,255,255,0.6); line-height: 1.8;
  margin-bottom: 8px; letter-spacing: 0.5px;
}
#disclaimer-box strong { color: #ff6b9d; }
#disclaimer-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.disclaimer-btn-accept {
  padding: 14px 20px; border: 2px solid #ff6b9d; background: rgba(255,107,157,0.1);
  color: #ff6b9d; font-family: 'Press Start 2P', monospace;
  font-size: 9px; cursor: pointer; transition: all 0.15s;
}
.disclaimer-btn-accept:hover { background: rgba(255,107,157,0.2); transform: scale(1.02); }
.disclaimer-btn-decline {
  padding: 10px 20px; border: 1px solid #2a2a3e; background: transparent;
  color: rgba(255,255,255,0.3); font-family: 'Press Start 2P', monospace;
  font-size: 8px; cursor: pointer; transition: all 0.15s;
}
.disclaimer-btn-decline:hover { color: rgba(255,255,255,0.5); }

/* ========== SCENE BACKGROUND ========== */
#scene-bg {
  position: absolute; inset: 0;
  background: #0a0a14;
  transition: background 1.5s ease;
  z-index: 0;
}

/* ========== AVATAR — below top bar, fills down to input ========== */
#avatar-area {
  position: absolute;
  top: 78px;
  bottom: 52px;
  left: 0; right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 2;
  pointer-events: none;
  overflow: hidden;
}

#npc-body {
  height: 100%;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  object-position: top center;
  image-rendering: pixelated;
  animation: idleNPC 3.5s ease-in-out infinite;
  pointer-events: none;
}

@keyframes idleNPC {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

/* ========== TOP BAR ========== */
#overlay-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px;
  background: rgba(10,10,20,0.8);
  border-bottom: 2px solid #1a1a2e;
  z-index: 10;
}
#level-badge { background: #1a1a2e; padding: 4px 10px; font-size: 10px; color: rgba(255,255,255,0.5); border: 1px solid #2a2a3e; letter-spacing: 1px; }
#music-toggle { background: none; border: none; font-size: 16px; cursor: pointer; padding: 0; opacity: 0.6; transition: opacity 0.15s; }
#music-toggle:hover { opacity: 1; }
#npc-name { font-size: 14px; color: #ff6b9d; text-shadow: 1px 1px 0 #000; }
#money-display { font-size: 11px; color: #4CAF50; letter-spacing: 1px; }
#hearts-row { display: flex; gap: 4px; align-items: center; }
.heart { font-size: 18px; transition: all 0.3s ease; }
.heart.full { color: #ff0000; opacity: 1; }
.heart.empty { color: #ff0000; opacity: 0.2; }

/* ========== NARRATION BOX ========== */
#narration-box {
  position: absolute;
  top: 82px; left: 16px; right: 16px;
  padding: 10px 14px;
  background: rgba(10,10,20,0.85);
  border: 2px solid #FFD700;
  color: #FFD700;
  font-size: 9px;
  line-height: 1.8;
  text-align: center;
  z-index: 15;
  letter-spacing: 0.5px;
  font-style: italic;
  box-shadow: 2px 2px 0 #000;
  transition: opacity 0.5s;
  opacity: 0;
}
#narration-box.visible { opacity: 1; }
#narration-box.hidden { display: none; }

/* ========== CHAT PANEL ========== */
#chat-feed {
  position: absolute;
  bottom: 52px; left: 0; right: 0;
  background: rgba(10,10,20,0.85);
  border-top: 2px solid #1a1a2e;
  display: flex;
  flex-direction: column;
  z-index: 8;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

/* Collapsed: only last NPC message + actions */
#chat-feed.collapsed {
  max-height: 140px;
}

#chat-feed.collapsed .chat-msg {
  display: none;
}
#chat-feed.collapsed .chat-msg.npc.collapsed-visible {
  display: block;
}
#chat-feed.collapsed .chat-msg.action.collapsed-visible {
  display: block;
}

/* Expanded: full chat history */
#chat-feed.expanded {
  max-height: 45vh;
}

#chat-toggle {
  display: flex; align-items: center; justify-content: center;
  padding: 5px 0;
  cursor: pointer;
  color: rgba(255,255,255,0.3);
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  letter-spacing: 1px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
  transition: color 0.15s;
}
#chat-toggle:hover { color: rgba(255,255,255,0.5); }

#chat-messages {
  padding: 6px 12px;
  display: flex; flex-direction: column; gap: 4px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: #2a2a3e; }

/* Chat message bubbles */
.chat-msg {
  max-width: 85%;
  padding: 10px 12px;
  font-size: 10px;
  line-height: 1.6;
  letter-spacing: 0.3px;
  box-shadow: 2px 2px 0 #000;
  margin-bottom: 8px;
}
.chat-msg.npc {
  align-self: flex-start;
  background: rgba(26,26,46,0.9);
  border: 2px solid #ff6b9d;
  color: #fff;
}
.chat-msg.player {
  align-self: flex-end;
  background: rgba(26,26,46,0.9);
  border: 2px solid #3a7bd5;
  color: #fff;
}
.chat-msg.action {
  align-self: center;
  background: rgba(255,215,0,0.08);
  border: 1px solid #FFD700;
  color: #FFD700;
  font-size: 8px;
  padding: 6px 12px;
  box-shadow: 1px 1px 0 #000;
}
.chat-msg .msg-name {
  font-size: 7px;
  color: rgba(255,255,255,0.3);
  margin-bottom: 4px;
  letter-spacing: 0.5px;
}

/* ========== ACTIONS ========== */
#actions-container {
  display: flex; gap: 6px;
  padding: 6px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
}
#actions-container::-webkit-scrollbar { display: none; }
.action-btn {
  flex-shrink: 0;
  padding: 6px 10px;
  border: 2px solid #2a2a3e;
  background: rgba(18,18,30,0.8);
  color: rgba(255,255,255,0.65);
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  box-shadow: 2px 2px 0 #000;
}
.action-btn:hover { border-color: #ff6b9d; background: rgba(255,107,157,0.08); }
.action-btn:disabled { opacity: 0.25; cursor: not-allowed; }

/* ========== INPUT ========== */
#input-area {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  gap: 8px;
  background: rgba(10,10,20,0.9);
  border-top: 2px solid #1a1a2e;
  z-index: 10;
}
#message-input {
  flex: 1; padding: 10px 12px;
  border: 2px solid #2a2a3e; background: #0a0a14;
  color: #e0e0e0; font-family: 'Press Start 2P', monospace;
  font-size: 10px; outline: none; transition: border-color 0.2s; letter-spacing: 0.5px;
}
#message-input:focus { border-color: #ff6b9d; }
#message-input::placeholder { color: rgba(255,255,255,0.15); }
#send-btn {
  width: 42px; height: 42px;
  border: 2px solid #ff6b9d; background: #ff6b9d;
  color: #0a0a14; font-family: 'Press Start 2P', monospace;
  font-size: 14px; cursor: pointer; transition: all 0.15s;
  box-shadow: 2px 2px 0 #000;
}
#send-btn:hover { background: #ff4081; border-color: #ff4081; }
#send-btn:disabled { background: #1a1a2e; border-color: #2a2a3e; color: #2a2a3e; cursor: not-allowed; box-shadow: none; }

/* ========== GAME OVER ========== */
#game-over {
  position: absolute; inset: 0;
  background: rgba(10,10,20,0.95);
  display: flex; align-items: center; justify-content: center;
  z-index: 20; animation: fadeIn 0.5s ease;
}
#game-over.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
#game-over-content { text-align: center; padding: 32px; max-width: 360px; max-height: 90vh; overflow-y: auto; }
#game-over-avatar { width: 100px; height: 150px; object-fit: contain; image-rendering: pixelated; margin: 0 auto 16px auto; display: block; }
#game-over-title { font-size: 16px; margin-bottom: 8px; letter-spacing: 1px; line-height: 1.6; }
#game-over-title.win { color: #ff6b9d; text-shadow: 2px 2px 0 #000; }
#game-over-title.lose { color: #ff4444; text-shadow: 2px 2px 0 #000; }
#game-over-subtitle { font-size: 10px; color: rgba(255,255,255,0.45); margin-bottom: 20px; letter-spacing: 0.5px; line-height: 1.6; }
#game-over-stats {
  display: flex; justify-content: center; gap: 24px;
  margin-bottom: 28px; padding: 12px 0;
  border-top: 2px solid #1a1a2e; border-bottom: 2px solid #1a1a2e;
}
.stat-item { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.stat-icon { font-size: 20px; }
.stat-value { font-size: 11px; color: rgba(255,255,255,0.8); letter-spacing: 0.5px; }
.stat-label { font-size: 7px; color: rgba(255,255,255,0.25); letter-spacing: 0.5px; }
#game-over-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ========== LEADERBOARD ========== */
#leaderboard-section {
  margin-bottom: 16px;
  text-align: center;
}
.lb-rank-notice {
  font-size: 9px;
  color: rgba(255,255,255,0.5);
  margin-top: 8px;
  margin-bottom: 4px;
  letter-spacing: 1px;
}
.lb-rank-notice.lb-rank-gold {
  color: #FFD700;
  text-shadow: 1px 1px 0 #000;
  font-size: 11px;
}
.lb-title {
  font-size: 7px;
  color: rgba(255,255,255,0.4);
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}
.lb-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  font-size: 8px;
  color: rgba(255,255,255,0.5);
}
.lb-row.lb-highlight {
  color: #ff6b9d;
  background: rgba(255,107,157,0.1);
  border-radius: 4px;
}
.lb-row.lb-player-rank {
  color: rgba(255,255,255,0.4);
  border-top: 1px solid rgba(255,255,255,0.1);
  margin-top: 4px;
  padding-top: 6px;
}
.lb-pos {
  min-width: 24px;
  text-align: right;
  color: rgba(255,255,255,0.25);
}
.lb-row.lb-highlight .lb-pos {
  color: #ff6b9d;
}
.lb-row.lb-player-rank .lb-pos {
  color: rgba(255,255,255,0.3);
}
.lb-name {
  min-width: 32px;
  text-align: left;
  letter-spacing: 1px;
}
.lb-msg {
  flex: 1;
  text-align: right;
  font-size: 7px;
}
.lb-time {
  min-width: 24px;
  text-align: right;
  font-size: 7px;
}
.lb-empty {
  font-size: 7px;
  color: rgba(255,255,255,0.2);
}
.lb-name-entry {
  margin-bottom: 12px;
}
.lb-name-label {
  font-size: 7px;
  color: rgba(255,255,255,0.4);
  margin-bottom: 6px;
  letter-spacing: 1px;
}
.lb-name-input-row {
  display: flex;
  justify-content: center;
  gap: 8px;
}
#lb-name-input {
  width: 60px;
  padding: 6px 8px;
  border: 2px solid #2a2a3e;
  background: #0a0a14;
  color: #ff6b9d;
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  text-align: center;
  letter-spacing: 4px;
  text-transform: uppercase;
  outline: none;
}
#lb-name-input:focus { border-color: #ff6b9d; }
.lb-name-btn {
  padding: 6px 12px;
  border: 2px solid #ff6b9d;
  background: #ff6b9d;
  color: #0a0a14;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  cursor: pointer;
  box-shadow: 2px 2px 0 #000;
}
.lb-name-btn:hover { background: #ff4081; border-color: #ff4081; }
#play-again-btn, #next-level-btn {
  padding: 12px 20px; font-family: 'Press Start 2P', monospace;
  font-size: 9px; cursor: pointer; box-shadow: 2px 2px 0 #000; transition: all 0.15s;
}
#play-again-btn { border: 2px solid #2a2a3e; background: #12121e; color: white; }
#play-again-btn:hover { border-color: #ff6b9d; }
#next-level-btn { border: 2px solid #ff6b9d; background: #ff6b9d; color: #0a0a14; }
#next-level-btn:hover { background: #ff4081; border-color: #ff4081; }

/* ========== LEVEL TRANSITION ========== */
#level-transition {
  position: absolute; inset: 0;
  background: #0a0a14;
  display: flex; align-items: center; justify-content: center;
  z-index: 25; opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
#level-transition.active { opacity: 1; pointer-events: all; }
#level-transition-text { font-size: 24px; color: #ff6b9d; text-shadow: 2px 2px 0 #000; letter-spacing: 2px; animation: pulseText 0.8s ease-in-out; }
@keyframes pulseText { 0% { transform: scale(0.8); opacity: 0; } 50% { transform: scale(1.1); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
/* ========== CLOSING MOVE ========== */
#closing-move-panel {
  position: absolute;
  bottom: 56px;
  left: 50%;
  transform: translateX(-50%);
  padding: 14px 18px;
  background: rgba(10,10,20,0.95);
  border: 2px solid #ff6b9d;
  z-index: 12;
  display: none;
  flex-direction: column;
  gap: 8px;
  animation: slideUp 0.3s ease;
  width: auto;
  max-width: 340px;
  min-width: 240px;
  box-shadow: 4px 4px 0 #000;
}
#closing-move-panel.active { display: flex; }
@keyframes slideUp { from { transform: translateX(-50%) translateY(20px); opacity: 0; } to { transform: translateX(-50%) translateY(0); opacity: 1; } }
.closing-move-label {
  text-align: center;
  font-size: 9px;
  color: #FFD700;
  letter-spacing: 2px;
  margin-bottom: 4px;
}
.closing-move-btn {
  padding: 10px 16px;
  border: 2px solid #2a2a3e;
  background: rgba(18,18,30,0.9);
  color: #fff;
  font-family: 'Press Start 2P', monospace;
  font-size: 8px;
  cursor: pointer;
  box-shadow: 2px 2px 0 #000;
  transition: all 0.15s;
  text-align: center;
  white-space: nowrap;
}
.closing-move-btn:hover { border-color: #ff6b9d; background: rgba(255,107,157,0.1); }

/* ========== MOBILE SPECIFIC ========== */
@media (max-width: 600px), (orientation: portrait) {
  #closing-move-panel {
    bottom: auto;
    top: 62%;
    transform: translate(-50%, -50%);
    max-width: 90vw;
    min-width: 0;
    width: 300px;
  }
  @keyframes slideUp { from { transform: translate(-50%, -62%) translateY(20px); opacity: 0; } to { transform: translate(-50%, -62%) translateY(0); opacity: 1; } }
  .closing-move-btn { font-size: 7px; padding: 10px 12px; }
  #avatar-area {
    top: 78px;
    bottom: 52px;
    align-items: flex-start;
    padding-top: 20px;
  }
  #npc-body {
    max-width: 100%;
    transform: scale(1.15);
    transform-origin: top center;
  }
  #avatar-area.avatar-male-area {
    padding-top: 70px;
  }
  #avatar-area.avatar-male-area #npc-body {
    animation: idleNPCMale 3.5s ease-in-out infinite;
  }
  @keyframes idleNPCMale {
    0%, 100% { transform: scale(1.15) translateY(0); }
    50% { transform: scale(1.15) translateY(-3px); }
  }
  #chat-feed {
    bottom: 52px;
    left: 8px; right: 8px;
    background: rgba(10,10,20,0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 8px;
    border: 1px solid rgba(255,107,157,0.2);
  }
  #chat-feed.collapsed { max-height: 240px; }
  #chat-feed.expanded { max-height: 50vh; }
  .chat-msg { font-size: 9px; }
}

/* ========== DESKTOP LANDSCAPE ========== */
@media (min-width: 601px) and (orientation: landscape) {
  #avatar-area {
    top: 78px;
    width: 50%;
    right: 0;
    left: auto;
    bottom: 52px;
  }
  #npc-body {
    max-height: calc(100vh - 120px);
  }
  #avatar-area.avatar-male-area {
    padding-top: 30px;
  }
  #chat-feed {
    left: 0;
    right: auto;
    width: 50%;
    bottom: 52px;
    top: 78px;
    position: absolute;
    max-height: none;
    background: rgba(10,10,20,0.85);
    border-right: 2px solid #1a1a2e;
  }
  #chat-feed.collapsed, #chat-feed.expanded {
    max-height: none;
  }
  #chat-feed.collapsed .chat-msg { display: block; }
  #chat-feed.collapsed .chat-msg.npc.collapsed-visible { display: block; }
  #chat-toggle { display: none; }
  #chat-messages { flex: 1; }
  .chat-msg { font-size: 10px; max-width: 80%; }
  #actions-container { padding: 8px 12px; flex-shrink: 0; }
  .action-btn { font-size: 9px; padding: 8px 14px; }
}
