@font-face {
  font-family: "Unifont";
  src: url("fonts/unifont-mono.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
}

:root {
  color-scheme: dark;
  --fg: #f5f5f5;
  --bg: #050505;
  --accent: #888;
  --ui-font-size: 14px;
  --ui-line-height: 1.2;
  --ui-letter-spacing: 0.05em;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: "Unifont", monospace;
  font-size: var(--ui-font-size);
  line-height: var(--ui-line-height);
}

.game-shell {
  min-height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.splash-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: rgba(5, 5, 5, 0.94);
  z-index: 200;
  text-align: center;
  font-family: "Unifont", monospace;
  font-size: var(--ui-font-size);
  line-height: var(--ui-line-height);
  letter-spacing: var(--ui-letter-spacing);
}

.splash-screen.hidden {
  display: none;
}

.splash-logo {
  margin: 0 0 1rem;
  white-space: pre;
  line-height: 1;
}

.splash-controls {
  max-width: 42rem;
}

.splash-controls p {
  margin: 0.25rem 0;
}

.splash-prompt {
  margin-top: 1.25rem;
  letter-spacing: var(--ui-letter-spacing);
  text-transform: uppercase;
}

header,
footer {
  padding: 1rem 1.5rem;
}

h1 {
  margin: 0;
  font-size: var(--ui-font-size);
  letter-spacing: var(--ui-letter-spacing);
}

#game-container {
  flex: 1 1 auto;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem 1.5rem 0.5rem;
}

#bottom-bar {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  border-top: 1px solid var(--accent);
  padding: 0.75rem 1.5rem 1.5rem;
}

#info-row {
  display: flex;
  gap: 1rem;
}

#status-bar {
  font-size: var(--ui-font-size);
  color: var(--accent);
  min-height: calc(var(--ui-font-size) * var(--ui-line-height));
}

#log {
  flex: 1 1 auto;
  min-height: 5rem;
  text-align: left;
  background: transparent;
  font-size: var(--ui-font-size);
  overflow-y: auto;
}

#map-container {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
}

#minimap {
  background: #050505;
  border: none;
  outline: none;
  image-rendering: pixelated;
}

canvas {
  image-rendering: pixelated;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.45);
  -webkit-font-smoothing: none;
  font-smooth: never;
}

#log p {
  margin: 0.25rem 0;
}

footer {
  font-size: var(--ui-font-size);
  color: var(--accent);
}

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

header h3 {
  margin: 0;
  flex: 1;
}

#sound-toggle-btn,
#export-map-btn {
  padding: 0.25rem 0.75rem;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--fg);
  font-family: "Unifont", monospace;
  font-size: var(--ui-font-size);
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: var(--ui-letter-spacing);
}

#sound-toggle-btn:hover,
#export-map-btn:hover {
  background: var(--fg);
  color: var(--bg);
}

#sound-toggle-btn:active,
#export-map-btn:active {
  opacity: 0.7;
}

#sound-toggle-btn.active {
  background: var(--fg);
  color: var(--bg);
}

/* Export Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(5, 5, 5, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  font-family: "Unifont", monospace;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg);
  border: 1px solid var(--fg);
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.8);
}

/* Export modal is always fullscreen */
#export-modal .modal-content {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--accent);
}

.modal-header h2 {
  margin: 0;
  font-size: var(--ui-font-size);
  letter-spacing: var(--ui-letter-spacing);
}

.close-btn {
  background: transparent;
  color: var(--fg);
  border: none;
  font-size: var(--ui-font-size);
  cursor: pointer;
  padding: 0;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-btn:hover {
  color: var(--accent);
}

.export-text {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  background: transparent;
  color: var(--fg);
  font-size: var(--ui-font-size);
  line-height: var(--ui-line-height);
  white-space: pre;
  overflow-x: auto;
  font-family: "Unifont", monospace;
}

.export-text.fullsize {
  font-size: calc(var(--ui-font-size) * 1.2);
  line-height: 1.3;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.modal-footer {
  display: flex;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--accent);
  justify-content: flex-end;
}

.action-btn {
  padding: 0.5rem 1rem;
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--fg);
  font-family: "Unifont", monospace;
  font-size: var(--ui-font-size);
  cursor: pointer;
  transition: all 0.15s ease;
}

.action-btn:hover {
  background: var(--fg);
  color: var(--bg);
}

/* ===== Multiplayer UI ===== */

/* Name Entry Modal */
.name-modal-content {
  width: 350px;
  height: auto;
  max-height: none;
  padding: 20px;
  text-align: center;
}

.name-modal-content p {
  margin: 0 0 12px;
  font-size: var(--ui-font-size);
  color: #ccc;
}

.name-modal-content input {
  width: 100%;
  padding: 8px;
  margin-bottom: 15px;
  border: 1px solid #666;
  background: #1a1a1a;
  color: #fff;
  font-family: monospace;
  font-size: var(--ui-font-size);
  box-sizing: border-box;
}

.name-modal-content input:focus {
  outline: none;
  border-color: #0f0;
  color: #fff;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.modal-btn {
  padding: 8px 20px;
  border: 1px solid #666;
  background: transparent;
  color: #ccc;
  cursor: pointer;
  font-family: monospace;
  font-size: var(--ui-font-size);
}

.modal-btn:hover {
  color: #fff;
  border-color: #999;
}

/* Player List Sidebar */
.player-list {
  position: fixed;
  right: 0;
  top: 50px;
  width: 160px;
  max-height: 300px;
  border-left: 1px solid #444;
  background: rgba(10, 10, 10, 0.95);
  padding: 10px;
  font-family: monospace;
  font-size: var(--ui-font-size);
  overflow-y: auto;
  z-index: 50;
}

.player-list-header {
  color: #888;
  font-size: var(--ui-font-size);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid #333;
}

#player-list-content {
  list-style: none;
  padding: 0;
  margin: 0;
}

#player-list-content li {
  padding: 4px 0;
  color: #aaa;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}

#player-list-content li.self {
  color: #0f0;
  font-weight: bold;
}

#player-list-content li.self::before {
  content: "▶ ";
  margin-right: 4px;
}

/* Chat Sidebar */
.chat-sidebar {
  position: fixed;
  right: 0;
  top: 50px;
  width: 280px;
  max-height: 450px;
  background: rgba(10, 10, 10, 0.98);
  border-left: 1px solid #444;
  border-bottom: 1px solid #444;
  font-family: monospace;
  font-size: var(--ui-font-size);
  display: none;
  flex-direction: column;
  z-index: 100;
}

.chat-sidebar.open {
  display: flex;
}

.chat-header {
  padding: 8px 10px;
  border-bottom: 1px solid #333;
  color: #888;
  font-size: var(--ui-font-size);
  text-transform: uppercase;
  letter-spacing: 1px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.chat-close-btn {
  background: none;
  border: none;
  color: #666;
  cursor: pointer;
  font-size: var(--ui-font-size);
  padding: 0;
  width: auto;
  height: auto;
  display: flex;
  align-items: center;
}

.chat-close-btn:hover {
  color: #aaa;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  min-height: 200px;
}

.chat-message {
  margin-bottom: 8px;
  color: #aaa;
  line-height: 1.3;
  word-wrap: break-word;
}

.chat-message .timestamp {
  color: #666;
  font-size: var(--ui-font-size);
  margin-right: 4px;
}

.chat-message .name {
  color: #0f0;
  font-weight: bold;
}

.chat-message .text {
  color: #ddd;
}

.chat-input-area {
  padding: 8px;
  border-top: 1px solid #333;
}

.chat-input {
  width: 100%;
  padding: 6px;
  border: 1px solid #555;
  background: #1a1a1a;
  color: #ddd;
  font-family: monospace;
  font-size: var(--ui-font-size);
  margin-bottom: 6px;
  box-sizing: border-box;
}

.chat-input:focus {
  outline: none;
  border-color: #0f0;
  color: #fff;
}

.chat-hint {
  font-size: var(--ui-font-size);
  color: #666;
  text-align: center;
}

/* Speech Bubble */
.speech-bubble {
  position: absolute;
  background: rgba(20, 20, 20, 0.95);
  color: #fff;
  padding: 6px 10px;
  border-radius: 4px;
  font-family: monospace;
  font-size: var(--ui-font-size);
  max-width: 120px;
  word-wrap: break-word;
  border: 1px solid #555;
  pointer-events: all;
  cursor: pointer;
  z-index: 50;
  animation: fadeInOut 15s ease-out forwards;
}

.speech-bubble::after {
  content: '';
  position: absolute;
  bottom: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid rgba(20, 20, 20, 0.95);
}

.speech-bubble:hover {
  border-color: #0f0;
  background: rgba(30, 30, 30, 0.95);
}

@keyframes fadeInOut {
  0% { opacity: 1; }
  85% { opacity: 1; }
  100% { opacity: 0; }
}
