:root {
  --bg: #1b1430;
  --bg-2: #261c44;
  --card: #2f2454;
  --text: #fff7ec;
  --muted: #b9add6;
  --accent: #ffb938;
  --accent-ink: #1b1430;
  --accent-shadow: #c7861a;
  --placeholder: #8f84b0;
  --radius: 18px;
  --font-display: 'Fredoka', ui-rounded, 'SF Pro Rounded', system-ui, sans-serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 var(--font-body); }
a { color: var(--accent); }
[hidden] { display: none !important; }

.brand {
  display: inline-flex; align-items: center; gap: 10px;
  font: 600 22px var(--font-display); color: var(--text); text-decoration: none; letter-spacing: .3px;
}
.brand img { width: 32px; height: 32px; }
.lab {
  font: 600 11px/1 var(--font-display); letter-spacing: 1px; color: var(--accent);
  background: rgba(255, 185, 56, .16); padding: 4px 7px; border-radius: 6px;
}

/* Catalog */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 16px; max-width: 1100px; margin: 0 auto;
}
.hero { max-width: 1100px; margin: 0 auto; padding: 8px 16px 24px; }
.hero h1 { font: 600 clamp(28px, 6vw, 44px)/1.1 var(--font-display); margin: 0 0 8px; }
.hero p { margin: 0; color: var(--muted); }
.grid {
  display: grid; gap: 12px; padding: 0 16px 48px; max-width: 1100px; margin: 0 auto;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); grid-auto-flow: dense;
}
.card {
  display: flex; flex-direction: column; text-decoration: none; color: var(--text);
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  transition: transform .15s ease;
}
.card:hover, .card:focus-visible { transform: translateY(-3px); }
.card .thumb {
  position: relative; flex: 1; aspect-ratio: 1; display: grid; place-items: center; overflow: hidden;
  background: linear-gradient(150deg, hsl(var(--hue) 70% 62%), hsl(calc(var(--hue) + 40) 60% 38%));
  font: 600 56px var(--font-display); color: rgba(255, 255, 255, .9);
}
.card .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.badge-new {
  position: absolute; top: 8px; left: 8px; padding: 3px 9px; border-radius: 99px;
  font: 600 12px/1.2 var(--font-display); letter-spacing: .5px; text-transform: uppercase;
  color: var(--accent-ink); background: var(--accent); box-shadow: 0 2px 0 var(--accent-shadow);
}
.card .name { padding: 8px 12px 0; font: 600 16px/1.3 var(--font-display); }
.card .tagline { padding: 0 12px 10px; font: 500 13px/1.4 var(--font-display); color: var(--muted); }
.card.big { grid-column: span 2; }
.card.big .name { font-size: 20px; padding-top: 10px; }
.card.big .tagline { font-size: 15px; padding-bottom: 12px; }
@media (min-width: 700px) {
  .grid { gap: 16px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
  .card.big { grid-row: span 2; }
}
.empty { grid-column: 1 / -1; color: var(--muted); padding: 32px 0; }
.site-footer {
  max-width: 1100px; margin: 0 auto; padding: 24px 16px 40px; color: var(--muted); font-size: 14px;
  display: flex; gap: 16px; flex-wrap: wrap;
}
.site-footer a { color: var(--muted); }

/* Play page */
.play-page { overflow: hidden; height: 100dvh; overscroll-behavior: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100dvh; border: 0; display: block; background: #000; }

#loader {
  position: fixed; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px;
  padding: 24px 16px; text-align: center;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255, 185, 56, .18), transparent 60%),
    var(--cover, none) center / cover no-repeat,
    var(--bg);
}
#loader::before { content: ''; position: absolute; inset: 0; background: rgba(27, 20, 48, .72); backdrop-filter: blur(6px); }
#loader > * { position: relative; }
#loader .brand { position: absolute; top: 20px; left: 16px; font-size: 18px; }
#loader .brand img { width: 26px; height: 26px; }
#art {
  width: min(220px, 52vw); height: auto; aspect-ratio: 1; border-radius: 32px;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, .12), 0 24px 50px rgba(0, 0, 0, .45);
}
#title { font: 600 clamp(30px, 8vw, 52px)/1.1 var(--font-display); margin: 0; max-width: 16ch; }
.loader-head { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.game-tagline { margin: 6px 0 0; color: var(--muted); font: 500 17px/1.3 var(--font-display); }
#loader.has-screens { justify-content: flex-start; gap: 18px; padding-top: max(72px, calc(env(safe-area-inset-top) + 60px)); }
#loader.has-screens .loader-head { flex-direction: row; gap: 14px; align-self: stretch; text-align: left; }
#loader.has-screens #art { width: 84px; border-radius: 20px; box-shadow: 0 0 0 3px rgba(255, 255, 255, .12), 0 10px 24px rgba(0, 0, 0, .4); }
#loader.has-screens #title { font-size: 26px; }
#loader.has-screens .loader-note { position: relative !important; bottom: auto; margin: auto 0 env(safe-area-inset-bottom); padding-top: 8px; }
.loader-screens {
  align-self: stretch; display: flex; gap: 10px; flex: 1 1 0; min-height: 150px; max-height: 400px;
  margin: 0 -16px; padding: 0 16px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
}
.loader-screens::-webkit-scrollbar { display: none; }
.loader-screens img {
  flex: none; height: 100%; width: auto; aspect-ratio: 9 / 16; object-fit: cover;
  border-radius: 16px; scroll-snap-align: center; background: var(--card);
}
@media (min-width: 700px) {
  .loader-screens { justify-content: safe center; }
  #loader.has-screens .loader-head { justify-content: center; }
}
#bar { width: min(280px, 70vw); height: 8px; border-radius: 99px; background: rgba(255, 255, 255, .14); overflow: hidden; }
#bar span {
  display: block; height: 100%; width: 35%; border-radius: inherit; background: var(--accent);
  animation: slide 1.1s ease-in-out infinite;
}
#bar.done span { width: 100%; animation: none; }
@keyframes slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(290%); } }
#status { color: var(--muted); min-height: 1.5em; margin: 0; }
#play {
  font: 600 26px var(--font-display); color: var(--accent-ink); background: var(--accent);
  border: 0; border-radius: 99px; padding: 16px 64px; cursor: pointer;
  box-shadow: 0 8px 0 var(--accent-shadow), 0 14px 30px rgba(0, 0, 0, .35);
  animation: pop .35s ease-out;
}
#play:active { transform: translateY(4px); box-shadow: 0 4px 0 var(--accent-shadow); }
@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.loader-note {
  position: absolute !important; left: 0; right: 0; bottom: max(32px, env(safe-area-inset-bottom));
  margin: 0; color: var(--muted); font-size: 14px;
}

#menu-btn {
  position: fixed; z-index: 20;
  top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left));
  width: 40px; height: 40px; border-radius: 50%; border: 0; cursor: pointer;
  display: grid; place-items: center; background: rgba(27, 20, 48, .6); color: var(--text); opacity: .75;
}
#menu-btn:hover, #menu-btn:focus-visible { opacity: 1; }

/* Game's own actions (valf.menu) at the top of the menu sheet */
.game-actions { display: flex; gap: 10px; margin-bottom: 16px; }
.game-actions .btn { display: flex; align-items: center; justify-content: center; gap: 8px; }

/* Buttons shared by the menu and the end screen */
.btn {
  display: block; width: 100%; text-align: center; text-decoration: none; cursor: pointer;
  font: 500 17px var(--font-display); color: var(--text); background: var(--card);
  border: 0; border-radius: 14px; padding: 14px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; font-size: 18px; }
.btn.pill { border-radius: 99px; font-size: 20px; padding: 15px; box-shadow: 0 6px 0 var(--accent-shadow); }
.btn.quiet { background: none; color: var(--muted); padding: 10px; }
.btn-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.btn-row > [hidden] + *, .btn-row > :has(+ [hidden]) { grid-column: 1 / -1; }

/* In-game menu: bottom sheet on phones, centered dialog on wide screens */
#menu {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(10, 6, 20, .62);
}
.sheet {
  width: 100%; max-width: 480px; max-height: 100dvh; overflow-y: auto;
  display: grid; gap: 14px; background: var(--bg-2); border-radius: 26px 26px 0 0;
  padding: 12px max(20px, env(safe-area-inset-right)) max(24px, calc(env(safe-area-inset-bottom) + 16px)) max(20px, env(safe-area-inset-left));
  animation: sheet-up .22s ease-out;
}
.handle { justify-self: center; width: 40px; height: 5px; border-radius: 99px; background: rgba(255, 255, 255, .2); }
.divider { height: 1px; background: rgba(255, 255, 255, .08); }

/* Sound / Music switches in the menu */
.toggles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.toggle {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer;
  background: var(--card); border-radius: 14px; padding: 12px 14px; font: 500 17px var(--font-display);
}
.toggle input {
  appearance: none; flex: none; margin: 0; cursor: pointer; position: relative;
  width: 44px; height: 26px; border-radius: 99px; background: rgba(255, 255, 255, .18); transition: background .15s;
}
.toggle input::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--text); transition: transform .15s;
}
.toggle input:checked { background: var(--accent); }
.toggle input:checked::after { transform: translateX(18px); background: var(--accent-ink); }
.toggle input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (min-width: 600px) {
  #menu { align-items: center; padding: 16px; }
  .sheet { border-radius: var(--radius); padding: 22px; }
  .handle { display: none; }
}

/* Vote and review */
.vote { display: grid; gap: 12px; }
.vote h2 { margin: 0; font: 600 22px/1.15 var(--font-display); text-wrap: balance; }
.vote .muted-line { margin: 0; color: var(--muted); font-size: 14px; }
.vote-buttons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.vote-buttons button {
  display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer;
  border: 0; border-radius: 16px; padding: 14px 8px;
  font: 500 16px var(--font-display); background: var(--card); color: var(--text);
}
.vote-buttons button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.review { display: grid; gap: 8px; }
.review label { color: var(--muted); font-size: 14px; }
.review-row { display: flex; gap: 8px; }
.review textarea {
  flex: 1; min-width: 0; resize: none; border: 0; border-radius: 12px;
  background: var(--card); color: var(--text); padding: 10px 12px; font: 400 16px var(--font-body);
}
.review textarea::placeholder { color: var(--placeholder); }
.review button {
  border: 0; border-radius: 12px; padding: 0 14px; cursor: pointer;
  background: var(--card); color: var(--accent); font: 600 15px var(--font-display);
}
.thanks { margin: 0; color: var(--accent); font-size: 15px; }
.card-box { background: var(--bg-2); border-radius: 20px; padding: 16px; }

/* All levels done */
#end {
  position: fixed; inset: 0; z-index: 25; overflow-y: auto;
  background: radial-gradient(110% 55% at 50% 18%, rgba(255, 185, 56, .22), transparent 60%), var(--bg);
}
.end-inner {
  min-height: 100%; max-width: 440px; margin: 0 auto; box-sizing: border-box;
  display: flex; flex-direction: column; gap: 18px;
  padding: max(20px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}
.end-inner .brand { font-size: 18px; }
.end-inner .brand img { width: 26px; height: 26px; }
.end-hero { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; }
.end-hero h1 { margin: 0; font: 600 32px/1.1 var(--font-display); text-wrap: balance; }
.end-hero p { margin: 0; color: var(--muted); max-width: 30ch; }
.star {
  width: 88px; height: 88px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 0 var(--accent-shadow);
}
.end-hero .end-levels { margin-top: 6px; color: var(--accent); font: 600 13px var(--font-display); letter-spacing: 1.5px; text-transform: uppercase; }
.end-actions { display: grid; gap: 6px; }

/* Desktop: portrait games sit in a phone-sized frame */
#desk-info { display: none; }
@media (min-width: 1000px) and (min-aspect-ratio: 5/4) {
  .play-page[data-orientation="portrait"] {
    background: radial-gradient(50% 70% at 50% 50%, rgba(255, 185, 56, .12), transparent 70%), var(--bg);
  }
  .play-page[data-orientation="portrait"] #game {
    top: 24px; bottom: 24px; left: 0; right: 0; margin: auto;
    height: calc(100dvh - 48px); width: calc((100dvh - 48px) * 9 / 16);
    border-radius: 24px; box-shadow: 0 0 0 6px var(--card), 0 30px 60px rgba(0, 0, 0, .5);
  }
  .play-page[data-orientation="portrait"] #desk-info {
    display: grid; gap: 20px; position: fixed; top: 32px; left: 40px; width: 240px;
  }
  .play-page[data-orientation="portrait"] #desk-info h2 { margin: 0; font: 600 34px/1.1 var(--font-display); text-wrap: balance; }
  .desk-screens { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .desk-screens img { width: 100%; height: auto; border-radius: 12px; background: var(--card); }
  .play-page[data-orientation="portrait"] #menu-btn { top: 32px; left: auto; right: 40px; }
}

/* Text pages */
.doc { max-width: 720px; margin: 0 auto; padding: 8px 16px 48px; }
.doc h1 { font: 600 34px var(--font-display); }
.doc h2 { font: 600 22px var(--font-display); margin-top: 32px; }
.doc p, .doc li { color: #e9e1f5; }
