:root {
  --meta-card: rgba(10, 26, 39, .88);
  --meta-card-strong: rgba(5, 17, 28, .96);
  --meta-line: rgba(255, 255, 255, .14);
  --meta-positive: #8bf18a;
  --meta-warning: #ffd166;
  --meta-locked: #8795a2;
}

.profile-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 4px;
  padding: 10px;
  border: 1px solid rgba(255, 209, 102, .24);
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(255, 209, 102, .085), rgba(104, 226, 255, .055));
}
.profile-summary > div {
  min-width: 0;
  padding: 8px 9px;
  border-radius: 9px;
  background: rgba(255,255,255,.055);
}
.profile-summary span,
.profile-balance-bar span {
  display: block;
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.profile-summary strong {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--ink);
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.profile-summary .profile-currency strong { color: var(--gold); }
.profile-summary > button { grid-column: 1 / -1; width: 100%; }

.operation-row { margin-top: 12px; }
.operation-info {
  min-height: 54px;
  margin: 10px 0 3px;
  padding: 10px 11px;
  border-left: 3px solid var(--gold);
  border-radius: 0 10px 10px 0;
  background: rgba(255,209,102,.06);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.48;
}
.operation-info strong { color: var(--ink); }
.operation-info .operation-lock { color: #ffc0c0; }

.quick-inventory {
  left: 50%;
  bottom: 68px;
  z-index: 7;
  display: grid;
  grid-template-columns: repeat(4, minmax(88px, 1fr));
  gap: 5px;
  padding: 6px;
  transform: translateX(-50%);
  pointer-events: auto;
}
.quick-inventory button {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 5px;
  min-width: 0;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 8px;
  padding: 6px 7px;
  background: rgba(255,255,255,.065);
  color: var(--ink);
  cursor: pointer;
}
.quick-inventory button:hover { background: rgba(255,255,255,.12); }
.quick-inventory button:disabled { opacity: .38; }
.quick-inventory kbd {
  min-width: 20px;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 5px;
  padding: 2px 4px;
  background: rgba(0,0,0,.18);
  color: var(--cyan);
  text-align: center;
}
.quick-inventory span { overflow: hidden; font-size: 9px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.quick-inventory strong { color: var(--gold); font-size: 11px; }

.pause-inventory {
  display: grid;
  gap: 10px;
  margin: 15px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255,255,255,.04);
}
.pause-inventory > div:first-child { display: grid; gap: 3px; }
.pause-inventory span { color: var(--muted); font-size: 11px; }
.pause-inventory b { margin-left: 4px; color: var(--gold); }

.profile-overlay { z-index: 42; transition: none; }
.profile-overlay.visible { opacity: 1; visibility: visible; }
.profile-card {
  width: min(1220px, 97vw);
  max-height: calc(100vh - 24px);
  padding: 0;
  overflow: hidden;
  background:
    linear-gradient(145deg, rgba(6, 19, 31, .985), rgba(7, 16, 25, .96)),
    url("assets/v640/branding/foxhunt3d-launch-screen.webp") center / cover no-repeat;
}
.profile-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px 13px;
  border-bottom: 1px solid var(--meta-line);
  background: rgba(4,14,23,.84);
}
.profile-header h2 { margin: 3px 0 4px; font-size: clamp(23px, 3vw, 34px); }
.profile-header p { max-width: 850px; margin: 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.profile-close {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--meta-line);
  border-radius: 10px;
  background: rgba(255,255,255,.07);
  color: var(--ink);
  font-size: 27px;
  line-height: 1;
  cursor: pointer;
}
.profile-close:hover { background: rgba(255,255,255,.13); }
.profile-balance-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--meta-line);
  background: rgba(4,14,23,.74);
}
.profile-balance-bar span {
  padding: 7px 9px;
  border-radius: 8px;
  background: rgba(255,255,255,.05);
}
.profile-balance-bar strong { display: block; margin-top: 2px; color: var(--gold); font-size: 16px; }
.profile-tabs {
  display: flex;
  gap: 5px;
  padding: 9px 20px;
  overflow-x: auto;
  border-bottom: 1px solid var(--meta-line);
  background: rgba(4,14,23,.68);
}
.profile-tabs button {
  flex: 0 0 auto;
  border: 1px solid var(--meta-line);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255,255,255,.045);
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  cursor: pointer;
}
.profile-tabs button.active {
  border-color: rgba(104,226,255,.56);
  background: rgba(104,226,255,.13);
  color: var(--cyan);
}
.profile-content {
  min-height: 300px;
  max-height: calc(100vh - 300px);
  padding: 16px 20px 22px;
  overflow: auto;
  background: rgba(2,10,17,.68);
}
.profile-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  border-top: 1px solid var(--meta-line);
  background: rgba(4,14,23,.88);
}
.profile-footer > span { color: var(--muted); font-size: 10px; line-height: 1.4; }

.profile-section { margin-bottom: 19px; }
.profile-section:last-child { margin-bottom: 0; }
.profile-section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 10px;
}
.profile-section-heading h3 { margin: 0; font-size: 17px; }
.profile-section-heading p { max-width: 720px; margin: 0; color: var(--muted); font-size: 10px; line-height: 1.45; text-align: right; }
.profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 10px;
}
.profile-grid.compact { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.character-card,
.shop-card,
.inventory-card,
.career-card,
.upgrade-card {
  position: relative;
  display: grid;
  gap: 9px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--meta-line);
  border-radius: 13px;
  background: linear-gradient(145deg, rgba(14,34,49,.86), rgba(5,17,28,.88));
  box-shadow: 0 12px 30px rgba(0,0,0,.16);
}
.character-card.selected { border-color: rgba(104,226,255,.72); box-shadow: inset 0 0 0 1px rgba(104,226,255,.2), 0 12px 30px rgba(0,0,0,.2); }
.character-card.locked { filter: saturate(.55); }
.character-card.owned::after,
.character-card.selected::after {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(120,227,107,.13);
  color: var(--meta-positive);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
  content: "Omistettu";
}
.character-card.selected::after { background: rgba(104,226,255,.14); color: var(--cyan); content: "Valittu"; }
.character-visual {
  position: relative;
  height: 84px;
  overflow: hidden;
  border-radius: 10px;
  background:
    radial-gradient(circle at 70% 30%, rgba(255,255,255,.18), transparent 24%),
    linear-gradient(150deg, var(--body-color, #c72d48), var(--wing-color, #7d1930));
}
.character-visual::before {
  content: "";
  position: absolute;
  left: 19%;
  top: 20%;
  width: 48%;
  height: 62%;
  border-radius: 52% 58% 45% 55%;
  background:
    repeating-linear-gradient(135deg, transparent 0 8px, var(--accent-color, rgba(255,255,255,.26)) 9px 11px),
    var(--body-color, #c72d48);
  box-shadow: -30px 10px 0 -17px var(--wing-color, #7d1930), 36px 7px 0 -17px var(--wing-color, #7d1930);
  transform: rotate(-5deg);
}
.character-visual::after {
  content: "";
  position: absolute;
  left: 64%;
  top: 39%;
  border-left: 28px solid var(--beak-color, #f6a623);
  border-top: 10px solid transparent;
  border-bottom: 10px solid transparent;
}
.character-card h4,
.shop-card h4,
.inventory-card h4,
.upgrade-card h4 { margin: 0; padding-right: 58px; font-size: 15px; }
.card-subtitle { min-height: 28px; margin: 0; color: var(--muted); font-size: 10px; line-height: 1.38; }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.stat-row span {
  padding: 5px 3px;
  border-radius: 7px;
  background: rgba(255,255,255,.05);
  color: var(--muted);
  font-size: 8px;
  text-align: center;
}
.stat-row strong { display: block; margin-top: 2px; color: var(--ink); font-size: 10px; }
.card-price,
.card-lock {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 9px;
}
.card-price strong { color: var(--gold); font-size: 13px; }
.card-lock strong { color: #ffc4c4; }
.card-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }
.card-actions button { flex: 1 1 92px; min-height: 34px; padding: 7px 9px; font-size: 9px; }

.upgrade-track {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}
.upgrade-track i {
  height: 7px;
  border-radius: 999px;
  background: rgba(255,255,255,.09);
}
.upgrade-track i.active { background: linear-gradient(90deg, var(--cyan), var(--gold)); }
.upgrade-level { color: var(--muted); font-size: 9px; }
.upgrade-level strong { color: var(--ink); }

.inventory-count {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.inventory-count strong { color: var(--gold); font-size: 28px; }
.inventory-effect { color: var(--muted); font-size: 10px; line-height: 1.45; }
.inventory-icon {
  display: grid;
  place-items: center;
  width: 45px;
  height: 45px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 12px;
  background: rgba(255,255,255,.07);
  font-size: 22px;
}

.career-summary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.career-summary div {
  padding: 11px;
  border: 1px solid var(--meta-line);
  border-radius: 11px;
  background: rgba(255,255,255,.045);
}
.career-summary span { display: block; color: var(--muted); font-size: 8px; text-transform: uppercase; }
.career-summary strong { display: block; margin-top: 3px; color: var(--gold); font-size: 18px; }
.level-card.locked { opacity: .62; }
.level-stars { color: var(--gold); letter-spacing: .12em; }
.level-progress-line { color: var(--muted); font-size: 9px; line-height: 1.5; }
.level-progress-line strong { color: var(--ink); }

.notice-box {
  padding: 10px 12px;
  border: 1px solid rgba(104,226,255,.22);
  border-radius: 10px;
  background: rgba(104,226,255,.06);
  color: var(--muted);
  font-size: 10px;
  line-height: 1.48;
}
.notice-box strong { color: var(--cyan); }
.purchase-error { border-color: rgba(255,93,93,.34); background: rgba(255,93,93,.08); color: #ffd4d4; }

.loot-pickup-label {
  position: absolute;
  z-index: 6;
  pointer-events: none;
  color: white;
}

.end-stats-expanded { grid-template-columns: repeat(3, 1fr); }

@media (pointer: coarse) {
  .quick-inventory { bottom: 170px; grid-template-columns: repeat(2, minmax(86px, 1fr)); }
}

@media (max-width: 900px) {
  .profile-content { max-height: calc(100vh - 340px); }
  .profile-footer { align-items: stretch; flex-direction: column; }
  .career-summary { grid-template-columns: repeat(3, 1fr); }
  .quick-inventory { left: auto; right: 12px; bottom: 240px; transform: none; grid-template-columns: repeat(2, minmax(80px, 1fr)); }
}

@media (max-width: 650px) {
  .profile-summary { grid-template-columns: 1fr 1fr; }
  .profile-summary > div:last-of-type { grid-column: 1 / -1; }
  .profile-header { padding: 14px; }
  .profile-balance-bar { grid-template-columns: 1fr 1fr; padding: 8px 14px; }
  .profile-tabs { padding: 8px 14px; }
  .profile-content { max-height: none; padding: 12px 14px 18px; }
  .profile-card { max-height: none; overflow: visible; }
  .profile-overlay { align-items: start; }
  .profile-section-heading { align-items: flex-start; flex-direction: column; }
  .profile-section-heading p { text-align: left; }
  .profile-grid { grid-template-columns: 1fr; }
  .career-summary { grid-template-columns: 1fr 1fr; }
  .end-stats-expanded { grid-template-columns: 1fr 1fr; }
  .quick-inventory { right: 8px; bottom: 164px; max-width: 210px; }
  .quick-inventory span { display: none; }
}

@media (max-height: 620px) and (orientation: landscape) {
  .profile-content { max-height: calc(100vh - 235px); }
  .profile-header { padding: 10px 16px 8px; }
  .profile-header p { display: none; }
  .profile-balance-bar { padding: 6px 16px; }
  .profile-tabs { padding: 6px 16px; }
  .profile-footer { padding: 7px 16px; }
  .quick-inventory { bottom: 62px; }
}

/* Kosketusohjainten selkeä, päällekkäisyydetön asettelu. */
@media (pointer: coarse) {
  .touch-action {
    padding: 6px;
    overflow: hidden;
    font-size: 9px;
    line-height: 1.08;
    white-space: normal;
    overflow-wrap: anywhere;
  }
}

@media (pointer: coarse) and (orientation: portrait) {
  #statusPanel {
    left: 8px;
    right: 8px;
    bottom: 190px;
    width: auto;
    padding: 9px 10px 10px;
  }
  #voiceDock {
    left: 8px;
    right: auto;
    top: 202px;
    bottom: auto;
    width: 190px;
    transform: none;
    flex-direction: column;
    align-items: stretch;
  }
  .quick-inventory {
    left: auto;
    right: 8px;
    top: 202px;
    bottom: auto;
    width: 180px;
    max-width: none;
    transform: none;
    grid-template-columns: repeat(2, minmax(78px, 1fr));
  }
  #joystickBase { left: 16px; bottom: 16px; }
  .action-stack { right: 16px; bottom: 16px; }
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 620px) {
  #rosterPanel,
  #radarPanel { display: none; }
  #chatToggleButton { right: 12px; top: 12px; }
  #settingsButton { right: 12px; top: 48px; }
  #joystickBase {
    left: 12px;
    bottom: 12px;
    width: 132px;
    height: 132px;
  }
  #statusPanel {
    left: 152px;
    right: auto;
    bottom: 12px;
    width: 202px;
    padding: 8px 9px 9px;
  }
  #statusPanel .bar-row {
    grid-template-columns: 52px 1fr 37px;
    gap: 5px;
    margin: 3px 0;
    font-size: 8px;
  }
  #statusPanel #flightData { gap: 4px; margin-top: 6px; }
  #statusPanel .metric { padding: 4px 2px; }
  #statusPanel .metric span { font-size: 6px; }
  #statusPanel .metric strong { font-size: 10px; }
  .quick-inventory {
    left: 50%;
    right: auto;
    top: auto;
    bottom: 12px;
    width: 210px;
    max-width: none;
    transform: translateX(-50%);
    grid-template-columns: repeat(2, minmax(92px, 1fr));
  }
  #voiceDock {
    left: 50%;
    right: auto;
    top: auto;
    bottom: 126px;
    width: auto;
    transform: translateX(-50%);
    flex-direction: row;
    align-items: center;
  }
  .action-stack { right: 16px; bottom: 12px; }
}

/* Tauko- ja tulosnäkymien pitää avautua välittömästi myös hitaalla WebGL-laitteella. */
#pauseOverlay,
#endOverlay { transition: none; }
#pauseOverlay.visible,
#endOverlay.visible { opacity: 1; visibility: visible; }

/* v4.2.9: profile panel uses a fixed internal scroll region on every viewport.
   Header, balances, tabs and backup controls remain reachable while only the
   selected tab content scrolls. */
.profile-overlay {
  overflow: hidden !important;
  overscroll-behavior: contain;
}
.profile-card {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  width: min(1460px, calc(100vw - 16px));
  height: min(848px, calc(100dvh - 16px));
  max-height: calc(100dvh - 16px);
  min-height: 0;
  overflow: hidden !important;
}
.profile-content {
  min-height: 0 !important;
  max-height: none !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}
.profile-header,
.profile-balance-bar,
.profile-tabs,
.profile-footer {
  min-height: 0;
}
@media (max-width: 650px) {
  .profile-card {
    height: calc(100dvh - 8px);
    max-height: calc(100dvh - 8px);
    overflow: hidden !important;
  }
  .profile-overlay { align-items: center !important; padding: 4px !important; }
  .profile-content { max-height: none !important; }
}
@media (max-height: 620px) and (orientation: landscape) {
  .profile-card {
    width: calc(100vw - 8px);
    height: calc(100dvh - 8px);
    max-height: calc(100dvh - 8px);
  }
  .profile-header h2 { font-size: clamp(20px, 4.4vh, 29px); }
  .profile-footer > span { display: none; }
}

/* v4.2.9 final: the overlay padding must match the card's viewport-based size.
   The generic overlay uses 20 px padding, which could push the fixed-height
   profile card 4–12 px outside desktop and landscape-mobile viewports. */
.profile-overlay {
  padding: 4px !important;
  place-items: center !important;
}
