@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;600&display=swap");

:root {
  --bg-1: #f4efe6;
  --bg-2: #d6e6ff;
  --bg-3: #ffd7c2;
  --ink: #1b2430;
  --accent: #ff6b4a;
  --accent-2: #2b8cff;
  --panel: rgba(255, 255, 255, 0.78);
  --shadow: 0 30px 80px rgba(18, 28, 45, 0.2);
  --grid: rgba(27, 36, 48, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, var(--bg-2), transparent 55%),
    radial-gradient(circle at 80% 10%, var(--bg-3), transparent 55%),
    linear-gradient(135deg, var(--bg-1), #fdfaf5 50%, #f8f6ff);
  display: grid;
  place-items: center;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: -20% -10% auto;
  height: 70vh;
  background: conic-gradient(from 90deg, rgba(255, 107, 74, 0.15), rgba(43, 140, 255, 0.1));
  filter: blur(60px);
  opacity: 0.6;
  pointer-events: none;
  animation: drift 18s ease-in-out infinite;
}

.page {
  width: min(1100px, 94vw);
  display: grid;
  gap: 24px;
  padding: 28px 0 40px;
  position: relative;
  z-index: 1;
  grid-template-columns: 1fr 320px;
  grid-template-rows: auto 1fr 240px;
  grid-template-areas:
    "hud hud"
    "stage entity"
    "log log";
  min-height: 70vh;
}

.hud {
  grid-area: hud;
}

.stage {
  grid-area: stage;
}

.entity-panel {
  grid-area: entity;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  /* allow proper flex overflow */
  overflow: hidden;
}

.log-panel {
  grid-area: log;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: none;
  overflow: auto;
}

.entity-empty {
  opacity: 0.7;
  font-style: italic;
  padding: 8px;
  color: rgba(27, 36, 48, 0.75);
}

.hud {
  background: var(--panel);
  border-radius: 22px;
  padding: 18px 22px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  animation: floatIn 0.6s ease both;
}

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
}

.status .ws {
  font-size: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(27, 36, 48, 0.08);
  text-transform: none;
  letter-spacing: 0.02em;
}

.status .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 12px rgba(43, 140, 255, 0.6);
  animation: pulse 2.2s ease infinite;
}

.status[data-state="offline"] .dot {
  background: var(--accent);
  box-shadow: 0 0 12px rgba(255, 107, 74, 0.6);
}

.status[data-state="connecting"] .dot {
  background: #ffd166;
  box-shadow: 0 0 12px rgba(255, 209, 102, 0.6);
}



.stage {
  background: rgba(255, 255, 255, 0.72);
  border-radius: 26px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  padding: 18px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  animation: floatIn 0.8s ease 0.1s both;
}

.stage .viewport {
  position: relative;
}

canvas {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 18px;
  border: 1px solid rgba(27, 36, 48, 0.08);
  background: #fdf9f3;
  display: block;
}

#game {
  position: relative;
  z-index: 1;
}



@media (max-width: 720px) {
  .hud {
    flex-direction: column;
    align-items: stretch;
  }

  .status {
    flex-direction: column;
    align-items: flex-start;
  }

  /* Stack everything vertically into a single column layout for small screens */
  .page {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    grid-template-areas:
      "hud"
      "stage"
      "entity"
      "log";
    padding: 18px 8px 28px;
    gap: 14px;
  }

  .stage {
    padding: 12px;
  }

  /* Use a taller canvas aspect ratio and cap its height on small screens */
  canvas {
    aspect-ratio: 4 / 3;
    max-height: 45vh;
  }

  .entity-panel,
  .log-panel {
    max-height: 40vh;
    overflow: auto;
  }

  .entity-panel {
    padding: 12px;
  }

  .log-panel {
    padding: 12px;
    max-height: 36vh;
  }

}

@keyframes floatIn {
  from {
    opacity: 0;
    transform: translateY(14px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes drift {
  0% {
    transform: translate3d(-2%, -6%, 0) rotate(0deg);
  }

  50% {
    transform: translate3d(2%, 6%, 0) rotate(8deg);
  }

  100% {
    transform: translate3d(-2%, -6%, 0) rotate(0deg);
  }
}

@keyframes pulse {

  0%,
  100% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.2);
  }
}

.log-panel {
  background: var(--panel);
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.65);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  padding: 18px 22px;
  animation: floatIn 0.8s ease 0.2s both;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 240px;
}

.log-header {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.6;
}

.log-content {
  overflow-y: auto;
  font-family: "Space Mono", monospace;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--ink);
  scrollbar-width: thin;
  scrollbar-color: var(--accent-2) transparent;
}

.log-content::-webkit-scrollbar {
  width: 6px;
}

.log-content::-webkit-scrollbar-thumb {
  background-color: var(--accent-2);
  border-radius: 10px;
}

/* Entity list styles */
.entity-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-radius: 10px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.4);
  border: 1px solid rgba(27, 36, 48, 0.04);
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.entity-list-header {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.6;
}

.entity-list-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.entity-item {
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.entity-item:hover {
  background: rgba(43, 140, 255, 0.06);
}

.entity-item.selected {
  background: rgba(255, 107, 74, 0.12);
  border-left: 3px solid var(--accent);
}

.entity-item .entity-name {
  font-weight: 600;
  color: var(--ink);
}

.entity-item .entity-id {
  font-weight: 400;
  opacity: 0.8;
  font-size: 0.9em;
  margin-left: 8px;
}

.log-entry {
  opacity: 0.9;
  line-height: 1.4;
  word-break: break-word;
}

.log-entry .timestamp {
  opacity: 0.5;
  font-size: 0.9em;
  margin-right: 8px;
}

.log-entry .entity {
  font-weight: 600;
  color: var(--accent-2);
}

.log-entry .highlight {
  color: var(--accent);
  font-weight: 600;
}

.log-entry .entity-id {
  font-weight: 400;
  opacity: 0.7;
  font-size: 0.9em;
  margin-left: 4px;
}