:root {
  --color-bg: #111318;
  --color-bg-soft: #171a21;
  --color-surface: #20242d;
  --color-surface-raised: #282d38;
  --color-line: #393f4f;
  --color-text: #f3f5f8;
  --color-text-muted: #aab2c2;
  --color-text-soft: #d2d7e2;
  --color-accent: #33c7b4;
  --color-accent-strong: #15a491;
  --color-gold: #f0b35f;
  --color-danger: #ef6b73;
  --color-success: #5dd39e;
  --color-info: #6da8ff;
  --radius-sm: 4px;
  --radius-md: 8px;
  --shadow-panel: 0 18px 40px rgba(0, 0, 0, 0.28);
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --max-page-width: 1180px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

img {
  max-width: 100%;
  display: block;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.app-header {
  display: block;
  position: sticky;
  top: 0;
  z-index: 30;
  width: 100%;
  min-height: auto;
  padding: 0;
  border-bottom: 1px solid var(--color-line);
  background: rgba(17, 19, 24, 0.94);
  backdrop-filter: blur(12px);
}

.app-header__inner {
  width: min(100%, var(--max-page-width));
  min-height: 68px;
  margin: 0 auto;
  padding: 0 var(--space-5);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-5);
}

.app-header a,
.app-header button,
.app-header summary {
  margin: 0;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0;
  min-width: max-content;
  min-height: 40px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--color-text);
  box-shadow: none;
}

.brand-link strong {
  font-size: 1.02rem;
  letter-spacing: 0;
}

.app-nav {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  justify-content: center;
}

.app-nav a,
.button,
button {
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  min-height: 40px;
  padding: 0.55rem 0.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  cursor: pointer;
  font-weight: 700;
}

.app-nav a {
  background: transparent;
  color: var(--color-text-muted);
  border-color: transparent;
}

.app-nav a:hover,
.app-nav a.is-active {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-line);
}

.button--primary,
button.button--primary {
  background: var(--color-accent);
  color: #071514;
  border-color: var(--color-accent);
}

.button--primary:hover,
button.button--primary:hover {
  background: var(--color-accent-strong);
  border-color: var(--color-accent-strong);
}

.button--ghost,
button.button--ghost {
  background: transparent;
  color: var(--color-text-soft);
  border-color: var(--color-line);
}

.button--danger,
button.button--danger {
  background: rgba(239, 107, 115, 0.12);
  color: var(--color-danger);
  border-color: rgba(239, 107, 115, 0.42);
}

.button--compact,
button.button--compact {
  min-height: 40px;
  padding: 0.42rem 0.65rem;
  font-size: 0.9rem;
}

button:disabled,
.button.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
}

.app-header .header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  min-width: 0;
  flex: 0 1 auto;
}

.app-header .header-actions > * {
  width: auto;
  min-width: 0;
}

.status-chip {
  min-height: 40px;
  padding: 0.42rem 0.68rem;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-bg-soft);
  color: var(--color-text-soft);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.88rem;
  font-weight: 700;
}

.status-chip strong {
  color: var(--color-text);
}

.app-header-pack-button,
.app-header-inbox-chip {
  white-space: nowrap;
}

.app-header-inbox-chip {
  position: relative;
  width: 40px;
  min-width: 40px;
  justify-content: center;
  padding: 0.42rem;
  cursor: pointer;
}

.app-header-inbox-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.app-header-inbox-icon svg {
  width: 18px;
  height: 18px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-notification-popover {
  position: fixed;
  inset: 0;
  z-index: 1450;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 5rem 1rem 1rem;
  background: rgba(4, 8, 16, 0.16);
}

.app-notification-popover[hidden] {
  display: none !important;
}

.app-notification-popover__dialog {
  position: relative;
  width: min(460px, calc(100vw - 2rem));
  max-height: min(680px, calc(100vh - 6rem));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  box-sizing: border-box;
  padding: 0.78rem;
  border: 1px solid rgba(123, 170, 255, 0.3);
  border-radius: 10px;
  background: rgba(13, 22, 38, 0.98);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.42);
}

.app-notification-popover__close {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  width: 2rem;
  height: 2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(170, 178, 194, 0.2);
  border-radius: 8px;
  background: rgba(7, 13, 24, 0.76);
  color: var(--color-text);
  font-size: 1.2rem;
  font-weight: 800;
  cursor: pointer;
}

.app-notification-popover__header {
  display: grid;
  gap: 0.12rem;
  padding-right: 2.35rem;
}

.app-notification-popover__header h2,
.app-notification-popover__header p,
.app-notification-popover__copy,
.app-notification-popover__empty,
.app-notification-popover__status {
  margin: 0;
}

.app-notification-popover__header h2 {
  color: var(--color-text);
  font-size: 1.05rem;
  line-height: 1.2;
}

.app-notification-popover__header p,
.app-notification-popover__status,
.app-notification-popover__empty {
  color: var(--color-text-muted);
  font-size: 0.82rem;
  font-weight: 750;
}

.app-notification-popover__list {
  display: grid;
  gap: 0.58rem;
}

.app-notification-popover__item {
  display: grid;
  gap: 0.5rem;
  padding: 0.68rem;
  border: 1px solid rgba(123, 170, 255, 0.18);
  border-radius: 8px;
  background: rgba(8, 13, 22, 0.78);
}

.app-notification-popover__item.is-unread {
  border-color: rgba(55, 214, 184, 0.34);
  background: rgba(31, 88, 85, 0.18);
}

.app-notification-popover__item-header {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}

.app-notification-popover__item-icon {
  width: 1.75rem;
  height: 1.75rem;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: rgba(123, 170, 255, 0.12);
  color: var(--color-text);
  font-size: 0.8rem;
  font-weight: 900;
}

.app-notification-popover__item-title {
  min-width: 0;
  display: grid;
  gap: 0.12rem;
}

.app-notification-popover__item-title strong {
  color: var(--color-text);
  font-size: 0.92rem;
  line-height: 1.25;
}

.app-notification-popover__item-title span,
.app-notification-popover__copy {
  color: var(--color-text-muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.app-notification-popover__action {
  width: fit-content;
  min-height: 34px;
  justify-self: flex-end;
  padding: 0.4rem 0.65rem;
  border: 1px solid rgba(123, 170, 255, 0.24);
  border-radius: 7px;
  background: rgba(13, 22, 38, 0.82);
  color: var(--color-text);
  font-size: 0.82rem;
  font-weight: 850;
  cursor: pointer;
}

@media (max-width: 560px) {
  .app-notification-popover {
    justify-content: center;
    padding: 4.5rem 0.75rem 0.75rem;
  }

  .app-notification-popover__dialog {
    width: 100%;
    max-height: calc(100vh - 5.25rem);
  }
}

.app-header-pack-button {
  background: rgba(109, 168, 255, 0.13);
  border-color: rgba(109, 168, 255, 0.32);
}

.app-header-pack-button:hover,
.app-header-inbox-chip:hover {
  border-color: rgba(109, 168, 255, 0.52);
  background: rgba(109, 168, 255, 0.2);
}

.app-header-user-avatar {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border-radius: 6px;
  object-fit: cover;
}

.app-header-user-avatar.is-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface-raised);
  color: var(--color-text);
  font-size: 0.78rem;
  font-weight: 800;
}

.app-header-profile-chip {
  max-width: 180px;
  cursor: pointer;
  list-style: none;
}

.app-header-profile-chip::-webkit-details-marker {
  display: none;
}

.app-header-profile-chip span:last-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-header-account-menu {
  position: relative;
  min-width: 0;
}

.app-header-account-menu[open] .app-header-profile-chip {
  border-color: rgba(51, 199, 180, 0.56);
  background: rgba(51, 199, 180, 0.12);
}

.app-header-account-panel {
  position: absolute;
  top: calc(100% + 0.55rem);
  right: 0;
  z-index: 80;
  width: min(260px, calc(100vw - 2rem));
  display: grid;
  gap: 0.45rem;
  padding: 0.55rem;
  border: 1px solid rgba(170, 178, 194, 0.2);
  border-radius: var(--radius-md);
  background: rgba(17, 19, 24, 0.98);
  box-shadow: 0 18px 34px rgba(0, 0, 0, 0.34);
}

.app-header-account-name {
  padding: 0.45rem 0.55rem 0.25rem;
  color: var(--color-text-muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.app-header-account-name strong {
  display: block;
  max-width: 100%;
  overflow: hidden;
  color: var(--color-text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-header-menu-button {
  width: 100%;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0.5rem 0.65rem;
  border: 1px solid transparent;
  border-radius: calc(var(--radius-md) - 2px);
  background: transparent;
  color: var(--color-text-soft);
  font-size: 0.92rem;
  font-weight: 800;
}

.app-header-menu-button:hover,
.app-header-menu-button:focus-visible {
  border-color: rgba(170, 178, 194, 0.22);
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text);
}

.page {
  width: min(100%, var(--max-page-width));
  margin: 0 auto;
  padding: var(--space-8) var(--space-5) 4rem;
}

.page-heading {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
}

.page-heading h1 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1.04;
  letter-spacing: 0;
}

.page-heading p {
  margin: 0;
  color: var(--color-text-muted);
  max-width: 64ch;
}

.panel {
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-panel);
}

.panel__body {
  padding: var(--space-5);
}

.panel__title {
  margin: 0 0 var(--space-2);
  font-size: 1.05rem;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.segmented-control {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-bg-soft);
}

.segmented-control button {
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--color-text-muted);
  padding: 0.32rem 0.62rem;
}

.segmented-control button.is-active {
  color: var(--color-text);
  background: var(--color-surface-raised);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-bg-soft);
  color: var(--color-text);
  min-height: 40px;
  padding: 0.55rem 0.7rem;
}

label {
  display: grid;
  gap: 0.35rem;
  color: var(--color-text-muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.message {
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg-soft);
  color: var(--color-text-soft);
}

.message--error {
  border-color: rgba(239, 107, 115, 0.45);
  color: var(--color-danger);
}

.message--success {
  border-color: rgba(93, 211, 158, 0.45);
  color: var(--color-success);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(164px, 1fr));
  gap: var(--space-4);
}

.game-card {
  aspect-ratio: 377 / 581;
  border: 0;
  border-radius: 7px;
  background: transparent;
  padding: 0;
  display: block;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  position: relative;
  isolation: isolate;
  transform: translateZ(0);
}

.game-card.is-selected {
  box-shadow: 0 0 0 2px rgba(51, 199, 180, 0.48), 0 14px 34px rgba(0, 0, 0, 0.3);
}

.game-card__art,
.game-card__frame,
.game-card__render {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.game-card__art {
  background: radial-gradient(circle at 50% 42%, color-mix(in srgb, var(--card-color, #282d38) 48%, transparent), transparent 42%), #101218;
}

.game-card__frame {
  z-index: 1;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
  user-select: none;
}

.game-card__render {
  z-index: 2;
  left: 20%;
  right: 20%;
  top: 23%;
  bottom: 23%;
  width: 60%;
  height: 54%;
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(0 12px 20px rgba(0, 0, 0, 0.62));
  pointer-events: none;
  user-select: none;
}

.game-card.is-fullart .game-card__render {
  display: none;
}

.game-card__rank {
  position: absolute;
  z-index: 3;
  left: 17%;
  right: 16%;
  bottom: 12.7%;
  height: 7.2%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #f7fbff;
  font-size: clamp(0.72rem, 1.55vw, 1rem);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.72), 0 0 10px rgba(0, 0, 0, 0.45);
}

.game-card__copy {
  position: absolute;
  z-index: 3;
  left: 14%;
  right: 14%;
  top: 10.4%;
  display: grid;
  gap: 0.18rem;
  pointer-events: none;
}

.game-card__name {
  color: #f7fbff;
  font-size: clamp(0.78rem, 1.7vw, 1rem);
  font-weight: 900;
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.72), 0 0 10px rgba(0, 0, 0, 0.45);
}

.game-card__meta {
  color: rgba(247, 251, 255, 0.82);
  font-size: clamp(0.52rem, 1.25vw, 0.74rem);
  line-height: 1.1;
  text-align: center;
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.62);
  display: grid;
  place-items: center;
  padding: var(--space-5);
}

.modal {
  width: min(520px, 100%);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-panel);
}

.modal__body {
  padding: var(--space-5);
  display: grid;
  gap: var(--space-4);
}

.empty-state {
  border: 1px dashed var(--color-line);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  color: var(--color-text-muted);
  text-align: center;
}

@media (max-width: 760px) {
  .app-header__inner {
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: var(--space-3);
    padding-top: var(--space-3);
    padding-bottom: var(--space-3);
  }

  .app-nav,
  .header-actions {
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .app-header .header-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
    overflow: visible;
  }

  .app-header-account-panel {
    right: auto;
    left: 0;
  }

  .page {
    padding: var(--space-5) var(--space-4) 3rem;
  }

  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}