:root {
  --bg: #05060f;
  --panel: rgba(14, 18, 40, 0.92);
  --line: rgba(130, 160, 255, 0.25);
  --text: #e8ecff;
  --muted: #8f9bc7;
  --accent: #ffcf3f;
  --accent-ink: #2a1b00;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Rubik', system-ui, sans-serif;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  display: block;
  background: #000;
  cursor: none;
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at 50% 30%, rgba(40, 30, 90, 0.55), rgba(0, 0, 0, 0.75));
  z-index: 10;
}

.overlay[hidden] { display: none; }

.panel {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 26px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

h1 {
  font-family: 'Bungee', 'Rubik', sans-serif;
  font-weight: 400;
  font-size: clamp(30px, 8vw, 42px);
  line-height: 1;
  margin: 0 0 8px;
  letter-spacing: 1px;
  text-align: center;
  color: #fff;
  text-shadow: 0 3px 0 #b3361f, 0 0 24px rgba(255, 120, 60, 0.45);
}

h1 span { color: var(--accent); }

.tag {
  text-align: center;
  color: var(--muted);
  margin: 0 0 22px;
  font-size: 14px;
}

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 1px; }

input {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}

input:focus { border-color: var(--accent); }

.btn {
  font: inherit;
  font-weight: 800;
  font-size: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 18px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.08s, filter 0.15s;
}

.btn:hover { filter: brightness(1.2); }
.btn:active { transform: translateY(1px); }
.btn.primary { width: 100%; background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.small { font-size: 12px; padding: 5px 10px; border-radius: 8px; }
.btn:disabled { opacity: 0.5; cursor: wait; }

.or {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  margin: 18px 0 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.join-row { display: flex; gap: 8px; }
.join-row input { text-transform: uppercase; letter-spacing: 6px; text-align: center; font-weight: 800; }

.error { color: var(--danger); min-height: 1.2em; margin: 10px 0 0; font-size: 14px; text-align: center; }

.controls {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  font-size: 12px;
  color: var(--muted);
}

kbd {
  font-family: inherit;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 0 4px;
  color: var(--text);
}

#roomBar {
  position: fixed;
  right: 10px;
  bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(8, 10, 24, 0.7);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 5px 6px 5px 10px;
  z-index: 5;
}
#roomBar[hidden] { display: none; }
#roomBar b { color: var(--accent); letter-spacing: 2px; }

.quit-panel { max-width: 360px; text-align: center; }
.quit-panel h2 { font-family: 'Bungee', 'Rubik', sans-serif; font-weight: 400; font-size: 26px; margin: 0 0 8px; color: #fff; }
.quit-panel .tag { margin-bottom: 18px; }
.quit-panel .join-row .btn { flex: 1; }

/* Hangar controls (host only): difficulty + launch */
#hangarCtl {
  position: fixed;
  left: 50%;
  bottom: 18%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  z-index: 5;
}
#hangarCtl[hidden] { display: none; }
.btn.launch-btn {
  width: auto;
  padding: 14px 40px;
  font-size: 20px;
  box-shadow: 0 0 30px rgba(255, 207, 63, 0.45);
}
.diff-picker { display: flex; gap: 8px; }
.diff-picker button {
  font: inherit;
  color: var(--text);
  background: rgb(14, 16, 34);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 118px;
}
.diff-picker button b { font-size: 15px; }
.diff-picker button small { font-size: 11px; color: var(--muted); }
.diff-picker button.on { border-color: var(--accent); background: rgba(255, 207, 63, 0.16); box-shadow: 0 0 0 1px var(--accent) inset; }

.touch-btn {
  position: fixed;
  left: 16px;
  bottom: 16px;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: rgba(255, 80, 60, 0.35);
  font-size: 28px;
  z-index: 5;
}
.touch-btn[hidden] { display: none; }
.touch-btn.skill { bottom: 92px; background: rgba(80, 200, 255, 0.35); }

.panel { max-width: 520px; }

.ship-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.ship-card {
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 6px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1px;
  transition: border-color 0.15s, background 0.15s, transform 0.08s;
}
.ship-card:active { transform: translateY(1px); }
.ship-card canvas { width: 80px; height: 60px; }
.ship-card b { font-size: 14px; }
.ship-card small { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.ship-card em { font-style: normal; font-weight: 800; font-size: 11px; color: var(--ship); margin-top: 4px; }
.ship-card span { font-size: 10px; line-height: 1.25; color: var(--muted); }
.ship-card.on {
  border-color: var(--ship);
  background: color-mix(in srgb, var(--ship) 14%, transparent);
  box-shadow: 0 0 0 1px var(--ship) inset;
}

@media (max-width: 520px) {
  .controls { grid-template-columns: 1fr; }
  .ship-picker { grid-template-columns: repeat(2, 1fr); }
  #roomBar { left: 10px; right: auto; bottom: auto; top: 10px; }
}

/* Let the taller lobby scroll on short screens */
#lobby { overflow-y: auto; }
#lobby .panel { margin: auto; position: relative; }
.music-btn { position: absolute; top: 12px; right: 12px; }
.music-btn.off { opacity: 0.55; text-decoration: line-through; }
.field .ship-card span { display: block; margin: 0; text-transform: none; letter-spacing: 0; }
