:root {
  color-scheme: dark;
  --bg: #101018;
  --ink: #09090f;
  --panel: #202033;
  --panel-2: #2b2b44;
  --line: #5d6281;
  --text: #fff3d2;
  --muted: #b8bdd8;
  --accent: #31d0aa;
  --accent-2: #ffd166;
  --danger: #ff6b6b;
  --blue: #5bbcff;
  --pink: #ff7ab6;
  --shadow: 8px 8px 0 #08080d;
  --pixel-font: "Microsoft YaHei", "SimHei", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
  image-rendering: pixelated;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  font-family: var(--pixel-font);
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(135deg, #111122 0%, #151629 45%, #11251e 100%);
  background-size: 18px 18px, 18px 18px, auto;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: 100vh;
  padding: 20px;
  border-right: 4px solid var(--ink);
  background: rgba(19, 20, 38, 0.96);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 4px solid var(--ink);
  background: var(--accent);
  box-shadow: 4px 4px 0 #07382f;
  color: #071412;
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.panel-label,
.eyebrow,
.game-card span,
.section-heading p,
#dialogMeta {
  color: var(--muted);
}

.nav-list {
  display: grid;
  gap: 10px;
}

.account-panel,
.sidebar-panel,
.score-row,
.empty-state {
  border: 4px solid var(--ink);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.account-panel {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.account-panel p,
.account-panel strong,
.account-panel span {
  margin: 0;
}

.account-panel strong {
  font-size: 1.08rem;
}

.account-panel span {
  color: var(--muted);
  word-break: break-all;
}

.account-actions,
.auth-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.nav-item,
.secondary-button,
.primary-button,
.icon-button {
  border: 4px solid var(--ink);
  color: var(--text);
  background: var(--panel-2);
  box-shadow: 4px 4px 0 #08080d;
}

.nav-item {
  min-height: 44px;
  padding: 0 12px;
  text-align: left;
}

.nav-item.active,
.nav-item:hover,
.secondary-button:hover {
  background: #263f43;
  color: #ffffff;
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 #08080d;
}

.sidebar-panel {
  margin-top: auto;
  padding: 14px;
}

.sidebar-panel p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.main-content {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 28px 28px 104px;
}

.topbar,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  color: #ffffff;
  font-size: clamp(2rem, 4vw, 4rem);
  line-height: 1;
  text-shadow: 4px 4px 0 #0b0b12, 8px 8px 0 #2c3156;
}

.search-box {
  display: grid;
  gap: 7px;
  min-width: min(360px, 100%);
  color: var(--muted);
}

.search-box input {
  width: 100%;
  min-height: 44px;
  padding: 0 13px;
  border: 4px solid var(--ink);
  outline: none;
  color: var(--text);
  background: #17172a;
  box-shadow: 4px 4px 0 #08080d;
}

.search-box input:focus {
  border-color: var(--accent-2);
}

.featured-game {
  position: relative;
  min-height: 260px;
  margin: 28px 0;
  overflow: hidden;
  border: 4px solid var(--ink);
  background: #0e1020;
  box-shadow: var(--shadow);
}

#heroCanvas {
  display: block;
  width: 100%;
  height: 280px;
}

.featured-copy {
  position: absolute;
  left: 28px;
  bottom: 28px;
  max-width: min(480px, calc(100% - 56px));
}

.featured-copy p {
  margin-bottom: 6px;
  color: var(--accent-2);
  font-weight: 900;
  text-shadow: 3px 3px 0 #08080d;
}

.featured-copy h2 {
  margin-bottom: 16px;
  color: #ffffff;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 1;
  text-shadow: 4px 4px 0 #08080d;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  padding: 0 16px;
  font-weight: 900;
}

.primary-button {
  background: var(--accent-2);
  color: #17110a;
}

.primary-button:hover {
  background: #ffe48a;
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 #08080d;
}

.section-heading {
  margin-bottom: 16px;
}

.section-heading h2 {
  margin-bottom: 5px;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
}

.leaderboard-heading {
  margin-top: 28px;
}

.leaderboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.leaderboard-card {
  display: grid;
  gap: 10px;
  min-height: 180px;
  padding: 12px;
  border: 4px solid var(--ink);
  background: rgba(31, 32, 52, 0.94);
  box-shadow: var(--shadow);
}

.leaderboard-card h3 {
  margin: 0;
  color: #ffffff;
  font-size: 1.02rem;
}

.leaderboard-list {
  display: grid;
  gap: 8px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 34px;
  padding: 6px 8px;
  border: 3px solid var(--ink);
  background: #151628;
  color: var(--muted);
  font-size: 0.86rem;
}

.leaderboard-row strong {
  color: var(--accent-2);
}

.leaderboard-name {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-empty {
  padding: 12px;
  border: 3px dashed var(--line);
  color: var(--muted);
  text-align: center;
}

.site-footer {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 260px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  min-height: 50px;
  padding: 10px 28px 12px;
  border-top: 4px solid #08080d;
  background:
    linear-gradient(90deg, rgba(255, 209, 102, 0.07) 0 2px, transparent 2px 14px),
    linear-gradient(180deg, rgba(43, 43, 68, 0.96), rgba(15, 16, 31, 0.98));
  box-shadow: 0 -4px 0 rgba(49, 208, 170, 0.16), 0 -14px 28px rgba(5, 5, 10, 0.35);
  color: #9fa8c8;
  font-size: 0.76rem;
  line-height: 1.7;
  text-align: center;
}

.site-footer span,
.site-footer a {
  text-shadow: 2px 2px 0 #08080d;
}

.site-footer a {
  color: #ffd166;
  text-decoration: none;
}

.site-footer a:hover {
  color: #ffe48a;
}

.game-card {
  display: grid;
  grid-template-rows: 142px auto auto auto;
  gap: 12px;
  min-height: 292px;
  padding: 12px;
  border: 4px solid var(--ink);
  background: rgba(31, 32, 52, 0.94);
  box-shadow: var(--shadow);
}

.game-card:hover {
  transform: translate(-3px, -3px);
  box-shadow: 11px 11px 0 #08080d;
}

.game-art {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 4px solid var(--ink);
  background: var(--art-bg);
}

.game-art canvas {
  width: 100%;
  height: 100%;
}

.game-icon-img {
  position: absolute;
  inset: 18px;
  width: calc(100% - 36px);
  height: calc(100% - 36px);
  object-fit: contain;
  padding: 8px;
  background: rgba(16, 16, 24, 0.82);
}

.game-card h3 {
  margin: 0 0 6px;
  color: #ffffff;
  font-size: 1.06rem;
}

.game-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
}

.tag {
  padding: 5px 8px;
  border: 3px solid var(--ink);
  background: #151628;
  color: var(--muted);
  font-size: 0.82rem;
}

.score-row {
  min-height: 32px;
  padding: 7px 9px;
  color: var(--accent-2);
  font-size: 0.9rem;
  font-weight: 900;
  box-shadow: 4px 4px 0 #08080d;
}

.game-dialog,
.auth-dialog {
  width: min(1180px, calc(100vw - 28px));
  height: min(820px, calc(100vh - 28px));
  padding: 0;
  border: 4px solid var(--ink);
  overflow: hidden;
  background: #0f111f;
  color: var(--text);
  box-shadow: var(--shadow);
}

.auth-dialog {
  width: min(460px, calc(100vw - 28px));
  height: auto;
}

.game-dialog::backdrop,
.auth-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.dialog-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 0 12px 0 16px;
  border-bottom: 4px solid var(--ink);
  background: var(--panel);
}

.dialog-bar strong,
.dialog-bar span {
  display: block;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  padding: 0;
  font-weight: 900;
}

#gameFrame {
  display: block;
  width: 100%;
  height: calc(100% - 52px);
  border: 0;
  background: #111;
}

.auth-form {
  margin: 0;
}

.auth-body {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.auth-body label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

.auth-body input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 4px solid var(--ink);
  outline: none;
  background: #151628;
  color: var(--text);
}

.auth-body input:focus {
  border-color: var(--accent-2);
}

.form-message {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
}

.form-message.error {
  color: var(--danger);
}

.empty-state {
  grid-column: 1 / -1;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 880px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
    border-right: 0;
    border-bottom: 4px solid var(--ink);
  }

  .nav-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .nav-item {
    text-align: center;
  }

  .sidebar-panel {
    display: none;
  }

  .account-panel {
    order: 3;
  }

  .main-content {
    padding: 18px;
  }

  .site-footer {
    left: 0;
    padding: 16px 18px;
  }

  .topbar,
  .section-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .featured-copy {
    left: 18px;
    bottom: 18px;
  }
}

@media (max-width: 560px) {
  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .game-grid {
    grid-template-columns: 1fr;
  }
}
