:root {
  --bg: #05060f;
  --bg-soft: #0c0f1e;
  --panel: rgba(18, 23, 42, 0.82);
  --panel-border: rgba(120, 140, 200, 0.18);
  --text: #e8ecf6;
  --muted: #97a2c0;
  --primary: #6b8bff;
  --primary-hover: #839dff;
  --accent: #35f0c8;
  --danger: #ff6b6b;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body.page {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 50% -10%, #16204a 0%, transparent 60%),
    var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
}

.stars {
  position: fixed;
  inset: 0;
  background-image:
    radial-gradient(1px 1px at 20% 30%, #fff, transparent),
    radial-gradient(1px 1px at 70% 60%, #cfe0ff, transparent),
    radial-gradient(1.5px 1.5px at 40% 80%, #fff, transparent),
    radial-gradient(1px 1px at 85% 20%, #fff, transparent),
    radial-gradient(1px 1px at 10% 70%, #bcd0ff, transparent),
    radial-gradient(1px 1px at 55% 15%, #fff, transparent);
  background-size: 400px 400px, 500px 500px, 600px 600px, 300px 300px, 450px 450px, 550px 550px;
  opacity: 0.7;
  pointer-events: none;
  z-index: 0;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, border-color .15s ease;
  font-family: inherit;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #0a0f24; }
.btn-primary:hover { background: var(--primary-hover); color: #0a0f24; }
.btn-ghost { background: transparent; border-color: var(--panel-border); color: var(--text); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn-lg { padding: 14px 26px; font-size: 16px; }
.btn-block { width: 100%; }
.btn.small { padding: 6px 12px; font-size: 13px; }

/* Landing */
.hero { position: relative; z-index: 1; max-width: 1080px; margin: 0 auto; padding: 28px 24px 60px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.topbar nav { display: flex; gap: 10px; }
.brand { font-weight: 800; letter-spacing: 3px; font-size: 18px; }
.brand.small { font-size: 14px; letter-spacing: 2px; }
.brand-center { text-align: center; justify-content: center; display: flex; margin-bottom: 12px; }

.hero-content { margin: 80px 0 60px; max-width: 760px; }
.hero-content h1 { font-size: clamp(30px, 4.5vw, 48px); line-height: 1.1; margin: 0 0 20px; }
.lede { color: var(--muted); font-size: 18px; line-height: 1.7; }
.actions { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-top: 28px; }
.welcome { color: var(--muted); margin: 0; }

.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; margin-top: 40px; }
.card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 22px;
  backdrop-filter: blur(6px);
}
.card h3 { margin: 0 0 10px; font-size: 17px; color: var(--accent); }
.card p { margin: 0; color: var(--muted); line-height: 1.6; font-size: 15px; }

.footer {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--panel-border);
}

/* Auth */
.auth-wrap {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.back-link { align-self: flex-start; margin: 0 auto 14px; max-width: 420px; width: 100%; color: var(--muted); font-size: 14px; }
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 34px 30px;
  backdrop-filter: blur(10px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
}
.auth-card.center { text-align: center; }
.auth-card h1 { margin: 0 0 6px; font-size: 24px; text-align: center; }
.auth-card .muted { text-align: center; margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 6px; font-size: 14px; color: var(--text); }
.field .opt { color: var(--muted); font-weight: 400; }
.field input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(6, 10, 24, .7);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(107, 139, 255, .18);
}
.field.invalid input { border-color: var(--danger); }
.hint { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.field-error { display: block; margin-top: 6px; color: var(--danger); font-size: 12px; }
.switch { text-align: center; margin: 18px 0 0; color: var(--muted); font-size: 14px; }

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert-error { background: rgba(255, 107, 107, .12); border-color: rgba(255, 107, 107, .4); color: #ffb3b3; }

/* Game */
.game-wrap { position: relative; width: 100vw; height: 100vh; overflow: hidden; }
.scene { position: absolute; inset: 0; }
.scene canvas { display: block; }

.hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  pointer-events: none;
  z-index: 5;
  background: linear-gradient(to bottom, rgba(3, 5, 14, .75), transparent);
}
.hud-left, .hud-right { display: flex; align-items: center; gap: 16px; }
.hud-right .btn { pointer-events: auto; }
.hud-stat { font-size: 14px; color: #dbe3f5; }
.hud-stat b { color: var(--accent); }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(600px 400px at 50% 40%, rgba(20, 30, 70, .55), rgba(3, 5, 14, .92));
  z-index: 10;
}
.overlay[hidden] { display: none; }
.overlay-card {
  max-width: 480px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 34px 30px;
  backdrop-filter: blur(10px);
}
.overlay-card h1 { margin: 0 0 8px; font-size: 28px; }
.overlay-card p { color: var(--muted); }
.controls { list-style: none; padding: 0; margin: 18px 0 24px; display: grid; gap: 10px; color: var(--muted); }
.controls kbd {
  display: inline-block;
  min-width: 26px;
  padding: 3px 7px;
  margin-right: 4px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  background: rgba(6, 10, 24, .8);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
}

.objective {
  position: absolute;
  top: 58px;
  left: 20px;
  z-index: 5;
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(6, 10, 24, .6);
  border: 1px solid var(--panel-border);
  color: #cfd8ef;
  font-size: 13px;
  pointer-events: none;
}

.toast {
  position: absolute;
  bottom: 68px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  padding: 10px 20px;
  border-radius: 999px;
  background: rgba(53, 240, 200, .14);
  border: 1px solid rgba(53, 240, 200, .5);
  color: #bffdf0;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
}
.toast.show { animation: toastIn 2.4s ease forwards; }
@keyframes toastIn {
  0% { opacity: 0; transform: translateX(-50%) translateY(12px); }
  12% { opacity: 1; transform: translateX(-50%) translateY(0); }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

.hud-net { font-size: 12px; color: var(--muted); }
.hud-net.online { color: var(--accent); }
.hud-net.offline { color: var(--danger); }

.oxygen {
  position: absolute;
  bottom: 20px;
  left: 20px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(6, 10, 24, .6);
  border: 1px solid var(--panel-border);
  pointer-events: none;
}
.o2-label { font-weight: 700; color: #7ad0ff; }
.o2-bar { width: 160px; height: 10px; border-radius: 999px; background: rgba(255, 255, 255, .12); overflow: hidden; }
.o2-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #2ee6a6, #7ad0ff); transition: width .2s linear; }
.o2-fill.low { background: linear-gradient(90deg, #ff6b6b, #ffb36b); }
.o2-value { font-size: 12px; color: var(--muted); width: 40px; text-align: right; }

.storm {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, rgba(180, 150, 110, .05), rgba(140, 110, 80, .4));
  animation: stormPulse 2.4s ease-in-out infinite;
}
.storm[hidden] { display: none; }
.storm-text {
  position: absolute;
  top: 96px;
  left: 50%;
  transform: translateX(-50%);
  color: #ffd9a8;
  font-weight: 700;
  letter-spacing: 1px;
}
@keyframes stormPulse { 0%, 100% { opacity: .5; } 50% { opacity: .85; } }

.overlay-wide { max-width: 560px; }
.assembly-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 18px auto; max-width: 360px; }
.slot {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 1px dashed var(--panel-border);
  background: rgba(6, 10, 24, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--muted);
  transition: all .2s ease;
  cursor: pointer;
}
.slot.filled { border-style: solid; border-color: var(--accent); color: var(--accent); background: rgba(53, 240, 200, .12); }

.nameplate {
  position: absolute;
  z-index: 5;
  font-size: 12px;
  color: #dbe3f5;
  background: rgba(6, 10, 24, .7);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  white-space: nowrap;
  pointer-events: none;
  transform: translate(-50%, -100%);
  display: none;
}

.err-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  background: rgba(120, 20, 20, .96);
  color: #ffe9c7;
  font-family: "Consolas", monospace;
  font-size: 12px;
  line-height: 1.4;
  padding: 8px 12px;
  max-height: 30vh;
  overflow: auto;
  white-space: pre-wrap;
  cursor: pointer;
}

/* ===== Modo Diseno ===== */
.design-wrap {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow: auto;
  background: radial-gradient(700px 500px at 50% 10%, rgba(40, 30, 80, .6), rgba(3, 5, 14, .92));
}
.design-wrap[hidden] { display: none; }
.design-card {
  position: relative;
  width: 100%;
  max-width: 560px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 26px 24px;
  backdrop-filter: blur(10px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
.design-card h2 { margin: 0 0 6px; text-align: center; font-size: 24px; }
.design-sub { text-align: center; color: var(--muted); margin: 0 0 16px; }
.design-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}
.design-close:hover { border-color: var(--danger); color: var(--danger); }

.design-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.chip {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(6, 10, 24, .6);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all .15s ease;
}
.chip:hover { border-color: var(--primary); }
.chip.active { background: rgba(107, 139, 255, .22); border-color: var(--primary); color: #cfe0ff; }

#designText {
  width: 100%;
  min-height: 96px;
  resize: vertical;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(6, 10, 24, .7);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}
#designText:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(107, 139, 255, .18); }

.design-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.design-count { margin-left: auto; color: var(--muted); font-size: 12px; }

.design-msg { margin-top: 14px; padding: 12px 14px; border-radius: 10px; font-size: 14px; }
.design-msg p { margin: 0; }
.design-msg-ok { background: rgba(53, 240, 200, .12); border: 1px solid rgba(53, 240, 200, .45); color: #bffdf0; }
.design-msg-warn { background: rgba(255, 200, 80, .12); border: 1px solid rgba(255, 200, 80, .45); color: #ffe6b0; }
.design-msg-error { background: rgba(255, 107, 107, .12); border: 1px solid rgba(255, 107, 107, .45); color: #ffb3b3; }

.design-h3 { margin: 22px 0 10px; font-size: 16px; }
.design-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.design-empty { color: var(--muted); font-size: 14px; text-align: center; padding: 14px; }
.design-item {
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px 14px;
  background: rgba(6, 10, 24, .45);
}
.design-item-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
.design-cat { font-size: 12px; color: var(--accent); font-weight: 700; }
.design-status { font-size: 12px; color: #cfd8ef; }
.design-item-text { margin: 0 0 10px; color: var(--text); font-size: 14px; line-height: 1.5; }
.design-item-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.status-select {
  margin-left: auto;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: rgba(6, 10, 24, .8);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
}

.sandbox-bar {
  width: 100%;
  max-width: 560px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 auto 14px;
}
.design-sandbox { justify-content: flex-start; }

@media (max-width: 640px) {
  .hud-left .hud-stat { display: none; }
  .hero-content { margin: 48px 0 40px; }
}
