:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-strong: #1f2430;
  --text: #f3f5f8;
  --muted: #9aa3b2;
  --accent: #4caf50;
  --accent-strong: #2e7d32;
  --border: rgba(255,255,255,0.12);
  --shadow: 0 18px 48px rgba(0,0,0,0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: Arial, Helvetica, sans-serif;
  background: linear-gradient(135deg, #0f1115 0%, #1a1f2b 100%);
  color: var(--text);
  overflow-x: hidden;
}

body.page {
  min-height: 100vh;
}

body.page-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.page-shell {
  width: min(100%, 480px);
}

.page-card {
  background: rgba(23, 26, 33, 0.95);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-card {
  width: 100%;
}

#login-form,
#register {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#login-form h2,
#register h2 {
  margin: 0 0 8px;
  font-size: 1.6rem;
  text-align: center;
}

input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: #ffffff;
  color: #222;
  font-size: 1rem;
}

button,
.login-button {
  width: 100%;
  padding: 12px 14px;
  border: none;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  cursor: pointer;
  font-size: 1rem;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

button:hover,
.login-button:hover {
  transform: translateY(-1px);
  opacity: 0.95;
}

.error {
  color: #ff7b7b;
  font-size: 0.95rem;
  min-height: 1.2em;
}

.page-link {
  text-align: center;
  color: var(--muted);
}

.page-link a {
  color: var(--accent);
  text-decoration: none;
}

.page-link a:hover {
  text-decoration: underline;
}

body.page-game {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: #07080b;
}

body.mobile-drawer-open {
  overflow: hidden;
}

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

#banner {
  width: 100%;
  height: 140px;
  overflow: hidden;
  background: #111;
  border-bottom: 1px solid var(--border);
}

#banner img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

#layout-container {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 240px;
  flex: 1;
  min-height: 0;
  min-width: 0;
  align-items: stretch;
}

#game-main-shell {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.app-sidebar {
  background: var(--panel);
  color: var(--text);
  padding: 16px;
  border-right: 1px solid var(--border);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.drawer-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-weight: 700;
  color: #d7e8ff;
}

.drawer-close,
.mobile-nav-button {
  width: auto;
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 0.95rem;
  background: linear-gradient(135deg, #284263 0%, #1f5ea8 100%);
}

.mobile-nav-bar {
  display: none;
  gap: 10px;
  padding: 10px 12px 0;
}

#mobile-drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(3, 6, 10, 0.62);
  z-index: 1100;
}

#right-sidebar {
  border-left: 1px solid var(--border);
  border-right: 0;
}

.app-sidebar nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  min-height: 0;
}

.app-sidebar a {
  color: #9fe59a;
  text-decoration: none;
  font-weight: 600;
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
}

.app-sidebar a:hover,
[data-scene].active {
  background: rgba(76, 175, 80, 0.16);
  color: #d9ffd8;
}

.maps-collapsible-item {
  list-style: none;
}

.maps-collapsible {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  padding: 4px;
}

.maps-collapsible summary {
  color: #9fe59a;
  font-weight: 700;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 6px;
  user-select: none;
}

.maps-collapsible summary:hover {
  background: rgba(76, 175, 80, 0.16);
  color: #d9ffd8;
}

.maps-collapsible ul {
  list-style: none;
  margin: 6px 0 2px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.maps-collapsible ul a {
  padding-left: 12px;
}

.maps-section {
  margin-top: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}

.maps-section h4 {
  color: #cfe3ff;
  margin: 0 0 8px;
  font-size: 14px;
  letter-spacing: 0.02em;
}

.maps-section ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#game-container {
  position: relative;
  background: #000;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

#game-container canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
}

@media (max-width: 1200px) {
  #layout-container {
    grid-template-columns: 210px minmax(0, 1fr) 210px;
  }
}

@media (max-width: 980px) {
  #banner {
    height: 96px;
  }

  #layout-container {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(320px, 1fr);
  }

  .app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    width: min(84vw, 320px);
    max-width: 320px;
    z-index: 1200;
    padding: 12px;
    gap: 12px;
    overflow-y: auto;
    border-left: 0;
    border-right: 0;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
    transition: transform 0.2s ease;
  }

  #left-sidebar {
    left: 0;
    transform: translateX(-100%);
  }

  #right-sidebar {
    right: 0;
    transform: translateX(100%);
  }

  #left-sidebar.drawer-open,
  #right-sidebar.drawer-open {
    transform: translateX(0);
  }

  .drawer-header,
  .mobile-nav-bar {
    display: flex;
  }

  .app-sidebar nav ul {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
  }

  .app-sidebar a {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  .maps-section {
    margin-top: 0;
  }

  #game-main-shell {
    min-height: 0;
  }

  #game-container {
    min-height: min(62vh, 540px);
    padding: 8px;
  }
}

@media (max-width: 640px) {
  #banner {
    height: 72px;
  }

  .app-sidebar {
    padding: 10px;
  }

  .app-sidebar nav ul {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .maps-section ul {
    gap: 8px;
  }

  .maps-section h4 {
    font-size: 13px;
  }

  #game-container {
    min-height: min(56vh, 420px);
    padding: 6px;
  }
}

@media (max-width: 420px) {
  .app-sidebar nav ul {
    grid-template-columns: 1fr;
  }

  .app-sidebar a {
    font-size: 0.95rem;
    padding: 10px 12px;
  }
}
