@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@500;600;700&family=Manrope:wght@400;500;600;700&display=swap');

:root {
  color-scheme: dark;
  font-family: Manrope, Arial, sans-serif;
  color: #ede6d8;
  background: #10191e;
  --accent: #6ed4cd;
}

* { box-sizing: border-box; }
body { margin: 0; overflow: hidden; user-select: none; }
canvas#world { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 1px solid #a09b8059;
  background: #182024cc;
  border-radius: 3px;
  padding: 8px 14px;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: #32434a; border-color: #6ed4cd88; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

#vignette { position: fixed; inset: 0; pointer-events: none; box-shadow: inset 0 0 160px 45px #040b1466; }
#hurt { position: fixed; inset: 0; background: radial-gradient(ellipse, transparent 40%, #bd351d99); opacity: 0; pointer-events: none; transition: opacity 0.15s; }

#prototype-notice {
  position: fixed;
  z-index: 30;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 12px;
  background: #15191eef;
  color: var(--accent);
  font: 700 11px system-ui;
  letter-spacing: .06em;
  border: 1px solid currentColor;
  border-radius: 2px;
}
#net-badge { font-weight: bold; }
#net-badge.online { color: #84f2bb; }
#net-badge.offline { color: #f28484; }

/* HUD Top */
#hud {
  position: absolute;
  top: 36px;
  left: 28px;
  right: 28px;
  display: flex;
  align-items: center;
  gap: 24px;
  pointer-events: none;
}
.brand {
  font-family: 'Cormorant Garamond', Georgia, serif;
  letter-spacing: 3px;
  font-size: 24px;
  text-shadow: 0 2px 8px #000;
}
.brand span {
  display: block;
  font: 9px Manrope;
  letter-spacing: 4px;
  margin-top: 4px;
  color: #b8b09c;
}

.vitals { width: 220px; }
.barlabel {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: 1.5px;
  margin-bottom: 5px;
  text-shadow: 0 1px 4px #000;
}
.bar {
  height: 8px;
  background: #080e14bb;
  border: 1px solid #baa2764d;
  transform: skewX(-8deg);
  overflow: hidden;
}
.bar i {
  display: block;
  height: 100%;
  width: 100%;
  transition: width 0.12s;
  background: linear-gradient(90deg, #9b352f, #df7963);
}
.energy { height: 4px; margin-top: 4px; border: 0; }
.energy i { background: linear-gradient(90deg, #637a72, #c0caa0); }

#match-timer-box {
  margin-left: auto;
  text-align: right;
  text-shadow: 0 2px 8px #000;
}
#match-timer-box .eyebrow {
  font-size: 9px;
  letter-spacing: 2px;
  color: #e7b879;
}
#match-timer {
  font: 700 20px 'Cormorant Garamond', Georgia, serif;
  letter-spacing: 2px;
  color: #fff;
}

/* Scoreboard (Compact FFA kills/deaths board) */
#scoreboard {
  position: absolute;
  top: 96px;
  right: 28px;
  width: 220px;
  background: #111a20dd;
  border: 1px solid #baa27644;
  padding: 8px 12px;
  border-radius: 4px;
  pointer-events: none;
  font-size: 11px;
  box-shadow: 0 4px 16px #00000088;
}
.board-header {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #4a595f66;
  padding-bottom: 4px;
  margin-bottom: 6px;
  font-size: 9px;
  letter-spacing: 1.5px;
  color: #8da3a9;
}
.board-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
}
.board-row.me {
  color: #6ed4cd;
  font-weight: 600;
}
.board-row.dead {
  opacity: 0.5;
  text-decoration: line-through;
}
.board-name {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.board-score {
  font-family: monospace;
  font-size: 11px;
}

/* Status Banner (Respawn & Protection) */
.hud-banner {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  text-align: center;
  z-index: 5;
}
#respawn-timer-box {
  font: 700 24px 'Cormorant Garamond', Georgia, serif;
  color: #ff6854;
  letter-spacing: 3px;
  background: #151010dd;
  border: 1px solid #ff685477;
  padding: 8px 20px;
  border-radius: 4px;
  text-shadow: 0 2px 8px #000;
}
#spawn-protection-box {
  font: 700 13px Manrope, sans-serif;
  color: #6ed4cd;
  letter-spacing: 2px;
  background: #101c22dd;
  border: 1px solid #6ed4cd77;
  padding: 6px 16px;
  border-radius: 3px;
  margin-top: 6px;
}

#location {
  position: absolute;
  left: 50%;
  top: 14%;
  transform: translateX(-50%);
  font: small-caps 28px 'Cormorant Garamond', Georgia;
  letter-spacing: 4px;
  text-shadow: 0 2px 12px #000;
  transition: opacity 1s;
  white-space: nowrap;
  pointer-events: none;
}
#toast {
  position: absolute;
  left: 50%;
  bottom: 100px;
  transform: translateX(-50%);
  padding: 10px 22px;
  background: #101c22e6;
  border-left: 2px solid #6ed4cd;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 6;
}

#map {
  position: absolute;
  bottom: 80px;
  right: 28px;
  width: 160px;
  height: 180px;
  opacity: 0.9;
  pointer-events: none;
}

#controls {
  position: absolute;
  bottom: 20px;
  left: 28px;
  right: 28px;
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 10px;
  color: #c5c7bf;
  text-shadow: 0 2px 4px #000;
  flex-wrap: wrap;
}
kbd {
  display: inline-block;
  font: 9px Manrope;
  background: #162128b8;
  border: 1px solid #adac954d;
  padding: 4px 6px;
  margin-right: 4px;
  border-radius: 2px;
}
#controls button {
  margin-left: auto;
  font-size: 9px;
  letter-spacing: 1px;
  padding: 6px 12px;
}
#controls #sound { margin-left: 0; }

/* Overlays & Lobby */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(90deg, #071118f5, #0b152be6 50%, #0a101bf0);
  z-index: 20;
}
.intro {
  text-align: center;
  padding: 30px;
  max-width: 680px;
  width: 90%;
}
.intro .eyebrow { letter-spacing: 4px; color: #6ed4cd; font-size: 11px; }
h1 {
  font: 600 clamp(48px, 8vw, 92px) / 0.85 'Cormorant Garamond', Georgia, serif;
  letter-spacing: -2px;
  margin: 20px 0 10px;
}
h1 em { font-style: normal; color: #6ed4cd; }
.subtitle {
  letter-spacing: 6px;
  font-size: 10px;
  color: #d7c5ad;
  margin: 12px 0 24px;
}

#lobby-panel {
  background: #0d161dcc;
  border: 1px solid #4a5c6655;
  padding: 24px;
  border-radius: 6px;
  margin: 20px auto;
}
.lobby-form { margin-bottom: 16px; font-size: 13px; }
.lobby-form input, .join-box input {
  background: #142028;
  border: 1px solid #6ed4cd66;
  color: #fff;
  padding: 8px 12px;
  font: inherit;
  border-radius: 3px;
  margin-left: 8px;
}
.lobby-actions {
  display: flex;
  gap: 16px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.lobby-actions button {
  background: #1f3742;
  border-color: #6ed4cd;
  color: #6ed4cd;
  font-weight: 600;
  padding: 10px 20px;
}
.lobby-actions button:hover { background: #2c4d5c; }
.join-box { display: flex; align-items: center; gap: 8px; }

.room-pill {
  font-size: 14px;
  letter-spacing: 1px;
  background: #14242d;
  padding: 8px 16px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
#btn-copy-invite { font-size: 10px; padding: 4px 8px; }

.lobby-roster {
  text-align: left;
  background: #091016;
  border: 1px solid #23343d;
  padding: 12px;
  border-radius: 4px;
  margin-bottom: 16px;
  max-height: 160px;
  overflow-y: auto;
}
.roster-item {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 12px;
  border-bottom: 1px solid #16242c;
}
.roster-ready { color: #84f2bb; font-weight: 600; }
.roster-waiting { color: #d6985a; }

.lobby-room-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
}
#btn-start-match {
  background: #347a66;
  border-color: #5cf2bd;
  color: #fff;
  font-weight: 700;
}
#btn-start-match:hover { background: #3fa084; }

#loadstatus { font-size: 11px; color: #8fa0a5; margin-top: 12px; }

/* Results Panel */
#results-panel {
  background: #0d161dee;
  border: 1px solid #baa27688;
  padding: 24px;
  border-radius: 6px;
}
#results-title {
  font: 500 28px 'Cormorant Garamond', Georgia, serif;
  color: #6ed4cd;
  margin: 0 0 10px;
}
#results-scoreboard {
  margin: 16px 0;
  text-align: left;
  background: #080f14;
  padding: 12px;
  border-radius: 4px;
}

.hint {
  font-size: 10px;
  color: #929f9e;
  line-height: 1.8;
  margin-top: 20px;
}

#mobile { display: none; }
body.playing .overlay { display: none; }

@media (max-width: 800px), (pointer: coarse) {
  #hud { left: 16px; top: 16px; right: 16px; }
  #scoreboard { top: 76px; right: 16px; width: 170px; font-size: 9px; }
  #map { right: 12px; width: 120px; height: 130px; bottom: 60px; }
  #controls { bottom: 8px; left: 12px; gap: 8px; font-size: 8px; }
  #mobile {
    display: flex;
    position: absolute;
    bottom: 45px;
    left: 18px;
    right: 18px;
    justify-content: space-between;
    pointer-events: none;
  }
  #stick {
    border: 1px solid #c6b89066;
    background: #16202788;
    border-radius: 50%;
    width: 95px;
    height: 95px;
    display: grid;
    place-items: center;
    font-size: 9px;
    touch-action: none;
    pointer-events: auto;
  }
  .touchactions { display: flex; gap: 5px; align-items: end; }
  .touchactions button {
    pointer-events: auto;
    touch-action: none;
    font-size: 9px;
    width: 52px;
    height: 48px;
  }
}

/* Keep the lobby usable on short laptop and phone screens. */
.overlay { overflow-y: auto; padding: 42px 16px 20px; }
.intro { margin: auto; padding: 18px; width: 100%; }
.intro .eyebrow { font-size: 12px; letter-spacing: 2px; }
.subtitle { font-size: 14px; letter-spacing: 2px; margin-bottom: 16px; }
.hint, #loadstatus, #btn-copy-invite { font-size: 12px; }
.lobby-form { font-size: 14px; }
#lobby-panel { padding: 18px; margin: 14px auto; }
@media (max-height: 720px) {
  .intro { padding: 8px; }
  h1 { font-size: 56px; margin: 12px 0 8px; }
  .hint { margin-top: 12px; }
  .lobby-roster { max-height: 110px; }
}
@media (max-width: 520px) {
  .intro .eyebrow { letter-spacing: 1px; }
  h1 { font-size: 52px; }
  .join-box input { min-width: 0; width: 120px; }
  .room-pill { flex-wrap: wrap; justify-content: center; }
  .lobby-form input { max-width: 160px; }
}

/* ---- Stage B/C: school selector, progression, skills, offer, build, loot/bag ---- */

.school-select { display: flex; gap: 8px; margin: 12px 0 4px; }
.school-option { flex: 1; text-transform: uppercase; font-size: 11px; letter-spacing: 1px; }
.school-option.active { border-color: var(--accent); color: var(--accent); background: #1d2f2dcc; }

.bar.xp { height: 4px; margin-top: 4px; border: 0; }
.bar.xp i { background: linear-gradient(90deg, #6ea0d4, #a0c0e8); }
#level-display { color: var(--accent); font-weight: 700; }

#skillbar {
  position: absolute;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  z-index: 20;
}
.skill-slot {
  position: relative;
  width: 58px;
  height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px;
  overflow: hidden;
}
.skill-key { font-size: 10px; color: #b8b09c; }
.skill-name { font-size: 8px; letter-spacing: .5px; text-align: center; line-height: 1.1; }
.skill-cd {
  position: absolute; inset: 0; display: block;
  background: #0009; font: 700 16px Manrope; color: #fff;
  align-items: center; justify-content: center;
}
.skill-cd:empty { display: none; }
.skill-cd { display: flex; }

#offer-panel {
  position: absolute;
  top: 96px;
  right: 28px;
  width: 300px;
  background: #101a1eec;
  border: 1px solid #baa2764d;
  border-radius: 4px;
  padding: 12px;
  z-index: 25;
  pointer-events: auto;
}
.offer-header { display: flex; justify-content: space-between; font-size: 12px; letter-spacing: 1px; margin-bottom: 8px; color: var(--accent); }
.offer-cards { display: flex; flex-direction: column; gap: 6px; }
.offer-card {
  text-align: left;
  width: 100%;
  padding: 8px 10px;
  font-size: 11px;
}
.offer-card .offer-card-title { font-weight: 700; display: flex; justify-content: space-between; }
.offer-card .offer-card-badge { font-size: 8px; color: #e7b879; letter-spacing: 1px; }
.offer-card .offer-card-desc { font-size: 10px; color: #c9c2ae; margin-top: 3px; }
.offer-replace { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 5px; }
.offer-replace button { font-size: 10px; padding: 5px 8px; }

.collapsible.panel-body { }
#build-panel, #bag-panel {
  position: absolute;
  left: 28px;
  bottom: 96px;
  width: 190px;
  background: #101a1eec;
  border: 1px solid #baa2764d;
  border-radius: 4px;
  z-index: 20;
  pointer-events: auto;
  font-size: 11px;
}
#bag-panel { bottom: 250px; }
.panel-toggle { width: 100%; text-align: left; border: 0; background: transparent; font-size: 11px; letter-spacing: 1px; }
.panel-body { padding: 0 10px 10px; display: none; }
.panel-body.open { display: block; }
.build-row { margin-bottom: 6px; }
.build-label { display: block; font-size: 9px; color: #b8b09c; letter-spacing: 1px; margin-bottom: 3px; }
.build-list { display: flex; flex-wrap: wrap; gap: 4px; }
.build-chip {
  padding: 3px 6px;
  border-radius: 2px;
  background: #1d2f2dcc;
  border: 1px solid #6ed4cd44;
  font-size: 9px;
}
.build-chip.empty { opacity: .4; background: transparent; }

.bag-equipped { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.bag-slots { display: flex; flex-direction: column; gap: 5px; }
.bag-slot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 7px;
  border: 1px solid #baa2764d;
  border-radius: 3px;
  gap: 6px;
}
.bag-slot .bag-item-label { font-size: 10px; }
.bag-slot button { font-size: 9px; padding: 3px 6px; }
.rarity-common { color: #b7c2c0; }
.rarity-rare { color: #5aa7e0; }
.rarity-epic { color: #c583ef; }

#loot-prompt {
  position: absolute;
  left: 50%;
  bottom: 172px;
  transform: translateX(-50%);
  z-index: 22;
  pointer-events: auto;
}
#loot-prompt button { font-size: 11px; }

.enemy-hp-bar { pointer-events: none; }


/* Keyboard hints and touch controls occupy separate layouts. */
@media (pointer: fine) { #mobile { display: none; } }
@media (pointer: coarse) {
  #controls .kbd, #controls > span { display: none; }
  #skillbar { bottom: 106px; }
}
@media (max-width: 800px) {
  #build-panel, #bag-panel { left: 12px; width: 142px; }
  #bag-panel { bottom: 180px; }
  #build-panel { bottom: 80px; }
  #offer-panel { right: 12px; width: min(270px, calc(100vw - 48px)); max-height: calc(100vh - 175px); overflow-y: auto; }
  #controls { flex-wrap: wrap; max-width: calc(100vw - 135px); }
}
@media (max-width: 520px) and (pointer: coarse) {
  #map { display:none; }
  #mobile { left: 10px; right: 10px; bottom: 45px; align-items: end; }
  #stick { width: 76px; height: 76px; flex-shrink: 0; }
  .touchactions { flex-wrap: wrap; width: 190px; justify-content: flex-end; }
  .touchactions button { width: 54px; height: 44px; }
  #skillbar { bottom: 149px; left: auto; right: 12px; transform: none; }
  #offer-panel { top: 108px; }
  #scoreboard { display: none; }
}
@media (pointer: coarse) {
  #build-panel { top: 118px; bottom: auto; max-height: calc(100vh - 280px); overflow-y: auto; }
  #bag-panel { top: 82px; bottom: auto; }
}

/* Connection state remains readable without covering touch vitals or actions. */
@media (pointer: coarse) {
  #prototype-notice { top: 4px; width: max-content; max-width: calc(100vw - 16px); font-size: 9px; padding: 3px 7px; white-space: nowrap; }
  #hud { top: 31px; }
  #toast { bottom: 178px; width: max-content; max-width: calc(100vw - 32px); font-size: 10px; padding: 6px 10px; }
}
@media (max-width: 520px) and (pointer: coarse) {
  #hud .brand { display: none; }
  #hud { gap: 14px; }
  .vitals { width: min(240px, calc(100vw - 100px)); }
  #toast { bottom: 219px; }
}

/* Completed standings stay readable on short and narrow screens. */
body.showing-results .intro > :not(#results-panel) { display: none !important; }
body.showing-results .intro { padding: 0; }
body.showing-results #results-panel { max-height: calc(100dvh - 80px); overflow-y: auto; padding: 18px; }
#results-scoreboard .board-row { gap: 8px; padding: 6px 0; font-size: 13px; }
#results-scoreboard .board-row span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 520px) {
  #results-scoreboard .board-row { flex-direction: column; align-items: flex-start; gap: 2px; }
  #results-scoreboard .board-row span:last-child { color: #aabbbf; font-size: 12px; text-align: left; }
}
