*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #070a12;
  --bg-card: rgba(12, 18, 32, 0.78);
  --border: rgba(255, 255, 255, 0.09);
  --text: #f0f4fc;
  --text-muted: #8b95a8;
  --lime: #b8ff3c;
  --lime-glow: rgba(184, 255, 60, 0.35);
  --cyan: #00e5ff;
  --yellow: #ffd93d;
  --red: #ff3b5c;
  --radius: 16px;
  --font: 'Inter', system-ui, sans-serif;
  --font-display: 'Space Grotesk', 'Inter', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.bg-gradient {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #070a12, #0a1520 40%, #0f1a0a 70%, #070a12);
  z-index: -2;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px);
  background-size: 40px 40px;
  z-index: -1;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 80%);
}

.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Header */
.k-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 10, 18, 0.9);
  backdrop-filter: blur(12px);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 50;
}

.k-back {
  font-size: 0.8rem;
  color: var(--cyan);
  text-decoration: none;
  font-weight: 600;
  transition: opacity 0.2s;
}

.k-back:hover { opacity: 0.75; }

.k-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.k-brand__icon { font-size: 1.5rem; }

.k-brand__title {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
}

.k-brand__sub {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.k-hud {
  display: flex;
  gap: 1rem;
}

.k-hud__item {
  text-align: center;
  padding: 0.35rem 0.75rem;
  background: rgba(0,0,0,0.3);
  border-radius: 8px;
  border: 1px solid var(--border);
  min-width: 72px;
}

.k-hud__item--money {
  border-color: rgba(184, 255, 60, 0.3);
  background: rgba(184, 255, 60, 0.06);
}

.k-hud__label {
  display: block;
  font-size: 0.6rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.k-hud__value {
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 700;
}

.k-hud__item--money .k-hud__value { color: var(--lime); }

.k-hud__item--savings {
  border-color: rgba(0, 229, 255, 0.3);
  background: rgba(0, 229, 255, 0.06);
}

.k-hud__item--savings .k-hud__value { color: var(--cyan); }

/* Bank panel */
.k-bank-balances {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.85rem;
}

.k-bank-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
}

.k-bank-row strong {
  font-family: var(--font-display);
  color: var(--text);
}

.k-bank-row--savings strong { color: var(--cyan); }
.k-bank-row--total strong { color: var(--lime); }

.k-bank-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 0.65rem;
}

.k-btn {
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.3);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.k-btn:hover { border-color: var(--border-glow); }

.k-btn--deposit {
  border-color: rgba(0, 229, 255, 0.3);
  color: var(--cyan);
}

.k-btn--deposit:hover {
  background: rgba(0, 229, 255, 0.1);
}

.k-btn--withdraw {
  border-color: rgba(184, 255, 60, 0.3);
  color: var(--lime);
}

.k-btn--buy {
  width: 100%;
  margin-top: 0.4rem;
  border-color: rgba(184, 255, 60, 0.35);
  color: var(--lime);
}

.k-btn--buy:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.k-bank-hint,
.k-shop-hint {
  font-size: 0.68rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.k-bank-hint kbd,
.k-shop-hint kbd {
  background: rgba(255,255,255,0.08);
  padding: 0.1rem 0.3rem;
  border-radius: 3px;
  font-size: 0.65rem;
}

/* Shop */
.k-shop-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.k-shop-item {
  padding: 0.6rem;
  background: rgba(0,0,0,0.25);
  border-radius: 8px;
  border: 1px solid var(--border);
}

.k-shop-item--owned {
  opacity: 0.55;
  border-color: rgba(184, 255, 60, 0.2);
}

.k-shop-item__top {
  display: flex;
  gap: 0.55rem;
  align-items: flex-start;
}

.k-shop-item__icon {
  flex-shrink: 0;
}

.k-shop-item strong {
  font-size: 0.78rem;
  display: block;
}

.k-shop-item p {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.k-owned-list {
  list-style: none;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.k-owned-list li {
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
}

.k-owned-empty {
  font-style: italic;
  font-size: 0.72rem;
}

.k-legend__dot--bank { background: #ff6b6b; }
.k-legend__dot--store { background: var(--lime); box-shadow: 0 0 8px var(--lime-glow); }

/* Main layout */
.k-main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  grid-template-areas:
    "game side"
    "extras side";
  gap: 1.25rem;
  align-items: start;
}

.k-game-wrap {
  grid-area: game;
}

.k-sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 901px) {
  .k-sidebar {
    position: sticky;
    top: 1rem;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
  }
}

.k-below-game {
  grid-area: extras;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  grid-template-rows: auto auto;
  gap: 1rem;
  min-width: 0;
}

.k-below-game__memes {
  grid-column: 1;
  grid-row: 1;
}

.k-below-game__legend {
  grid-column: 2;
  grid-row: 1;
}

.k-below-game__feed {
  grid-column: 1;
  grid-row: 2;
}

.k-below-game__ranking {
  grid-column: 2;
  grid-row: 2;
}

.k-below-game .k-meme-feed {
  max-height: 160px;
}

@media (min-width: 1180px) {
  .k-below-game {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: auto auto;
  }

  .k-below-game__memes {
    grid-column: 1 / -1;
    grid-row: 1;
  }

  .k-below-game__legend {
    grid-column: 1;
    grid-row: 2;
  }

  .k-below-game__feed {
    grid-column: 2;
    grid-row: 2;
  }

  .k-below-game__ranking {
    grid-column: 3;
    grid-row: 2;
  }

  .k-below-game .k-meme-strip__grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .k-below-game .k-meme-feed {
    max-height: 180px;
  }
}

.k-game-wrap {
  position: relative;
  overflow: hidden;
  padding: 0;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  cursor: crosshair;
  image-rendering: pixelated;
  touch-action: none;
}

.k-controls-hint {
  position: absolute;
  bottom: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: var(--text-muted);
  background: rgba(0,0,0,0.65);
  padding: 0.4rem 0.85rem;
  border-radius: 100px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

.k-controls-hint kbd {
  background: rgba(255,255,255,0.1);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.65rem;
  border: 1px solid var(--border);
}

.k-action-prompt {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -80px);
  background: rgba(184, 255, 60, 0.15);
  border: 1px solid rgba(184, 255, 60, 0.4);
  color: var(--lime);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  animation: promptBounce 1s ease infinite;
  pointer-events: none;
  z-index: 5;
}

.k-game-wrap--in-zone #gameCanvas {
  box-shadow: inset 0 0 0 3px rgba(184, 255, 60, 0.55);
}

.k-game-wrap--in-zone .k-action-prompt {
  background: rgba(184, 255, 60, 0.28);
  border-color: var(--lime);
  box-shadow: 0 0 24px rgba(184, 255, 60, 0.45);
  color: #e8ffc0;
}

@keyframes promptBounce {
  0%, 100% { transform: translate(-50%, -80px); }
  50% { transform: translate(-50%, -88px); }
}

/* Sidebar panels */
.k-panel {
  padding: 1.15rem;
}

.k-panel__title {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.k-legend {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.k-legend li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.k-legend__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.k-legend__dot--shop { background: var(--yellow); box-shadow: 0 0 8px rgba(255,217,61,0.5); }
.k-legend__dot--beer { background: #4ade80; }
.k-legend__dot--pet { background: #60a5fa; }
.k-legend__dot--can { background: #c084fc; }

.k-meme-feed {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 200px;
  overflow-y: auto;
}

.k-meme-feed__empty {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

.k-meme-item {
  font-size: 0.75rem;
  padding: 0.5rem 0.65rem;
  background: rgba(0,0,0,0.25);
  border-radius: 8px;
  border-left: 3px solid var(--lime);
  animation: memeSlide 0.3s ease;
}

@keyframes memeSlide {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

.k-leaderboard {
  list-style: none;
  counter-reset: lb;
}

.k-leaderboard li {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}

.k-leaderboard li:first-child {
  color: var(--lime);
  font-weight: 600;
}

.k-leaderboard li span:last-child {
  font-family: var(--font-display);
  font-weight: 700;
}

/* Meme popup */
.k-meme-popup {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 10, 18, 0.85);
  backdrop-filter: blur(6px);
}

.k-meme-popup__card {
  max-width: 400px;
  width: 90%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  animation: popupIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popupIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

.k-meme-popup__img {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: 10px;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}

.k-meme-popup__text {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  margin-bottom: 1rem;
}

.k-meme-popup__close {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid rgba(184, 255, 60, 0.4);
  background: rgba(184, 255, 60, 0.1);
  color: var(--lime);
  border-radius: 10px;
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.k-meme-popup__close:hover {
  background: rgba(184, 255, 60, 0.2);
  box-shadow: 0 0 20px var(--lime-glow);
}

/* Toast & footer */
.k-toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.65rem 1.1rem;
  background: rgba(14, 20, 36, 0.95);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.8rem;
  z-index: 100;
  transition: opacity 0.3s;
}

.k-footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.k-footer__sub {
  margin-top: 0.3rem;
  opacity: 0.6;
  font-style: italic;
}

.hidden { display: none !important; }

.k-brand__img {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}

.k-meme-strip { padding: 1rem; }

.k-meme-strip__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.k-meme-strip__grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.k-footer__brand-logo {
  width: min(160px, 55vw);
  height: auto;
  object-fit: contain;
  margin: 0 auto 0.5rem;
  display: block;
  opacity: 0.9;
  filter: drop-shadow(0 4px 14px rgba(255, 90, 30, 0.2));
}

.k-footer__meme {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 0.5rem;
}

/* ===== TOUCH CONTROLS ===== */
.k-controls-hint--touch {
  display: none;
}

.k-touch-controls {
  display: none;
}

.k-dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 4px;
}

.k-dpad__btn {
  width: 52px;
  height: 52px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.55);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  transition: background 0.15s, border-color 0.15s;
}

.k-dpad__btn:active,
.k-dpad__btn--active {
  background: rgba(0, 229, 255, 0.2);
  border-color: var(--cyan);
}

.k-dpad__btn--up { grid-column: 2; grid-row: 1; }
.k-dpad__btn--left { grid-column: 1; grid-row: 2; }
.k-dpad__btn--center { grid-column: 2; grid-row: 2; opacity: 0; pointer-events: none; }
.k-dpad__btn--right { grid-column: 3; grid-row: 2; }
.k-dpad__btn--down { grid-column: 2; grid-row: 3; }

.k-action-pad {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.k-action-btn {
  min-width: 52px;
  min-height: 48px;
  padding: 0 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.55);
  color: var(--text);
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  touch-action: manipulation;
  user-select: none;
}

.k-action-btn--e {
  border-color: rgba(184, 255, 60, 0.4);
  color: var(--lime);
  min-height: 56px;
  font-size: 1rem;
}

.k-action-btn--ready {
  background: rgba(184, 255, 60, 0.25) !important;
  border-color: var(--lime) !important;
  box-shadow: 0 0 20px rgba(184, 255, 60, 0.55);
  animation: eBtnPulse 0.8s ease infinite;
}

@keyframes eBtnPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.k-action-btn--b {
  border-color: rgba(255, 107, 107, 0.4);
  color: #ff6b6b;
}

.k-action-btn--q {
  border-color: rgba(184, 255, 60, 0.3);
  color: var(--lime);
}

.k-action-btn--meme {
  font-size: 1.1rem;
}

.k-action-btn:active {
  transform: scale(0.96);
  background: rgba(255, 255, 255, 0.08);
}

/* ===== MOBILE TABS ===== */
.k-mobile-tabs {
  display: none;
}

/* ===== MOBILE LAYOUT ===== */
@media (max-width: 900px) {
  .k-main {
    display: flex;
    flex-direction: column;
    padding: 0.85rem;
    gap: 0.75rem;
  }

  .k-below-game {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .k-header {
    padding: 0.65rem 0.85rem;
    gap: 0.5rem;
  }

  .k-brand__title {
    font-size: 0.9rem;
  }

  .k-brand__sub {
    display: none;
  }

  .k-hud {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.35rem;
  }

  .k-hud__item {
    min-width: 0;
    padding: 0.3rem 0.4rem;
  }

  .k-hud__label {
    font-size: 0.52rem;
  }

  .k-hud__value {
    font-size: 0.75rem;
  }

  .k-game-wrap {
    border-radius: 12px;
    margin-bottom: 0;
  }

  #gameCanvas {
    border-radius: 12px 12px 0 0;
    touch-action: none;
    pointer-events: none;
  }

  .k-controls-hint--desktop {
    display: none;
  }

  .k-controls-hint--touch {
    display: block;
    position: static;
    transform: none;
    margin: 0;
    border-radius: 0;
    text-align: center;
    font-size: 0.62rem;
    padding: 0.35rem 0.5rem;
    border: none;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.4);
  }

  .k-touch-controls {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 0.75rem;
    padding: 0.65rem 0.75rem calc(0.65rem + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(to top, rgba(7, 10, 18, 0.95), rgba(7, 10, 18, 0.7));
    border-top: 1px solid var(--border);
  }

  .k-action-prompt {
    top: 0.5rem;
    left: 50%;
    bottom: auto;
    transform: translateX(-50%);
    font-size: 0.72rem;
    max-width: 90%;
    text-align: center;
    animation: promptBounceMobile 1s ease infinite;
  }

  @keyframes promptBounceMobile {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-6px); }
  }

  .k-mobile-tabs {
    display: flex;
    gap: 0.35rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 0.15rem 0;
  }

  .k-mobile-tabs::-webkit-scrollbar {
    display: none;
  }

  .k-mobile-tab {
    flex-shrink: 0;
    min-height: 44px;
    padding: 0.45rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 100px;
    background: rgba(0, 0, 0, 0.35);
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
  }

  .k-mobile-tab--active {
    border-color: rgba(184, 255, 60, 0.4);
    background: rgba(184, 255, 60, 0.1);
    color: var(--lime);
  }

  .k-main [data-panel] {
    display: none;
  }

  .k-main [data-panel].k-panel--mobile-active {
    display: block;
  }

  .k-bank-actions {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .k-btn {
    min-height: 44px;
    font-size: 0.75rem;
  }

  .k-btn--buy {
    min-height: 44px;
  }

  .k-shop-item .k-btn {
    min-height: 44px;
    width: 100%;
  }

  .k-meme-popup__card {
    margin: 1rem;
    max-width: calc(100vw - 2rem);
  }

  .k-meme-popup__close {
    min-height: 48px;
  }

  .k-footer {
    padding: 1.25rem 1rem 2rem;
  }
}

@media (max-width: 500px) {
  .k-header {
    flex-direction: column;
    align-items: stretch;
  }

  .k-back {
    align-self: flex-start;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .k-brand {
    justify-content: center;
  }

  .k-hud {
    grid-template-columns: repeat(2, 1fr);
  }

  .k-dpad {
    grid-template-columns: repeat(3, 48px);
    grid-template-rows: repeat(3, 48px);
  }

  .k-dpad__btn {
    width: 48px;
    height: 48px;
  }

  .k-action-btn {
    min-width: 48px;
    min-height: 44px;
  }

  .k-action-btn--e {
    min-height: 52px;
  }

  .k-meme-strip__grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
