:root {
  --bg-void: #0c0d12;
  --panel: #1b1d27;
  --panel-hi: #262838;
  --border: #3a3d52;
  --text: #ecebf5;
  --text-dim: #a0a2b8;
  --accent: #6ea8ff;
  --accent-2: #7fe7c4;
  --gold: #ffcf5c;
  --danger: #e35c5c;
  --ok: #5fd35f;
  --radius: 10px;
  --footer-h: 34px;
  font-family: 'Segoe UI', ui-sans-serif, system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-void);
  color: var(--text);
  overflow: hidden;
}

#game-root {
  position: relative;
  width: 100%;
  height: calc(100vh - var(--footer-h));
  overflow: hidden;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #0c0d12;
  cursor: crosshair;
}

#ui-root {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hidden {
  display: none !important;
}

/* --------------------------------------------------------------------- */
/* HUD */
/* --------------------------------------------------------------------- */
.hud {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  pointer-events: none;
}

.bar-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 200px;
}

.bar {
  position: relative;
  height: 18px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border);
  overflow: hidden;
}

.bar-fill {
  position: absolute;
  inset: 0;
  width: 100%;
  transition: width 0.2s ease;
}

.bar-health .bar-fill {
  background: linear-gradient(90deg, #c23a3a, var(--danger));
}

.bar-warmth .bar-fill {
  background: linear-gradient(90deg, #3a7bc2, var(--accent));
}

.bar-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.clock-badge, .mode-badge {
  padding: 5px 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--border);
  font-size: 12px;
  white-space: nowrap;
}

.clock-badge.is-night {
  color: var(--accent);
}

.mode-badge.mode-live {
  color: var(--gold);
}

/* --------------------------------------------------------------------- */
/* Hotbar */
/* --------------------------------------------------------------------- */
.hotbar {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  pointer-events: auto;
}

.slot {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 6px;
  background: rgba(20, 21, 30, 0.85);
  border: 1px solid var(--border);
  cursor: pointer;
}

.hotbar-slot.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px rgba(255, 207, 92, 0.4);
}

.slot-key {
  position: absolute;
  top: 1px;
  left: 3px;
  font-size: 10px;
  color: var(--text-dim);
}

.slot-icon {
  position: absolute;
  inset: 8px 4px 4px 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
}

.slot-qty {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 10px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}

/* --------------------------------------------------------------------- */
/* Panel toggle buttons */
/* --------------------------------------------------------------------- */
.panel-buttons {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 6px;
  pointer-events: auto;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(20, 21, 30, 0.85);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--panel-hi);
}

/* --------------------------------------------------------------------- */
/* Panels */
/* --------------------------------------------------------------------- */
.panel {
  position: absolute;
  top: 62px;
  right: 14px;
  width: 340px;
  max-height: min(70vh, 560px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  pointer-events: auto;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

.panel h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.panel h4 {
  margin: 14px 0 6px;
  font-size: 13px;
  color: var(--text-dim);
}

.grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.backpack-slot {
  width: 100%;
  aspect-ratio: 1;
  cursor: default;
}

.empty-note {
  color: var(--text-dim);
  font-size: 13px;
}

/* Crafting */
.station-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.station-btn {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  text-transform: capitalize;
}

.station-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.station-btn.disabled,
.station-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.recipe-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recipe-row {
  padding: 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}

.recipe-name {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.recipe-costs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11px;
  margin-bottom: 6px;
}

.cost-ok {
  color: var(--ok);
}

.cost-missing {
  color: var(--danger);
}

/* --------------------------------------------------------------------- */
/* Buttons (shared) */
/* --------------------------------------------------------------------- */
.btn {
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: rgba(110, 168, 255, 0.15);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
}

.btn:hover:not(:disabled) {
  background: rgba(110, 168, 255, 0.3);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.craft-btn {
  width: 100%;
}

.cancel-btn {
  border-color: var(--border);
  background: transparent;
}

/* --------------------------------------------------------------------- */
/* Shop */
/* --------------------------------------------------------------------- */
.shop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.prisms-balance {
  color: var(--gold);
  font-size: 13px;
  font-weight: 600;
}

.shop-packs, .shop-spend {
  grid-template-columns: repeat(2, 1fr);
}

.shop-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.03);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.shop-card-name {
  font-size: 12px;
  font-weight: 700;
}

.shop-card-price {
  font-size: 15px;
  color: var(--gold);
}

.shop-card-prisms {
  font-size: 11px;
  color: var(--text-dim);
}

.buy-btn {
  margin-top: 4px;
}

/* --------------------------------------------------------------------- */
/* Overlays (auth / purchase gate) */
/* --------------------------------------------------------------------- */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 7, 12, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  padding: 20px;
  overflow-y: auto;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 26px;
  max-width: 640px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.auth-title {
  margin: 0 0 6px;
  font-size: 28px;
  letter-spacing: 0.04em;
}

.auth-intro {
  margin: 0 0 20px;
  color: var(--text-dim);
  font-size: 13px;
}

.mode-choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.mode-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.03);
  display: flex;
  flex-direction: column;
}

.mode-card h3 {
  margin: 0 0 8px;
}

.mode-card p {
  font-size: 12.5px;
  color: var(--text-dim);
  flex-grow: 1;
  line-height: 1.5;
}

.auth-tabs {
  display: flex;
  gap: 6px;
  margin-top: 14px;
  margin-bottom: 8px;
}

.auth-tab {
  flex: 1;
  padding: 6px 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 12px;
}

.auth-tab.active {
  color: var(--text);
  border-color: var(--accent);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-form input {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  font-size: 13px;
}

.auth-error {
  color: var(--danger);
  font-size: 12px;
  min-height: 14px;
}

.gate-card h3 {
  margin: 0 0 10px;
}

.gate-text {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}

.gate-check-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.5px;
  margin-top: 12px;
  cursor: pointer;
  line-height: 1.4;
}

.gate-check-row input {
  margin-top: 2px;
}

.gate-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* --------------------------------------------------------------------- */
/* Toast */
/* --------------------------------------------------------------------- */
.toast {
  position: absolute;
  bottom: 74px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 21, 30, 0.95);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  pointer-events: none;
}

/* --------------------------------------------------------------------- */
/* Footer */
/* --------------------------------------------------------------------- */
#site-footer {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: #08090d;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
}

.footer-brand {
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.footer-links {
  display: flex;
  gap: 14px;
}

.footer-links a {
  color: var(--text-dim);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--text);
  text-decoration: underline;
}

@media (max-width: 640px) {
  .mode-choice-row {
    grid-template-columns: 1fr;
  }
  .panel {
    width: min(92vw, 340px);
  }
}
