/* ***************************************************************
 * Miro Flight - dark TradeMire shell theme
 * One stylesheet for the static host: brand header, game stage,
 * and the frozen mf- ui class inventory used by every panel.
 * *************************************************************** */

/* Theme tokens sampled from the game's dark canvas palette */
:root {
  --mf-sky-top: #10131c;
  --mf-sky-bottom: #1c2230;
  --mf-text: #eef1f7;
  --mf-dim: rgba(255, 255, 255, 0.55);
  --mf-faint: rgba(255, 255, 255, 0.12);
  --mf-accent: #b8a8d8;
  --mf-rose: #880e4f;
  --mf-rose-hi: #b21466;
  --mf-up: #0ecb81;
  --mf-down: #f6465d;
  --mf-card-bg: rgba(28, 34, 48, 0.86);
  --mf-card-border: rgba(184, 168, 216, 0.18);
  --mf-radius: 14px;
  --mf-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
}

/* Reset and base page, no scroll bounce inside the Telegram webview */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--mf-font);
  color: var(--mf-text);
  background: linear-gradient(
    160deg,
    var(--mf-sky-top) 0%,
    var(--mf-sky-bottom) 100%
  );
  display: flex;
  flex-direction: column;
  /* Respect the device notch on the top and sides */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0
    env(safe-area-inset-left);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Utility hide flag used across all ui */
.mf-hidden {
  display: none !important;
}

/* ***************************************************************
 * Loading veil
 * *************************************************************** */

#loading {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: linear-gradient(
    160deg,
    var(--mf-sky-top) 0%,
    var(--mf-sky-bottom) 100%
  );
}

.mf-loading-icon {
  width: 84px;
  height: 84px;
  /* Gentle breathing pulse, the login screen look */
  animation: mf-pulse 2.2s ease-in-out infinite;
}

#loading-text {
  font-size: 12px;
  letter-spacing: 3px;
  color: var(--mf-dim);
  text-transform: uppercase;
}

/* Soft scale and opacity pulse for the brand icon */
@keyframes mf-pulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 0.7;
  }
  50% {
    transform: scale(1.08);
    opacity: 1;
  }
}

/* ***************************************************************
 * Brand header
 * *************************************************************** */

.mf-brand-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--mf-faint);
  background: rgba(16, 19, 28, 0.55);
}

.mf-brand-icon {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  /* Same calm pulse as the loading icon, kept very subtle in the header */
  animation: mf-pulse 3.4s ease-in-out infinite;
}

.mf-brand-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.mf-brand-wordmark {
  /* Wordmark keeps its 5:1 ratio, sized by height */
  height: 17px;
  width: auto;
}

#brand-tagline {
  font-size: 9px;
  letter-spacing: 1.6px;
  color: var(--mf-dim);
  text-transform: uppercase;
}

/* ***************************************************************
 * Game stage
 * *************************************************************** */

#game-shell {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Floating pause button anchored to the top-right of the stage */
.mf-pause-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 20;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--mf-text);
  background: rgba(16, 19, 28, 0.6);
  border: 1px solid var(--mf-card-border);
  border-radius: 50%;
  cursor: pointer;
  backdrop-filter: blur(4px);
}

.mf-pause-btn:active {
  background: rgba(16, 19, 28, 0.85);
}

/* Menu and overlay mount points cover the stage */
#menu-root,
#overlay-root {
  position: absolute;
  inset: 0;
  z-index: 10;
}

#overlay-root {
  z-index: 30;
  pointer-events: none;
}

/* Overlay children take pointer events back when present */
#overlay-root > * {
  pointer-events: auto;
}

/* Empty mount points must not block the canvas */
#menu-root:empty,
#overlay-root:empty {
  pointer-events: none;
}

/* ***************************************************************
 * Card and headings
 * *************************************************************** */

.mf-card {
  position: relative;
  margin: auto;
  width: min(420px, 92%);
  max-height: 100%;
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  background: var(--mf-card-bg);
  border: 1px solid var(--mf-card-border);
  border-radius: var(--mf-radius);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
}

/* The menu root centers its single card over the stage */
#menu-root {
  display: flex;
  padding: 16px;
}

.mf-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--mf-text);
  text-align: center;
}

.mf-subtitle {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--mf-dim);
  text-align: center;
}

/* ***************************************************************
 * Buttons
 * *************************************************************** */

.mf-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--mf-text);
  background: rgba(184, 168, 216, 0.1);
  border: 1px solid var(--mf-card-border);
  border-radius: 11px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}

.mf-btn:hover {
  background: rgba(184, 168, 216, 0.18);
}

.mf-btn:active {
  transform: scale(0.98);
}

.mf-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Primary call to action uses the brand rose */
.mf-btn-primary {
  color: #fff;
  background: linear-gradient(180deg, var(--mf-rose-hi), var(--mf-rose));
  border-color: transparent;
  font-size: 16px;
  padding: 14px 18px;
  box-shadow: 0 8px 22px rgba(136, 14, 79, 0.4);
}

.mf-btn-primary:hover {
  background: linear-gradient(180deg, #c61673, var(--mf-rose-hi));
}

/* Row of buttons that share a line */
.mf-btn-row {
  display: flex;
  gap: 10px;
}

.mf-btn-row > .mf-btn {
  flex: 1 1 0;
}

/* ***************************************************************
 * Toggle group (difficulty)
 * *************************************************************** */

.mf-toggle-group {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: rgba(16, 19, 28, 0.5);
  border: 1px solid var(--mf-faint);
  border-radius: 11px;
}

.mf-toggle {
  flex: 1 1 0;
  padding: 9px 4px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--mf-dim);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.mf-toggle:hover {
  color: var(--mf-text);
}

/* Selected difficulty stands out in the accent lavender */
.mf-toggle-active {
  color: var(--mf-sky-top);
  background: var(--mf-accent);
}

.mf-toggle-active:hover {
  color: var(--mf-sky-top);
}

/* ***************************************************************
 * Stats row
 * *************************************************************** */

.mf-stats-row {
  display: flex;
  gap: 8px;
}

.mf-stat {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 6px;
  background: rgba(16, 19, 28, 0.4);
  border: 1px solid var(--mf-faint);
  border-radius: 10px;
}

/* First line of a stat is its big value, the label is the dim second line */
.mf-stat strong {
  font-size: 18px;
  font-weight: 700;
  color: var(--mf-text);
}

.mf-stat span {
  font-size: 10px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--mf-dim);
}

/* ***************************************************************
 * Links row (secondary navigation)
 * *************************************************************** */

.mf-links-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mf-link-btn {
  flex: 1 1 calc(50% - 4px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 10px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--mf-accent);
  background: rgba(184, 168, 216, 0.07);
  border: 1px solid var(--mf-card-border);
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.mf-link-btn:hover {
  background: rgba(184, 168, 216, 0.15);
}

/* ***************************************************************
 * Lists (wardrobe, missions, workshop, leaderboard)
 * *************************************************************** */

.mf-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mf-list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: rgba(16, 19, 28, 0.4);
  border: 1px solid var(--mf-faint);
  border-radius: 11px;
}

/* Text block grows to fill the row between icon and trailing control */
.mf-list-label {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 14px;
  font-weight: 600;
  color: var(--mf-text);
}

.mf-list-hint {
  font-size: 11px;
  color: var(--mf-accent);
}

.mf-list-desc {
  font-size: 12px;
  line-height: 1.4;
  color: var(--mf-dim);
}

/* Small chip marking the active or equipped item */
.mf-active-chip {
  flex: 0 0 auto;
  padding: 3px 9px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--mf-up);
  background: rgba(14, 203, 129, 0.14);
  border: 1px solid rgba(14, 203, 129, 0.35);
  border-radius: 999px;
}

/* ***************************************************************
 * Tier dots (workshop upgrade levels)
 * *************************************************************** */

.mf-dots {
  display: flex;
  gap: 5px;
}

.mf-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: transparent;
  border: 1.5px solid var(--mf-dim);
}

/* A purchased tier fills the dot with the accent */
.mf-dot-filled {
  background: var(--mf-accent);
  border-color: var(--mf-accent);
}

/* ***************************************************************
 * Mission markers
 * *************************************************************** */

.mf-mission-icon {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  border-radius: 8px;
  background: rgba(184, 168, 216, 0.1);
}

/* A completed mission glows in the up-green */
.mf-mission-done {
  color: var(--mf-up);
  background: rgba(14, 203, 129, 0.14);
}

/* ***************************************************************
 * Overlays (pause, revive, rotate hint)
 * *************************************************************** */

.mf-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

/* Dim backdrop behind an overlay card */
.mf-dim {
  position: absolute;
  inset: 0;
  background: rgba(8, 10, 16, 0.72);
  backdrop-filter: blur(3px);
}

/* The overlay card itself reuses the menu card look and floats above the dim */
.mf-overlay .mf-card {
  position: relative;
  z-index: 1;
  margin: 0;
}

/* Small banner asking the player to rotate the device */
.mf-rotate-hint {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--mf-text);
  background: rgba(16, 19, 28, 0.92);
  border: 1px solid var(--mf-card-border);
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}

/* ***************************************************************
 * Revive bar (countdown)
 * *************************************************************** */

.mf-revive-bar-track {
  width: 100%;
  height: 8px;
  background: rgba(16, 19, 28, 0.6);
  border: 1px solid var(--mf-faint);
  border-radius: 999px;
  overflow: hidden;
}

.mf-revive-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--mf-rose-hi), var(--mf-accent));
  border-radius: 999px;
}

/* When this flag is added the bar drains over the revive window */
.mf-revive-bar-shrink {
  width: 0%;
  transition: width 5000ms linear;
}

/* ***************************************************************
 * Game over summary
 * *************************************************************** */

.mf-summary {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  background: rgba(16, 19, 28, 0.4);
  border: 1px solid var(--mf-faint);
  border-radius: 11px;
}

.mf-summary-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 14px;
  color: var(--mf-dim);
}

/* Right-aligned tally value on each summary line */
.mf-summary-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--mf-text);
  font-variant-numeric: tabular-nums;
}

/* Grade badge, neutral by default, callers add a modifier letter via text */
.mf-grade-chip {
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  padding: 8px 18px;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--mf-sky-top);
  background: var(--mf-accent);
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(184, 168, 216, 0.35);
}

/* Chip shown when the player used a revive this run */
.mf-revived-chip {
  align-self: center;
  padding: 4px 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--mf-accent);
  background: rgba(184, 168, 216, 0.12);
  border: 1px solid var(--mf-card-border);
  border-radius: 999px;
}

/* New record banner, celebratory in the up-green */
.mf-newbest {
  align-self: center;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--mf-up);
  background: rgba(14, 203, 129, 0.14);
  border: 1px solid rgba(14, 203, 129, 0.35);
  border-radius: 999px;
}

/* ***************************************************************
 * Skin preview (wardrobe)
 * *************************************************************** */

.mf-skin-preview {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  object-fit: contain;
  border-radius: 10px;
  background: rgba(16, 19, 28, 0.5);
  border: 1px solid var(--mf-faint);
}

/* A locked skin shows grayed out until it is bought */
.mf-skin-locked {
  filter: grayscale(1);
  opacity: 0.5;
}

/* ***************************************************************
 * Leaderboard board rows
 * *************************************************************** */

.mf-board-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  font-size: 14px;
  background: rgba(16, 19, 28, 0.4);
  border: 1px solid var(--mf-faint);
  border-radius: 10px;
}

/* Position number leads the row */
.mf-board-row > :first-child {
  flex: 0 0 26px;
  font-weight: 700;
  color: var(--mf-dim);
}

/* Player name fills the middle, score trails */
.mf-board-row > :nth-child(2) {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--mf-text);
}

.mf-board-row > :last-child {
  flex: 0 0 auto;
  font-weight: 700;
  color: var(--mf-text);
  font-variant-numeric: tabular-nums;
}

/* The signed-in player's own row is highlighted in the accent */
.mf-board-me {
  background: rgba(184, 168, 216, 0.14);
  border-color: var(--mf-accent);
}

.mf-board-me > :first-child {
  color: var(--mf-accent);
}

/* ***************************************************************
 * Mascot
 * *************************************************************** */

.mf-mascot {
  display: block;
  width: 96px;
  height: auto;
  margin: 0 auto;
  image-rendering: auto;
}

/* ***************************************************************
 * Responsive layout
 * *************************************************************** */

/* Portrait phones: let the menu card use the full width and scroll */
@media (orientation: portrait) and (max-width: 560px) {
  .mf-card {
    width: 100%;
    border-radius: 16px;
  }

  #menu-root {
    padding: 12px;
    align-items: stretch;
  }

  .mf-title {
    font-size: 21px;
  }
}

/* Landscape: keep the card compact and centered, header gets tighter */
@media (orientation: landscape) and (max-height: 480px) {
  .mf-brand-row {
    padding: 6px 14px;
  }

  .mf-brand-icon {
    width: 26px;
    height: 26px;
  }

  .mf-brand-wordmark {
    height: 14px;
  }

  #brand-tagline {
    font-size: 8px;
  }

  .mf-card {
    width: min(460px, 86%);
    padding: 16px 18px;
    gap: 10px;
  }

  .mf-title {
    font-size: 20px;
  }
}

/* Very short stages: trim card padding so it never clips off screen */
@media (max-height: 420px) {
  .mf-card {
    padding-top: 14px;
    padding-bottom: 14px;
  }
}
