/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Courier New', monospace;
  background: #0a0a0a;
  color: #e0e0e0;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
}
#app { width: 100%; height: 100vh; position: relative; }
.hidden { display: none !important; }
button {
  font-family: inherit;
  background: #1a1a2e;
  color: #e0e0e0;
  border: 1px solid #4a4a6a;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 0;
}
button:hover { background: #2a2a4e; border-color: #6a6a9a; }
button:active { background: #3a3a5e; }

/* ===== LOADING SCREEN ===== */
#loading-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #000;
  z-index: 1000;
  transition: opacity 0.5s;
}
.loading-content { text-align: center; }
.loading-content h1 {
  font-size: 48px; color: #ff6b35;
  text-shadow: 0 0 20px rgba(255,107,53,0.5);
  margin-bottom: 20px;
  letter-spacing: 0;
}
.loading-text { color: #888; margin-bottom: 15px; }
.loading-bar {
  width: 300px; height: 4px;
  background: #1a1a2e; border-radius: 2px; overflow: hidden;
}
.loading-fill {
  width: 0; height: 100%;
  background: linear-gradient(90deg, #ff6b35, #ffd700);
  animation: loading 2s ease-in-out forwards;
}
@keyframes loading { to { width: 100%; } }

/* ===== MAIN MENU ===== */
#main-menu {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
.menu-background {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, #0a0a1a 0%, #1a0a0a 50%, #0a0a1a 100%);
}
.menu-content { position: relative; text-align: center; z-index: 1; }
.menu-content h1 {
  font-size: 56px; color: #ff6b35;
  text-shadow: 0 0 30px rgba(255,107,53,0.5), 0 2px 4px rgba(0,0,0,0.8);
  letter-spacing: 0; margin-bottom: 8px;
}
.subtitle {
  color: #888; font-size: 14px; margin-bottom: 40px;
  letter-spacing: 0;
}
.menu-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.menu-buttons button {
  width: 280px; padding: 14px; font-size: 16px;
  background: transparent; border: 1px solid #4a4a6a;
  letter-spacing: 0;
}
.menu-buttons button:hover {
  background: rgba(255,107,53,0.1);
  border-color: #ff6b35; color: #ff6b35;
}
.language-select {
  margin-top: 30px; color: #666; font-size: 12px;
}
.language-select select {
  background: #1a1a2e; color: #e0e0e0;
  border: 1px solid #4a4a6a; padding: 4px 8px;
  font-family: inherit; margin-left: 8px;
}

/* ===== GENERIC SCREEN ===== */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #0a0a1a, #1a0a0a);
  z-index: 100;
}
.screen-panel {
  background: rgba(10,10,26,0.95);
  border: 1px solid #4a4a6a; padding: 30px;
  max-width: 500px; width: 90%;
  text-align: center;
}
.screen-panel h2 {
  color: #ff6b35; margin-bottom: 20px;
  letter-spacing: 0;
}
.screen-panel p { margin-bottom: 15px; line-height: 1.6; color: #aaa; }
.screen-panel button { margin-top: 10px; }

/* Settings */
.setting-row { margin: 15px 0; display: flex; justify-content: center; gap: 10px; align-items: center; }
.setting-row select { background: #1a1a2e; color: #e0e0e0; border: 1px solid #4a4a6a; padding: 4px 8px; font-family: inherit; }

/* About */
.about-panel p { text-align: left; }

/* Save Slots */
#save-slots { margin: 15px 0; }
.save-slot {
  padding: 10px; margin: 5px 0;
  background: #1a1a2e; border: 1px solid #333;
  cursor: pointer; text-align: left;
}
.save-slot:hover { border-color: #ff6b35; }
.save-slot.empty { color: #666; font-style: italic; }

/* ===== GAME HUD ===== */
#game-hud {
  display: flex; flex-direction: column;
  height: 100vh; width: 100vw;
}

/* Top Bar */
#top-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 16px;
  background: #0d0d1a;
  border-bottom: 1px solid #2a2a4a;
  font-size: 13px; text-transform: uppercase; letter-spacing: 0;
  min-height: 36px;
}
#location-name { color: #ff6b35; font-weight: bold; flex: 1; }
#game-time { color: #888; margin: 0 15px; }
#party-credits { color: #ffd700; margin-right: 15px; }
#controls-hint { color: #555; font-size: 11px; margin-right: 10px; letter-spacing: 0; }
.hud-buttons { display: flex; gap: 6px; }
.hud-buttons button {
  padding: 4px 12px; font-size: 11px;
  background: #1a1a2e; border: 1px solid #3a3a5a;
}

/* Game Area */
#game-area {
  display: flex; flex: 1; overflow: hidden;
}
#game-canvas {
  flex: 1; background: #111; image-rendering: pixelated;
}

/* Side Panel */
#side-panel {
  width: 220px; background: #0d0d1a;
  border-left: 1px solid #2a2a4a;
  overflow-y: auto;
}
#party-header h3 {
  padding: 10px; text-align: center;
  color: #ff6b35; font-size: 13px; letter-spacing: 0;
  border-bottom: 1px solid #2a2a4a;
}
.party-member {
  padding: 8px 10px; border-bottom: 1px solid #1a1a2e;
  cursor: pointer; transition: background 0.2s;
}
.party-member:hover { background: #1a1a2e; }
.party-member .name { color: #fff; font-size: 13px; }
.party-member .title { color: #888; font-size: 11px; }
.party-member .stats { font-size: 11px; color: #666; margin-top: 2px; }
.health-bar-wrap {
  height: 4px; background: #1a1a2e; border-radius: 2px; margin-top: 4px;
}
.health-bar-fill {
  height: 100%; background: linear-gradient(90deg, #ff4444, #44ff44);
  border-radius: 2px; transition: width 0.3s;
}
.stamina-bar-fill { background: linear-gradient(90deg, #ffaa00, #44ff44); }

/* Message Log */
#message-log {
  height: 80px; background: #0a0a0a;
  border-top: 1px solid #2a2a4a;
  overflow-y: auto; padding: 6px 12px;
}
#message-log p {
  font-size: 12px; color: #aaa; line-height: 1.4;
  margin: 2px 0;
}
#message-log p.log-combat { color: #ff6b35; }
#message-log p.log-loot { color: #ffd700; }
#message-log p.log-info { color: #6baaff; }
#message-log p.log-danger { color: #ff4444; }

/* ===== MODALS ===== */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-content {
  background: #0d0d1a;
  border: 1px solid #4a4a6a;
  max-width: 600px; width: 90%; max-height: 80vh;
  overflow-y: auto; padding: 20px;
}

/* Dialogue */
.dialogue-content { max-width: 650px; }
#dialogue-speaker {
  font-size: 18px; color: #ff6b35; margin-bottom: 15px;
  font-weight: bold;
}
#dialogue-text {
  font-size: 15px; line-height: 1.7; color: #ddd;
  margin-bottom: 20px; min-height: 60px;
}
#dialogue-options button {
  display: block; width: 100%; text-align: left;
  margin: 6px 0; padding: 10px 14px;
  background: #1a1a2e; border: 1px solid #333;
  font-size: 14px;
}
#dialogue-options button:hover { border-color: #ff6b35; }
#dialogue-next {
  display: block; margin: 15px auto 0;
}
#dialogue-exit {
  display: block; margin: 15px auto 0;
  background: transparent;
  border-color: #663333;
  color: #ff6666;
  font-size: 12px;
  padding: 6px 16px;
}
#dialogue-exit:hover {
  background: rgba(255,50,50,0.1);
  border-color: #ff4444;
}
.dialogue-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 10px;
}
.dialogue-actions button {
  margin: 0;
}

/* Shop */
.shop-content { max-width: 550px; }
#shop-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 15px;
}
#shop-title { color: #ff6b35; }
#shop-credits { color: #ffd700; }
#shop-tabs { margin-bottom: 10px; }
#shop-tabs .tab-btn {
  padding: 6px 14px; font-size: 12px; margin-right: 4px;
  background: #1a1a2e; border: 1px solid #333;
}
#shop-tabs .tab-btn.active { border-color: #ff6b35; color: #ff6b35; }
.shop-item {
  display: flex; justify-content: space-between;
  padding: 8px; margin: 4px 0;
  background: #1a1a2e; border: 1px solid #2a2a4a;
  cursor: pointer;
}
.shop-item:hover { border-color: #4a4a6a; }
.shop-item .item-name { color: #fff; }
.shop-item .item-price { color: #ffd700; }
.shop-item .item-desc { color: #888; font-size: 11px; }

/* Combat */
.combat-content { max-width: 700px; }
#combat-area { display: flex; gap: 15px; margin: 10px 0; }
#combat-party, #combat-enemies { flex: 1; }
.combat-unit {
  padding: 8px; margin: 4px 0;
  background: #1a1a2e; border: 1px solid #333;
}
.combat-unit .name { color: #fff; }
.combat-unit .hp { color: #44ff44; font-size: 12px; }
#combat-log {
  height: 80px; overflow-y: auto;
  background: #0a0a0a; border: 1px solid #333;
  padding: 6px; margin: 10px 0; font-size: 12px;
  color: #aaa;
}
#combat-actions { display: flex; gap: 6px; justify-content: center; }
#combat-actions button { padding: 8px 16px; }

/* Menu Modal */
.menu-modal-content button {
  display: block; width: 100%; text-align: center;
  margin: 6px 0; padding: 12px;
}
.travel-option {
  padding: 10px; margin: 6px 0;
  background: #1a1a2e; border: 1px solid #333;
  cursor: pointer;
}
.travel-option:hover { border-color: #ff6b35; }
.travel-option .city-name { color: #fff; font-weight: bold; }
.travel-option .city-desc { color: #888; font-size: 12px; }
.travel-option .city-dist { color: #ffd700; font-size: 11px; }

/* Notification */
#notification {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.9); border: 1px solid #ff6b35;
  padding: 12px 24px; z-index: 300;
  text-align: center; font-size: 14px;
  animation: notifIn 0.3s ease-out;
}
@keyframes notifIn {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== CHARACTER SCREEN ===== */
#char-screen {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.95); z-index: 250;
  display: flex; flex-direction: column; padding: 20px;
}
#char-screen h2 { color: #ff6b35; text-align: center; margin-bottom: 15px; }
.char-list { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.char-card {
  background: #1a1a2e; border: 1px solid #333;
  padding: 15px; width: 280px;
}
.char-card .name { color: #fff; font-size: 16px; font-weight: bold; }
.char-card .title { color: #888; font-size: 12px; margin-bottom: 8px; }
.char-card .attr-row { display: flex; justify-content: space-between; font-size: 12px; padding: 2px 0; color: #aaa; }
.char-card .attr-row .val { color: #ffd700; }
.char-card.sel { border-color: #ff6b35; box-shadow: 0 0 10px rgba(255,107,53,0.2); }
.char-card.dead { opacity: 0.6; border-color: #660000; }
.char-card.dead .name { color: #ff4444; }
.char-close { margin-top: 15px; align-self: center; padding: 10px 30px; }
.small-btn {
  font-size: 10px; padding: 3px 8px;
  background: transparent; border: 1px solid #555;
  color: #aaa; cursor: pointer;
}
.small-btn:hover { border-color: #ff6b35; color: #ff6b35; }
.health-bar-fill.dead { background: #660000; }
.inv-mini { border-top: 1px solid #222; margin-top: 4px; padding-top: 2px; }

/* ===== INVENTORY SCREEN ===== */
#inv-screen {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.95); z-index: 250;
  display: flex; flex-direction: column; padding: 20px;
}
#inv-screen h2 { color: #ff6b35; text-align: center; margin-bottom: 15px; }
.inv-list { max-width: 500px; margin: 0 auto; width: 100%; }
.inv-item {
  display: flex; justify-content: space-between;
  padding: 8px 12px; margin: 3px 0;
  background: #1a1a2e; border: 1px solid #2a2a4a;
}
.inv-item .iname { color: #fff; }
.inv-item .icount { color: #888; }
.inv-close { margin-top: 15px; align-self: center; padding: 10px 30px; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #0a0a0a; }
::-webkit-scrollbar-thumb { background: #3a3a5a; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #5a5a7a; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  #side-panel { width: 150px; }
  .menu-content h1 { font-size: 32px; }
  .menu-buttons button { width: 220px; padding: 10px; }
  #combat-area { flex-direction: column; }
}

/* ===== RECRUITMENT SCREEN ===== */
#recruit-screen {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.95); z-index: 250;
  display: flex; flex-direction: column; padding: 20px;
}
#recruit-screen h2 { color: #ff6b35; text-align: center; margin-bottom: 15px; }
.recruit-list { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.recruit-card {
  background: #1a1a2e; border: 1px solid #333;
  padding: 15px; width: 300px; cursor: pointer;
}
.recruit-card:hover { border-color: #ff6b35; }
.recruit-card .name { color: #fff; font-size: 15px; }
.recruit-card .title { color: #888; font-size: 12px; }
.recruit-card .desc { color: #aaa; font-size: 12px; margin: 6px 0; line-height: 1.5; }
.recruit-card .skills { font-size: 11px; color: #6baaff; }
.recruit-card .cost { color: #ffd700; font-size: 13px; margin-top: 4px; }
.recruit-close { margin-top: 15px; align-self: center; padding: 10px 30px; }

/* ===== DOS / EGA PRESENTATION OVERRIDES ===== */
body {
  background: #000;
  color: #d8d8d8;
}
button {
  background: #0000aa;
  color: #fff;
  border-color: #55ffff;
  border-radius: 0;
}
button:hover {
  background: #000055;
  color: #ffff55;
  border-color: #ffff55;
}
.menu-background,
.screen {
  background:
    repeating-linear-gradient(0deg, rgba(85,255,255,0.05) 0, rgba(85,255,255,0.05) 1px, transparent 1px, transparent 4px),
    #000;
}
.loading-content h1,
.menu-content h1,
.screen-panel h2,
#party-header h3,
#location-name,
#shop-title,
#dialogue-speaker,
#char-screen h2,
#inv-screen h2,
#recruit-screen h2,
#map-screen h2,
#legend-screen h2 {
  color: #ffff55;
  text-shadow: none;
}
.menu-content h1 {
  text-shadow: 4px 4px 0 #aa0000;
}
.screen-panel,
.modal-content,
.char-card,
.recruit-card {
  background: #000;
  border: 2px solid #55ffff;
}
#top-bar,
#side-panel,
#message-log {
  background: #000;
  border-color: #55ffff;
}
#top-bar {
  background: #0000aa;
}
#game-canvas {
  background: #000;
}
.party-member,
.combat-unit,
.shop-item,
.inv-item,
.travel-option,
.save-slot {
  background: #000055;
  border-color: #5555ff;
}
.party-member.selected,
.char-card.sel,
.tab-btn.active {
  border-color: #ffff55 !important;
  color: #ffff55;
}

/* ===== AUTO MAP / LEGEND SCREENS ===== */
#map-screen,
#legend-screen {
  position: fixed;
  inset: 0;
  z-index: 260;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
}
#map-screen h2,
#legend-screen h2 {
  margin-bottom: 12px;
}
#full-map-canvas {
  width: min(92vw, 720px);
  height: min(68vh, 460px);
  border: 2px solid #55ffff;
  background: #000;
  image-rendering: pixelated;
}
.map-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
  justify-content: center;
}
.legend-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 6px 18px;
  width: min(720px, 92vw);
  border: 2px solid #55ffff;
  padding: 16px;
  background: #000055;
}
.legend-row {
  display: grid;
  grid-template-columns: 32px 1fr;
  align-items: center;
  min-height: 28px;
  color: #fff;
}
.legend-row span {
  color: #ffff55;
  font-weight: bold;
}
.legend-row em {
  font-style: normal;
  color: #d8d8d8;
}
.legend-close {
  margin-top: 14px;
}

/* ===== TACTICAL COMBAT ===== */
.combat-content {
  max-width: 820px;
}
#combat-area {
  display: block;
}
#combat-battlefield {
  display: grid;
  grid-template-columns: repeat(8, 34px);
  grid-template-rows: repeat(6, 34px);
  gap: 2px;
  justify-content: center;
  margin: 8px auto 12px;
  padding: 8px;
  border: 2px solid #55ffff;
  background: #000;
  width: max-content;
}
.combat-cell {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #2222aa;
  background: #050505;
  color: #777;
  font-weight: bold;
}
.combat-cell.party {
  color: #55ff55;
  border-color: #55ff55;
}
.combat-cell.enemy {
  color: #ff5555;
  border-color: #ff5555;
}
.combat-cell.active {
  background: #555500;
  color: #ffff55;
}
.combat-rosters {
  display: flex;
  gap: 15px;
}
.combat-rosters > div {
  flex: 1;
}

@media (max-width: 768px) {
  #side-panel { width: 170px; }
  #combat-battlefield {
    grid-template-columns: repeat(8, 28px);
    grid-template-rows: repeat(6, 28px);
  }
  .combat-cell {
    width: 28px;
    height: 28px;
  }
  .combat-rosters,
  .legend-grid {
    grid-template-columns: 1fr;
    flex-direction: column;
  }
  #controls-hint {
    display: none;
  }
}
