:root {
  --gold: #DFB562;
  --gold-hi: #F6DC9E;
  --gold-dim: rgba(223, 181, 98, 0.34);
  --jade: #32B87A;
  --jade-hi: #7EF0B8;
  --lacquer-top: rgba(24, 11, 8, 0.92);
  --lacquer-bot: rgba(10, 4, 3, 0.97);
  --text-main: #F6EFE2;
  --text-muted: rgba(246, 239, 226, 0.56);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  background: #090302;
  color: var(--text-main);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

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

/* ==================== ENGRAVED TOP HEADER (ZERO PILLS) ==================== */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 10px max(18px, env(safe-area-inset-left));
  background: linear-gradient(180deg, rgba(10, 4, 3, 0.72) 0%, rgba(10, 4, 3, 0.25) 70%, rgba(10, 4, 3, 0) 100%);
  pointer-events: none;
}

/* MAMA-JONG Engraved Gold Wordmark — No Pill */
.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  pointer-events: auto;
}

.brand-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 29px;
  border-radius: 5px;
  background: linear-gradient(155deg, #FFFDF7 0%, #ECE1CA 100%);
  border-bottom: 3px solid #1B7A50;
  border-right: 2px solid #166240;
  color: #C42520;
  font-family: "Yu Mincho", "SimSun", Georgia, serif;
  font-weight: 800;
  font-size: 14px;
  line-height: 1;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.55);
  flex-shrink: 0;
}

.brand-wordmark {
  font-family: Georgia, "Palatino Linotype", "Book Antiqua", "Times New Roman", serif;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2em;
  line-height: 1;
  white-space: nowrap;
  background: linear-gradient(180deg, #FFF5D8 0%, #E7BF6B 58%, #B98734 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.72));
}

/* Desktop Editorial Formation Tabs */
.formation-tabs {
  display: inline-flex;
  align-items: center;
  gap: 22px;
  pointer-events: auto;
}

.formation-tab {
  position: relative;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 2px 8px;
  cursor: pointer;
  transition: color 0.18s ease;
  white-space: nowrap;
}

.formation-tab::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold-hi), transparent);
  opacity: 0;
  transform: scaleX(0.4);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.formation-tab:hover {
  color: var(--text-main);
}

.formation-tab.is-active {
  color: var(--gold-hi);
}

.formation-tab.is-active::after {
  opacity: 1;
  transform: scaleX(1);
}

.topbar-right {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

/* Mobile Compact Formation Selector (Hairline Brass, Not a Pill) */
.formation-select-wrap {
  display: none;
  align-items: center;
  border-bottom: 1px solid var(--gold-dim);
  padding: 2px 0;
}

.formation-select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  color: var(--gold-hi);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 5px 18px 5px 2px;
  cursor: pointer;
  outline: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--gold) 50%),
    linear-gradient(135deg, var(--gold) 50%, transparent 50%);
  background-position: calc(100% - 7px) 54%, calc(100% - 2px) 54%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.formation-select option {
  background: #170B08;
  color: #F6EFE2;
}

/* Refined Install Link */
.install-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: 6px;
  border: 1px solid rgba(223, 181, 98, 0.55);
  background: linear-gradient(180deg, rgba(223, 181, 98, 0.22), rgba(164, 118, 42, 0.14));
  color: var(--gold-hi);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.install-link:hover {
  background: linear-gradient(180deg, rgba(223, 181, 98, 0.34), rgba(164, 118, 42, 0.24));
  border-color: var(--gold-hi);
}

/* Minimal Header Sound Button */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: rgba(246, 239, 226, 0.8);
  cursor: pointer;
  transition: color 0.16s ease, background 0.16s ease;
}

.icon-btn:hover {
  color: var(--gold-hi);
  background: rgba(255, 235, 195, 0.07);
}

.icon-btn.is-muted {
  color: rgba(246, 239, 226, 0.35);
}

/* ==================== HEIRLOOM LACQUER & BRASS COMMAND CONSOLE ==================== */
.console-wrap {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  padding: 0 16px max(12px, env(safe-area-inset-bottom));
  pointer-events: none;
}

.console {
  position: relative;
  width: min(620px, 100%);
  border-radius: 14px;
  background: linear-gradient(180deg, var(--lacquer-top) 0%, var(--lacquer-bot) 100%);
  border: 1px solid rgba(223, 181, 98, 0.24);
  box-shadow:
    0 16px 40px rgba(0, 0, 0, 0.65),
    inset 0 1px 0 rgba(255, 228, 170, 0.14);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  overflow: hidden;
  pointer-events: auto;
}

/* Ultra-thin Combo Energy Beam along top console edge */
.combo-beam-track {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2.5px;
  background: rgba(255, 255, 255, 0.04);
  overflow: hidden;
}

.combo-beam-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #2EC981 0%, #F4CE6A 65%, #FFF2B8 100%);
  box-shadow: 0 0 10px rgba(244, 206, 106, 0.8);
  transform-origin: left center;
  transform: scaleX(0);
  opacity: 0;
  transition: opacity 0.2s ease;
}

/* Telemetry Strip */
.telemetry-bar {
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  padding: 7px 14px 6px;
  border-bottom: 1px solid rgba(223, 181, 98, 0.12);
}

.telemetry-cell {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.t-label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.13em;
  color: rgba(246, 239, 226, 0.48);
}

.t-val {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.t-sep {
  width: 1px;
  height: 12px;
  background: rgba(223, 181, 98, 0.18);
}

.combo-val {
  color: rgba(246, 239, 226, 0.5);
  transition: color 0.2s ease;
}

.combo-cell.is-active .combo-val {
  color: #FFD96B;
  text-shadow: 0 0 10px rgba(255, 217, 107, 0.55);
}

/* Precision-Machined Lacquer Command Keys */
.command-deck {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  padding: 7px 8px 8px;
}

.cmd-key {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 46px;
  padding: 6px 4px;
  border-radius: 9px;
  border: 1px solid rgba(255, 235, 195, 0.09);
  background: linear-gradient(180deg, rgba(255, 238, 204, 0.065) 0%, rgba(255, 238, 204, 0.015) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 240, 208, 0.09),
    0 2px 5px rgba(0, 0, 0, 0.42);
  color: rgba(246, 239, 226, 0.88);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.cmd-key svg {
  opacity: 0.92;
  transition: transform 0.15s ease;
}

.cmd-key:hover:not(:disabled) {
  background: linear-gradient(180deg, rgba(223, 181, 98, 0.16) 0%, rgba(223, 181, 98, 0.05) 100%);
  border-color: rgba(223, 181, 98, 0.36);
  color: var(--gold-hi);
}

.cmd-key:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.55);
}

.cmd-key:disabled {
  opacity: 0.28;
  cursor: not-allowed;
}

.cmd-key.cmd-gold {
  border-color: rgba(223, 181, 98, 0.24);
  background: linear-gradient(180deg, rgba(223, 181, 98, 0.13) 0%, rgba(180, 128, 44, 0.04) 100%);
  color: var(--gold-hi);
}

.cmd-key.cmd-jade {
  border-color: rgba(50, 184, 122, 0.26);
  background: linear-gradient(180deg, rgba(50, 184, 122, 0.13) 0%, rgba(22, 108, 70, 0.04) 100%);
  color: #B4F8D5;
}

.cmd-key.is-active {
  border-color: rgba(126, 240, 184, 0.52);
  background: linear-gradient(180deg, rgba(50, 184, 122, 0.26) 0%, rgba(22, 108, 70, 0.12) 100%);
  color: var(--jade-hi);
  box-shadow:
    inset 0 1px 0 rgba(190, 255, 224, 0.2),
    0 0 12px rgba(50, 184, 122, 0.24);
}

/* ==================== TOAST ==================== */
.toast {
  position: fixed;
  top: max(60px, calc(env(safe-area-inset-top) + 48px));
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  z-index: 20;
  padding: 9px 18px;
  border-radius: 8px;
  background: rgba(18, 8, 6, 0.94);
  border: 1px solid rgba(223, 181, 98, 0.45);
  backdrop-filter: blur(14px);
  color: var(--gold-hi);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ==================== VICTORY MODAL ==================== */
.victory-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 3, 2, 0.72);
  backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.victory-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.victory-card {
  width: min(370px, 90vw);
  padding: 32px 26px 26px;
  border-radius: 18px;
  background: linear-gradient(170deg, rgba(28, 13, 9, 0.97), rgba(11, 5, 3, 0.98));
  border: 1px solid rgba(223, 181, 98, 0.42);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.75), inset 0 1px 0 rgba(255, 232, 182, 0.14);
  text-align: center;
  transform: scale(0.93) translateY(10px);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
}

.victory-overlay.is-visible .victory-card {
  transform: scale(1) translateY(0);
}

.victory-crest {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 62px;
  border-radius: 10px;
  background: linear-gradient(155deg, #FFFDF7, #EAE0CA);
  border-bottom: 5px solid #1B7A50;
  border-right: 4px solid #135A3B;
  color: #C42520;
  font-family: "Yu Mincho", "SimSun", Georgia, serif;
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 16px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.55);
}

.victory-title {
  font-family: Georgia, "Palatino Linotype", serif;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--gold-hi);
  margin-bottom: 4px;
}

.victory-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 22px;
}

.victory-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 24px;
}

.v-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 6px;
  border-radius: 10px;
  background: rgba(255, 238, 200, 0.04);
  border: 1px solid rgba(223, 181, 98, 0.14);
}

.v-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.v-val {
  font-size: 17px;
  font-weight: 700;
  color: var(--gold-hi);
}

.victory-actions {
  display: flex;
  gap: 10px;
}

.v-btn {
  flex: 1;
  min-height: 46px;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  border: none;
  transition: transform 0.12s ease, filter 0.18s ease;
}

.v-btn:active {
  transform: translateY(1px);
}

.v-btn.secondary {
  background: rgba(255, 238, 200, 0.08);
  color: var(--text-main);
  border: 1px solid rgba(223, 181, 98, 0.24);
}

.v-btn.primary {
  background: linear-gradient(180deg, #F3D388, #C99235);
  color: #1A0E06;
}

/* ==================== ANDROID SMARTPHONE EDGE-TO-EDGE ==================== */
@media (max-width: 820px) {
  .formation-tabs {
    display: none;
  }
  .formation-select-wrap {
    display: inline-flex;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  }
  .brand-wordmark {
    font-size: 15px;
    letter-spacing: 0.16em;
  }
  .brand-glyph {
    width: 21px;
    height: 26px;
    font-size: 13px;
  }
  .console-wrap {
    padding: 0;
  }
  .console {
    width: 100%;
    border-radius: 14px 14px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }
  .telemetry-bar {
    padding: 6px 10px 5px;
  }
  .hide-xs {
    display: none;
  }
  .command-deck {
    gap: 6px;
    padding: 6px 8px 6px;
  }
  .cmd-key {
    min-height: 48px;
    font-size: 9.5px;
    letter-spacing: 0.06em;
  }
}
