@layer components {
  .topbar {
    display: grid;
    align-items: stretch;
    padding: 8px 14px 0;
    position: relative;
    z-index: 3;
  }

  .topbar__inner {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    column-gap: 12px;
  }

  .player {
    justify-self: start;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    column-gap: 10px;
    padding: 4px 16px 4px 4px;
    border-radius: 999px;
    max-width: 100%;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0) 50%),
      linear-gradient(180deg, rgba(40, 26, 76, 0.82), rgba(12, 8, 26, 0.9));
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.55),
      0 0 0 2px rgba(240, 181, 52, 0.45),
      0 8px 20px rgba(0, 0, 0, 0.4),
      inset 0 1px 0 rgba(255, 255, 255, 0.2);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    transition: transform 0.2s var(--ease-spring);
  }

  .player:hover {
    transform: translateY(-1px);
  }

  .player.is-glow {
    animation: player-glow 1.4s ease;
  }

  .player__avatar {
    position: relative;
    width: 50px;
    height: 50px;
    display: grid;
    place-items: center;
  }

  .player__ring {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
  }

  .player__ring-track {
    fill: none;
    stroke: rgba(0, 0, 0, 0.55);
    stroke-width: 5;
  }

  .player__ring-fill {
    fill: none;
    stroke: #5de9ff;
    stroke-width: 5;
    stroke-linecap: round;
    stroke-dasharray: 100;
    stroke-dashoffset: 100;
    filter: drop-shadow(0 0 3px rgba(93, 233, 255, 0.8));
    transition: stroke-dashoffset 0.8s var(--ease-out);
  }

  .player__photo {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    overflow: hidden;
    display: grid;
    place-items: center;
    background: radial-gradient(circle at 40% 30%, #3a2a6e, #120a24);
    box-shadow: 0 0 0 2px #1a0c02;
  }

  .player__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  .player__letter {
    font-size: 18px;
    font-weight: 900;
    color: var(--gold);
  }

  .player__level {
    position: absolute;
    right: -4px;
    bottom: -3px;
    min-width: 22px;
    height: 22px;
    padding: 0 5px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    font-size: 11.5px;
    font-weight: 900;
    color: #062538;
    background: linear-gradient(180deg, #e8fdff, #5de9ff 55%, #22a6d8);
    box-shadow: 0 0 0 2px #06121c, 0 2px 6px rgba(0, 0, 0, 0.5);
  }

  .player__level.is-levelup {
    animation: value-bump 0.6s var(--ease-spring) 2;
  }

  .player__meta {
    display: grid;
    min-width: 0;
    gap: 3px;
  }

  .player__name {
    font-size: 14.5px;
    font-weight: 900;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .player__xp {
    position: relative;
    width: 108px;
    height: 7px;
    border-radius: 99px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.55);
    box-shadow: inset 0 0 0 1px rgba(93, 233, 255, 0.2);
  }

  .player__xp-fill {
    position: absolute;
    inset: 0;
    transform-origin: 0 50%;
    transform: scaleX(0.02);
    border-radius: inherit;
    background: linear-gradient(90deg, #22a6d8, #5de9ff 70%, #c8f8ff);
    transition: transform 0.8s var(--ease-out);
  }

  .player__xp-text {
    font-size: 10px;
    font-weight: 700;
    color: var(--text-faint);
    line-height: 1;
  }

  .wallet {
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .pill {
    position: relative;
    height: 42px;
    min-width: 132px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 8px;
    padding: 0 5px 0 4px;
    border-radius: 999px;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0) 50%),
      linear-gradient(180deg, rgba(10, 6, 20, 0.86), rgba(24, 16, 44, 0.9));
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.6),
      0 0 0 2px rgba(240, 181, 52, 0.5),
      0 8px 18px rgba(0, 0, 0, 0.4),
      inset 0 2px 6px rgba(0, 0, 0, 0.5);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    transition: transform 0.2s var(--ease-spring);
  }

  .pill:hover {
    transform: translateY(-1px);
  }

  .pill__icon {
    width: 40px;
    height: 40px;
    margin: -6px 0 -6px -8px;
    object-fit: contain;
    filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.5));
  }

  .pill__icon.is-bump {
    animation: value-bump 0.3s var(--ease-spring);
  }

  .pill__value {
    font-size: 17px;
    font-weight: 900;
    text-align: right;
    white-space: nowrap;
    color: #fff;
    text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
  }

  .pill__plus {
    position: relative;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background:
      radial-gradient(120% 70% at 50% 0%, rgba(255, 255, 255, 0.6), rgba(255, 255, 255, 0) 55%),
      linear-gradient(180deg, #7df27a, #2fbf45);
    box-shadow: 0 0 0 2px #0b3a12, inset 0 -3px 4px rgba(0, 60, 10, 0.35);
  }

  .pill__plus::before,
  .pill__plus::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    width: 14px;
    height: 4px;
    margin: -2px 0 0 -7px;
    border-radius: 2px;
    background: #fff;
    box-shadow: 0 1px 0 rgba(0, 70, 10, 0.7);
  }

  .pill__plus::after {
    transform: rotate(90deg);
  }

  .pill--gems {
    min-width: 108px;
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.6),
      0 0 0 2px rgba(93, 233, 255, 0.5),
      0 8px 18px rgba(0, 0, 0, 0.4),
      inset 0 2px 6px rgba(0, 0, 0, 0.5);
  }

  .pill.is-flash[data-trend='up'] .pill__value {
    animation: value-up 0.9s ease;
  }

  .pill.is-flash[data-trend='down'] .pill__value {
    animation: value-down 0.6s ease;
  }

  .topbar__actions {
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .top-btn {
    position: relative;
    height: 48px;
    min-width: 48px;
    padding: 0 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 16px;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 50%),
      linear-gradient(180deg, rgba(46, 30, 88, 0.86), rgba(16, 10, 34, 0.92));
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.6),
      0 0 0 2px rgba(240, 181, 52, 0.45),
      0 4px 0 0 rgba(8, 4, 18, 0.9),
      0 10px 18px rgba(0, 0, 0, 0.4),
      inset 0 1px 0 rgba(255, 255, 255, 0.22);
    transition: transform 0.08s ease;
  }

  .top-btn:active {
    transform: translateY(3px);
  }

  .top-btn img {
    width: 30px;
    height: 30px;
  }

  .top-btn__label {
    font-size: 13px;
    font-weight: 900;
    letter-spacing: 0.1em;
  }

  .top-btn__badge {
    position: absolute;
    top: -7px;
    left: -7px;
    min-width: 21px;
    height: 21px;
    padding: 0 5px;
    display: grid;
    place-items: center;
    border-radius: 11px;
    font-size: 11px;
    font-weight: 900;
    color: #fff;
    background: linear-gradient(180deg, #ff7a88, #e8263c);
    box-shadow: 0 0 0 2px #1a0c02, 0 3px 8px rgba(0, 0, 0, 0.5);
    animation: badge-in 0.4s var(--ease-spring);
    pointer-events: none;
    z-index: 2;
  }

  .top-btn__badge[hidden] {
    display: none;
  }

  .top-btn[data-dev-force]::after {
    content: 'FORCED';
    position: absolute;
    top: -7px;
    right: -6px;
    height: 18px;
    padding: 0 6px;
    display: grid;
    place-items: center;
    border-radius: 99px;
    font-size: 9px;
    font-weight: 900;
    letter-spacing: 0.1em;
    color: #fff;
    background: linear-gradient(180deg, #c9a2ff, #7a4de0);
    box-shadow: 0 0 0 1.5px #1b0c3a, 0 0 10px rgba(155, 107, 255, 0.6);
    pointer-events: none;
  }

  .top-btn[aria-expanded='true'] {
    box-shadow:
      0 0 0 1px rgba(0, 0, 0, 0.6),
      0 0 0 2px #ffd44a,
      0 0 18px rgba(255, 212, 74, 0.5),
      inset 0 1px 0 rgba(255, 255, 255, 0.22);
  }

  @media (max-width: 1100px) {
    .player__xp {
      width: 84px;
    }

    .pill {
      min-width: 118px;
    }
  }

  @media (orientation: portrait) and (max-aspect-ratio: 4/5) {
    .topbar {
      padding: 6px 8px 0;
    }

    .topbar__inner {
      grid-template-columns: auto minmax(0, 1fr) auto;
      column-gap: 6px;
    }

    .player {
      padding: 3px;
      column-gap: 0;
    }

    .player__meta {
      display: none;
    }

    .player__avatar {
      width: 44px;
      height: 44px;
    }

    .player__photo {
      width: 33px;
      height: 33px;
    }

    .wallet {
      justify-content: center;
      gap: 6px;
      min-width: 0;
    }

    .pill {
      height: 36px;
      min-width: 0;
      padding-right: 3px;
      column-gap: 4px;
    }

    .pill__icon {
      width: 32px;
      height: 32px;
      margin: -4px 0 -4px -6px;
    }

    .pill__value {
      font-size: 14px;
    }

    .pill__plus {
      width: 24px;
      height: 24px;
    }

    .pill__plus::before,
    .pill__plus::after {
      width: 11px;
      height: 3px;
      margin: -1.5px 0 0 -5.5px;
    }

    .top-btn {
      height: 40px;
      min-width: 40px;
      padding: 0 8px;
      border-radius: 13px;
    }

    .top-btn img {
      width: 24px;
      height: 24px;
    }

    .top-btn__label {
      display: none;
    }
  }

  @media (orientation: portrait) and (max-aspect-ratio: 4/5) and (max-height: 800px) {
    .topbar {
      padding-top: 4px;
    }

    .player__avatar {
      width: 40px;
      height: 40px;
    }

    .player__photo {
      width: 30px;
      height: 30px;
    }

    .player__level {
      min-width: 20px;
      height: 20px;
      font-size: 11px;
    }

    .pill {
      height: 34px;
    }

    .pill__icon {
      width: 30px;
      height: 30px;
    }

    .top-btn {
      height: 38px;
      min-width: 38px;
    }
  }

  @media (orientation: portrait) and (max-aspect-ratio: 4/5) and (max-height: 620px) {
    .player__avatar {
      width: 36px;
      height: 36px;
    }

    .player__photo {
      width: 27px;
      height: 27px;
    }

    .pill {
      height: 32px;
    }

    .pill__icon {
      width: 28px;
      height: 28px;
    }

    .top-btn {
      height: 36px;
      min-width: 36px;
    }
  }

  @media (max-height: 540px) and (orientation: landscape) {
    .topbar {
      padding: 4px 10px 0;
    }

    .topbar__inner {
      column-gap: 8px;
    }

    .player {
      padding: 3px;
      column-gap: 0;
    }

    .player__meta,
    .top-btn__label {
      display: none;
    }

    .wallet {
      gap: 8px;
    }

    .pill {
      min-width: 0;
      padding-right: 3px;
    }

    .player__avatar {
      width: 40px;
      height: 40px;
    }

    .player__photo {
      width: 30px;
      height: 30px;
    }

    .player__xp-text {
      display: none;
    }

    .pill {
      height: 34px;
    }

    .pill__icon {
      width: 30px;
      height: 30px;
    }

    .pill__value {
      font-size: 14px;
    }

    .pill__plus {
      width: 24px;
      height: 24px;
    }

    .top-btn {
      height: 38px;
      border-radius: 12px;
    }

    .top-btn img {
      width: 24px;
      height: 24px;
    }
  }
}

@layer fx {
  @keyframes value-up {
    0% {
      color: #fff;
    }

    20% {
      color: #9dff8a;
      text-shadow: 0 0 12px rgba(120, 255, 110, 0.8);
    }

    100% {
      color: #fff;
    }
  }

  @keyframes value-down {
    0% {
      color: #fff;
    }

    30% {
      color: #ff8a9a;
    }

    100% {
      color: #fff;
    }
  }

  @keyframes player-glow {
    0%,
    100% {
      box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.55),
        0 0 0 2px rgba(240, 181, 52, 0.45),
        0 8px 20px rgba(0, 0, 0, 0.4);
    }

    40% {
      box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.55),
        0 0 0 3px #5de9ff,
        0 0 30px rgba(93, 233, 255, 0.8);
    }
  }
}
