/* Bundled rather than fetched: the game has to run from a file:// path with
   no network, and the Hebrew has to look the same on a machine with no Hebrew
   UI font of its own. Two subsets of one variable face - Hebrew and Latin -
   which is why every weight points at the same file. */
@font-face {
  font-family: 'Heebo';
  src: url('assets/fonts/heebo-hebrew.woff2') format('woff2');
  font-weight: 100 900;
  font-display: block;
  unicode-range: U+0590-05FF, U+200C-2010, U+20AA, U+25CC, U+FB1D-FB4F;
}
@font-face {
  font-family: 'Heebo';
  src: url('assets/fonts/heebo-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-display: block;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+2000-206F,
                 U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #0d1017;
  color: #cdd6e4;
  font-family: "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 12px 40px;
}

#stage {
  position: relative;
}

canvas#game {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  background: #000;
  border: 1px solid #2a3242;
  border-radius: 6px;
  touch-action: none;
}

#legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

#legend .col {
  background: #141926;
  border: 1px solid #232b3b;
  border-radius: 6px;
  padding: 10px 14px;
}

#legend h3 {
  margin: 0 0 8px;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #7f8ca3;
}

#legend p {
  margin: 4px 0;
  font-size: 13px;
  line-height: 1.5;
}

#legend b {
  color: #f0c674;
  font-weight: 600;
}

/* --- touch controls ---------------------------------------------------- */

/* Off unless the page decided this is a touch device, and off during menus
   so that taps land on the canvas instead of on the pads. */
#touch,
#rotate {
  display: none;
}

body.touch #touch.armed {
  display: block;
}

#touch {
  position: absolute;
  inset: 0;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#stickZone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 50%;
  height: 66%;
  pointer-events: auto;
  touch-action: none;
}

#stickBase {
  position: absolute;
  left: 100px;
  top: 50%;
  width: 124px;
  height: 124px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px solid rgba(190, 214, 245, 0.28);
  background: rgba(20, 26, 40, 0.35);
  transition: opacity 0.15s;
  opacity: 0.55;
}

#stickBase.active {
  opacity: 0.9;
}

#stickKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(180, 208, 244, 0.4);
  border: 2px solid rgba(226, 238, 255, 0.55);
}

#btnZone {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: grid;
  /* Four across rather than three: a seventh button had to go somewhere,
     and on a phone held sideways width is what there is spare - a third row
     would eat the picture. */
  grid-template-columns: repeat(4, var(--btn, 72px));
  grid-auto-rows: var(--btn, 72px);
  gap: 12px;
  pointer-events: none;
}

.tbtn {
  pointer-events: auto;
  touch-action: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #eef4ff;
  background: rgba(38, 48, 70, 0.6);
  border: 2px solid rgba(160, 186, 224, 0.4);
  transition: transform 0.06s, background 0.06s;
}

.tbtn.down {
  transform: scale(0.92);
  background: rgba(96, 122, 168, 0.8);
}

.tbtn-hit {
  background: rgba(190, 62, 46, 0.62);
  border-color: rgba(255, 150, 130, 0.5);
  font-size: 15px;
}

.tbtn-hit.down { background: rgba(240, 90, 68, 0.85); }

.tbtn-sp {
  background: rgba(34, 92, 132, 0.62);
  border-color: rgba(120, 200, 255, 0.45);
}

.tbtn-sp.down { background: rgba(60, 160, 224, 0.85); }

.tbtn-ult {
  background: rgba(122, 84, 24, 0.62);
  border-color: rgba(240, 198, 116, 0.5);
}

.tbtn-ult.down { background: rgba(224, 168, 52, 0.88); }

.tbtn-grab {
  background: rgba(46, 96, 66, 0.62);
  border-color: rgba(126, 224, 138, 0.45);
  font-size: 11px;
}

.tbtn-grab.down { background: rgba(76, 168, 108, 0.85); }

/* The second row is one short, and the gap belongs at the far side from the
   thumb - so hit and jump stay where the hand already is. */
.tbtn-hvy { grid-column: 2; }

/* --- filling the screen ------------------------------------------------- */

/* A phone and a fullscreened desktop want exactly the same thing: the stage
   filling the viewport, the picture letterboxed inside it at 16:9, and none
   of the page furniture. One set of rules, two ways in. `body.fs` is set from
   the fullscreenchange event, so it follows the browser's own exit as well as
   the game's toggle. */

body.touch,
body.fs {
  position: fixed;
  inset: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body.touch #wrap,
body.fs #wrap {
  max-width: none;
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
}

body.touch #stage,
body.fs #stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

/* Sized by the two caps against the aspect ratio, so whichever of the two
   screen dimensions runs out first decides, and the bars land on the other. */
body.touch canvas#game,
body.fs canvas#game {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border: none;
  border-radius: 0;
}

body.touch #legend,
body.fs #legend {
  display: none;
}

/* Small landscape screens do not have room for full-size pads. */
@media (max-height: 420px) {
  #btnZone { --btn: 58px; gap: 8px; }
  .tbtn { font-size: 11px; }
  .tbtn-grab { font-size: 9px; }
  .tbtn-hit { font-size: 13px; }
  .tbtn-blast { font-size: 10px; }
  #stickBase { width: 104px; height: 104px; }
  #stickKnob { width: 48px; height: 48px; }
}

/* --- rotate prompt ------------------------------------------------------ */

@media (orientation: portrait) {
  body.touch:not(.ignore-rotate) #rotate {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 10;
    align-items: center;
    justify-content: center;
    background: #0b0e15;
    text-align: center;
    padding: 24px;
  }

  body.touch:not(.ignore-rotate) #touch.armed {
    display: none;
  }
}

.rotate-icon {
  font-size: 46px;
  color: #f0c674;
  margin-bottom: 8px;
}

#rotate p {
  font-size: 17px;
  margin: 0 0 22px;
  color: #cdd6e4;
}

#rotateDismiss {
  font: inherit;
  font-weight: 700;
  color: #0d1017;
  background: #f0c674;
  border: none;
  border-radius: 8px;
  padding: 12px 22px;
}

/* --- callsign editor ---------------------------------------------------- */

#nameOverlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 7, 12, 0.72);
}

#nameBox {
  background: #131826;
  border: 1px solid #3a4560;
  border-radius: 14px;
  padding: 26px 30px;
  width: min(92vw, 380px);
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

#namePrompt {
  margin: 0 0 14px;
  font-size: 19px;
  font-weight: 700;
  color: #f0c674;
}

#nameInput {
  width: 100%;
  box-sizing: border-box;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  color: #e8edf6;
  background: #0d1017;
  border: 1px solid #3a4560;
  border-radius: 9px;
  padding: 10px 12px;
  outline: none;
}

#nameInput:focus { border-color: #f0c674; }

#nameHint {
  margin: 10px 0 16px;
  font-size: 13px;
  color: #8b98b2;
}

#nameBtns { display: flex; gap: 10px; justify-content: center; }

#nameBtns button {
  font: inherit;
  font-weight: 700;
  font-size: 15px;
  padding: 9px 26px;
  border-radius: 9px;
  border: none;
  cursor: pointer;
}

#nameSave { background: #f0c674; color: #0d1017; }
#nameCancel { background: #2a3247; color: #c3cee2; }

/* --- iPhone install hint ------------------------------------------------ */

#iosHint {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 14px;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 12px;
  background: #131826;
  border: 1px solid #3a4560;
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14px;
  color: #d8dce6;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

#iosHint span { flex: 1; }

#iosHintClose {
  font: inherit;
  font-size: 16px;
  background: none;
  border: none;
  color: #8b98b2;
  cursor: pointer;
  padding: 4px 8px;
}

#nameOverlay[hidden], #iosHint[hidden] { display: none; }
