:root {
  --fg: #e6f6ff;
  --muted: #9fb3c8;
  --bg: #030816;
  --panel: rgba(10, 14, 28, 0.72);
  --accent: #8b5cf6;
  --good: #34d399;
  --bad: #f87171;
  --gold: #fbbf24;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --neb1: #0ea5e9;
  --neb2: #a78bfa;
  --neb3: #f472b6;
  --stars: #e5e7eb;
}
html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    Segoe UI,
    Roboto,
    Arial,
    Noto Sans;
  overflow: hidden;
  user-select: none;
}
#wrap {
  position: relative;
  width: 100vw;
  height: 100vh;
}
canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* HUD */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: 20px;
  z-index: 2;
}
.row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.pill {
  background: var(--panel);
  backdrop-filter: blur(4px);
  border: 1px solid #262938;
  padding: 8px 12px;
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.bar {
  position: relative;
  height: 14px;
  min-width: 220px;
  width: 560px;
  border-radius: 999px;
  background: #1b1e2b;
  border: 1px solid #2a2f44;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.bar > .fill {
  position: absolute;
  inset: 0;
  width: 0%;
  background: linear-gradient(90deg, #60a5fa, #22d3ee);
}
.hpbar {
  width: 220px;
}
.hpbar > .fill {
  background: linear-gradient(90deg, #f87171, #fbbf24);
}

.cdbar {
  width: 100%;
  min-width: 120px;
  height: 8px;
}
.cdbar > .fill {
  background: linear-gradient(90deg, #f97316, #fbbf24);
}
.timer {
  font-weight: 700;
  letter-spacing: 0.05em;
}

/* Boss bar */
#bossWrap {
  position: absolute;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  display: none;
  z-index: 2;
}
#bossWrap.show {
  display: block;
}
#bossName {
  text-align: center;
  margin-bottom: 6px;
  color: #f59e0b;
  font-weight: 800;
}
#bossBar {
  width: min(640px, 70vw);
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: radial-gradient(
    120% 80% at 50% 20%,
    rgba(2, 6, 23, 0.6),
    rgba(2, 6, 23, 0.9)
  );
  padding: 24px;
  z-index: 3;
}
.overlay.show {
  display: grid;
}
.overlay .close-panel {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--fg);
}
.overlay .card > .close-panel {
  position: absolute;
  top: 8px;
  right: 12px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.modal-header h2 {
  margin: 0;
  font-size: 24px;
}
.modal-header .close-panel {
  position: static;
  margin-left: 16px;
  font-size: 24px;
}
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: linear-gradient(180deg, #0b1120, #0a0f1a);
  border: 1px solid #29334f;
  border-radius: 16px;
  padding: 16px;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.6),
    inset 0 0 0 1px rgba(148, 163, 184, 0.08);
  max-width: min(1200px, 96%);
  max-height: 65%;
}

.modal-body {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.title {
  font-size: 22px;
  font-weight: 800;
  margin: 0 0 8px;
}
.subtitle {
  margin: 0 0 12px;
  color: var(--muted);
}
.btns {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}
button {
  appearance: none;
  border: 1px solid #2a2f44;
  background: #1a1c28;
  color: #e6f6ff;
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  transition:
    transform 0.05s ease,
    background 0.2s ease,
    border-color 0.2s;
  font-weight: 700;
}

/* Main menu layout */
#menu {
  position: relative;
  padding: 0;
  background: #030816;
  height: 100%;
}

#menu::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(at 20% 30%, rgba(62, 105, 255, 0.25), transparent 60%),
    radial-gradient(at 80% 20%, rgba(255, 153, 51, 0.2), transparent 60%),
    radial-gradient(at 60% 80%, rgba(0, 204, 255, 0.2), transparent 60%),
    radial-gradient(2px 2px at 15% 25%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 35% 40%, #fff, transparent),
    radial-gradient(1px 1px at 55% 65%, #fff, transparent),
    radial-gradient(1.8px 1.8px at 75% 30%, #fff, transparent),
    radial-gradient(1.2px 1.2px at 85% 80%, #fff, transparent),
    radial-gradient(1px 1px at 25% 75%, #fff, transparent);
  background-repeat: no-repeat;
  z-index: 0;
}

#menu > * {
  z-index: 1;
}
#scrapInfo {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 2;
}
#topCenter {
  position: absolute;
  top: 116px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 2;
}
#tabIcons {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 12px;
  z-index: 2;
}
#tabIcons .menu-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 20px;
  padding: 10px 14px;
}
.play-btn {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 24px;
  padding: 12px 32px;
  z-index: 2;
}

/* Prevent jump on click due to global button:active transform */
.play-btn:active {
  transform: translateX(-50%);
}

/* Fullscreen map */
#menu .map {
  position: absolute;
  inset: 0;
  margin: 0;
  background: transparent;
  z-index: 0;
}
#menu .map-inner {
  position: absolute;
  top: 70%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 50%;
  height: 50%;
  max-width: none;
  max-height: none;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: none;
}

#menu .map .node .planet {
  transition:
    transform 0.2s,
    filter 0.2s,
    stroke 0.2s;
  stroke: #223049;
  stroke-width: 2px;
}
#menu .map .node.available .planet {
  stroke: #94a3b8;
  filter: drop-shadow(0 0 3px rgba(148, 163, 184, 0.5));
}
#menu .map .node.selected .planet {
  transform: scale(1.3);
  stroke: #ffd84a;
  stroke-width: 4px;
  filter: drop-shadow(0 0 6px rgba(255, 216, 74, 0.8));
}
#menu .map .node.locked .planet,
#menu .map .node.coming .planet {
  stroke: #475569;
  filter: grayscale(1) opacity(0.5);
}
#menu .map .node .label {
  fill: #cfeaff;
  transition: fill 0.2s;
}
#menu .map .node.selected .label {
  fill: #fef3c7;
}
#menu .map .node.locked .label,
#menu .map .node.coming .label {
  fill: #475569;
}
button:hover {
  background: #202335;
}
button:active {
  transform: scale(0.98);
}
.btn-primary {
  background:
    radial-gradient(
      120% 120% at 20% -10%,
      rgba(34, 211, 238, 0.25),
      transparent 40%
    ),
    linear-gradient(90deg, #0b1020, #0d1430);
  border-color: #243b55;
  box-shadow:
    inset 0 0 0 1px rgba(148, 163, 184, 0.08),
    0 8px 26px rgba(14, 165, 233, 0.25);
}
.btn-primary:hover {
  background:
    radial-gradient(
      120% 120% at 20% -10%,
      rgba(99, 102, 241, 0.25),
      transparent 40%
    ),
    linear-gradient(90deg, #0e1736, #101c44);
}
button[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Level up */
#levelup .choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}
.upgrade-card {
  border-radius: 14px;
  padding: 12px;
  border: 1px solid #2a2f44;
  background: #141724;
  cursor: pointer;
}
.upgrade-card:hover {
  outline: 2px solid #3252a6;
}
.upgrade-name {
  font-weight: 800;
  margin-bottom: 4px;
}
.upgrade-desc {
  color: var(--muted);
  font-size: 14px;
}

/* Toast */
#toast {
  position: absolute;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 999px;
  background: #162326;
  border: 1px solid #2b464c;
  display: none;
  z-index: 4;
}
#toast.show {
  display: block;
  animation: pop 0.25s ease;
}
@keyframes pop {
  from {
    transform: translateX(-50%) scale(0.9);
    opacity: 0.5;
  }
  to {
    transform: translateX(-50%) scale(1);
    opacity: 1;
  }
}

#help {
  position: absolute;
  right: 4px;
  bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  opacity: 0.75;
  z-index: 2;
}

/* Loading screen */
#loading {
  z-index: 999;
  transition: opacity 0.5s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  text-align: center;
  background: var(--bg);
  padding: 8vh 0 12vh;
}
#loading.hide {
  opacity: 0;
  pointer-events: none;
}
#loading .center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
#loading .logo {
  font-size: clamp(48px, 10vw, 96px);
}
#loading .studio {
  color: var(--muted);
  font-weight: 600;
  font-size: clamp(14px, 2vw, 24px);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
#loading .loading-bar {
  width: min(480px, 80vw);
  height: 18px;
}

/* Menu tabs */
.tabs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  position: static;
  background: none;
  padding: 0;
}
.tab {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid #263149;
  background: #0b1220;
  cursor: pointer;
  box-shadow:
    inset 0 0 0 1px rgba(148, 163, 184, 0.06),
    0 6px 18px rgba(2, 8, 23, 0.6);
  width: 100%;
  text-align: left;
}
.tab.active {
  background: linear-gradient(
    90deg,
    rgba(99, 102, 241, 0.25),
    rgba(14, 165, 233, 0.25)
  );
  box-shadow:
    inset 0 0 0 1px rgba(56, 189, 248, 0.35),
    0 0 30px rgba(99, 102, 241, 0.35);
}
/*#panelPlay {*/
/*  overflow-y: initial;*/
/*}*/
.panel {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding-right: 8px;
}
.panel.show {
  display: block;
}

.menu-left {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.menu-right {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.panel::-webkit-scrollbar {
  width: 8px;
}
.panel::-webkit-scrollbar-track {
  background: rgba(148, 163, 184, 0.1);
  border-radius: 4px;
}
.panel::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.3);
  border-radius: 4px;
}
.panel::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.5);
}

/* Shop / settings */
.meta-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}
.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  background: #121420;
  border: 1px solid #2a2f44;
  border-radius: 12px;
  padding: 10px;
}
.meta-row .info {
  color: var(--muted);
}
.meta-row .bar {
  width: 300px;
}
.meta-row .info b {
  color: #e6f6ff;
}

/* Daily tasks styling */
.daily-row {
  flex-direction: column;
  align-items: flex-start;
}

.daily-row.done {
  opacity: 0.6;
}

.daily-row .task-head {
  display: flex;
  justify-content: space-between;
  width: 100%;
  gap: 8px;
}

.daily-row .reward {
  color: var(--accent);
  font-weight: 700;
}

.daily-row .reward::after {
  content: "\2699";
  margin-left: 2px;
}

.daily-row .bar {
  width: 100%;
  margin-top: 6px;
}
.range {
  width: min(360px, 60vw);
}
.selects {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin: 0 0 10px;
}
select {
  background: #0b1220;
  color: #e6f6ff;
  border: 1px solid #223049;
  border-radius: 10px;
  padding: 8px 10px;
}
.char-list {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 4px;
}

.char-select {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.char-select > span {
  margin-bottom: 12px;
}
.char-option {
  border: 1px solid #223049;
  border-radius: 8px;
  padding: 8px;
  width: 120px;
  height: 150px;
  flex: 0 0 auto;
  text-align: center;
  position: relative;
  cursor: pointer;
  background: #0b1220;
  color: #e6f6ff;
  font-size: 12px;
  display: flex;
  flex-direction: column;
}
.char-option.selected {
  border-color: #ffd84a;
}
.char-option.locked {
  opacity: 0.5;
  cursor: default;
}
.char-option input {
  display: none;
}
.char-option .icon {
  font-size: 32px;
  margin-bottom: 6px;
}
.char-option .desc {
  font-size: 12px;
  flex: 1 1 auto;
  overflow: auto;
  white-space: pre-line;
}

.char-option button {
  margin-top: auto;
  font-size: 12px;
  padding: 4px 6px;
}

.diff-select {
  display: flex;
  align-items: center;
  gap: 8px;
}

.diff-options {
  display: flex;
  gap: 4px;
}

.diff-option {
  border: 1px solid #223049;
  background: #0b1220;
  color: #e6f6ff;
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

.diff-option.selected {
  border-color: #ffd84a;
  color: #ffd84a;
}

/* Cosmic backdrop (pure CSS) */
body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
body::before {
  background:
    radial-gradient(
      1200px 600px at 10% 0%,
      rgba(14, 165, 233, 0.18),
      transparent 60%
    ),
    radial-gradient(
      900px 700px at 90% 10%,
      rgba(167, 139, 250, 0.14),
      transparent 65%
    ),
    radial-gradient(
      800px 900px at 40% 90%,
      rgba(244, 114, 182, 0.1),
      transparent 70%
    );
  filter: saturate(1.1) blur(0.2px);
}
body::after {
  background-image:
    radial-gradient(2px 2px at 10% 20%, var(--stars), transparent 50%),
    radial-gradient(1.5px 1.5px at 25% 35%, var(--stars), transparent 50%),
    radial-gradient(1.3px 1.3px at 40% 70%, var(--stars), transparent 50%),
    radial-gradient(1.7px 1.7px at 65% 25%, var(--stars), transparent 50%),
    radial-gradient(1.2px 1.2px at 78% 55%, var(--stars), transparent 50%),
    radial-gradient(1.1px 1.1px at 88% 85%, var(--stars), transparent 50%),
    radial-gradient(1.6px 1.6px at 15% 85%, var(--stars), transparent 50%);
  opacity: 0.25;
  animation: twinkle 6s linear infinite alternate;
}
@keyframes twinkle {
  from {
    opacity: 0.2;
  }
  to {
    opacity: 0.35;
  }
}

/* Hero header */
.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  align-items: center;
  margin-bottom: 16px;
}
.logo {
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: linear-gradient(90deg, var(--neb1), var(--neb2), var(--neb3));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 16px rgba(99, 102, 241, 0.35);
}
.logo span {
  text-shadow: 0 0 12px rgba(14, 165, 233, 0.25);
}
.tagline {
  grid-column: 1 / -1;
  color: var(--muted);
  margin-top: -2px;
}

/* 🆕 achievements visuals */
.meta-row.locked {
  opacity: 0.75;
}
.ach-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 100%);
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  padding: 8px 16px;
  border-radius: 4px;
  opacity: 0;
  transition:
    opacity 0.3s,
    transform 0.3s;
  z-index: 1000;
}
.ach-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Map Panel */
.map {
  position: relative;
  margin-top: 18px;
}
.map-inner {
  position: relative;
  border-radius: 12px;
  height: 240px;
  background:
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.03),
      rgba(255, 255, 255, 0.015)
    ),
    radial-gradient(
      100% 100% at 0% 0%,
      rgba(35, 210, 238, 0.08) 0%,
      transparent 60%
    ),
    #081a30;
  overflow: hidden;
  border: 1px solid rgba(35, 210, 238, 0.35);
  box-shadow: var(--shadow);
}
.grid-lines {
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background:
    linear-gradient(transparent 23px, rgba(66, 164, 245, 0.12) 24px),
    linear-gradient(90deg, transparent 23px, rgba(66, 164, 245, 0.12) 24px);
  background-size:
    24px 24px,
    24px 24px;
}
.map svg {
  position: absolute;
  inset: 0;
}
.map .edge {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 64px;
  display: grid;
  place-items: center;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.06),
    rgba(255, 255, 255, 0.02)
  );
  border: 1px solid rgba(35, 210, 238, 0.45);
  box-shadow: var(--shadow);
  border-radius: 10px;
  cursor: pointer;
}
.edge.left {
  left: -6px;
}
.edge.right {
  right: -6px;
}
.edge svg {
  width: 22px;
  height: 22px;
}

:root {
  --base-w: 1366;
  --base-h: 768;
  --scale: 1;
}

/* По умолчанию — как сейчас */
body:not(.scale-fit) #wrap {
  width: 100vw;
  height: 100vh;
  position: relative;
  transform: none;
}

/* Когда надо вписать меньше 1366x768 — масштабируем и центрируем */
body.scale-fit #wrap {
  width: calc(var(--base-w) * 1px);
  height: calc(var(--base-h) * 1px);
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: center center;
  transform: translate(-50%, -50%) scale(var(--scale));
}
