:root {
  color-scheme: dark;
  font-family: "IBM Plex Mono", "Courier New", monospace;
  --bg: #020617;
  --panel-bg: rgba(2, 6, 23, 0.82);
  --panel-border: rgba(148, 163, 184, 0.35);
  --accent: #38bdf8;
  --text: #e2e8f0;
  --muted: rgba(148, 163, 184, 0.75);
  --tile-bg: #0b1120;
  --layout-padding: clamp(1.5rem, 2vw + 1rem, 3rem);
  --layout-gap: clamp(1.5rem, 2vw + 1rem, 3rem);
  --sidebar-width: clamp(280px, 24vw, 360px);
  --screen-width: max(0px, calc(100% - var(--sidebar-width) - var(--layout-gap)));
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: var(--layout-padding);
  box-sizing: border-box;
  overflow: hidden;
  background: radial-gradient(circle at center, rgba(15, 23, 42, 0.75) 0%, #000814 100%);
  color: var(--text);
}

.layout {
  width: 100%;
  margin: 0 auto;
  display: grid;
  gap: var(--layout-gap);
  grid-template-columns: minmax(0, var(--screen-width)) var(--sidebar-width);
  align-items: stretch;
  height: calc(100vh - 2 * var(--layout-padding));
  min-height: 0;
  overflow: hidden;
}

.screen {
  position: relative;
  padding: 1.5rem;
  background: linear-gradient(155deg, rgba(15, 23, 42, 0.9), rgba(15, 23, 42, 0.7));
  box-shadow: inset 0 0 40px rgba(15, 23, 42, 0.6), 0 20px 48px rgba(2, 6, 23, 0.65);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: stretch;
  gap: 1rem;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.viewport {
  position: relative;
  width: 100%;
  height: 100%;
  max-height: 100%;
  display: flex;
  align-items: stretch;
  justify-content: center;
  flex: 1 1 auto;
  min-height: 0;
}

.viewport > canvas {
  width: 100%;
  height: 100%;
  flex: 1 1 auto;
}

#game {
  display: block;
  image-rendering: pixelated;
  background: var(--tile-bg);
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.viewport .dialogue {
  position: absolute;
  inset: auto 1rem 1rem;
  min-height: 140px;
  padding: 1rem 1.25rem;
  border-radius: 0.75rem;
  background: rgba(6, 12, 24, 0.78);
  border: 1px solid rgba(94, 234, 212, 0.35);
  box-shadow: 0 10px 26px rgba(2, 6, 23, 0.55);
  font-size: 0.9rem;
  line-height: 1.5;
  display: none;
  z-index: 2;
}

.viewport .dialogue.active {
  display: block;
}

.viewport .dialogue h3 {
  margin: 0 0 0.5rem;
  color: var(--accent);
  font-size: 1rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.viewport .dialogue p {
  margin: 0.5rem 0;
}

.viewport .dialogue ul {
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.4rem;
}

.viewport .dialogue li {
  border: 1px solid rgba(59, 130, 246, 0.35);
  border-radius: 0.6rem;
  padding: 0.55rem 0.75rem;
  background: rgba(15, 23, 42, 0.72);
}

.viewport .dialogue li span.key {
  color: rgba(129, 140, 248, 0.9);
  margin-right: 0.5rem;
}

.viewport .map-overlay {
  position: absolute;
  inset: 1rem;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(2, 6, 23, 0.85);
  border: 1px solid rgba(94, 234, 212, 0.35);
  border-radius: 1rem;
  box-shadow: 0 12px 32px rgba(2, 6, 23, 0.65);
  z-index: 4;
}

.viewport .map-overlay.active {
  display: flex;
}

.map-card {
  width: min(100%, 420px);
  display: grid;
  gap: 1rem;
  text-align: center;
}

.map-card header {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.map-card header h3 {
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.map-card header p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

#world-map {
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  border-radius: 0.75rem;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.85);
}

.map-card .legend {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.map-card .legend li {
  display: inline-flex;
  gap: 0.4rem;
  align-items: center;
  justify-content: center;
}

.map-card .legend .marker {
  width: 0.8rem;
  height: 0.8rem;
  border-radius: 999px;
  display: inline-block;
  background: var(--muted);
  box-shadow: 0 0 6px rgba(148, 163, 184, 0.45);
}

.map-card .legend .marker-player {
  background: #f8fafc;
}

.map-card .legend .marker-npc {
  background: #38bdf8;
}

.map-card .legend .marker-gate {
  background: #f472b6;
}

.map-card .legend .marker-item {
  background: #34d399;
}

.map-card .legend .marker-monster {
  background: #fbbf24;
}

.hud-container {
  height: 100%;
  min-height: 0;
  display: flex;
  width: var(--sidebar-width);
}

.hud-scroll {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding-right: 0.5rem;
  margin-right: -0.5rem;
}

.hud {
  display: grid;
  gap: 1rem;
  flex: 1;
  min-height: 0;
}

.panel {
  padding: 1rem 1.25rem;
  border-radius: 0.9rem;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(6px);
  box-shadow: 0 10px 28px rgba(2, 6, 23, 0.55);
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.panel ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

.panel ul li {
  font-size: 0.95rem;
  color: var(--muted);
}

.panel.log ul {
  max-height: 160px;
  overflow: hidden;
  display: flex;
  flex-direction: column-reverse;
}

.panel.help p {
  margin: 0.2rem 0;
  font-size: 0.9rem;
  color: var(--muted);
}

@media (max-width: 960px) {
  body {
    padding: 1.5rem 1rem;
    overflow: auto;
  }

  .layout {
    grid-template-columns: 1fr;
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .screen {
    height: auto;
    align-items: center;
  }

  .hud-container {
    height: auto;
    width: 100%;
  }

  .hud-scroll {
    overflow: visible;
    padding-right: 0;
    margin-right: 0;
  }

  .hud {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
}
