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

@import url("https://fonts.googleapis.com/css2?family=Inter:wght@500;600;700;800&display=swap");

:root {
  /* Palette PoliNetwork — tema chiaro */
  --bg: #f1f3f4;
  --header-bg: rgba(255, 255, 255, 0.85);
  --card: #ffffff;
  --accent: #0b5394;
  --accent2: #f4c32b;
  --hover-accent: #0b4880;
  --text: #202124;
  --muted: #5f6368;
  --border: #bdc1c6;
  --on-accent: #ffffff;
  --footer-bg: #ffffff;
  --chip-bg: rgba(95, 99, 104, 0.08);
  --hover-bg: rgba(95, 99, 104, 0.16);
  --accent-soft: rgba(11, 83, 148, 0.15);
  --accent-border: rgba(11, 83, 148, 0.4);
  --shadow-color: rgba(0, 0, 0, 0.16);
  --img-a: #e8eaed;
  --img-b: #ffffff;
  --easing: cubic-bezier(0.25, 1, 0.5, 1);
  --speed: 0.3s;
}

[data-theme="dark"] {
  /* Palette PoliNetwork — tema scuro */
  --bg: #121212;
  --header-bg: rgba(23, 23, 23, 0.85);
  --card: #171717;
  --accent: #eedcb8;
  --accent2: #bb86fc;
  --hover-accent: #e6d0a6;
  --text: #ffffff;
  --muted: #c4c4c4;
  --border: rgba(255, 255, 255, 0.18);
  --on-accent: #121212;
  --footer-bg: #171717;
  --chip-bg: rgba(255, 255, 255, 0.06);
  --hover-bg: rgba(255, 255, 255, 0.12);
  --accent-soft: rgba(238, 220, 184, 0.18);
  --accent-border: rgba(238, 220, 184, 0.45);
  --shadow-color: rgba(0, 0, 0, 0.5);
  --img-a: #242b3a;
  --img-b: #171717;
}

html, body {
  width: 100%;
  min-height: 100%;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.main-header {
  height: 90px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  padding: 0 40px;
  background: var(--header-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 4px 30px var(--shadow-color);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.main-header h1 {
  justify-self: start;
  font-size: 2.2rem;
  font-weight: 800;
  white-space: nowrap;
  background: linear-gradient(90deg, var(--text), var(--muted));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}

.header-spacer {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
}

.search-bar {
  position: relative;
  justify-self: center;
  width: min(460px, 50vw);
}

#search-input {
  width: 100%;
  padding: 14px 45px 14px 45px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 500;
  outline: none;
  transition: all var(--speed) var(--easing);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%235f6368'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 16px center;
  background-size: 20px;
}

#search-input::placeholder {
  color: var(--muted);
}

#search-input:focus {
  border-color: var(--accent);
  background: var(--card);
  box-shadow: 0 0 0 4px var(--accent-soft), 0 8px 20px var(--shadow-color);
}

.search-clear {
  position: absolute;
  top: 50%;
  right: 10px;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.25s var(--easing);
}

.search-clear:hover {
  background: var(--hover-bg);
  color: var(--text);
  transform: translateY(-50%) scale(1.1);
}

.no-results {
  text-align: center;
  color: var(--muted);
  font-size: 1.1rem;
  padding: 80px 20px;
  animation: fadeIn var(--speed) var(--easing);
}

#game-container {
  max-width: 1600px;
  margin: auto;
  padding: 50px 40px 80px;
}

.game-section {
  position: relative;
  margin-bottom: 70px;
  animation: slideUp 0.4s var(--easing) both;
}

.game-section:nth-child(1) { animation-delay: 0.1s; }
.game-section:nth-child(2) { animation-delay: 0.2s; }
.game-section:nth-child(3) { animation-delay: 0.3s; }

.section-header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 24px;
}

.section-header h2 {
  font-size: 2.2rem;
  font-weight: 800;
  text-transform: capitalize;
  position: relative;
  padding-bottom: 8px;
}

.section-header h2::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 48px;
  height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 4px;
}

.section-header span {
  background: var(--chip-bg);
  color: var(--muted);
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  border: 1px solid var(--border);
}

.game-row {
  display: flex;
  gap: 24px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 20px 40px 40px 10px;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
}

.game-row::-webkit-scrollbar {
  display: none;
}

.game-card {
  flex: 0 0 200px;
  height: 280px;
  position: relative;
  z-index: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: var(--text);
  box-shadow: 0 10px 20px var(--shadow-color);
  transition: transform var(--speed) var(--easing), box-shadow var(--speed) var(--easing), border-color var(--speed) var(--easing);
}

.game-card:hover {
  z-index: 20;
  transform: translateY(-12px) scale(1.04);
  border-color: var(--accent-border);
  box-shadow: 0 20px 40px var(--shadow-color), 0 0 30px var(--accent-soft);
}

.game-card img {
  width: 100%;
  height: 190px;
  object-fit: cover;
  background: linear-gradient(180deg, var(--img-a), var(--img-b));
  border-bottom: 1px solid var(--border);
  transition: transform 0.4s var(--easing), filter 0.4s var(--easing);
}

.game-card:hover img {
  transform: scale(1.1);
  filter: brightness(1.1);
}

.game-card h3 {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 14px 16px;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
  background: linear-gradient(to top, var(--card) 60%, transparent);
  z-index: 2;
}

.scroll-arrow {
  position: absolute;
  top: 55%;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  border: 1px solid var(--border);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--header-bg);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-size: 32px;
  font-weight: 400;
  cursor: pointer;
  z-index: 50;
  box-shadow: 0 8px 24px var(--shadow-color);
  transition: all 0.25s var(--easing);
}

.scroll-arrow:hover {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  transform: translateY(-50%) scale(1.15);
  box-shadow: 0 10px 30px var(--accent-soft);
  border-color: transparent;
}

.scroll-arrow.left { left: 4px; }
.scroll-arrow.right { right: 4px; }

.game-view {
  min-height: 100dvh;
  height: 100dvh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}

.game-main-layout {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.iframe-wrapper {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 30px;
  animation: fadeIn 0.4s var(--easing);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

#game-frame {
  width: 100%;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: #000;
  box-shadow: 0 30px 80px var(--shadow-color), 0 0 40px var(--accent-soft);
}

.game-footer {
  height: 90px;
  min-height: 90px;
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 40px;
  background: var(--header-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -10px 30px var(--shadow-color);
}

.footer-titles {
  display: flex;
  align-items: baseline;
  gap: 16px;
  overflow: hidden;
}

#game-title {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#game-creator {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.game-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.nav-btn {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.25s var(--easing);
  cursor: pointer;
}

.nav-btn svg {
  width: 24px;
  height: 24px;
  fill: var(--text);
  transition: transform 0.25s var(--easing), fill 0.25s var(--easing);
}

.nav-btn:hover {
  background: var(--hover-bg);
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 8px 20px var(--shadow-color);
}

.like-btn.active {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
}

.like-btn.active svg {
  fill: #ef4444;
  animation: heartBeat 0.35s var(--easing);
}

.like-btn:active svg {
  transform: scale(0.8);
}

/* ===== CAMBIO TEMA (chiaro/scuro PoliNetwork) ===== */
theme-toggle {
  display: inline-flex;
}

.theme-toggle-btn {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: all 0.25s var(--easing);
}

.theme-toggle-btn:hover {
  background: var(--hover-bg);
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 8px 20px var(--shadow-color);
}

.theme-toggle-btn .theme-icon {
  width: 24px;
  height: 24px;
  pointer-events: none;
}

.theme-icon-sun {
  display: none;
}

[data-theme="dark"] .theme-icon-sun {
  display: block;
}

[data-theme="dark"] .theme-icon-moon {
  display: none;
}

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--footer-bg);
  padding: 40px 40px 50px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 16px 36px;
  position: relative;
}

.site-footer::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 150px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

.site-footer a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 600;
  position: relative;
  transition: color 0.25s var(--easing);
}

.site-footer a::after {
  content: '';
  position: absolute;
  width: 0;
  height: 2px;
  bottom: -4px;
  left: 0;
  background-color: var(--accent);
  transition: width 0.25s var(--easing);
  border-radius: 2px;
}

.site-footer a:hover {
  color: var(--text);
}

.site-footer a:hover::after {
  width: 100%;
}

.site-footer .footer-note {
  width: 100%;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 12px;
  font-weight: 500;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes heartBeat {
  0% { transform: scale(1); }
  50% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.legal-page {
  max-width: 860px;
  margin: 0 auto;
  padding: 80px 40px 100px;
  color: var(--muted);
  line-height: 1.8;
  animation: fadeIn 0.4s var(--easing);
}

.legal-page h1 {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 12px;
}

.legal-page .back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 40px;
  transition: transform 0.2s var(--easing);
}

.legal-page .back-link:hover {
  transform: translateX(-5px);
}

@media (max-width: 768px) {
  .main-header {
    height: auto;
    padding: 20px;
    grid-template-columns: 1fr;
    gap: 16px;
  }
  
  .main-header h1 {
    font-size: 2rem;
    justify-self: center;
  }
  
  .header-spacer {
    position: absolute;
    top: 14px;
    right: 16px;
    grid-column: 1;
  }
  
  .search-bar {
    width: 100%;
    justify-self: center;
  }
  
  #search-input {
    padding: 12px 40px 12px 40px;
    font-size: 0.95rem;
    background-position: 12px center;
  }
  
  #game-container {
    padding: 30px 20px 60px;
  }
  
  .section-header h2 {
    font-size: 1.6rem;
  }
  
  .game-row {
    gap: 16px;
    padding: 10px 20px 30px 0;
  }
  
  .game-card {
    flex-basis: 150px;
    height: 230px;
    border-radius: 16px;
  }
  
  .game-card img {
    height: 150px;
  }
  
  .game-card h3 {
    font-size: 0.9rem;
    padding: 10px;
  }
  
  .scroll-arrow {
    width: 40px;
    height: 40px;
    font-size: 24px;
  }
  
  .iframe-wrapper {
    padding: 10px;
  }
  
  #game-frame {
    border-radius: 16px;
  }
  
  .game-footer {
    height: 76px;
    min-height: 76px;
    padding: 0 20px;
  }
  
  #game-title {
    font-size: 1.2rem;
    max-width: 45vw;
  }
  
  #game-creator {
    font-size: 0.85rem;
    max-width: 30vw;
  }
  
  .footer-titles {
    flex-direction: column;
    gap: 2px;
  }
  
  .nav-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
  }

  .theme-toggle-btn {
    width: 44px;
    height: 44px;
    border-radius: 12px;
  }

  .theme-toggle-btn .theme-icon {
    width: 20px;
    height: 20px;
  }

  .game-controls {
    gap: 10px;
  }
  
  .site-footer {
    padding: 30px 20px 40px;
    gap: 12px 20px;
  }
}