/* ==========================================================================
   Flappy Bird — 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%, #16204a 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: #ffe27a;
  text-shadow: 0 0 12px rgba(255, 212, 0, .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(124, 243, 255, .22);
  border-radius: 999px;
  background: rgba(9, 16, 40, .75);
  font-size: 10px;
  letter-spacing: 1.6px;
  color: #7f8bb5;
  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(124, 243, 255, .3);
  border-radius: 10px;
  background: rgba(13, 22, 52, .85);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.4px;
  color: #9fe9ff;
  cursor: pointer;
  -webkit-transition: background .12s linear;
  transition: background .12s linear;
}

.chip:active, .chip.is-active { background: rgba(0, 199, 255, .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 RADAR stays right, so the reading order of the info panels never
   flips. `order` needs no old-WebKit box fallback beyond box-ordinal-group. */
.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: #6f7ca8;
  margin-bottom: 6px;
}

.mini-canvas {
  display: block;
  width: 100%;
  border: 1px solid rgba(124, 243, 255, .18);
  border-radius: 12px;
  background: rgba(6, 10, 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(124, 243, 255, .2);
  border-radius: 5px;
  color: #9fe9ff;
  font-weight: 700;
  background: rgba(13, 22, 52, .7);
}

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

.board-wrap { position: relative; }

.board-canvas {
  display: block;
  border: 1px solid rgba(124, 243, 255, .28);
  border-radius: 14px;
  background: #06121f;
  -webkit-box-shadow: 0 0 40px rgba(0, 160, 120, .18), inset 0 0 60px rgba(0, 0, 0, .6);
  box-shadow: 0 0 40px rgba(0, 160, 120, .18), inset 0 0 60px rgba(0, 0, 0, .6);
}

.toast {
  position: absolute;
  left: 0;
  right: 0;
  top: 26%;
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 4px;
  color: #ffffff;
  text-shadow: 0 0 18px rgba(63, 191, 90, .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(124, 243, 255, .16);
  border-radius: 16px;
  background: rgba(8, 13, 32, .7);
}

.pad__btn {
  position: absolute;
  border: 1px solid rgba(124, 243, 255, .26);
  border-radius: 12px;
  background: -webkit-linear-gradient(top, rgba(30, 46, 96, .95), rgba(14, 22, 52, .95));
  background: linear-gradient(to bottom, rgba(30, 46, 96, .95), rgba(14, 22, 52, .95));
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1px;
  color: #cfe6ff;
  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(63, 191, 90, .9), rgba(10, 110, 50, .9));
  background: linear-gradient(to bottom, rgba(63, 191, 90, .9), rgba(10, 110, 50, .9));
  color: #04140a;
  -webkit-transform: translateY(2px);
  transform: translateY(2px);
}

/* One huge flap target: while driving, hitting it must never be in question. */
.pad__btn--flap    { left: 1.5%;  top: 2%;    width: 97%;   height: 62%; font-size: 26px; letter-spacing: 6px; }
.pad__btn--pause   { left: 1.5%;  top: 69%;   width: 47.5%; height: 29%; font-size: 16px; }
.pad__btn--restart { left: 51%;   top: 69%;   width: 47.5%; height: 29%; font-size: 11px; }

/* ---------------------------------------------------------------- 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(3, 5, 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(124, 243, 255, .3);
  border-radius: 18px;
  background: rgba(9, 15, 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: 32px;
  font-weight: 800;
  letter-spacing: 7px;
  color: #ffe27a;
  text-shadow: 0 0 22px rgba(255, 212, 0, .55);
  margin-bottom: 10px;
}

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

.overlay__stats { font-size: 13px; color: #cfe6ff; 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: #63708f; line-height: 1.6; }

.btn {
  display: inline-block;
  padding: 14px 34px;
  border-radius: 12px;
  border: 1px solid rgba(124, 243, 255, .5);
  background: -webkit-linear-gradient(top, #4ede6d, #0f8f45);
  background: linear-gradient(to bottom, #4ede6d, #0f8f45);
  color: #04140a;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 3px;
  cursor: pointer;
  -webkit-box-shadow: 0 6px 20px rgba(0, 190, 90, .35);
  box-shadow: 0 6px 20px rgba(0, 190, 90, .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: #4d5878;
  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--flap { 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; }
}
