/* Command to launch: `npx serve .` then open http://localhost:3000/game.html */

:root {
  color-scheme: dark;
  --bg-color: #05060a;
  --ui-bg: rgba(0, 0, 0, 0.5);
  --ui-border: rgba(255, 255, 255, 0.2);
  --accent: #4fc3f7;
  --text: #f5f5f5;
  --danger: #ff5252;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(circle at top, #10131f 0, #05060a 50%, #000 100%);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  touch-action: none;
}

body {
  display: flex;
  flex-direction: column;
}

/* GAME LAYOUT */

#game-container {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
}

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

/* HUD */

.hud {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 6px 10px;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  font-size: 12px;
  z-index: 10;
  backdrop-filter: blur(4px);
}

.hud-row {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 2px;
}

.hud-row:last-child {
  margin-bottom: 0;
}

.label {
  opacity: 0.7;
}

.value {
  font-weight: 600;
  color: var(--accent);
}

.money-value {
  color: #ffd54f;
}

/* MINIMAP */

#minimap {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 140px;
  height: 140px;
  background: var(--ui-bg);
  border-radius: 12px;
  border: 1px solid var(--ui-border);
  padding: 4px;
  z-index: 10;
  backdrop-filter: blur(4px);
}

#minimap canvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 8px;
  background: radial-gradient(circle at center, #202436 0, #05060a 70%);
}

#inventory-btn {
  position: absolute;
  top: calc(8px + 140px + 8px); /* 8px (top minimap) + 140px (minimap height) + 8px margin */
  right: 8px;
  width: 140px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--ui-border);
  background: var(--ui-bg);
  color: var(--text);
  font-size: 12px;
  text-align: center;
  cursor: pointer;
  z-index: 11;
  backdrop-filter: blur(4px);
  opacity: 0.6;
  transition: opacity 0.2s, border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}

.tab-menu-container, .subtab-menu-container { display:flex; gap:8px; flex-wrap:wrap; }
.tab-btn, .subtab-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}
.tab-btn.is-active, .subtab-btn.is-active {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.35);
}


#galaxy-map-btn {
  position: absolute;
  top: calc(8px + 140px + 8px + 28px); /* 8px (top minimap) + 140px (minimap height) + 8px margin */
  right: 8px;
  width: 140px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--ui-border);
  background: var(--ui-bg);
  color: var(--text);
  font-size: 12px;
  text-align: center;
  cursor: pointer;
  z-index: 11;
  backdrop-filter: blur(4px);
  opacity: 0.6;
  transition: opacity 0.2s, border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}

#station-overlay-btn {
  position: absolute;
  top: calc(8px + 140px + 8px + 28px + 28px); /* 8px (top minimap) + 140px (minimap height) + 8px margin */
  right: 8px;
  width: 140px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--ui-border);
  background: var(--ui-bg);
  color: var(--text);
  font-size: 12px;
  text-align: center;
  cursor: pointer;
  z-index: 11;
  backdrop-filter: blur(4px);
  opacity: 0.6;
  transition: opacity 0.2s, border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}

#hyperspace-btn {
  position: absolute;
  top: calc(8px + 140px + 8px + 28px + 28px + 28px);
  right: 8px;
  width: 140px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid var(--ui-border);
  background: var(--ui-bg);
  color: var(--text);
  font-size: 12px;
  text-align: center;
  cursor: pointer;
  z-index: 11;
  backdrop-filter: blur(4px);
  opacity: 0.6;
  transition: opacity 0.2s, border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
}

.death-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 2000;
}
.death-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.tutorial-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.05);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 2000;
}

.tutorial-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.tutorial-dialog {
  background: #020916;
  color: #d8ecff;
  padding: 24px;
  border: 1px solid #26597e;
  border-radius: 10px;
  width: min(650px, 92vw);
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

.tutorial-center-dialog {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  text-align: center;
  width: min(280px, 90vw);
}

.tutorial-dialog h2 {
  margin-top: 0;
  color: #67c7ff;
}

.tutorial-dialog p {
  margin: 8px 0;
}

.tutorial-actions {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

.tutorial-actions button {
  padding: 10px 14px;
  background: #0e2f4a;
  color: #dff5ff;
  border: 1px solid #2f88bf;
  border-radius: 6px;
  cursor: pointer;
}

.tutorial-actions button:hover {
  background: #14456a;
}

#tutorial-annotations {
  position: absolute;
  inset: 0;
}

.tutorial-callout {
  position: absolute;
  max-width: 210px;
  background: rgba(4, 18, 32, 0.95);
  border: 1px solid #2f88bf;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  color: #e4f5ff;
  line-height: 1.35;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.inventory-header-actions {
  display: flex;
  gap: 8px;
}

#inventory-close-btn,
#galaxy-close-btn {
  padding: 8px 12px;
  background: #0e2f4a;
  color: #dff5ff;
  border: 1px solid #2f88bf;
  border-radius: 6px;
  cursor: pointer;
}

#inventory-close-btn:hover,
#galaxy-close-btn:hover {
  background: #14456a;
}

.death-dialog {
  background: #120000;
  color: #f55;
  padding: 24px;
  border: 1px solid #400;
  border-radius: 10px;
  text-align: center;
  width: 420px;
}

.death-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 20px;
}

.death-actions button {
  padding: 10px 14px;
  background: #200;
  color: #fff;
  border: 1px solid #600;
  cursor: pointer;
}
.death-actions button:hover {
  background: #400;
}

.galaxy-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 1500;
}
.galaxy-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.galaxy-dialog {
  width: 90vw;
  height: 90vh;
  background: #080808;
  border: 1px solid #333;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
}

.galaxy-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid #333;
  color: #0ff;
}

.galaxy-body {
  flex: 1;
  overflow: hidden;
}

.galaxy-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #000;
}

.station-overlay{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 2000;
}
.station-overlay.open {
  opacity: 1;
  pointer-events: auto;
  touch-action: auto;
}

.station-dialog {
  width: 90vw;
  height: 90vh;
  background: #080808;
  border: 1px solid #333;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  touch-action: auto;
}

.station-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid #333;
  color: #0ff;
}

.station-dialog-body {
  flex: 1;
  overflow: hidden;
  touch-action: pan-y;
}

#station-content {
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.outfits-shop-iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #000;
}




@keyframes dockBlink {
  from {
    transform: translateY(0);
  }
  to {
    transform: translateY(-2px);
  }
}

/* TOUCH CONTROLS */

#touch-controls {
  position: absolute;
  bottom: 10px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 10px;
  z-index: 10;
  pointer-events: none;
}

.touch-group {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.touch-column {
  flex-direction: column;
  gap: 6px;
}

.touch-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 1px solid var(--ui-border);
  background: var(--ui-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--text);
  backdrop-filter: blur(4px);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.touch-btn:active {
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(79, 195, 247, 0.7);
}

.touch-btn.primary {
  border-color: var(--accent);
  color: var(--accent);
}

/* Lock / special button toggled state */
.touch-btn.toggled {
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(79, 195, 247, 0.9);
  background: rgba(79, 195, 247, 0.12);
}

.inventory-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 1001;
}
.inventory-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.inventory-dialog {
  width: min(820px, 92vw);
  background: #111;
  color: #eee;
  border: 1px solid #333;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
}

.inventory-header {
  display: flex;
  justify-content: space-between;
  padding: 12px;
  border-bottom: 1px solid #333;
}

.inventory-body {
  padding: 16px;
}

.inventory-stats li {
  margin-bottom: 8px;
}

/* Tabs */
.inv-tabs {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.inv-tab {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
}

.inv-tab.is-active {
  background: rgba(255,255,255,0.18);
  border-color: rgba(255,255,255,0.35);
}

.inv-panel { display: none; }
.inv-panel.is-active { display: block; }
.inv-panel[data-panel="current"].is-active {
  max-height: 52vh;
  overflow-y: auto;
  padding-right: 6px;
}

.inv-missions-list {
  display: grid;
  gap: 12px;
  max-height: 52vh;
  overflow-y: auto;
  padding-right: 6px;
}

.inv-mission-card {
  background: rgba(20,30,60,0.85);
  border: 1px solid #2c4aa0;
  border-radius: 8px;
  padding: 12px;
}

.inv-progress {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.15);
  overflow: hidden;
  margin: 8px 0;
}

.inv-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #2c7cff, #38d39f);
}

.inv-mission-card button {
  background: #2c7cff;
  border: none;
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.inv-mission-card button:disabled {
  background: #555;
  cursor: not-allowed;
}


/* Owned tab grid */
.inv-owned-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
  padding: 8px 0;
  max-height: 52vh;          /* scroll area inside dialog */
  overflow-y: auto;
  padding-right: 6px;        /* room for scrollbar */
}

/* reuse shop-like card look */
.inv-owned-grid .ship-card {
  background: rgba(20,30,60,0.85);
  border: 1px solid #2c4aa0;
  border-radius: 8px;
  padding: 12px;
}

.inv-owned-grid .ship-preview {
  height: 96px;
  background: linear-gradient(135deg, #1b2a55, #0a1433);
  border-radius: 6px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: #9fb8ff;
}

.inv-owned-grid .ship-name {
  font-weight: 700;
  margin-bottom: 4px;
}

.inv-owned-grid .ship-stats {
  font-size: 12px;
  line-height: 1.4;
  margin-bottom: 8px;
  opacity: 0.95;
}

.inv-owned-grid .ship-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.inv-owned-grid .price {
  color: #7dff9f;
  font-weight: 700;
}

.inv-owned-grid button {
  background: #2c7cff;
  border: none;
  color: white;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.inv-owned-grid button:disabled {
  background: #555;
  cursor: not-allowed;
}

/* RESPONSIVE TWEAKS (game UI) */

@media (min-width: 768px) {
  #touch-controls {
    opacity: 0.4;
  }

  #touch-controls:hover {
    opacity: 1;
  }
}

@media (max-width: 480px) {
  .touch-btn {
    width: 52px;
    height: 52px;
    font-size: 20px;
  }
}

/* dialog layout: header fixed, body fills */
.station-dialog{
  display:flex;
  flex-direction:column;
  height:90vh;
  max-height:90vh;
}
.station-dialog-header{ flex:0 0 auto; }
.station-dialog-body{
  flex:1 1 auto;
  display:flex;
  overflow:hidden; /* avoid double scroll */
}

#ship-shop-list{
  flex: 1 1 auto;
  overflow-y: auto;
  padding-right: 6px;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

/* your existing shop css + small tweaks */
.ship-shop-grid{
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
}
.ship-card { border: 1px solid #333; border-radius: 10px; padding: 10px; }
.ship-card-title { font-weight: 700; margin-bottom: 6px; }
.ship-card-meta { font-size: 12px; opacity: 0.9; display: grid; gap: 2px; margin: 8px 0; }
.ship-buy-btn { width: 100%; padding: 8px; }
.ship-card-warn { font-size: 12px; opacity: 0.8; margin-top: 6px; }
.ship-card-row{
  display:flex;
  gap:10px;
  align-items:flex-start;
}

/* small square image */
.ship-card-thumb{
  width:96px;
  height:96px;
  flex:0 0 96px;
  border-radius:8px;
  overflow:hidden;
  background:#111;
  display:flex;
  align-items:center;
  justify-content:center;
}

.ship-card-thumb img{
  width:100%;
  height:100%;
  object-fit:contain;
}

.ship-card-info{
  flex:1 1 auto;
  min-width:0;
}


#outfit-shop-list{
  flex: 1 1 auto;
  overflow-y: auto;
  padding-right: 6px;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.outfit-shop-toolbar{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  margin-bottom:10px;
}

.outfit-shop-toolbar label{
  display:grid;
  gap:4px;
  font-size:12px;
}

.outfit-shop-toolbar select{
  background:#111;
  color:#e7eefc;
  border:1px solid #3a4f79;
  border-radius:6px;
  padding:6px 8px;
}

.outfit-shop-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(320px,1fr));
  gap:12px;
}

.outfit-card{
  border:1px solid #333;
  border-radius:10px;
  padding:10px;
  background:#0b1322;
}

.outfit-card-title-row{
  display:flex;
  justify-content:space-between;
  gap:8px;
  align-items:flex-start;
}

.outfit-card-title{
  margin:0;
  font-size:16px;
}

.outfit-card-category{
  font-size:11px;
  padding:3px 6px;
  border:1px solid #3a4f79;
  border-radius:999px;
  white-space:nowrap;
}

.outfit-card-meta{
  font-size:12px;
  opacity:0.95;
  display:grid;
  gap:3px;
  margin:8px 0;
}

.outfit-card-description{
  margin:0 0 10px;
  font-size:13px;
  line-height:1.35;
  opacity:0.88;
}
