:root {
  --bg: #0f1220;
  --bg-soft: #171b2e;
  --panel: #1c2138;
  --panel-2: #232945;
  --border: #2e3555;
  --text: #e8ecff;
  --muted: #97a0c7;
  --accent: #6c8cff;
  --accent-2: #37e0a1;
  --danger: #ff5c7a;
  --warn: #ffc857;
  --gold: #ffd166;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --radius-sm: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(108, 140, 255, 0.18), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(55, 224, 161, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  width: min(1100px, 92vw);
  margin: 0 auto;
  padding: 24px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.lang-switch {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  margin-left: 8px;
}

.lang-switch button {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  cursor: pointer;
  line-height: 1.2;
}

.lang-switch button:hover {
  color: var(--text);
  border-color: var(--accent);
}

.lang-switch button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0e1a;
}

.topbar .nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.brand:hover {
  text-decoration: none;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b0e1a;
  font-weight: 800;
}

.nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.nav a {
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--muted);
  border: 1px solid transparent;
}

.nav a:hover,
.nav a.active {
  color: var(--text);
  background: var(--panel);
  border-color: var(--border);
  text-decoration: none;
}

.hero {
  background: linear-gradient(135deg, rgba(108, 140, 255, 0.16), rgba(55, 224, 161, 0.08));
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 6px);
  padding: 28px;
  box-shadow: var(--shadow);
  margin-bottom: 28px;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
}

.hero p {
  margin: 0;
  color: var(--muted);
  max-width: 65ch;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-top: 22px;
}

.stat {
  background: rgba(15, 18, 32, 0.55);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
}

.stat .label {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
}

.stat .value {
  font-size: 1.5rem;
  font-weight: 700;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 30px 0 14px;
}

.section-title h2 {
  margin: 0;
  font-size: 1.25rem;
}

.section-title span {
  color: var(--muted);
  font-size: 0.9rem;
}

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

.game-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  color: inherit;
  text-decoration: none;
}

.game-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
  text-decoration: none;
}

.game-card .icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 1.5rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.game-card h3 {
  margin: 0;
  font-size: 1.05rem;
}

.game-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  flex: 1;
}

.game-card .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
}

.badge.accent {
  color: var(--accent-2);
  border-color: rgba(55, 224, 161, 0.35);
  background: rgba(55, 224, 161, 0.08);
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.btn:hover {
  border-color: var(--accent);
}

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

.btn.primary {
  background: linear-gradient(135deg, var(--accent), #4f6fff);
  border-color: transparent;
  color: white;
}

.btn.ghost {
  background: transparent;
}

.btn.small {
  padding: 6px 12px;
  font-size: 0.9rem;
}

/* ===== Game shell ===== */
.game-shell {
  display: grid;
  gap: 16px;
}

.game-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.hud-items {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hud-item {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 12px;
  min-width: 90px;
}

.hud-item .k {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.hud-item .v {
  font-weight: 700;
  font-size: 1.05rem;
}

.game-stage {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 320px;
}

.game-stage canvas {
  background: #0b0e1a;
  border-radius: 10px;
  max-width: 100%;
  touch-action: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(10, 12, 22, 0.78);
  border-radius: var(--radius);
  backdrop-filter: blur(3px);
  z-index: 5;
  padding: 20px;
  text-align: center;
}

.overlay.show {
  display: grid;
}

.overlay .panel {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: min(420px, 100%);
  box-shadow: var(--shadow);
}

.overlay h2 {
  margin: 0 0 8px;
}

.overlay p {
  margin: 0 0 16px;
  color: var(--muted);
}

.overlay .score-line {
  font-size: 2rem;
  font-weight: 800;
  margin: 8px 0 16px;
  color: var(--gold);
}

.overlay .actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.controls-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.touch-pad {
  display: none;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 6px;
  justify-content: center;
}

.touch-pad button {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  font-size: 1.2rem;
  cursor: pointer;
}

.touch-pad button:active {
  background: var(--accent);
  color: #0b0e1a;
}

.touch-pad .up { grid-column: 2; grid-row: 1; }
.touch-pad .left { grid-column: 1; grid-row: 2; }
.touch-pad .down { grid-column: 2; grid-row: 2; }
.touch-pad .right { grid-column: 3; grid-row: 2; }

@media (hover: none) and (pointer: coarse) {
  .touch-pad {
    display: grid;
  }
}

/* ===== Achievements ===== */
.ach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.ach-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  opacity: 0.55;
  filter: grayscale(0.7);
  transition: all 0.2s ease;
}

.ach-card.unlocked {
  opacity: 1;
  filter: none;
  border-color: rgba(255, 209, 102, 0.5);
  box-shadow: 0 0 0 1px rgba(255, 209, 102, 0.12), var(--shadow);
}

.ach-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 1.3rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.ach-card.unlocked .ach-icon {
  background: linear-gradient(135deg, rgba(255, 209, 102, 0.25), rgba(255, 200, 87, 0.1));
  border-color: rgba(255, 209, 102, 0.5);
}

.ach-card h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.ach-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.ach-card .ach-date {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--accent-2);
}

.progress-bar {
  height: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

/* ===== Toast ===== */
.toast-wrap {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
}

.toast {
  background: var(--panel-2);
  border: 1px solid rgba(255, 209, 102, 0.55);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  min-width: 260px;
  animation: toast-in 0.25s ease;
}

.toast strong {
  color: var(--gold);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== Leaderboard table ===== */
table.lb {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

table.lb th,
table.lb td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

table.lb th {
  background: var(--panel-2);
  color: var(--muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

table.lb tr:last-child td {
  border-bottom: none;
}

table.lb tr:hover td {
  background: rgba(108, 140, 255, 0.06);
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 30px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

footer {
  margin-top: 40px;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .game-stage {
    padding: 12px;
  }
}

/* --- Invisible embed mode (?embed=1) --- */
html.embed,
body.embed {
  background: var(--bg);
  min-height: 100%;
}

body.embed .topbar {
  display: none !important;
}

body.embed .container,
body.embed .game-shell {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 8px 10px 16px;
}

body.embed .game-hud {
  margin-top: 0;
}

body.embed .controls-row a.ghost,
body.embed .controls-row a[href*="index.html"] {
  display: none !important;
}

body.embed-no-hud .game-hud {
  display: none !important;
}

body.embed-no-hints .hint {
  display: none !important;
}

body.embed .overlay .actions a.ghost {
  display: none !important;
}

body.embed .toast-wrap {
  z-index: 1000;
}

body.embed .game-stage {
  align-items: stretch;
}
