/* ==========================================================================
   Bust-a-Move — Tesla-friendly stylesheet
   Safe for old WebKit: no flexbox `gap`, no aspect-ratio, no :is()
   ========================================================================== */

* { margin: 0; padding: 0; -webkit-box-sizing: border-box; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #05070f;
  color: #e8ecff;
  font-family: "Avenir Next", "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -ms-touch-action: none;
  touch-action: none;
  overscroll-behavior: none;
}

body { background: radial-gradient(120% 90% at 50% 0%, #2a1440 0%, #05070f 60%, #02030a 100%); }

button { font-family: inherit; color: inherit; background: none; border: 0; }

.app {
  position: relative;
  width: 100%;
  height: 100%;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
  -ms-flex-direction: column;
  flex-direction: column;
  padding: 6px 8px;
  padding: calc(6px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right))
           calc(6px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left));
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  position: relative;
  z-index: 50;
  -webkit-box-flex: 0;
  -ms-flex: 0 0 auto;
  flex: 0 0 auto;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  padding: 2px 4px 8px 4px;
}

.brand {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 4px;
  color: #ff9ecb;
  text-shadow: 0 0 12px rgba(255, 77, 109, .5);
  white-space: nowrap;
}

.topbar__stats {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
  margin: 0 -5px;
}

.stat {
  display: inline-block;
  margin: 0 5px;
  padding: 4px 10px;
  border: 1px solid rgba(255, 158, 203, .22);
  border-radius: 999px;
  background: rgba(24, 9, 40, .75);
  font-size: 10px;
  letter-spacing: 1.6px;
  color: #a48bb5;
  white-space: nowrap;
}

.stat b {
  margin-left: 6px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #ffffff;
}

.topbar__buttons {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
}

.chip {
  margin-left: 8px;
  padding: 9px 14px;
  border: 1px solid rgba(255, 158, 203, .3);
  border-radius: 10px;
  background: rgba(30, 13, 52, .85);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.4px;
  color: #ffc4e2;
  cursor: pointer;
  -webkit-transition: background .12s linear;
  transition: background .12s linear;
}

.chip:active, .chip.is-active { background: rgba(255, 77, 109, .28); color: #ffffff; }
.chip.is-off { color: #6b7494; border-color: rgba(120, 130, 160, .3); }

/* ------------------------------------------------------------------ stage */

.stage {
  -webkit-box-flex: 1;
  -ms-flex: 1 1 auto;
  flex: 1 1 auto;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
  overflow: hidden;
  min-height: 0;
}

.col { display: -webkit-box; display: -ms-flexbox; display: flex; -webkit-box-orient: vertical; -webkit-box-direction: normal; -ms-flex-direction: column; flex-direction: column; min-width: 0; }
/* Horizontal margins are symmetric on purpose: the pad can be reordered to
   either side of the board without the gaps needing a second set of rules. */
.col--left { width: 168px; margin: 0 9px; }
.col--board { -webkit-box-flex: 0; -ms-flex: 0 0 auto; flex: 0 0 auto; }
.col--right { width: 168px; margin: 0 9px; }
.col--pad { width: 250px; margin: 0 11px; }

/* Invisible counterweight so the board sits dead centre next to the pad.
   Its width is computed at runtime by Renderer.fit(). */
.col--balance { width: 0; }

/* Controls on the left: only the pad changes side, RECORD stays left of the
   board and the ceiling map stays right, so the reading order of the info
   panels never flips. */
.layout-pad-left .col--pad { -webkit-box-ordinal-group: 1; order: 1; }
.layout-pad-left .col--left { -webkit-box-ordinal-group: 2; order: 2; }
.layout-pad-left .col--board { -webkit-box-ordinal-group: 3; order: 3; }
.layout-pad-left .col--right { -webkit-box-ordinal-group: 4; order: 4; }
.layout-pad-left .col--balance { -webkit-box-ordinal-group: 5; order: 5; }

.panel-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 3px;
  color: #8f6f9f;
  margin-bottom: 6px;
}

.mini-canvas {
  display: block;
  width: 100%;
  border: 1px solid rgba(255, 158, 203, .18);
  border-radius: 12px;
  background: rgba(14, 6, 26, .8);
}

.legend { margin-top: 14px; }
.legend__row {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: justify;
  -ms-flex-pack: justify;
  justify-content: space-between;
  font-size: 10px;
  letter-spacing: .6px;
  color: #6b7494;
  margin-bottom: 5px;
}
.legend__key {
  padding: 1px 6px;
  border: 1px solid rgba(255, 158, 203, .2);
  border-radius: 5px;
  color: #ffc4e2;
  font-weight: 700;
  background: rgba(30, 13, 52, .7);
}

/* ------------------------------------------------------------------ board */

.board-wrap { position: relative; }

.board-canvas {
  display: block;
  border: 1px solid rgba(255, 158, 203, .28);
  border-radius: 14px;
  background: #0d0618;
  -webkit-box-shadow: 0 0 40px rgba(180, 60, 160, .2), inset 0 0 60px rgba(0, 0, 0, .6);
  box-shadow: 0 0 40px rgba(180, 60, 160, .2), inset 0 0 60px rgba(0, 0, 0, .6);
}

.toast {
  position: absolute;
  left: 0;
  right: 0;
  top: 40%;
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 4px;
  color: #ffffff;
  text-shadow: 0 0 18px rgba(255, 77, 109, .9);
  opacity: 0;
  pointer-events: none;
  -webkit-transition: opacity .25s linear;
  transition: opacity .25s linear;
}
.toast.is-on { opacity: 1; }

/* ------------------------------------------------------------- touch pad  */

.pad {
  position: relative;
  width: 100%;
  height: 250px;
  border: 1px solid rgba(255, 158, 203, .16);
  border-radius: 16px;
  background: rgba(20, 8, 34, .7);
}

.pad__btn {
  position: absolute;
  border: 1px solid rgba(255, 158, 203, .26);
  border-radius: 12px;
  background: -webkit-linear-gradient(top, rgba(62, 30, 96, .95), rgba(24, 12, 52, .95));
  background: linear-gradient(to bottom, rgba(62, 30, 96, .95), rgba(24, 12, 52, .95));
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #ffdcee;
  cursor: pointer;
  -webkit-box-shadow: 0 3px 0 rgba(0, 0, 0, .5);
  box-shadow: 0 3px 0 rgba(0, 0, 0, .5);
  -webkit-transition: background .08s linear, -webkit-transform .08s linear;
  transition: background .08s linear, transform .08s linear;
}

.pad__btn.is-down {
  background: -webkit-linear-gradient(top, rgba(255, 77, 109, .9), rgba(140, 20, 60, .9));
  background: linear-gradient(to bottom, rgba(255, 77, 109, .9), rgba(140, 20, 60, .9));
  color: #ffffff;
  -webkit-transform: translateY(2px);
  transform: translateY(2px);
}

/* Aim on the top row, one huge fire target in the middle: while driving,
   hitting FIRE must never be in question. */
.pad__btn--left    { left: 1.5%;  top: 2%;   width: 47.5%; height: 18%; }
.pad__btn--right   { left: 51%;   top: 2%;   width: 47.5%; height: 18%; }
.pad__btn--fire    { left: 1.5%;  top: 23%;  width: 97%;   height: 38%; font-size: 26px; letter-spacing: 6px; }
.pad__btn--swap    { left: 1.5%;  top: 64%;  width: 31%;   height: 15%; font-size: 10px; }
.pad__btn--pause   { left: 34.5%; top: 64%;  width: 31%;   height: 15%; font-size: 14px; }
.pad__btn--restart { left: 67.5%; top: 64%;  width: 31%;   height: 15%; font-size: 10px; }

/* ---------------------------------------------------------------- overlay */

.overlay {
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  padding: 52px 8px 8px 8px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
  background: rgba(6, 3, 14, .82);
  z-index: 40;
}
.overlay.is-hidden { display: none; }

.overlay__box {
  width: 90%;
  max-width: 460px;
  max-height: 92%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 26px 28px;
  border: 1px solid rgba(255, 158, 203, .3);
  border-radius: 18px;
  background: rgba(20, 9, 38, .96);
  text-align: center;
  -webkit-box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}

.overlay__title {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 6px;
  color: #ff9ecb;
  text-shadow: 0 0 22px rgba(255, 77, 109, .55);
  margin-bottom: 10px;
}

.overlay__body { font-size: 14px; color: #c0a8d6; line-height: 1.5; margin-bottom: 16px; }

.overlay__stats { font-size: 13px; color: #ffdcee; line-height: 1.7; margin-bottom: 16px; }
.overlay__stats b { color: #ffffff; font-size: 17px; }
.overlay__stats:empty { display: none; }

.overlay__hint { margin-top: 14px; font-size: 11px; color: #7a688f; line-height: 1.6; }

.btn {
  display: inline-block;
  padding: 14px 34px;
  border-radius: 12px;
  border: 1px solid rgba(255, 158, 203, .5);
  background: -webkit-linear-gradient(top, #ff7d9c, #c81f52);
  background: linear-gradient(to bottom, #ff7d9c, #c81f52);
  color: #ffffff;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 3px;
  cursor: pointer;
  -webkit-box-shadow: 0 6px 20px rgba(220, 40, 100, .35);
  box-shadow: 0 6px 20px rgba(220, 40, 100, .35);
}
.btn:active { -webkit-transform: translateY(2px); transform: translateY(2px); }

/* ------------------------------------------------------------- statusline */

.statusline {
  -webkit-box-flex: 0;
  -ms-flex: 0 0 auto;
  flex: 0 0 auto;
  padding: 4px 4px 0 4px;
  font-size: 9px;
  letter-spacing: 1.6px;
  color: #6a4d78;
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
}

/* ------------------------------------------------------------- breakpoints */

/* Tesla Model 3 / Y in landscape is ~1280x720 (and 1920x720 on S/X): keep it wide. */
@media (max-width: 1120px) {
  .col--left { width: 140px; margin: 0 6px; }
  .col--right { width: 140px; margin: 0 6px; }
  .col--pad { width: 210px; margin: 0 7px; }
  .pad { height: 214px; }
  .legend { display: none; }
}

/* Compact landscape (phones/tablets on their side, small windows).
   Keep everything on one row: the board needs the height, not the pad. */
@media (max-width: 900px) and (orientation: landscape) {
  .app { padding: 4px 6px; }
  .topbar { padding: 0 2px 4px 2px; }
  .brand { font-size: 13px; letter-spacing: 2px; }
  .stat { font-size: 8px; padding: 2px 7px; letter-spacing: 1px; }
  .stat b { font-size: 11px; margin-left: 4px; }
  .chip { padding: 6px 9px; font-size: 9px; letter-spacing: 1px; margin-left: 5px; }
  .panel-title { font-size: 8px; letter-spacing: 2px; margin-bottom: 3px; }
  .col--left { width: 96px; margin: 0 4px; }
  .col--right { width: 96px; margin: 0 4px; }
  .col--pad { width: 150px; margin: 0 5px; }
  .pad { height: 168px; border-radius: 12px; }
  .pad__btn { border-radius: 9px; }
  .pad__btn--fire { font-size: 18px; letter-spacing: 4px; }
  .statusline { display: none; }
}

/* Portrait / very narrow: drop the control pad under the board. */
@media (max-width: 860px) and (orientation: portrait), (max-width: 620px) {
  .stage { -webkit-box-pack: center; -ms-flex-pack: center; justify-content: center; -ms-flex-line-pack: start; align-content: flex-start; overflow: auto; }
  .col--left { width: 20%; margin: 0 3px; }
  .col--right { width: 20%; margin: 0 3px; }
  .col--pad { width: 100%; margin: 12px 0 0 0; }
  /* The pad is full width here, so it always stacks below the board: reset the
     mirrored ordering rather than letting the pad jump above it. */
  .layout-pad-left .col { -webkit-box-ordinal-group: 0; order: 0; }
  .layout-pad-left .col--balance { -webkit-box-ordinal-group: 0; order: 0; }
  .pad { height: 190px; }
  .legend { display: none; }
  .brand { font-size: 16px; letter-spacing: 2px; }
  .stat { font-size: 9px; padding: 3px 8px; }
  .stat b { font-size: 13px; }
}

@media (max-height: 620px) {
  .topbar { padding-bottom: 4px; }
  .panel-title { margin-bottom: 3px; font-size: 9px; }
}

/* Keep the modal readable on short screens (Tesla dashboards are only 720px). */
@media (max-height: 640px) {
  .overlay__box { padding: 16px 22px; max-width: 400px; }
  .overlay__title { font-size: 22px; letter-spacing: 5px; margin-bottom: 6px; }
  .overlay__body { font-size: 12px; margin-bottom: 10px; }
  .overlay__stats { font-size: 11px; margin-bottom: 10px; }
  .overlay__stats b { font-size: 14px; }
  .overlay__hint { font-size: 10px; margin-top: 8px; }
  .btn { padding: 11px 26px; font-size: 14px; }
}

@media (max-height: 460px) {
  .overlay__box { padding: 12px 18px; }
  .overlay__title { font-size: 19px; letter-spacing: 4px; }
  .overlay__body { display: none; }
  .overlay__hint { display: none; }
  .btn { padding: 9px 22px; }
}
