* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0a0a0f;
  --surface: #15151d;
  --surface-2: #1c1c26;
  --border: #26262f;
  --text: #e8e8ec;
  --muted: #9b9ba6;
  --faint: #6b6b76;
  --accent: #cf4564;
  --accent-soft: rgba(207, 69, 100, 0.15);
  --radius: 14px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.layout {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
}

.brand-logo { font-size: 1.4rem; }

.brand-name {
  font-size: 1.15rem;
  letter-spacing: -0.5px;
}
.brand-name strong { color: var(--accent); }

.new-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.new-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.new-btn .plus { color: var(--accent); font-weight: 800; margin-right: 4px; }

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--faint);
  margin: 14px 8px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-ico { font-size: 1rem; width: 18px; text-align: center; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.streak {
  font-size: 0.85rem;
  color: var(--muted);
}
.streak strong { color: var(--text); }

/* ---------- Main ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 9px 14px;
  width: 460px;
  max-width: 50%;
}
.search:focus-within { border-color: var(--accent); }
.search-ico { color: var(--faint); }
.search input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 0.92rem;
  flex: 1;
}
.search input::placeholder { color: var(--faint); }
.search-kbd {
  font-size: 0.72rem;
  color: var(--faint);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 7px;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}
.pill {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.pill span { color: var(--text); }
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #0f3460);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.content {
  padding: 28px;
  max-width: 1400px;
}

.page-title {
  font-size: 1.6rem;
  letter-spacing: -0.5px;
}
.page-sub {
  color: var(--muted);
  margin-top: 4px;
  margin-bottom: 24px;
  font-size: 0.92rem;
}

/* ---------- Grid + cards ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.18s ease, border-color 0.18s, box-shadow 0.18s;
}
.card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

.card-cover {
  position: relative;
  height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.card-emoji { font-size: 3.2rem; filter: drop-shadow(0 4px 8px rgba(0,0,0,0.4)); }

/* Game-style "2048" tile icon */
.tile-icon {
  width: 76px;
  height: 76px;
  border-radius: 10px;
  background: #edc22e;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.5rem;
  letter-spacing: 1px;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.12);
}

.fav {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.4);
  border: none;
  color: #fff;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 1rem;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}
.fav:hover { background: rgba(0, 0, 0, 0.6); transform: scale(1.1); }
.fav.on { color: #ffd700; }

.card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.card-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  font-size: 0.72rem;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 6px;
  padding: 2px 8px;
}

.card-title { font-size: 1.15rem; letter-spacing: -0.3px; }
.card-desc {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
  flex: 1;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--faint);
}

.card-play {
  margin-top: 6px;
  text-align: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  padding: 9px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.18s, border-color 0.18s;
}
.card-play:hover { background: var(--accent); border-color: var(--accent); }

/* ---------- In-shell game player ---------- */
.player {
  display: flex;
  flex-direction: column;
}
.player-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 28px;
  border-bottom: 1px solid var(--border);
}
.player-back {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.player-back:hover { border-color: var(--accent); background: var(--accent-soft); }
.player-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}
/* Topbar is hidden while a game is open */
body.playing .topbar { display: none; }

.player-stage {
  position: relative;
}
#game-frame {
  display: block;
  width: 100%;
  height: calc(100vh - 50px); /* viewport minus the player-bar (no topbar) */
  border: 0;
  background: #0a0a0f;
}

/* Loading spinner shown while a game's iframe loads */
.player-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0a0f;
  z-index: 2;
}
.spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Empty ---------- */
.empty {
  text-align: center;
  padding: 80px 20px;
  color: var(--faint);
}
.empty-ico { font-size: 3rem; margin-bottom: 12px; }

/* ---------- Game request dialog ---------- */
.wish-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 3000;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.wish-dialog {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  animation: slideUp 0.25s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.wish-dialog h2 {
  font-size: 1.4rem;
  letter-spacing: -0.3px;
}
.wish-sub {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 6px 0 20px;
}

.wish-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  color: var(--faint);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.wish-close:hover { color: var(--accent); }

#wish-form { display: flex; flex-direction: column; gap: 14px; }

#wish-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}
#wish-form label .opt { color: var(--faint); font-weight: 400; }

#wish-form input,
#wish-form select,
#wish-form textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.92rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
#wish-form input:focus,
#wish-form select:focus,
#wish-form textarea:focus { border-color: var(--accent); }
#wish-form textarea { resize: vertical; min-height: 90px; }
#wish-form input::placeholder,
#wish-form textarea::placeholder { color: var(--faint); }

.wish-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}
.wish-cancel,
.wish-submit {
  border-radius: 9px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
}
.wish-cancel {
  background: transparent;
  color: var(--muted);
}
.wish-cancel:hover { color: var(--text); border-color: var(--muted); }
.wish-submit {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.wish-submit:hover { filter: brightness(1.1); }

.hidden { display: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }
  .nav { flex-direction: row; flex-wrap: wrap; flex: 1; }
  .nav-label { display: none; }
  .sidebar-footer { display: none; }
  .search { max-width: none; width: 100%; }
  .search-kbd { display: none; }
}
