:root {
  --background: #0E0601;
  --foreground: #F5E6C8;
  --card: #1C0904;
  --card-foreground: #F5E6C8;
  --primary: #C9922A;
  --primary-foreground: #0E0601;
  --secondary: #2D1508;
  --secondary-foreground: #F5E6C8;
  --muted: #3A1A08;
  --muted-foreground: #C4A882;
  --accent: #E8C654;
  --accent-foreground: #0E0601;
  --border: rgba(201, 146, 42, 0.35);
  --ring: #C9922A;
  --radius: 0.75rem;
}

* { box-sizing: border-box; }

body {
  font-family: 'Nunito', sans-serif;
  background-color: var(--background);
  background-image: linear-gradient(rgba(14, 6, 1, 0.68), rgba(14, 6, 1, 0.78)), url('../images/system-background-v2.png');
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  background-attachment: fixed;
  color: var(--foreground);
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

.font-cinzel {
  font-family: 'Cinzel', serif;
}

/* Card flip */
.card-scene {
  perspective: 800px;
}
.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.4, 0, 0.2, 1);
}
.card-inner.flipped {
  transform: rotateY(180deg);
}
.card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.card-back-face {
  transform: rotateY(180deg);
}
.memory-grid {
  grid-template-columns: repeat(6, minmax(0, 1fr));
  max-width: 920px;
}
.memory-card-revealed { position: absolute; }
.memory-card-logo {
  display: block;
  width: 74%;
  height: 74%;
  object-fit: contain;
  user-select: none;
  opacity: 0.92;
  filter: drop-shadow(0 5px 8px rgba(0, 0, 0, 0.72)) drop-shadow(0 0 8px rgba(201, 146, 42, 0.2));
  transition: transform 0.25s ease, filter 0.25s ease;
}
.card-scene:hover .memory-card-logo {
  transform: scale(1.04);
  filter: drop-shadow(0 6px 9px rgba(0, 0, 0, 0.8)) drop-shadow(0 0 12px rgba(232, 198, 84, 0.32));
}
.memory-card-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  user-select: none;
}
.memory-match-mark {
  position: absolute;
  top: 0.45rem;
  right: 0.45rem;
  display: grid;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  border: 1px solid #F5E09A;
  border-radius: 999px;
  color: #FFF5CD;
  background: rgba(14, 6, 1, 0.82);
  box-shadow: 0 0 14px rgba(232, 198, 84, 0.65);
  font-weight: 900;
  text-shadow: 0 1px 2px #000;
}
@media (max-width: 900px) {
  .memory-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 620px; }
}
@media (max-width: 600px) {
  .memory-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); max-width: 440px; }
}
@media (max-width: 380px) {
  .memory-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); max-width: 300px; }
}

/* Gold shimmer text */
.gold-text {
  background: linear-gradient(135deg, #E8C654 0%, #C9922A 40%, #F5E09A 70%, #C9922A 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  color: transparent;
}

/* Cross pattern background */
.cross-bg {
  background-image:
    linear-gradient(rgba(201, 146, 42, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(201, 146, 42, 0.04) 1px, transparent 1px);
  background-size: 40px 40px;
}

/* Shared page background */
.system-background.cross-bg {
  background-color: transparent;
  background-image:
    linear-gradient(rgba(14, 6, 1, 0.68), rgba(14, 6, 1, 0.78)),
    linear-gradient(rgba(201, 146, 42, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(201, 146, 42, 0.04) 1px, transparent 1px),
    url('../images/system-background-v2.png');
  background-position: center, center, center, center;
  background-repeat: no-repeat, repeat, repeat, no-repeat;
  background-size: cover, 40px 40px, 40px 40px, cover;
  background-attachment: fixed;
}

/* Readability over the photographic background */
.system-background {
  color: #FFF3D6;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.95), 0 0 8px rgba(0, 0, 0, 0.55);
}
.system-background > header {
  background: rgba(20, 9, 3, 0.62);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.system-background .gold-text {
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.9));
}

/* Home brand hero */
.home-screen { position: relative; }
.home-edge-line { position: absolute; left: 0; z-index: 2; }
.home-edge-line-top { top: 0; }
.home-edge-line-bottom { bottom: 0; }
.home-hero {
  position: relative;
  width: min(100%, 760px);
  overflow: hidden;
  background: transparent !important;
  border: 0;
  box-shadow: none;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}
.home-brand-mark { display: flex; align-items: center; justify-content: center; width: min(100%, 500px); margin-bottom: 0.2rem; }
.home-brand-line { width: clamp(46px, 10vw, 112px); height: 1px; background: linear-gradient(90deg, transparent, rgba(232, 198, 84, 0.85)); }
.home-brand-line-right { transform: rotate(180deg); }
.home-logo-halo { position: relative; flex: 0 0 auto; width: clamp(116px, 12vw, 160px); height: clamp(92px, 9.5vw, 126px); margin-inline: clamp(12px, 2vw, 24px); display: grid; place-items: center; }
.home-logo-halo::before { content: ''; position: absolute; inset: 14%; border-radius: 50%; background: rgba(24, 60, 130, 0.42); box-shadow: 0 0 35px rgba(43, 93, 190, 0.34), 0 0 45px rgba(232, 198, 84, 0.16); filter: blur(10px); }
.home-logo { position: relative; z-index: 1; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 7px 10px rgba(0, 0, 0, 0.72)); }
.home-eyebrow { margin-top: 0.25rem; color: #E1BE72; font-size: clamp(0.62rem, 1vw, 0.75rem); font-weight: 700; letter-spacing: clamp(0.18em, 0.45vw, 0.42em); }
.home-title { margin-top: 0.35rem; font-size: clamp(2.25rem, 5vw, 4.25rem); line-height: 1; letter-spacing: 0.025em; }
.home-subtitle-row { display: flex; align-items: center; width: min(100%, 520px); gap: 1rem; margin-top: 0.9rem; color: #F0D9AA; }
.home-subtitle-row span { flex: 1; height: 1px; background: linear-gradient(90deg, transparent, rgba(232, 198, 84, 0.75)); }
.home-subtitle-row span:last-child { transform: rotate(180deg); }
.home-subtitle-row p { font-size: clamp(0.65rem, 1.1vw, 0.82rem); font-weight: 700; letter-spacing: clamp(0.14em, 0.35vw, 0.3em); white-space: nowrap; }
.home-brand-new {
  display: block;
  width: clamp(210px, 26vw, 310px);
  height: auto;
  object-fit: contain;
  user-select: none;
  filter: drop-shadow(0 14px 18px rgba(0, 0, 0, 0.68)) drop-shadow(0 0 18px rgba(232, 198, 84, 0.12));
}

/* Main game cards */
.menu-card { isolation: isolate; overflow: hidden; }
.menu-card::before {
  content: '';
  position: absolute;
  z-index: -1;
  inset: -35% 15% 48%;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--game-color) 24%, transparent), transparent 68%);
  opacity: 0.75;
  transition: opacity 0.3s ease, transform 0.35s ease;
}
.menu-card:hover::before { opacity: 1; transform: scale(1.12); }
.menu-card-visual {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(92px, 9vw, 132px);
  height: clamp(92px, 9vw, 132px);
  margin-bottom: 0.65rem;
}
.menu-card-orbit {
  position: absolute;
  inset: 8%;
  border: 1px solid color-mix(in srgb, var(--game-color) 55%, transparent);
  border-radius: 50%;
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.28), 0 0 22px color-mix(in srgb, var(--game-color) 18%, transparent);
  opacity: 0.7;
  transition: transform 0.45s ease, opacity 0.3s ease;
}
.menu-card-orbit::before,
.menu-card-orbit::after {
  content: '';
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #F5E09A;
  box-shadow: 0 0 8px #E8C654;
}
.menu-card-orbit::before { top: 10%; right: 12%; }
.menu-card-orbit::after { bottom: 10%; left: 12%; }
.menu-card-logo {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.65));
  transition: transform 0.35s ease, filter 0.35s ease;
}
.menu-card:hover .menu-card-logo {
  transform: translateY(-3px) scale(1.06);
  filter: drop-shadow(0 10px 13px rgba(0, 0, 0, 0.72)) drop-shadow(0 0 10px color-mix(in srgb, var(--game-color) 38%, transparent));
}
.menu-card:hover .menu-card-orbit { transform: rotate(12deg) scale(1.06); opacity: 1; }

@media (max-width: 480px) {
  .home-hero { padding-inline: 1rem; }
  .home-subtitle-row { gap: 0.65rem; }
  .home-subtitle-row p { white-space: normal; }
}

/* Large displays: use the available canvas instead of clustering at the top */
@media (min-width: 1440px) and (min-height: 800px) {
  .home-screen {
    min-height: 100vh;
    background-position: center 42%;
    justify-content: center;
    padding-block: clamp(2.5rem, 5vh, 5rem);
  }
  .home-hero {
    width: min(72vw, 1080px);
    padding-top: clamp(2rem, 3.5vh, 3.25rem);
    padding-bottom: clamp(1.75rem, 3vh, 2.75rem);
  }
  .home-logo-halo {
    width: clamp(160px, 10vw, 220px);
    height: clamp(126px, 8vw, 174px);
  }
  .home-brand-new { width: clamp(280px, 19vw, 360px); }
  .home-title { font-size: clamp(4.25rem, 4.2vw, 5.75rem); }
  .home-eyebrow { font-size: 0.82rem; }
  .home-subtitle-row { width: min(100%, 650px); margin-top: 1.15rem; }
  .home-subtitle-row p { font-size: 0.9rem; }
  .home-invitation {
    margin-top: clamp(1rem, 2vh, 1.75rem);
    margin-bottom: clamp(2rem, 3.5vh, 3.5rem);
    padding: 0.75rem 2rem;
    font-size: 1rem;
  }
  .home-games-grid {
    max-width: min(82vw, 1380px) !important;
    gap: clamp(1.5rem, 2vw, 2.5rem);
    padding-bottom: clamp(2.5rem, 4vh, 4rem);
  }
  .home-games-grid .menu-card {
    min-height: clamp(300px, 31vh, 390px);
    padding: clamp(2rem, 2.4vw, 3rem);
    justify-content: center;
  }
  .home-games-grid .menu-card-visual { width: clamp(125px, 8vw, 170px); height: clamp(125px, 8vw, 170px); }
  .home-games-grid .menu-card h2 { font-size: clamp(1.35rem, 1.35vw, 1.75rem); }
  .home-games-grid .menu-card p { font-size: clamp(0.95rem, 0.9vw, 1.1rem); }
}

@media (min-width: 2200px) and (min-height: 1000px) {
  .home-hero { width: min(60vw, 1280px); }
  .home-games-grid { max-width: min(68vw, 1560px) !important; }
  .home-games-grid .menu-card { min-height: 360px; }
}

/* Glow effect */
.gold-glow {
  box-shadow: 0 0 20px rgba(201, 146, 42, 0.3), 0 0 60px rgba(201, 146, 42, 0.1);
}
.gold-glow-text {
  text-shadow: 0 0 20px rgba(232, 198, 84, 0.5);
}

/* Pulse animation */
@keyframes pulse-gold {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}
.pulse-gold {
  animation: pulse-gold 2s ease-in-out infinite;
}

/* Float animation */
@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-8px); }
}
.float-anim {
  animation: float 3s ease-in-out infinite;
}

/* Celebration particles */
@keyframes particle-fall {
  0% { transform: translateY(-20px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}
.particle {
  position: fixed;
  top: 0;
  z-index: 60;
  pointer-events: none;
  animation: particle-fall 3s ease-in forwards;
}

/* Word search cell */
.ws-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  width: clamp(28px, 3.2vw, 42px);
  height: clamp(28px, 3.2vw, 42px);
  font-size: clamp(15px, 1.5vw, 20px);
  border: 1px solid rgba(232, 198, 84, 0.28);
  font-weight: 700;
  color: #FFE4AE;
  background: rgba(18, 8, 3, 0.58);
  text-shadow: 0 1px 2px #000, 0 0 5px rgba(0, 0, 0, 0.9);
}
.ws-cell:active {
  transform: scale(0.92);
}
.ws-cell.sel {
  background: rgba(201, 146, 42, 0.4);
  color: #F5E6C8;
  font-weight: 800;
}
.ws-cell.found {
  background: rgba(232, 198, 84, 0.3);
  color: #E8C654;
  font-weight: 800;
}
.ws-panel {
  background: rgba(20, 9, 3, 0.68);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.32);
}
.ws-word {
  color: #F5D69B !important;
  font-size: 0.875rem;
  letter-spacing: 0.035em;
  text-shadow: 0 1px 2px #000;
}

/* Word search level selection */
.ws-level-main {
  background: radial-gradient(circle at center, rgba(201, 146, 42, 0.08), transparent 58%);
}
.ws-level-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(1rem, 2vw, 1.75rem);
  width: min(100%, 1080px);
}
.ws-level-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 310px;
  padding: 2rem 1.5rem;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--level-color) 58%, transparent);
  border-radius: 1rem;
  color: #FFF3D6;
  background: linear-gradient(145deg, rgba(22, 10, 4, 0.9), rgba(55, 29, 9, 0.82));
  box-shadow: 0 15px 38px rgba(0, 0, 0, 0.42), inset 0 1px rgba(255, 255, 255, 0.04);
  transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}
.ws-level-card::before {
  content: '';
  position: absolute;
  inset: -45% 12% 52%;
  border-radius: 50%;
  background: var(--level-color);
  opacity: 0.12;
  filter: blur(28px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.ws-level-card:hover {
  transform: translateY(-7px);
  border-color: var(--level-color);
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.52), 0 0 25px color-mix(in srgb, var(--level-color) 18%, transparent);
}
.ws-level-card:hover::before { opacity: 0.23; transform: scale(1.15); }
.ws-level-icon { position: relative; font-size: 2rem; margin-bottom: 1rem; filter: drop-shadow(0 0 10px var(--level-color)); }
.ws-level-description { margin-top: 0.8rem; color: #F0D9AA; text-align: center; line-height: 1.55; }
.ws-level-meta { margin-top: 1rem; color: var(--level-color); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }
.ws-level-action { margin-top: auto; padding: 0.65rem 1.4rem; border: 1px solid color-mix(in srgb, var(--level-color) 65%, transparent); border-radius: 999px; color: #FFF3D6; background: color-mix(in srgb, var(--level-color) 12%, transparent); font-weight: 800; }
@media (max-width: 760px) {
  .ws-level-grid { grid-template-columns: 1fr; max-width: 430px; }
  .ws-level-card { min-height: 245px; }
}

/* Keyboard key press */
.hm-game-layout { gap: clamp(1rem, 2.4vh, 1.75rem); }
.hm-stage {
  width: min(100%, 430px);
  padding: clamp(0.75rem, 1.5vh, 1.15rem) 1.5rem;
  border: 1px solid rgba(201, 146, 42, 0.25);
  border-radius: 1rem;
  background: radial-gradient(circle at 50% 42%, rgba(201, 146, 42, 0.12), rgba(20, 9, 3, 0.62) 70%);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.32), inset 0 1px rgba(255, 255, 255, 0.03);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.hm-stage svg {
  display: block;
  width: clamp(150px, 13vw, 205px);
  height: auto;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.5));
}
.hm-word-area { width: min(100%, 980px); }
.hm-hint-area { min-height: 38px; }
.hm-hint-box {
  width: min(92vw, 720px);
  max-height: 190px;
  overflow-y: auto;
  text-align: left;
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}
.hm-hint-line {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.65rem;
  align-items: start;
  line-height: 1.45;
}
.hm-hint-line + .hm-hint-line {
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px solid rgba(201, 146, 42, 0.18);
}
.hm-hint-line span {
  color: #E8C654;
  font-family: 'Cinzel', serif;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}
@media (max-height: 760px) and (min-width: 700px) {
  .hm-game-layout { gap: 0.7rem; padding-block: 0.75rem; }
  .hm-stage { padding-block: 0.5rem; }
  .hm-stage svg { width: 135px; }
}
.kb-key {
  transition: all 0.1s;
}
.kb-key:active {
  transform: scale(0.9);
}
.kb-key:disabled {
  cursor: not-allowed;
}

/* Screen transitions */
.screen { display: none; }
.screen.active { display: flex; flex-direction: column; }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Utility to hide */
.hidden-el { display: none !important; }
