/* ══════════════════════════════════════════════════════════════
   MAIN STYLES — layout, components, responsive
   Relies on CSS custom properties defined in skins.css
   ══════════════════════════════════════════════════════════════ */

/* ── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { height: 100%; }

body {
  font-family: -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--body-bg);
  color: var(--text-primary);
  height: 100%;
  transition: background 0.25s ease, color 0.25s ease;
}

ul { list-style: none; }
button { cursor: pointer; font-family: inherit; }
svg { display: block; flex-shrink: 0; }


/* ── Header ─────────────────────────────────────────────────── */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 64px;
  background: var(--header-bg);
  color: var(--header-text);
  display: flex;
  align-items: center;
  padding: 0 12px 0 16px;
  gap: 10px;
  z-index: 200;
  box-shadow: var(--header-shadow, 0 2px 6px rgba(0,0,0,.2));
  border-bottom: 1px solid var(--header-border, transparent);
  transition: background 0.25s ease, box-shadow 0.25s ease;
}

.menu-toggle {
  background: none;
  border: none;
  color: var(--header-text);
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}
.menu-toggle:hover { background: rgba(255,255,255,0.15); }

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  text-decoration: none;
  color: inherit;
}
.brand-icon { opacity: 0.95; }
.brand-name {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

/* Search bar */
.header-search {
  flex: 1;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 12px;
  color: var(--header-text);
  opacity: 0.8;
  pointer-events: none;
}
.header-search input {
  width: 100%;
  padding: 9px 14px 9px 38px;
  background: var(--header-search-bg);
  border: 1px solid var(--header-search-border);
  border-radius: 24px;
  color: var(--header-search-text, var(--header-text));
  font-size: 0.9rem;
  outline: none;
  transition: background 0.2s, border-color 0.2s;
}
.header-search input::placeholder { color: var(--header-search-placeholder, rgba(255,255,255,0.65)); }
.header-search input:focus {
  background: var(--header-search-focus-bg);
  border-color: rgba(0,0,0,0.2);
}

/* Skin switcher */
.skin-switcher {
  display: flex;
  gap: 3px;
  background: var(--switcher-bg, rgba(0,0,0,0.2));
  padding: 4px;
  border-radius: 8px;
  flex-shrink: 0;
  margin-left: auto;
}
.skin-btn {
  padding: 4px 10px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--switcher-inactive, rgba(255,255,255,0.65));
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.skin-btn:hover { background: var(--switcher-active-bg); color: var(--switcher-active-text); }
.skin-btn.active { background: var(--switcher-active-bg); color: var(--switcher-active-text); }


/* ── App Layout ─────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
  padding-top: 64px; /* below fixed header */
}


/* ── Sidebar ─────────────────────────────────────────────────── */
.app-sidebar {
  width: 256px;
  flex-shrink: 0;
  position: fixed;
  top: 64px;
  left: 0;
  bottom: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  transition: background 0.25s ease, transform 0.3s cubic-bezier(0.4,0,0.2,1);
}

.sidebar-inner { padding: 12px 0; }

.sidebar-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sidebar-label-color);
  padding: 8px 20px 6px;
}

.sidebar-list { padding: 0 8px; }

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 12px;
  border-radius: 0 24px 24px 0;
  margin-right: 8px;
  color: var(--sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  transition: background 0.15s, color 0.15s;
  user-select: none;
  min-height: 44px;
}
.sidebar-item:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-active-text);
}
.sidebar-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  font-weight: 600;
}
.sidebar-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 4px;
  background: var(--sidebar-active-bar);
  border-radius: 0 2px 2px 0;
}
.sidebar-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Two-line item text block */
.sidebar-item-label {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  line-height: 1.25;
  font-size: 0.875rem;
}
.sidebar-item-sub {
  font-size: 0.7rem;
  font-weight: 400;
  opacity: 0.65;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.sidebar-item.active .sidebar-item-sub { opacity: 0.7; }

/* Divider between top nav and enrolled section */
.sidebar-divider {
  height: 1px;
  background: var(--sidebar-border);
  margin: 6px 0;
}

/* "Enrolled" section header */
.sidebar-section-hdr {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 4px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--sidebar-text);
  opacity: 0.9;
  user-select: none;
}
.section-chevron { margin-left: auto; opacity: 0.6; }

/* Top nav list (Home) — tighter spacing */
.sidebar-list--top { margin-bottom: 2px; }

/* Colored letter-circle avatars */
.sidebar-avatar {
  display: flex;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: 0;
}

/* In non-classroom skins, hide avatars (keep SVG icons) */
[data-skin="canvas"] .sidebar-avatar,
[data-skin="schoology"] .sidebar-avatar { display: none; }

/* Classroom skin: show avatars, hide SVG icons */
[data-skin="classroom"] .sidebar-item > svg:not(.section-chevron) { display: none; }
/* Home item exception: keep its SVG, no avatar needed */
[data-skin="classroom"] .sidebar-list--top .sidebar-item > svg { display: block; }
[data-skin="classroom"] .sidebar-list--top .sidebar-avatar       { display: none; }

/* Avatar colors (match Google Classroom palette) */
.av-red    { background: #d93025; }
.av-blue   { background: #1a73e8; }
.av-purple { background: #7b1fa2; }
.av-teal   { background: #007b83; }
.av-orange { background: #e37400; }
.av-indigo { background: #3949ab; }

/* Sidebar backdrop (mobile only) */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 64px 0 0 0;
  background: rgba(0,0,0,0.45);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.3s;
}
.sidebar-backdrop.visible { opacity: 1; }


/* ── Main Content ───────────────────────────────────────────── */
.app-content {
  flex: 1;
  margin-left: 256px;
  min-height: calc(100vh - 64px);
  padding: 24px 24px 48px;
  transition: margin 0.3s cubic-bezier(0.4,0,0.2,1);
}

/* Content banner */
.content-banner {
  background: var(--banner-bg);
  border: 1px solid var(--banner-border);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--card-shadow);
  transition: background 0.25s, border-color 0.25s;
}

.content-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.content-sub {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-top: 2px;
}


/* ── Games Grid ─────────────────────────────────────────────── */
.games-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}


/* ── Game Card ──────────────────────────────────────────────── */
.game-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--card-shadow);
  cursor: pointer;
  transition:
    box-shadow 0.2s ease,
    transform 0.2s ease,
    background 0.25s;
  display: flex;
  flex-direction: column;
  outline: none;
}
.game-card:hover {
  box-shadow: var(--card-shadow-hover);
  transform: translateY(-3px);
}
.game-card:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}
.game-card:active { transform: translateY(-1px); }

/* Card thumbnail */
.card-thumb {
  aspect-ratio: 16 / 9;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
}
.card-emoji {
  font-size: 3.5rem;
  line-height: 1;
  filter: drop-shadow(0 3px 10px rgba(0,0,0,0.35));
  transition: transform 0.25s ease;
  user-select: none;
}
.game-card:hover .card-emoji { transform: scale(0.9) rotate(-4deg); }
.card-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  transition: transform .3s ease;
}
.game-card:hover .card-thumb-img { transform: scale(1.05); }

/* Hover overlay on thumbnail */
.card-hover-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.game-card:hover .card-hover-overlay { opacity: 1; }

.card-hover-btn {
  background: rgba(255,255,255,0.15);
  border: 2px solid rgba(255,255,255,0.7);
  border-radius: 50%;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  transition: background 0.15s, transform 0.15s;
  backdrop-filter: blur(4px);
}
.card-hover-btn:hover {
  background: rgba(255,255,255,0.3);
  transform: scale(1.1);
}

/* Card body */
.card-body {
  padding: 14px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  flex: 1;
  min-width: 0;
}
.card-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

/* Category badge */
.card-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
  flex-shrink: 0;
}
.cat-action   { background: #fce4e4; color: #c62828; }
.cat-arcade   { background: #ede7f6; color: #4527a0; }
.cat-puzzle   { background: #e3f2fd; color: #1565c0; }
.cat-strategy { background: #e0f7fa; color: #00695c; }
.cat-sports   { background: #fff3e0; color: #e65100; }

/* Play button */
.play-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  align-self: flex-start;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
.play-btn:hover  { background: var(--accent-hover); }
.play-btn:active { transform: scale(0.97); }


/* ── No Results ─────────────────────────────────────────────── */
.no-results {
  display: none;  /* shown via JS */
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 80px 24px;
  color: var(--text-muted);
  text-align: center;
}
.no-results p { font-size: 1rem; }


/* ── Game Overlay ───────────────────────────────────────────── */
.game-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  flex-direction: column;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.game-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.overlay-bar {
  height: 52px;
  min-height: 52px;
  background: #1a1a1a;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.overlay-back {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 6px;
  transition: background 0.15s;
  flex-shrink: 0;
}
.overlay-back:hover { background: rgba(255,255,255,0.12); }

.overlay-title {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.overlay-fullscreen {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}
.overlay-fullscreen:hover { background: rgba(255,255,255,0.12); color: #fff; }

.game-frame {
  flex: 1;
  width: 100%;
  border: none;
  display: block;
}


/* ══════════════════════════════════════════════════════════════
   VIEW SYSTEM
   ══════════════════════════════════════════════════════════════ */

.view { animation: fadeIn 0.18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }


/* ── Class / Category Cards (Home view) ─────────────────────── */
.class-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.class-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  overflow: visible; /* allow avatar to bleed */
  box-shadow: var(--card-shadow);
  cursor: pointer;
  transition: box-shadow 0.2s ease, transform 0.15s ease;
  display: flex;
  flex-direction: column;
  position: relative;
}
.class-card:hover {
  box-shadow: var(--card-shadow-hover);
  transform: translateY(-2px);
}

/* Banner (colorful top section) */
.class-banner {
  border-radius: 8px 8px 0 0;
  height: 128px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  position: relative;
  overflow: hidden;
}
.class-name {
  font-size: 1.15rem;
  font-weight: 500;
  color: #fff;
  line-height: 1.2;
  text-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.class-teacher {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.82);
  margin-top: 3px;
}

/* Avatar circle — overlaps banner/footer boundary */
.class-card-avatar {
  position: absolute;
  right: 18px;
  bottom: -22px;   /* pulls it below the banner edge */
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255,255,255,0.22);
  border: 3px solid var(--card-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,.22);
  backdrop-filter: blur(6px);
  z-index: 1;
  transition: border-color 0.25s;
}

/* Footer strip */
.class-footer {
  padding: 30px 14px 12px; /* top padding leaves room for the avatar */
  display: flex;
  align-items: center;
  border-top: 1px solid var(--card-border);
  gap: 8px;
  flex-shrink: 0;
}
.class-game-count {
  font-size: 0.78rem;
  color: var(--text-secondary);
  flex: 1;
}
.class-footer-icons { display: flex; gap: 2px; }
.class-icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 7px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}
.class-icon-btn:hover { background: rgba(0,0,0,0.06); color: var(--text-primary); }


/* ── Stream view ─────────────────────────────────────────────── */
.stream-banner {
  border-radius: 8px;
  min-height: 200px;
  padding: 24px 28px;
  display: flex;
  align-items: flex-end;
  position: relative;
  overflow: hidden;
  margin-bottom: 24px;
}

/* subtle dark gradient at bottom so text is readable */
.stream-banner::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,.38) 0%, transparent 55%);
  pointer-events: none;
}

.stream-banner-text {
  position: relative;
  z-index: 1;
  flex: 1;
}
.stream-title {
  font-size: 2rem;
  font-weight: 400;
  color: #fff;
  line-height: 1.1;
  letter-spacing: -0.01em;
  text-shadow: 0 1px 6px rgba(0,0,0,.3);
}
.stream-sub {
  font-size: 0.875rem;
  color: rgba(255,255,255,0.85);
  margin-top: 5px;
}

.stream-banner-avatar {
  position: absolute;
  right: 28px;
  bottom: 24px;
  z-index: 1;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(255,255,255,0.18);
  border: 3px solid rgba(255,255,255,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0;
  backdrop-filter: blur(8px);
}

.stream-body { /* game cards below the banner */ }


/* ══════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════ */

/* Tablet: tighter grid */
@media (max-width: 1024px) {
  .games-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
  }
}

/* Mobile: sidebar becomes a drawer */
@media (max-width: 768px) {
  .brand-name { display: none; }

  .header-search {
    max-width: none;
    margin: 0;
  }

  .app-sidebar {
    transform: translateX(-100%);
    box-shadow: none;
    width: 240px;
    z-index: 150;
  }
  .app-sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 16px rgba(0,0,0,.2);
  }

  .sidebar-backdrop {
    display: block;
    pointer-events: none;
  }
  .sidebar-backdrop.visible {
    pointer-events: all;
  }

  .app-content {
    margin-left: 0;
    padding: 16px 16px 40px;
  }

  .class-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
  }
  .stream-banner { min-height: 140px; padding: 18px 20px; }
  .stream-title  { font-size: 1.5rem; }
  .stream-banner-avatar { width: 56px; height: 56px; font-size: 1.3rem; }

  .games-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
  }

  .card-body { padding: 10px 12px 12px; }
  .card-desc { display: none; } /* hide on small screens to keep cards compact */
}

@media (max-width: 420px) {
  .app-header { padding: 0 8px 0 10px; gap: 6px; }
  .skin-btn { padding: 4px 7px; font-size: 0.65rem; }
  .games-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
}

/* Very small: single column */
@media (max-width: 320px) {
  .games-grid { grid-template-columns: 1fr; }
}
