:root {
  --cg-bg: #f5f7fa;
  --cg-surface: #ffffff;
  --cg-primary: #1a237e;
  --cg-accent: #007bff;
  --cg-text: #333333;
  --cg-text-muted: #6c757d;
  --cg-border: #e0e0e0;
  --header-height: 64px;
  --sidebar-width: 320px;
}

* { box-sizing: border-box; }

body.cg-desktop-active {
  margin: 0; padding: 0;
  background-color: var(--cg-bg);
  color: var(--cg-text);
  font-family: 'Nunito', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  overflow-x: hidden;
}

.cg-btn {
  background: var(--cg-primary); color: #fff; border: none; border-radius: 30px;
  padding: 8px 18px; font-weight: 700; cursor: pointer; transition: transform 0.1s;
}
.cg-btn:hover { filter: brightness(1.1); }
.cg-btn:active { transform: scale(0.96); }

/* Main Layout Grid */
.cg-layout {
  display: flex;
  justify-content: center;
  max-width: 1920px;
  margin: 0 auto;
  padding: 24px;
  gap: 24px;
}
.cg-main {
  flex: 1;
  min-width: 0; /* Prevent flex overflow */
  display: flex;
  flex-direction: column;
}
.cg-left-sidebar {
  width: 48px;
  margin-left: -12px;
  padding: 16px 12px 16px 0;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  background: transparent;
  border-right: 1px solid var(--cg-border);
  position: sticky;
  top: 24px;
  align-self: stretch;
}
.cg-left-sidebar .cg-icon-btn {
  width: 100%;
  background: transparent;
  border: none;
  display: flex;
  justify-content: center;
  align-items: center;
  color: var(--cg-text-muted);
  font-size: 18px;
  transition: all 0.2s;
  cursor: pointer;
  padding: 8px 0;
}
.cg-left-sidebar .cg-icon-btn:hover {
  color: var(--cg-primary);
  background: transparent;
  border-color: transparent;
  transform: scale(1.15);
}
.cg-left-sidebar #fsBtn {
  padding: 8px 0 !important;
}
.cg-right-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}

/* Optional: style the scrollbar for the sidebar */
.cg-right-sidebar::-webkit-scrollbar {
  width: 6px;
}
.cg-right-sidebar::-webkit-scrollbar-thumb {
  background-color: var(--cg-border);
  border-radius: 6px;
}

/* 16:9 Game Container */
.cg-game-container-wrapper {
  background: #000;
  border-radius: 12px;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  position: relative;
  /* Was min(98vw, ...) - that's the VIEWPORT width, not the space this
     box's actual flex parent (.cg-main) has left after both sidebars +
     gaps + layout padding are accounted for. 98vw is almost always wider
     than .cg-main's real allocation on desktop, so the box overflowed
     past .cg-main's right edge and visually overlapped the right
     sidebar. 100% correctly caps it to whatever .cg-main (flex:1) is
     actually given - on mobile this is a no-op since .cg-main is already
     forced to width:100% there with both sidebars hidden. */
  width: min(100%, calc((100vh - 120px) * 16 / 9));
  aspect-ratio: 16 / 9;
  margin: 0 auto;
}
.cg-game-player-area {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Interaction Bar */
.cg-interaction-bar {
  background: var(--cg-surface);
  border-radius: 12px;
  padding: 16px 20px;
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.cg-interaction-left { display: flex; flex-direction: column; }
.cg-interaction-title { font-size: 22px; font-weight: 800; margin: 0; color: var(--cg-primary); line-height: 1.2; }
.cg-interaction-dev { font-size: 13px; color: var(--cg-text-muted); margin: 4px 0 0; font-weight: 600; }
.cg-interaction-right { display: flex; align-items: center; gap: 16px; }

.cg-rating { display: flex; align-items: center; gap: 8px; background: var(--cg-bg); padding: 8px 12px; border-radius: 20px; }
.cg-rating-btn { background: none; border: none; color: var(--cg-text-muted); cursor: pointer; font-size: 16px; transition: color 0.2s; }
.cg-rating-btn:hover { color: #4caf50; }
.cg-rating-btn.down:hover { color: #f44336; }
.cg-rating-bar { width: 70px; height: 6px; background: var(--cg-border); border-radius: 3px; overflow: hidden; }
.cg-rating-fill { height: 100%; background: #4caf50; width: 88%; }

.cg-icon-btn {
  background: var(--cg-bg); border: 1px solid var(--cg-border); color: var(--cg-text-muted);
  border-radius: 50%; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.2s;
}
.cg-icon-btn:hover { background: var(--cg-primary); color: #fff; border-color: var(--cg-primary); }
.cg-icon-btn:active { transform: scale(0.95); }

/* Meta Data Block */
.cg-meta-data {
  background: var(--cg-surface);
  border-radius: 12px;
  padding: 24px;
  margin-top: 16px;
  line-height: 1.6;
  color: var(--cg-text-muted);
}
.cg-meta-data h2, .cg-meta-data h3 { color: var(--cg-primary); margin-top: 0; margin-bottom: 12px; font-weight: 800; }
.cg-meta-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; margin-top: 20px; }
.cg-controls-box { background: var(--cg-bg); padding: 16px; border-radius: 12px; border: 1px solid var(--cg-border); }
.cg-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.cg-tag { background: var(--cg-bg); border: 1px solid var(--cg-border); padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 700; color: var(--cg-text); text-decoration: none; }
.cg-tag:hover { background: var(--cg-primary); }

/* Discovery Sidebar (Right) */
.cg-sidebar-title { font-size: 16px; font-weight: 800; color: var(--cg-primary); margin: 0 0 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.cg-thumbnail-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.cg-thumbnail {
  background: var(--cg-surface); border-radius: 10px; overflow: hidden; aspect-ratio: 1;
  position: relative; display: block; text-decoration: none; transition: transform 0.2s;
}
.cg-thumbnail:hover { transform: scale(1.05); z-index: 2; box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.cg-thumbnail img { width: 100%; height: 100%; object-fit: cover; }
.cg-thumbnail-title {
  position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(transparent, rgba(0,0,0,0.9));
  color: #fff; font-size: 12px; font-weight: 700; padding: 20px 8px 8px; text-align: center;
}

.cg-mobile-controls {
  display: none;
}

/* Mobile Media Query */
@media (max-width: 991px) {
  .cg-header-global, .cg-left-sidebar, .cg-right-sidebar, .cg-interaction-bar, .cg-meta-data { 
    display: none !important; 
  }
  .cg-layout {
    display: block !important;
    padding: 0 !important;
  }
  .cg-main {
    margin-left: 0 !important;
    width: 100% !important;
  }
  body.cg-desktop-active {
    padding-top: 0 !important;
  }
  .cg-mobile-controls {
    display: block;
    margin-top: 16px;
    padding: 0 16px;
  }
  /* .cg-game-container-wrapper's desktop sizing (width: min(98vw, ...),
     aspect-ratio: 16/9) collapses to an unusably short box on a narrow
     portrait phone - e.g. ~367px wide -> ~206px tall - because the width
     is capped by 98vw long before the height-driven half of that min()
     ever applies. Menu-heavy games (Count Masters' start screen: title +
     level/coin pills + 2 upgrade cards + two buttons) need real vertical
     room to render without clipping off the bottom of the box. Drop the
     strict aspect-ratio here and size off viewport height instead - every
     game's own internal resize logic (canvas games read
     parentElement.getBoundingClientRect() every resize; Unity/iframe
     embeds are width:100%/height:100%) already adapts to whatever size
     this box actually ends up being, so this doesn't require any
     per-game changes. */
  .cg-game-container-wrapper {
    width: 100%;
    aspect-ratio: auto;
    height: min(75vh, 620px);
    min-height: 420px;
  }
}
.game-btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
}
.game-btn {
  background: var(--brand-soft, #e6e8fc);
  color: var(--brand, #3b42c4);
  border: none;
  border-radius: 12px;
  padding: 12px;
  font-weight: 600;
  font-size: .95rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  transition: transform 0.15s;
}
.game-btn:active {
  transform: scale(0.95);
}
