/* Charlization — Main Styles */

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { background: #1a1a2e; color: #e0e0e0; font-family: 'Segoe UI', Tahoma, sans-serif; overflow: hidden; height: 100%; }

/* ═══════════════════════════════════════════════════════════════════
   Scene system — only one scene visible at a time
   ═══════════════════════════════════════════════════════════════════ */
.scene { width: 100vw; height: 100vh; height: 100dvh; }

/* ═══════════════════════════════════════════════════════════════════
   Scene: Main Menu — Civ2 Startup Screen
   ═══════════════════════════════════════════════════════════════════ */
#menu-scene {
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  background: #8f7b63;
  position: relative;
  overflow-y: auto;
}

#menu-layout {
  display: flex; flex-direction: column; align-items: center;
  gap: 12px; padding: 16px 16px 40px;
  max-height: 100vh; max-height: 100dvh;
  animation: menuFadeIn 0.4s ease-out;
}
@keyframes menuFadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Map preview in gold picture frame */
#menu-map-frame {
  border: 6px solid;
  border-color: #d4a840 #8a6820 #8a6820 #d4a840;
  box-shadow:
    inset 2px 2px 0 #e8c860,
    inset -2px -2px 0 #6a5018,
    3px 3px 8px rgba(0,0,0,0.4);
  background: #2a2a2a;
  line-height: 0;
}
#menu-map-img {
  display: block;
  max-width: 280px;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
}

/* Medallion seal — fills screen initially, shrinks when dialog appears */
#menu-seal {
  width: 340px;
  height: auto;
  image-rendering: pixelated;
  flex-shrink: 1;
  min-height: 0;
  object-fit: contain;
}
#menu-layout:not(.menu-open) #menu-seal {
  width: 90vmin;
}

#menu-dialog {
  position: relative;
  flex-shrink: 0;
  opacity: 0;
  max-height: 0;
  overflow: hidden;
  pointer-events: none;
}
#menu-layout.menu-open #menu-dialog {
  opacity: 1;
  max-height: 600px;
  pointer-events: auto;
}

/* Outer frame — city-dialog-style stone texture border with 3D bevel */
#menu-frame {
  position: relative;
  background: url('../assets/menu/stone-border.png') repeat;
  border: 2px solid;
  border-color: #fff #dfdfdf #dfdfdf #fff;
  box-shadow: 3px 3px 8px rgba(0,0,0,0.5);
  padding: 10px;
}
#menu-frame::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  box-shadow: inset -1px -1px 0 #000;
  pointer-events: none;
}

/* Title bar — stone texture, matches city dialog */
#menu-titlebar {
  background: url('../assets/menu/stone-border.png') repeat;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: -10px -10px 0;
}
#menu-title {
  font-family: 'Times New Roman', 'Georgia', serif;
  font-size: 28px;
  font-weight: 400;
  color: rgb(135,135,135);
  text-shadow: 2px 1px 0 rgb(0,0,0), 1px 0 0 rgb(67,67,67);
  letter-spacing: 3px;
}

/* Inner panel — pebbly texture background */
#menu-panel {
  background: url('../assets/menu/pebbly-bg.png') repeat;
  padding: 6px 8px;
  text-align: left;
  margin-bottom: 0;
  border: 2px solid;
  border-color: #404040 #fff #fff #404040;
}

/* Radio-button menu items */
#menu-items {
  display: flex; flex-direction: column; gap: 1px;
  margin-bottom: 0;
}
.menu-radio {
  display: flex; align-items: center; gap: 8px;
  font-family: 'Times New Roman', 'Georgia', serif;
  font-size: 24px;
  color: #333333;
  text-shadow: 1px 1px 0 rgba(191,191,191,0.4);
  padding: 3px 4px 3px 0;
  cursor: pointer;
}
.menu-radio:hover:not(.disabled) {
  background: rgba(255,255,255,0.08);
}
.menu-radio.disabled {
  color: #666666;
  cursor: default;
}
.menu-radio input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  width: 14px; height: 14px;
  flex-shrink: 0;
  border: 2px solid #b0b0b0;
  border-radius: 50%;
  background: transparent;
  position: relative;
  cursor: pointer;
  box-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}
.menu-radio input[type="radio"]::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #b0b0b0;
  box-shadow: 1px 1px 1px rgba(0,0,0,0.5);
}
.menu-radio input[type="radio"]:checked::after {
  background: #000;
}
.menu-radio.disabled input[type="radio"]::after {
  background: #555;
}

/* OK / Cancel button row — stone footer */
#menu-btn-row {
  display: flex; gap: 4px;
  margin: 0 -10px -10px;
  padding: 6px 10px;
}
#menu-btn-row .civ2-btn {
  flex: 1;
}

/* Win95/Civ2-style 3D button */
.civ2-btn {
  display: block;
  width: 100%;
  padding: 4px 16px;
  font-family: 'Times New Roman', 'Georgia', serif;
  font-size: 17px;
  color: #333;
  background: #c0c0c0;
  border: none;
  box-shadow:
    inset 1px 1px 0 #fff,
    inset 2px 2px 0 #dfdfdf,
    inset -1px -1px 0 #404040,
    inset -2px -2px 0 #808080;
  cursor: pointer;
  text-align: center;
  outline: none;
}
.civ2-btn:hover:not(:disabled) {
  background: #cccccc;
}
.civ2-btn:active:not(:disabled) {
  box-shadow:
    inset 1px 1px 0 #404040,
    inset 2px 2px 0 #808080,
    inset -1px -1px 0 #fff,
    inset -2px -2px 0 #dfdfdf;
  padding: 5px 15px 3px 17px;
}
.civ2-btn:disabled {
  color: #808080;
  text-shadow: 1px 1px 0 #dfdfdf;
  cursor: default;
}

/* ═══════════════════════════════════════════════════════════════════
   Reusable Civ2 popup dialog — same stone/pebbly theme as startup menu
   Usage: .civ2-dialog-overlay > .civ2-dialog-frame > titlebar + panel + btn-row
   ═══════════════════════════════════════════════════════════════════ */
.civ2-dialog-overlay {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.5);
}
.civ2-dialog-frame {
  position: relative;
  background: url('../assets/menu/stone-border.png') repeat;
  border: 2px solid;
  border-color: #fff #dfdfdf #dfdfdf #fff;
  box-shadow: 3px 3px 8px rgba(0,0,0,0.5);
  padding: 10px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow: hidden;
}
.civ2-dialog-frame::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  box-shadow: inset -1px -1px 0 #000;
  pointer-events: none;
}
.civ2-dialog-titlebar {
  background: url('../assets/menu/stone-border.png') repeat;
  height: 36px;
  display: flex; align-items: center; justify-content: center;
  margin: -10px -10px 0;
  flex-shrink: 0;
}
.civ2-dialog-title {
  font-family: 'Times New Roman', 'Georgia', serif;
  font-size: 22px;
  font-weight: 400;
  color: rgb(135,135,135);
  text-shadow: 2px 1px 0 rgb(0,0,0), 1px 0 0 rgb(67,67,67);
  letter-spacing: 2px;
}
.civ2-dialog-panel {
  background: #c0c0c0;
  padding: 6px 8px;
  text-align: left;
  border: 2px solid;
  border-color: #404040 #fff #fff #404040;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  flex: 1;
  max-width: 100%;
}
.civ2-dialog-items {
  display: flex; flex-direction: column; gap: 1px;
}
.civ2-dialog-radio {
  display: flex; align-items: center; gap: 8px;
  font-family: 'Times New Roman', 'Georgia', serif;
  font-size: 20px;
  color: #333333;
  text-shadow: 1px 1px 0 rgba(191,191,191,0.4);
  padding: 3px 4px 3px 0;
  cursor: pointer;
}
.civ2-dialog-radio:hover:not(.disabled) {
  background: rgba(255,255,255,0.08);
}
.civ2-dialog-radio.disabled {
  color: #666666;
  cursor: default;
}
.civ2-dialog-radio input[type="radio"] {
  appearance: none; -webkit-appearance: none;
  margin: 0; width: 14px; height: 14px; flex-shrink: 0;
  border: 2px solid #b0b0b0; border-radius: 50%;
  background: transparent; position: relative;
  cursor: pointer;
  box-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}
.civ2-dialog-radio input[type="radio"]::after {
  content: ''; position: absolute;
  top: 2px; left: 2px; width: 6px; height: 6px;
  border-radius: 50%; background: #b0b0b0;
  box-shadow: 1px 1px 1px rgba(0,0,0,0.5);
}
.civ2-dialog-radio input[type="radio"]:checked::after {
  background: #000;
}
.civ2-dialog-radio.disabled input[type="radio"] {
  cursor: default;
}
.civ2-dialog-btn-row {
  display: flex; gap: 4px;
  margin: 0 -10px -10px;
  padding: 6px 10px;
  flex-shrink: 0;
}
.civ2-dialog-btn-row .civ2-btn {
  flex: 1;
}
/* Close (X) button in dialog title bar */
.civ2-dialog-close {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 18px;
  background: #c0c0c0;
  border: none;
  box-shadow:
    inset 1px 1px 0 #fff,
    inset -1px -1px 0 #404040;
  font-size: 12px; line-height: 1;
  color: #333; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
}
.civ2-dialog-close:hover { background: #d0d0d0; }
.civ2-dialog-close:active {
  box-shadow:
    inset 1px 1px 0 #404040,
    inset -1px -1px 0 #fff;
}
/* Win95-style range sliders */
.civ2-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: #808080;
  border: 1px inset #c0c0c0;
  outline: none;
}
.civ2-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px; height: 20px;
  background: #c0c0c0;
  border: 2px outset #dfdfdf;
  cursor: pointer;
}
.civ2-slider::-moz-range-thumb {
  width: 12px; height: 20px;
  background: #c0c0c0;
  border: 2px outset #dfdfdf;
  cursor: pointer;
}
/* Production picker category headers */
.pp-category-header {
  padding: 4px 6px 2px;
  font: bold 12px 'Times New Roman', Georgia, serif;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid #999;
  margin-top: 4px;
}

#menu-footer {
  position: absolute;
  bottom: 20px;
  font-size: 11px;
  color: #b0a088;
  font-family: 'Times New Roman', serif;
  letter-spacing: 0.5px;
}

/* ═══════════════════════════════════════════════════════════════════
   Scene: Lobby — full-page room browser
   ═══════════════════════════════════════════════════════════════════ */
#lobby-scene {
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, #12121e 0%, #0a0a15 100%);
}

/* ── Lobby header bar ── */
#lobby-header {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: rgba(22, 33, 62, 0.95);
  border-bottom: 1px solid #0f3460;
  flex-shrink: 0;
}
.lobby-nav-btn {
  background: #0f3460; color: #c0c0c0; border: 1px solid #1a5276;
  padding: 4px 12px; border-radius: 3px; cursor: pointer; font-size: 12px;
  flex-shrink: 0;
}
.lobby-nav-btn:hover { background: #1a5276; color: #fff; }
.lobby-leave-btn { background: #5a1a1a; border-color: #7a2a2a; }
.lobby-leave-btn:hover { background: #7a2a2a; }

#lobby-heading {
  font-family: 'Times New Roman', serif;
  font-size: 20px; font-weight: 700;
  color: #d4c4a0;
  margin: 0; flex: 1;
}

#lobby-right {
  display: flex; align-items: center; gap: 12px; flex-shrink: 0;
}

#lobby-name-label {
  font-size: 12px; color: #888;
}
#lobby-name-input {
  background: transparent; border: none; border-bottom: 1px solid #444;
  color: #e0e0e0; font-size: 13px; font-family: inherit;
  padding: 2px 4px; width: 100px; outline: none;
}
#lobby-name-input:focus { border-bottom-color: #2ecc71; }

/* ── WS status indicator ── */
#ws-status {
  display: flex; align-items: center; gap: 4px; font-size: 11px;
  flex-shrink: 0; cursor: default;
}
.ws-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; flex-shrink: 0;
}
.ws-off .ws-dot { background: #e74c3c; }
.ws-off .ws-label { color: #e74c3c; }
.ws-on .ws-dot { background: #2ecc71; }
.ws-on .ws-label { color: #2ecc71; }
.ws-connecting .ws-dot { background: #f39c12; animation: pulse 1s ease-in-out infinite; }
.ws-connecting .ws-label { color: #f39c12; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ── Lobby room list ── */
#lobby-rooms-view {
  flex: 1; overflow-y: auto; padding: 20px 16px;
  -webkit-overflow-scrolling: touch;
}
#lobby-rooms-view::-webkit-scrollbar { width: 6px; }
#lobby-rooms-view::-webkit-scrollbar-track { background: transparent; }
#lobby-rooms-view::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }

#lobby-room-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  max-width: 860px;
  margin: 0 auto;
}

/* ── Create game tile ── */
.lobby-create-tile {
  border: 2px dashed #3a3a5a;
  border-radius: 6px;
  background: transparent;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 110px;
  color: #555;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.lobby-create-tile:hover {
  border-color: #4caf50;
  color: #4caf50;
}
.lobby-create-tile .create-plus {
  font-size: 36px; line-height: 1; font-weight: 300;
}
.lobby-create-tile .create-label {
  font-size: 13px; margin-top: 4px;
}

/* ── Room tile ── */
.lobby-room-tile {
  background: rgba(25, 25, 45, 0.85);
  border: 1px solid #2a2a4a;
  border-left: 3px solid #4caf50;
  border-radius: 6px;
  padding: 14px 16px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  display: flex; flex-direction: column; gap: 8px;
}
.lobby-room-tile:hover {
  background: rgba(35, 35, 60, 0.95);
  border-color: #3a3a6a;
  border-left-color: #66bb6a;
}
.lobby-room-tile.started { border-left-color: #5c8dd6; }
.lobby-room-tile.started:hover { border-left-color: #7aa3e8; }

.tile-top {
  display: flex; align-items: center; justify-content: space-between;
}
.tile-name {
  font-size: 14px; font-weight: 600; color: #e0e0e0;
}
.tile-status {
  font-size: 11px; padding: 2px 6px; border-radius: 3px;
  background: rgba(76,175,80,0.15); color: #4caf50;
}
.tile-status.in-progress {
  background: rgba(92,141,214,0.15); color: #5c8dd6;
}
.tile-info {
  font-size: 12px; color: #777;
}
.tile-join-btn {
  align-self: flex-end;
  background: #0f3460; color: #c0c0c0; border: 1px solid #1a5276;
  padding: 4px 14px; border-radius: 3px; cursor: pointer; font-size: 12px;
}
.tile-join-btn:hover { background: #1a5276; color: #fff; }

/* ── Room detail view ── */
#lobby-room-view {
  flex: 1; overflow-y: auto; padding: 20px 16px;
}
#room-detail-header {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 500px; margin: 0 auto 16px;
}
#room-name {
  font-family: 'Times New Roman', serif;
  font-size: 22px; font-weight: 700; color: #d4c4a0;
  margin: 0;
}
#room-seats {
  max-width: 500px; margin: 0 auto;
}
.room-seat {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 4px; margin-bottom: 4px;
  font-size: 13px;
}
.room-seat.occupied {
  background: rgba(46,204,113,0.08);
  color: #e0e0e0;
}
.room-seat.empty {
  background: rgba(255,255,255,0.03);
  color: #555;
}
.seat-num {
  width: 24px; font-weight: 700; color: #666;
  text-align: center; flex-shrink: 0;
}
.seat-name { flex: 1; }
.seat-status {
  font-size: 11px; padding: 1px 6px; border-radius: 3px;
}
.seat-status.online { background: rgba(46,204,113,0.15); color: #2ecc71; }
.seat-status.offline { background: rgba(231,76,60,0.15); color: #e74c3c; }
/* ── AI seat styling ── */
.room-seat.ai {
  background: rgba(100, 160, 220, 0.08);
  color: #99ccff;
}
.seat-ai-tag {
  color: #7ab0e0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.seat-add-ai {
  background: transparent; border: 1px solid #3a5a7a;
  color: #7ab0e0; font-size: 11px; padding: 1px 6px;
  border-radius: 3px; cursor: pointer; margin-left: 8px;
}
.seat-add-ai:hover { background: rgba(100, 160, 220, 0.15); border-color: #5a8aba; color: #aad0f0; }
.seat-remove-ai {
  background: transparent; border: 1px solid #5a3a3a;
  color: #cc8888; font-size: 11px; padding: 0 5px; line-height: 1.4;
  border-radius: 3px; cursor: pointer; margin-left: 8px;
}
.seat-remove-ai:hover { background: rgba(220, 100, 100, 0.15); border-color: #8a4a4a; color: #eea0a0; }
.seat-difficulty {
  background: #1a2a3a; border: 1px solid #3a5a7a;
  color: #99ccff; font-size: 11px; padding: 1px 4px;
  border-radius: 3px; cursor: pointer; margin-left: 8px;
  font-family: inherit;
}
.seat-difficulty:hover { border-color: #5a8aba; color: #aad0f0; }
.seat-difficulty:focus { outline: none; border-color: #5a8aba; }
.seat-difficulty-label {
  color: #668faa; font-size: 11px; margin-left: 8px;
}

.room-spectators {
  margin-top: 12px; padding: 8px 12px;
  font-size: 11px; color: #666;
  border-top: 1px solid rgba(255,255,255,0.05);
}

/* ── Active game banner ── */
#lobby-banner {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 8px 16px;
  background: rgba(76,175,80,0.12);
  border-bottom: 1px solid rgba(76,175,80,0.25);
  flex-shrink: 0;
  font-size: 13px; color: #4caf50;
}
#lobby-banner-resume {
  background: #4caf50; color: #000; border-color: #66bb6a;
  font-weight: 600;
}
#lobby-banner-resume:hover { background: #66bb6a; }

/* ── Room actions (ready, status) ── */
#room-actions {
  max-width: 500px; margin: 16px auto 0;
  display: flex; align-items: center; gap: 12px;
}
#room-status-text {
  flex: 1; font-size: 13px; color: #888;
}
#room-status-text.started {
  color: #4caf50; font-weight: 600;
}
.room-ready-btn {
  width: auto; padding: 6px 24px; font-size: 15px;
}
.room-ready-btn.is-ready {
  background: #a0a0a0;
}

/* ── Activity dot (inline colored circle) ── */
.activity-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; flex-shrink: 0; margin-right: 6px;
}

/* ── Lobby status bar ── */
#lobby-status-bar {
  padding: 6px 16px;
  border-top: 1px solid rgba(255,255,255,0.05);
  font-size: 11px; color: #555;
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════════════
   Scene: Game — map viewer
   ═══════════════════════════════════════════════════════════════════ */

/* ── Controls bar (floating overlay, single-line, scrollable) ── */
#controls {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  padding: 4px 8px; background: rgba(22, 33, 62, 0.92); border-bottom: 1px solid #0f3460;
  display: flex; align-items: center; gap: 8px; flex-wrap: nowrap;
  overflow-x: auto; overflow-y: hidden; white-space: nowrap;
  backdrop-filter: blur(4px);
}
.ctrl-back-btn {
  flex-shrink: 0;
  background: #0f3460; color: #c0c0c0; border: 1px solid #1a5276;
  padding: 3px 8px; border-radius: 3px; cursor: pointer; font-size: 13px;
  font-weight: 700;
}
.ctrl-back-btn:hover { background: #1a5276; color: #fff; }

.file-btn {
  flex-shrink: 0;
  background: #0f3460; color: #e0e0e0; border: 1px solid #1a5276;
  padding: 3px 10px; border-radius: 3px; cursor: pointer; font-size: 12px;
}
.file-btn:hover { background: #1a5276; }
.file-btn.loaded { border-color: #2ecc71; color: #2ecc71; }
.ctl-option { display: flex; align-items: center; gap: 3px; font-size: 12px; cursor: pointer; flex-shrink: 0; }
#fow-civ {
  background: #0f3460; color: #e0e0e0; border: 1px solid #1a5276;
  padding: 2px 6px; border-radius: 3px; font-size: 12px; flex-shrink: 0;
}
#status { font-size: 11px; color: #7f8c8d; flex-shrink: 0; }
#game-info {
  font-size: 12px; color: #c0c0c0; flex-shrink: 0;
  display: flex; align-items: center; gap: 10px;
  margin-left: auto; padding-left: 12px;
  font-family: 'Times New Roman', serif;
}
#game-info:empty { display: none; }
#game-players { font-size: 11px; color: #999; flex-shrink: 0; }
#game-players:empty { display: none; }
#game-players .gp-player { color: #2ecc71; }
#game-players .gp-spectator { color: #f39c12; }
#game-players .gp-offline { color: #e74c3c; opacity: 0.6; }
#game-players .gp-sep { color: #555; }
#game-info .gi-player { font-weight: 700; }
#game-info .gi-year { color: #e0e0e0; }
#game-info .gi-gold { color: #ffd700; }
#game-info .gi-pop { color: #e0e0e0; }
#game-info .gi-govt { color: #e0e0e0; }
#game-info .gi-sep { color: #555; user-select: none; }
#render-btn {
  flex-shrink: 0;
  background: #2ecc71; color: #000; border: none; padding: 4px 12px;
  border-radius: 3px; font-weight: bold; cursor: pointer; font-size: 12px;
}
#render-btn:disabled { background: #555; color: #999; cursor: not-allowed; }
#render-btn:hover:not(:disabled) { background: #27ae60; }

/* ── Map viewport ── */
#map-container {
  width: 100vw; height: 100vh; height: 100dvh; overflow: hidden; position: relative;
  background: #0a0a1a;
}
#map-canvas { display: none; }
#viewport-canvas { image-rendering: -moz-crisp-edges; image-rendering: pixelated; cursor: grab; touch-action: none; }
#viewport-canvas.dragging { cursor: grabbing; }

/* ═══════════════════════════════════════════════════════════════════
   Global overlays
   ═══════════════════════════════════════════════════════════════════ */

/* ── Tooltip ── */
#tooltip {
  position: fixed; background: rgba(0,0,0,0.9); color: #fff; padding: 6px 10px;
  border-radius: 4px; font-size: 12px; pointer-events: none; display: none;
  border: 1px solid #555; z-index: 100; font-family: monospace; white-space: pre;
}

/* ── Loading overlay ── */
#loading-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.7); display: none; justify-content: center;
  align-items: center; z-index: 200; flex-direction: column; gap: 12px;
}
#loading-overlay .spinner {
  width: 40px; height: 40px; border: 4px solid #333; border-top: 4px solid #2ecc71;
  border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-overlay .msg { font-size: 14px; color: #ccc; }

/* ── City View overlay ── */
#cityview-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  display: none; justify-content: center; align-items: center;
  z-index: 300;
}
#cityview-backdrop {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.8);
}
#cityview-container {
  position: relative; z-index: 1;
  max-width: 95vw; max-height: 90vh;
}
#cityview-canvas {
  display: block; max-width: 95vw; max-height: 90vh;
  image-rendering: pixelated; border: 2px solid #555;
}
#cityview-close {
  position: absolute; top: -14px; right: -14px;
  width: 28px; height: 28px; border-radius: 50%;
  background: #333; color: #fff; border: 2px solid #777;
  font-size: 16px; cursor: pointer; display: flex;
  align-items: center; justify-content: center; line-height: 1;
}
#cityview-close:hover { background: #c0392b; border-color: #e74c3c; }

/* ── City Dialog overlay ── */
#citydialog-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  display: none; justify-content: center; align-items: center;
  z-index: 300;
}
#citydialog-backdrop {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.8);
}
#citydialog-viewport {
  position: relative; z-index: 1;
  image-rendering: pixelated; cursor: grab; touch-action: none;
}
#citydialog-viewport.dragging { cursor: grabbing; }
#citydialog-close {
  position: fixed; top: 12px; right: 12px; z-index: 301;
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(50,50,50,0.8); color: #fff; border: 2px solid #777;
  font-size: 18px; cursor: pointer; display: flex;
  align-items: center; justify-content: center; line-height: 1;
}
#citydialog-close:hover { background: #c0392b; border-color: #e74c3c; }

/* ═══════════════════════════════════════════════════════════════════
   Unit context menu (tap/hold on map tile)
   ═══════════════════════════════════════════════════════════════════ */
#unit-menu {
  position: fixed; z-index: 150;
  display: none;
  background: url('../assets/menu/pebbly-bg.png') repeat;
  border: 2px solid;
  border-color: #fff #404040 #404040 #fff;
  box-shadow: 3px 3px 8px rgba(0,0,0,0.6);
  padding: 2px;
  min-width: 160px;
  font-family: 'Times New Roman', 'Georgia', serif;
}
#unit-menu.visible { display: block; }

.unit-menu-item {
  display: flex; align-items: center; width: 100%;
  padding: 4px 10px;
  font-family: 'Times New Roman', 'Georgia', serif;
  font-size: 16px;
  color: #333;
  background: transparent;
  border: none;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  gap: 6px;
}
.unit-menu-item:hover {
  background: #0a246a;
  color: #fff;
}
.unit-menu-selected {
  background: rgba(10, 36, 106, 0.15);
  font-weight: bold;
}
.unit-menu-sprite {
  image-rendering: pixelated;
  height: 48px;
  width: 64px;
  flex-shrink: 0;
}
.unit-menu-separator {
  height: 1px;
  margin: 2px 6px;
  background: #888;
  border: none;
}
.unit-menu-header {
  padding: 4px 10px 2px;
  font-family: 'Times New Roman', 'Georgia', serif;
  font-size: 13px;
  font-weight: bold;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.unit-menu-highlight {
  background: #0a246a;
  color: #fff;
}

/* ═══════════════════════════════════════════════════════════════════
   Status Bar (multiplayer HUD — replaces old #turn-ui)
   ═══════════════════════════════════════════════════════════════════ */
#status-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  height: 32px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 8px;
  background: rgba(22, 33, 62, 0.92);
  border-bottom: 2px solid rgba(255,255,255,0.1);
  backdrop-filter: blur(4px);
  font: 13px 'Segoe UI', sans-serif;
  color: #ddd;
  transition: background-color 0.5s ease, border-bottom-color 0.5s ease;
}

#status-bar-left, #status-bar-right {
  display: flex; align-items: center; gap: 12px;
}

.hamburger-btn {
  background: none; border: none; color: #fff; font-size: 20px;
  cursor: pointer; padding: 2px 8px; border-radius: 4px;
}
.hamburger-btn:hover { background: rgba(255,255,255,0.15); }

.status-item {
  cursor: pointer; padding: 2px 8px; border-radius: 4px;
  white-space: nowrap;
}
.status-item:hover { background: rgba(255,255,255,0.1); }

#status-gold { color: #ffd700; font-weight: 600; }

#status-research-name { margin-right: 4px; }

.research-progress-bar {
  display: inline-block; width: 48px; height: 6px;
  background: rgba(255,255,255,0.15); border-radius: 3px;
  vertical-align: middle; overflow: hidden;
}
.research-progress-fill {
  display: block; height: 100%; background: #3498db;
  border-radius: 3px; transition: width 0.3s ease;
  width: 0%;
}

.end-turn-btn {
  background: #2a7d2a; color: #fff; border: none;
  padding: 4px 14px; border-radius: 4px; font-size: 12px;
  font-weight: 600; cursor: pointer; white-space: nowrap;
}
.end-turn-btn:hover { background: #339933; }
.end-turn-btn.flash {
  animation: endTurnFlash 0.8s step-start infinite;
}
@keyframes endTurnFlash {
  0%, 100% { color: #fff; }
  50% { color: #aaa; }
}

.status-waiting {
  color: #aaa; font-style: italic; font-size: 12px;
  animation: pulse 1.5s ease-in-out infinite;
}
.status-waiting.hidden { display: none; }

/* Hamburger dropdown */
#hamburger-menu {
  position: fixed; top: 34px; left: 8px; z-index: 25;
  background: rgba(20, 20, 20, 0.95);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  min-width: 220px;
  padding: 4px 0;
  backdrop-filter: blur(8px);
  font: 13px 'Segoe UI', sans-serif;
  color: #ddd;
  max-height: 80vh;
  overflow-y: auto;
}
#hamburger-menu.hidden { display: none; }

.menu-section { padding: 4px 0; }
.menu-section + .menu-section { border-top: 1px solid rgba(255,255,255,0.08); }

.menu-section-title {
  padding: 6px 16px 2px;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: #888;
}

#hamburger-menu .menu-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
}
#hamburger-menu .menu-item:hover { background: rgba(255,255,255,0.08); }

.menu-shortcut { color: #666; font-size: 11px; margin-left: 16px; }

.menu-check::after { content: ''; display: inline-block; width: 14px; }
.menu-check.checked::after { content: '\2713'; color: #7fba6a; }

/* Unit info strip */
#unit-info-strip {
  position: fixed; bottom: 12px; left: 12px; z-index: 15;
  background: rgba(20, 20, 20, 0.88);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 6px 14px;
  font: 13px 'Segoe UI', sans-serif;
  color: #ddd;
  pointer-events: auto;
  max-width: 50vw;
  white-space: nowrap;
  backdrop-filter: blur(4px);
}
#unit-info-strip.hidden { display: none; }

.unit-strip-name { font-weight: 600; }
.unit-strip-sep { color: #555; margin: 0 6px; }
.unit-strip-moves { color: #aaa; }
.unit-strip-hp { display: inline-block; width: 40px; height: 5px; background: rgba(255,255,255,0.15); border-radius: 2px; vertical-align: middle; overflow: hidden; }
.unit-strip-hp-fill { display: block; height: 100%; border-radius: 2px; }
.unit-strip-terrain { color: #aaa; }
.unit-strip-orders { color: #f39c12; }

/* ═══════════════════════════════════════════════════════════════════
   Tech Tree Viewer — category-banded layout with prerequisite graph
   ═══════════════════════════════════════════════════════════════════ */
.tt-container {
  background: #2a2a3a;
}
/* ── Row band backgrounds ── */
.tt-row-band {
  pointer-events: none;
}
/* ── Row labels (vertical text on left) ── */
.tt-row-label {
  pointer-events: none;
}
/* ── Era headers (top) ── */
.tt-era-header {
  font: bold 11px 'Times New Roman', Georgia, serif;
  color: rgba(255,255,255,0.45);
  letter-spacing: 1px;
  text-transform: uppercase;
  pointer-events: none;
}
/* ── Tech node base ── */
.tt-node {
  display: flex; align-items: center; gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.2);
  cursor: pointer;
  box-sizing: border-box;
  overflow: hidden;
  transition: filter 0.2s, box-shadow 0.2s, opacity 0.2s, border-color 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.tt-node:hover {
  filter: brightness(1.3);
  z-index: 10 !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
.tt-node-icon, .tt-icon-slot {
  flex-shrink: 0;
  image-rendering: pixelated;
}
.tt-node-name {
  font: 11px 'Times New Roman', Georgia, serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}
/* ── Status variants ── */
.tt-known {
  background: #1a5c1a;
  border-color: #2d8a2d;
  color: #e0ffe0;
}
.tt-available {
  background: #0a246a;
  border-color: #1a5aaa;
  color: #cce0ff;
}
.tt-locked {
  background: #555;
  border-color: #777;
  color: #ccc;
}
.tt-locked .tt-node-name { color: #999; }
.tt-locked .tt-node-icon { opacity: 0.5; }
/* ── Selection states ── */
.tt-selected {
  border-color: #f0c040 !important;
  box-shadow: 0 0 8px 2px rgba(240,192,64,0.6), 0 0 20px 4px rgba(240,192,64,0.25) !important;
  z-index: 12 !important;
  filter: brightness(1.2);
}
.tt-prereq-of-selected {
  border-color: rgba(240,192,64,0.7) !important;
  box-shadow: 0 0 6px 1px rgba(240,192,64,0.35) !important;
  z-index: 11 !important;
}
.tt-dimmed {
  opacity: 0.35;
  filter: saturate(0.3);
}

/* ═══════════════════════════════════════════════════════════════════
   Chat / Event Log Panel
   ═══════════════════════════════════════════════════════════════════ */
#chatPanel {
  position: fixed; bottom: 12px; right: 12px; z-index: 15;
  display: flex; flex-direction: column; align-items: flex-end;
  pointer-events: none;
}
#chatPanel > * { pointer-events: auto; }
#chatPanel.hidden { display: none; }

.chatToggleBtn {
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: rgba(0,0,0,0.75); color: #fff; font-size: 20px;
  cursor: pointer; position: relative;
  transition: background 0.15s;
}
.chatToggleBtn:hover { background: rgba(0,0,0,0.9); }

.chatBadge {
  position: absolute; top: -4px; right: -4px;
  height: 18px; min-width: 18px; padding: 0 4px;
  background: #D94A4A; color: #fff;
  font-size: 11px; font-weight: bold; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
}
.chatBadge.hidden { display: none; }

.chatToastStack {
  display: flex; flex-direction: column; align-items: flex-end;
  gap: 6px; margin-bottom: 8px;
}
.chatToast {
  max-width: 280px; background: rgba(0,0,0,0.82);
  font: 13px 'Segoe UI', sans-serif; color: #ddd;
  padding: 8px 12px; border-radius: 10px;
  word-break: break-word; cursor: pointer;
  animation: chatToastIn 0.2s ease-out;
}
.chatToast.event { border-left: 3px solid #886; font-style: italic; color: #bba; }
@keyframes chatToastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.chatBox {
  width: 320px; max-height: 45vh;
  background: rgba(20,20,20,0.92);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px; margin-bottom: 8px;
  display: flex; flex-direction: column;
}
.chatBox.hidden { display: none; }

.chatMessages {
  flex: 1; overflow-y: auto; padding: 10px 12px;
  min-height: 120px; font: 13px 'Segoe UI', sans-serif;
  color: #ddd; line-height: 1.45;
}
.chatHeader {
  display: flex; align-items: center; justify-content: flex-end; gap: 12px;
  padding: 4px 10px 2px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.gameLogToggleLabel {
  display: flex; align-items: center; gap: 4px;
  font-size: 11px; color: #888; cursor: pointer; user-select: none;
}
.gameLogToggleLabel input[type="checkbox"] {
  margin: 0; cursor: pointer;
}

.chatMsg { margin-bottom: 4px; }
.chatMsg.event { color: #aa9; font-style: italic; border-left: 2px solid #665; padding-left: 6px; }
.chatSender { font-weight: 600; }

/* Game log messages */
.chatMsg.game-log-msg {
  font-style: italic; font-size: 12px;
  border-left: 2px solid currentColor; padding-left: 6px;
  line-height: 1.35; word-break: break-word;
}
.game-log-turn {
  opacity: 0.65; font-size: 10px;
}
.game-log-combat { color: #e74c3c; }
.game-log-city { color: #f39c12; }
.game-log-tech { color: #3498db; }
.game-log-diplomacy { color: #e67e22; }
.game-log-general { color: #95a5a6; }

.chatMsg.debug-log-msg {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 11px;
  color: #7fba6a;
  border-left: 2px solid #4a7a3a;
  padding-left: 6px;
  line-height: 1.3;
  word-break: break-word;
  opacity: 0.85;
}
.debug-log-category {
  color: #9ccc7c;
  font-weight: 600;
  text-transform: uppercase;
  font-size: 9px;
  margin-right: 4px;
}

.chatInputRow {
  display: flex; border-top: 1px solid rgba(255,255,255,0.1);
}
.chatInput {
  flex: 1; padding: 10px 12px; border: none; background: transparent;
  color: #fff; font-size: 14px; outline: none;
}
.chatInput::placeholder { color: rgba(255,255,255,0.35); }
.chatSendBtn {
  padding: 10px 14px; border: none; background: transparent;
  color: rgba(255,255,255,0.6); font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.chatSendBtn:hover { color: #fff; }

/* ═══════════════════════════════════════════════════════════════════
   Civilopedia Dialog
   ═══════════════════════════════════════════════════════════════════ */
.civpedia-tabs {
  display: flex; gap: 0; border-bottom: 2px solid #a08060;
  margin-bottom: 8px; flex-wrap: wrap;
}
.civpedia-tab {
  padding: 4px 12px; font: 13px 'Times New Roman', Georgia, serif;
  color: #654; background: #c8b494; border: 1px solid #a08060;
  border-bottom: none; cursor: pointer; margin-bottom: -2px;
}
.civpedia-tab.active {
  background: #d4b896; color: #333; font-weight: bold;
  border-bottom: 2px solid #d4b896;
}
.civpedia-tab:hover:not(.active) { background: #d0b88c; }
.civpedia-page { display: none; }
.civpedia-page.active { display: block; }
.civpedia-entry {
  padding: 3px 0; font: 13px 'Times New Roman', Georgia, serif;
  color: #333; border-bottom: 1px solid #c8b494;
}
.civpedia-entry:last-child { border-bottom: none; }
.civpedia-stat { display: flex; justify-content: space-between; padding: 1px 0; }
.civpedia-stat-label { color: #555; }
.civpedia-stat-value { font-weight: bold; color: #333; }
.civpedia-stat-value a { color: #1a5276; }
.civpedia-stat-value a:hover { color: #2980b9; }
.civpedia-list-active { background: #b89c6a; font-weight: bold; }

/* ═══════════════════════════════════════════════════════════════════
   Demographics Dialog
   ═══════════════════════════════════════════════════════════════════ */
.demo-table { width: 100%; border-collapse: collapse; font: 13px 'Times New Roman', Georgia, serif; }
.demo-table th { text-align: left; color: #654; font-weight: bold; padding: 4px 8px; border-bottom: 2px solid #a08060; }
.demo-table td { padding: 3px 8px; color: #333; border-bottom: 1px solid #c8b494; }
.demo-table td:nth-child(2) { text-align: right; font-weight: bold; }
.demo-rank { font-size: 11px; color: #886; }

/* ═══════════════════════════════════════════════════════════════════
   Advisor Tables (City List, Military, Trade, Science advisors)
   ═══════════════════════════════════════════════════════════════════ */
.advisor-table { width: 100%; border-collapse: collapse; font: 13px 'Times New Roman', Georgia, serif; }
.advisor-table th {
  text-align: left; color: #654; font-weight: bold; padding: 4px 8px;
  border-bottom: 2px solid #a08060; cursor: pointer; user-select: none;
}
.advisor-table th:hover { color: #321; }
.advisor-table td { padding: 3px 8px; color: #333; border-bottom: 1px solid #c8b494; }
.advisor-table tr:hover td { background: #e8d8c0; }
.advisor-table td.num { text-align: right; font-weight: bold; }
.advisor-table .sort-arrow { font-size: 10px; margin-left: 4px; }
.advisor-table tr.clickable { cursor: pointer; }

/* Advisor summary row */
.advisor-summary {
  margin-top: 8px; padding: 6px 8px; background: #d8c8a8;
  font: bold 13px 'Times New Roman', Georgia, serif; color: #333;
  border-top: 2px solid #a08060;
}

/* Tech list in science advisor */
.tech-list { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.tech-chip {
  padding: 2px 6px; background: #c8b494;
  font-size: 11px; color: #333; cursor: default;
}
.tech-chip.available { background: #a0c890; cursor: pointer; }
.tech-chip.available:hover { background: #80b870; }

/* ═══════════════════════════════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 520px) {
  #lobby-room-grid { grid-template-columns: 1fr; }
  #menu-panel { padding: 16px 20px; min-width: 0; }
  #menu-title { font-size: 16px; }
  #menu-seal { width: 240px; }
  #menu-map-img { max-width: 200px; }
}
