* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: #1a1a16; color: #e8e2d0;
  font-family: 'Courier New', Courier, monospace;
}
.hidden { display: none !important; }

.game-chat {
  position: fixed;
  z-index: 900;
  left: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
  padding: 10px;
  border: 1px solid #95865b;
  border-radius: 4px;
  background: rgba(25, 25, 19, 0.97);
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.55);
}
.game-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #f0d58a;
}
#chat-status { color: #a3a08c; font-size: 11px; }
#chat-messages {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 80px;
  max-height: min(260px, 35vh);
  overflow-y: auto;
  margin: 0;
  padding: 8px;
  list-style: none;
  background: #17170f;
  border: 1px solid #4a4a3c;
  font-size: 12px;
  overflow-wrap: anywhere;
}
.chat-message-name { color: #f0d58a; font-weight: bold; }
.chat-message-time { color: #8d8978; font-size: 10px; margin-left: 5px; }
#chat-form { display: flex; gap: 5px; }
#chat-name { width: 84px; flex: 0 0 84px; }
#chat-input { min-width: 0; flex: 1; }
#chat-name, #chat-input {
  padding: 6px;
  border: 1px solid #4a4a3c;
  border-radius: 2px;
  background: #17170f;
  color: #e8e2d0;
  font: inherit;
}
#chat-form button, #chat-copy-link {
  padding: 6px 9px;
  border: 1px solid #6b3a2c;
  border-radius: 3px;
  background: #33301f;
  color: #e8e2d0;
  cursor: pointer;
  font: inherit;
  font-size: 11px;
}
#chat-form button:hover, #chat-copy-link:hover { background: #6b3a2c; }

#game-tooltip {
  position: fixed;
  z-index: 1000;
  display: none;
  width: min(340px, calc(100vw - 16px));
  max-height: min(320px, calc(100vh - 16px));
  overflow: auto;
  padding: 10px 12px;
  border: 1px solid #95865b;
  border-radius: 4px;
  background: rgba(25, 25, 19, 0.97);
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.55);
  color: #e8e2d0;
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
}
#game-tooltip.visible { display: block; }
#game-tooltip strong {
  display: block;
  margin-bottom: 5px;
  color: #f0d58a;
  font-size: 14px;
}
.game-tooltip-body { white-space: pre-line; }

#setup {
  max-width: 480px; margin: 60px auto; padding: 24px;
  background: #24241e; border: 1px solid #4a4a3c; border-radius: 4px;
}
#setup h1 { margin: 0 0 4px; letter-spacing: 1px; }
#setup h2 { margin: 10px 0; font-size: 16px; }
.subtitle { color: #a3a08c; margin-top: 0; }
#setup label { display: block; margin-top: 16px; margin-bottom: 4px; color: #c9c4ac; }
#setup select, #setup input[type=text] {
  background: #17170f; color: #e8e2d0; border: 1px solid #4a4a3c;
  padding: 6px 8px; border-radius: 2px; font-family: inherit;
}
.player-row {
  display: flex; align-items: center; gap: 8px; margin-top: 8px;
}
.player-row input[type=text] { flex: 1; }
.swatch, .legend-swatch {
  display: inline-block; width: 14px; height: 14px; border-radius: 2px; border: 1px solid #000;
}
#start-btn {
  margin-top: 20px; padding: 10px 16px; background: #6b3a2c; color: #fff;
  border: none; border-radius: 3px; cursor: pointer; font-family: inherit; font-size: 14px;
}
#start-btn:hover { background: #8a4a36; }
#party-menu { margin-top: 24px; padding-top: 14px; border-top: 1px solid #4a4a3c; }
#create-party-btn, #join-party-form button, #start-party-btn, #leave-party-btn, #copy-party-code {
  padding: 8px 12px;
  border: 1px solid #6b3a2c;
  border-radius: 3px;
  background: #33301f;
  color: #e8e2d0;
  cursor: pointer;
  font: inherit;
}
#create-party-btn:hover, #join-party-form button:hover, #start-party-btn:hover, #leave-party-btn:hover, #copy-party-code:hover {
  background: #6b3a2c;
}
#join-party-form { display: flex; gap: 8px; margin-top: 10px; }
#party-code-input { min-width: 0; flex: 1; text-transform: uppercase; }
#party-lobby { margin-top: 14px; padding: 12px; border: 1px solid #4a4a3c; background: #1a1a16; }
#party-lobby p { margin: 0 0 8px; }
#party-code { letter-spacing: 2px; color: #f0d58a; }
#party-status { color: #a3a08c; font-size: 12px; }
#party-host-settings { display: flex; align-items: center; gap: 8px; margin: 10px 0; }
#party-host-settings label { margin: 0 !important; }
#party-roster { margin: 10px 0; padding-left: 22px; }
#party-roster li { margin: 4px 0; }
#start-party-btn:disabled { opacity: 0.5; cursor: not-allowed; }

#game { display: flex; flex-direction: column; height: 100vh; }
#player-bar {
  display: flex; flex-wrap: wrap; gap: 10px; padding: 6px 12px;
  background: #2c2c22; border-bottom: 1px solid #4a4a3c;
}
.player-chip {
  display: flex; align-items: center; gap: 6px; padding: 4px 10px;
  border-radius: 3px; background: #17170f; border: 1px solid #4a4a3c; font-size: 13px;
}
.player-chip .swatch { width: 12px; height: 12px; }
.player-chip .ptype { color: #a3a08c; font-size: 11px; }
.player-chip .gold { color: #d9b455; font-size: 11px; }
.player-chip.eliminated { opacity: 0.45; filter: grayscale(0.7); }
.player-chip.eliminated .ptype { color: #c0392b; font-weight: bold; }

#build-panel {
  display: flex; align-items: center; gap: 14px; padding: 8px 12px;
  background: #33301f; border-bottom: 1px solid #4a4a3c; font-size: 13px;
}
#build-panel-title { color: #e8e2d0; font-weight: bold; }
#build-panel-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.unit-stats {
  flex-basis: 100%;
  color: #d9c98a;
  font-size: 12px;
  line-height: 1.5;
}
.build-btn {
  padding: 6px 12px; background: #6b3a2c; color: #fff; border: none;
  border-radius: 3px; cursor: pointer; font-family: inherit; font-size: 12px;
}
.build-btn:hover:not(:disabled) { background: #8a4a36; }
.build-btn:disabled { background: #3a3a30; color: #8a8676; cursor: not-allowed; }

.build-progress { display: flex; flex-direction: column; gap: 3px; min-width: 160px; }
.build-progress-label { font-size: 11px; color: #d9c98a; }
.build-progress-track {
  width: 100%; height: 8px; background: #17170f; border: 1px solid #4a4a3c; border-radius: 2px; overflow: hidden;
}
.build-progress-fill { height: 100%; background: #e8c33d; transition: width 0.2s linear; }
#toolbar {
  display: flex; align-items: center; gap: 16px; padding: 4px 12px;
  background: #24241e; border-bottom: 1px solid #4a4a3c;
}
#hex-info { color: #a3a08c; font-size: 13px; }
#map-container {
  position: relative;
  flex: 1; overflow: hidden; background: #10100c; cursor: default;
  /* A far perspective distance keeps the 3D projection close to flat, so content
     away from screen center doesn't cross behind the virtual camera and render as
     clipped/black — a real risk with a close distance at a steep tilt angle. */
  perspective: 4500px;
}
#map-container.pan-ready { cursor: grab; }
#map-container.panning { cursor: grabbing; }
#hexmap-svg {
  width: 100%; height: 100%;
  transform: none;
  transform-origin: 50% 100%;
  transition: transform 0.45s ease;
}
#map-container.side-view #hexmap-svg {
  transform: rotateX(52deg) scale(1.25, 1.95);
}
#city-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  transform-style: preserve-3d;
  transform-origin: 50% 100%;
  transition: transform 0.45s ease;
}
#city-overlay-inner {
  position: absolute; inset: 0;
  transform-style: preserve-3d;
  transform-origin: 0 0;
}
.unit-figure {
  transition: left 0.7s linear, top 0.7s linear;
}
.unit-figure.walking {
  animation: unit-walk 0.55s ease-in-out infinite;
}
@keyframes unit-walk {
  0%   { transform: translateZ(0) rotateZ(0deg); }
  25%  { transform: translateZ(2px) rotateZ(-5deg); }
  50%  { transform: translateZ(0) rotateZ(0deg); }
  75%  { transform: translateZ(2px) rotateZ(5deg); }
  100% { transform: translateZ(0) rotateZ(0deg); }
}
.hex-tile { transition: fill 0.15s; }
.hex-tile:hover { filter: brightness(1.25); }
.build-hologram { animation: holo-flicker 1.6s ease-in-out infinite; }
@keyframes holo-flicker {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 0.3; }
}
.capital-flame {
  position: absolute;
  width: 4px; height: 6px;
  border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%;
  transform: translateZ(3px);
  box-shadow: 0 0 5px 1px rgba(255, 140, 40, 0.75);
  animation: capital-flame-flicker 0.55s ease-in-out infinite alternate;
}
@keyframes capital-flame-flicker {
  0% { transform: translateZ(3px) scaleY(0.75) scaleX(0.9); opacity: 0.8; }
  100% { transform: translateZ(3px) scaleY(1.25) scaleX(1.05); opacity: 1; }
}
.capital-smoke {
  position: absolute;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: rgba(90, 90, 90, 0.5);
  animation: capital-smoke-rise 2.6s ease-out infinite;
}
@keyframes capital-smoke-rise {
  0% { transform: translateZ(4px) translateY(0) scale(0.6); opacity: 0.55; }
  100% { transform: translateZ(36px) translateY(-22px) scale(1.7); opacity: 0; }
}
.hex-tile.hex-hit { fill: var(--flash-color, #ff3b30) !important; }
.hex-label {
  fill: #fff2c9; font-size: 12px; text-anchor: middle; pointer-events: none; user-select: none;
}
.hex-unit-count {
  fill: #fff; font-size: 10px; text-anchor: middle; pointer-events: none; user-select: none;
  font-weight: bold; paint-order: stroke; stroke: #000; stroke-width: 2px;
}
#legend {
  display: flex; flex-wrap: wrap; gap: 12px; padding: 8px 12px;
  background: #24241e; border-top: 1px solid #4a4a3c; font-size: 12px;
}
.legend-item { display: flex; align-items: center; gap: 4px; color: #c9c4ac; }
