* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: #0a0d14;
  color: #e6ecf2;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
}

.hud {
  position: fixed;
  background: rgba(15, 20, 30, 0.78);
  border: 1px solid rgba(120, 150, 200, 0.25);
  border-radius: 8px;
  padding: 10px 14px;
  backdrop-filter: blur(6px);
  user-select: none;
  pointer-events: auto;
  font-size: 14px;
  line-height: 1.45;
}

#hud-top-left {
  top: 16px;
  left: 16px;
  min-width: 180px;
}

#level-name {
  font-weight: 600;
  font-size: 16px;
  color: #b9d1ff;
  margin-bottom: 4px;
}

#completed-badge {
  display: inline-block;
  background: rgba(60, 140, 90, 0.25);
  color: #a8e6c2;
  border: 1px solid rgba(120, 200, 150, 0.45);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  margin-bottom: 4px;
  letter-spacing: 0.3px;
}

#completed-badge.hidden {
  display: none;
}

#hud-top-right {
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  align-items: center;
}

#hud-top-right button,
#hud-top-right #level-trigger {
  background: #1a2230;
  color: #e6ecf2;
  border: 1px solid rgba(120, 150, 200, 0.35);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
}

#hud-top-right button:hover,
#hud-top-right #level-trigger:hover {
  background: #243047;
  border-color: rgba(180, 200, 240, 0.6);
}

#hud-top-right button:active,
#hud-top-right #level-trigger:active {
  background: #2c3a55;
}

.dropdown-wrap {
  position: relative;
}

#level-trigger {
  text-align: left;
  min-width: 180px;
  display: flex;
  align-items: center;
  gap: 6px;
}

#level-trigger .check {
  display: inline-block;
  width: 12px;
  text-align: center;
  color: #6fe09a;
  font-weight: bold;
  flex-shrink: 0;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: #141d2b;
  border: 1px solid rgba(120, 150, 200, 0.45);
  border-radius: 8px;
  padding: 4px 0;
  margin: 0;
  list-style: none;
  max-height: 60vh;
  overflow-y: auto;
  min-width: 220px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 20;
}

.dropdown-menu.hidden {
  display: none;
}

.dropdown-menu li {
  padding: 6px 14px 6px 10px;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  user-select: none;
}

.dropdown-menu li:hover {
  background: rgba(80, 120, 180, 0.30);
}

.dropdown-menu li.current {
  background: rgba(80, 120, 180, 0.45);
}

.dropdown-menu .check {
  display: inline-block;
  width: 14px;
  text-align: center;
  color: #6fe09a;
  font-weight: bold;
  flex-shrink: 0;
}

#legend {
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 18px;
  font-size: 13px;
}

.lg-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sw {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

.sw-start    { background: #ffd35c; box-shadow: 0 0 8px #ffd35c; }
.sw-dot      { background: #62d2ff; box-shadow: 0 0 8px #62d2ff; }
.sw-visited  { background: #4a5970; }
.sw-knight   { background: #ff7ad0; box-shadow: 0 0 8px #ff7ad0; }
.sw-ghost    { background: rgba(180, 255, 200, 0.4); box-shadow: 0 0 8px rgba(180,255,200,0.5); }

#win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 10, 20, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(4px);
}

#win-overlay.hidden { display: none; }

.win-card {
  background: #141d2b;
  border: 1px solid rgba(180, 200, 240, 0.4);
  border-radius: 12px;
  padding: 28px 36px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

.win-card h2 {
  margin: 0 0 8px;
  font-size: 28px;
  color: #ffd35c;
}

.win-card p {
  margin: 0 0 18px;
  color: #cfd8e3;
}

.win-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.win-actions button {
  background: #2a3a55;
  color: #e6ecf2;
  border: 1px solid rgba(180, 200, 240, 0.4);
  border-radius: 6px;
  padding: 8px 16px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}

.win-actions button:hover {
  background: #3a4d70;
}

#intro-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(180deg, rgba(8, 12, 20, 0.96), rgba(20, 14, 30, 0.96));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
  padding: 24px;
  overflow-y: auto;
}

#intro-overlay.hidden { display: none; }

.intro-card {
  background: #141d2b;
  border: 1px solid rgba(180, 200, 240, 0.35);
  border-radius: 14px;
  padding: 36px 40px;
  max-width: 640px;
  width: 100%;
  text-align: center;
  box-shadow: 0 16px 60px rgba(0, 0, 0, 0.7);
}

.intro-card h1 {
  margin: 0 0 10px;
  font-size: 32px;
  color: #ffd35c;
  letter-spacing: 0.5px;
}

.intro-tagline {
  margin: 0 0 28px;
  color: #b9c5d4;
  font-size: 15px;
  line-height: 1.5;
}

.intro-modes {
  display: flex;
  gap: 14px;
  margin-bottom: 20px;
}

.intro-mode {
  flex: 1;
  background: #1c2738;
  color: #e6ecf2;
  border: 1px solid rgba(120, 150, 200, 0.4);
  border-radius: 10px;
  padding: 16px 16px 18px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: background 0.12s, border-color 0.12s, transform 0.12s;
}

.intro-preview {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  margin-bottom: 12px;
  background: linear-gradient(180deg, #0a0d14 0%, #11151f 100%);
  border-radius: 6px;
  border: 1px solid rgba(120, 150, 200, 0.15);
}

.intro-mode:hover {
  background: #243246;
  border-color: rgba(180, 200, 240, 0.7);
  transform: translateY(-1px);
}

.intro-mode h2 {
  margin: 0 0 6px;
  font-size: 18px;
  color: #b9d1ff;
}

.intro-mode p {
  margin: 0;
  font-size: 13px;
  color: #99a5b8;
  line-height: 1.4;
}

.intro-howto {
  text-align: left;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(120, 150, 200, 0.2);
  border-radius: 8px;
  padding: 10px 14px;
  color: #aab5c8;
  font-size: 13px;
  margin-top: 8px;
}

.intro-howto summary {
  cursor: pointer;
  color: #b9d1ff;
  font-weight: 500;
}

.intro-howto ul {
  margin: 10px 0 0;
  padding-left: 18px;
  line-height: 1.6;
}

@media (max-width: 640px) {
  .intro-card { padding: 24px 20px; }
  .intro-card h1 { font-size: 24px; }
  .intro-modes { flex-direction: column; }
}

@media (max-width: 640px) {
  #hud-top-left {
    font-size: 11px;
    padding: 6px 10px;
    min-width: 0;
    max-width: 44vw;
    line-height: 1.35;
  }
  #level-name {
    font-size: 13px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  #hud-top-right {
    padding: 6px 8px;
    gap: 4px;
    max-width: 52vw;
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  #hud-top-right #level-trigger {
    max-width: 150px;
    font-size: 11px;
    padding: 4px 6px;
    min-width: 0;
  }
  #hud-top-right button {
    font-size: 11px;
    padding: 4px 8px;
  }
  .dropdown-menu {
    font-size: 12px;
    max-width: 80vw;
  }
  .dropdown-menu li {
    font-size: 12px;
  }

  #legend {
    font-size: 11px;
    gap: 10px;
    padding: 6px 10px;
    bottom: 12px;
    max-width: calc(100vw - 24px);
    flex-wrap: wrap;
    justify-content: center;
  }

  .win-card {
    padding: 22px 24px;
    margin: 0 16px;
  }
  .win-card h2 { font-size: 22px; }
}
