/* ============ PlayHub design system — per Claude Design handoff ============ */
:root {
  /* color */
  --bg: #FFF8EF;  --surface: #FFFFFF;  --line: #EDE6DA;
  --ink: #2E2A45;  --ink-soft: #6E6787;
  --grape: #7C5CFF;  --grape-deep: #6247D9;  --grape-tint: #F1ECFF;
  --pink: #FF5E9A;   --pink-deep: #D6336C;   --pink-tint: #FFE9F1;
  --sun: #FFA41B;    --sun-tint: #FFF1DC;
  --teal: #17B8A6;   --teal-deep: #0B7568;   --teal-tint: #E2F7F4;
  --leaf: #3BB273;   --leaf-deep: #2E8A59;   --leaf-tint: #E6F6EC;
  --absent: #B9B3C9;
  --grad-brand: linear-gradient(92deg, var(--grape), var(--pink));

  /* type */
  --font-display: 'Fredoka', system-ui, sans-serif;
  --font-body: 'Outfit', system-ui, sans-serif;
  --fs-xs: 12px; --fs-sm: 14px; --fs-md: 16px; --fs-lg: 18px; --fs-xl: 22px;
  --fs-h2: 32px; --fs-h1: 40px; --fs-hero: clamp(32px, 6vw, 56px);

  /* space (4px base) */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 24px; --sp-6: 32px; --sp-7: 48px; --sp-8: 64px;

  /* radius */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 24px; --r-full: 999px;

  /* shadow (grape-tinted) */
  --shadow-sm: 0 2px 10px rgba(76, 50, 160, .07);
  --shadow-md: 0 8px 24px rgba(76, 50, 160, .12);
  --shadow-lg: 0 16px 48px rgba(76, 50, 160, .16);
  --ring: 0 0 0 3px var(--bg), 0 0 0 6px var(--grape);

  /* motion */
  --t-fast: 120ms; --t-med: 200ms; --t-slow: 320ms;
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);

  /* legacy aliases used by game modules */
  --card: var(--surface); --card-solid: var(--surface);
  --border: var(--line); --text: var(--ink); --muted: var(--ink-soft);
  --accent: var(--grape); --accent2: var(--grape-deep);
  --good: var(--leaf-deep); --bad: var(--pink-deep); --warn: var(--sun);
  --grad: var(--grad-brand);
  --bg2: #262040; --radius: var(--r-xl); --shadow: var(--shadow-md);
  --font-fun: var(--font-display);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  font-size: var(--fs-md);
  min-height: 100dvh;
  overflow-x: hidden;
}
h1, h2, h3, .logo, .big-msg, .banner { font-family: var(--font-display); font-weight: 600; }
button { font-family: inherit; color: inherit; cursor: pointer; }
input { font-family: inherit; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }

@keyframes floaty { 0%, 100% { transform: translateY(0) } 50% { transform: translateY(-12px) } }
@keyframes wiggle { 0%, 100% { transform: rotate(-5deg) } 50% { transform: rotate(5deg) } }
@keyframes pop-in { 0% { transform: scale(.6); opacity: 0 } 100% { transform: scale(1); opacity: 1 } }
@keyframes confetti-fall { 0% { transform: translateY(-10px) rotate(0) } 100% { transform: translateY(105vh) rotate(340deg) } }
@keyframes dot-bounce { 0%, 100% { transform: translateY(0) } 50% { transform: translateY(-10px) } }
@keyframes fade-in { from { opacity: 0 } }

#bg3d { position: fixed; inset: 0; z-index: 0; pointer-events: none; opacity: .4; }

/* ---------- hero / nav ---------- */
.hero { position: relative; z-index: 1; padding: 0 clamp(16px, 4vw, 40px); }
.nav { display: flex; align-items: center; justify-content: space-between; padding: 20px 0; }
.logo { font-size: 26px; display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.logo-icon { display: inline-block; animation: wiggle 3.2s ease-in-out infinite; }
.logo-text { display: flex; flex-direction: column; line-height: 1.05; }
.logo-sub {
  font-family: var(--font-body); font-size: 11px; font-weight: 600;
  color: var(--ink-soft); letter-spacing: .03em;
}
@media (max-width: 480px) { .logo { font-size: 21px; } .logo-sub { font-size: 9.5px; } }
.grad { background: var(--grad-brand); -webkit-background-clip: text; background-clip: text; color: transparent; }
.pill {
  font-size: var(--fs-sm); color: var(--ink-soft); font-weight: 600;
  border: 1px solid var(--line); border-radius: var(--r-full); padding: 8px 16px;
  background: var(--surface);
}
a.pill { text-decoration: none; }
.crumb { font-size: var(--fs-sm); color: var(--ink-soft); }
.crumb a { color: var(--grape-deep); text-decoration: none; }
.crumb a:hover { color: var(--grape); text-decoration: underline; }
.hero-inner { position: relative; max-width: 780px; margin: 0 auto; text-align: center; padding: clamp(20px, 4vh, 40px) 0 8px; }
.hero h1 { font-size: var(--fs-hero); line-height: 1.05; }
.tagline { color: var(--ink-soft); font-size: var(--fs-lg); margin: 14px auto 26px; max-width: 560px; }

.float-emoji { position: absolute; font-size: clamp(1.7rem, 4vw, 2.1rem); pointer-events: none; animation: floaty 5s ease-in-out infinite; }
.float-emoji:nth-child(1) { left: -7%; top: 2%; }
.float-emoji:nth-child(2) { right: -7%; top: 10%; animation-duration: 6.5s; animation-delay: .8s; }
.float-emoji:nth-child(3) { left: -4%; bottom: 4%; animation-delay: 2.1s; }
.float-emoji:nth-child(4) { right: -5%; bottom: 0; animation-duration: 6.5s; animation-delay: 3s; }
@media (max-width: 900px) { .float-emoji { display: none; } }
@media (max-width: 480px) { .float-emoji { display: none; } }

/* search — 56px pill with clear button */
.search-wrap { position: relative; max-width: 520px; margin: 0 auto; }
.search-ico { position: absolute; left: 20px; top: 50%; translate: 0 -50%; width: 18px; color: var(--ink-soft); }
#search {
  width: 100%; height: 56px; padding: 0 52px;
  font-size: var(--fs-md); color: var(--ink);
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--r-full);
  outline: none; box-shadow: var(--shadow-sm);
  transition: border-color var(--t-med) var(--ease-out), box-shadow var(--t-med) var(--ease-out);
}
#search::placeholder { color: #A9A1BE; }
#search:hover { border-color: #C9B8FF; }
#search:focus { border-color: var(--grape); box-shadow: 0 0 0 4px rgba(124, 92, 255, .18); }
.search-clear {
  position: absolute; right: 12px; top: 50%; translate: 0 -50%;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--grape-tint); border: none; color: var(--grape-deep);
  font-weight: 700; font-size: 14px; display: grid; place-items: center;
}
.search-clear[hidden] { display: none; }

/* chips — 40px, emoji prefix, selected = grape fill */
.chips { display: flex; gap: 10px; justify-content: center; margin: 20px 0 6px; overflow-x: auto; scrollbar-width: none; padding: 4px; }
.chips::-webkit-scrollbar { display: none; }
@media (max-width: 640px) { .chips { justify-content: flex-start; } }
.chip {
  height: 40px; flex: none; display: inline-flex; align-items: center; padding: 0 18px;
  border: 2px solid var(--line); background: var(--surface);
  color: var(--ink); border-radius: var(--r-full);
  font-size: var(--fs-sm); font-weight: 600;
  transition: all var(--t-fast) var(--ease-out);
}
.chip:hover { background: #F8F5FF; border-color: #C9B8FF; }
.chip.active {
  background: var(--grape); border-color: var(--grape); color: #fff;
  box-shadow: 0 4px 12px rgba(124, 92, 255, .30);
  animation: pop-in var(--t-fast) var(--ease-out);
}

/* ---------- grid of cards ---------- */
main { position: relative; z-index: 1; padding: 20px clamp(16px, 4vw, 40px) 40px; max-width: 1280px; margin: 0 auto; }
.grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 7px;
  text-align: center; color: inherit; text-decoration: none; cursor: pointer;
  background: var(--surface); border: 2px solid transparent; border-radius: 20px;
  padding: 20px 12px 16px;
  box-shadow: var(--shadow-sm);
  transition: all var(--t-med) var(--ease-out);
  animation: pop-in .3s var(--ease-out) backwards;
}
.card:hover, .card:focus-visible {
  transform: translateY(-4px);
  border-color: var(--grape);
  box-shadow: 0 10px 24px rgba(124, 92, 255, .18);
}
.card:focus-visible { box-shadow: var(--ring); }
.card:hover .card-emoji { animation: wiggle 1.6s ease-in-out infinite; }
.card:active { transform: translateY(-1px) scale(.98); }
.card-emoji {
  width: 56px; height: 56px; border-radius: var(--r-lg);
  display: flex; align-items: center; justify-content: center; font-size: 30px;
}
.card-title { font-family: var(--font-display); font-weight: 600; font-size: 15px; line-height: 1.2; }
.card-cat { font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-soft); }
.card-best { font-size: 12px; font-weight: 600; background: var(--sun-tint); color: var(--ink); border-radius: var(--r-full); padding: 3px 10px; }
.card-3d { position: absolute; top: 10px; right: 10px; font-size: 10px; font-weight: 800; letter-spacing: .08em; background: var(--grad-brand); color: #fff; border-radius: 7px; padding: 3px 7px; }
.empty { text-align: center; padding: 40px 32px 48px; }
.empty .empty-emoji { font-size: 52px; display: block; margin-bottom: 8px; }
.empty .empty-title { font-family: var(--font-display); font-weight: 600; font-size: var(--fs-xl); display: block; margin-bottom: 6px; }
.empty p { color: var(--ink-soft); margin-bottom: 18px; }

/* ---------- footer ---------- */
.footer { position: relative; z-index: 1; background: var(--surface); border-top: 1px solid var(--line); text-align: center; color: var(--ink-soft); font-size: 13px; padding: 24px 16px 28px; }
.footer a { color: var(--grape-deep); text-decoration: none; }
.footer a:hover { color: var(--grape); text-decoration: underline; }
.footer-links { display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: center; max-width: 1000px; margin: 0 auto 12px; }
.footer-links a { line-height: 2.2; }

/* ---------- SEO content / FAQ ---------- */
.seo-section { max-width: 780px; margin: 56px auto 0; color: var(--ink-soft); line-height: 1.7; }
.seo-section h2 { color: var(--ink); margin: 28px 0 12px; font-size: 26px; }
.seo-section a { color: var(--grape-deep); text-decoration: none; font-weight: 600; }
.seo-section a:hover { color: var(--grape); text-decoration: underline; }
.seo-section details { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 18px; margin-bottom: 8px; transition: border-color var(--t-med); }
.seo-section details[open] { border: 2px solid #C9B8FF; }
.seo-section summary { cursor: pointer; font-weight: 600; color: var(--ink); list-style: none; display: flex; justify-content: space-between; align-items: center; }
.seo-section summary::after { content: '▸'; color: var(--grape-deep); transition: transform var(--t-med) var(--ease-out); }
.seo-section details[open] summary::after { transform: rotate(90deg); }
.seo-section details p { margin-top: 10px; }

/* ---------- game overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; flex-direction: column;
  animation: fade-in var(--t-slow) var(--ease-out);
}
.overlay[hidden] { display: none; }
.overlay-bar {
  display: flex; align-items: center; gap: 14px;
  height: 64px; padding: 10px clamp(12px, 3vw, 24px);
  background: var(--surface); box-shadow: 0 1px 0 var(--line);
}
.overlay-title {
  flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 10px;
  font-family: var(--font-display); font-weight: 600; font-size: 21px;
}
.overlay-title span:first-child { font-size: 24px; }
.overlay-score {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--grape-tint); border-radius: 14px; padding: 8px 16px;
  font-family: var(--font-display); font-weight: 600; font-size: var(--fs-md);
  white-space: nowrap;
}
.overlay-score:empty { display: none; }

/* back button — ghost pill, arrow nudges on hover */
.back-btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 44px; padding: 0 16px; flex: none;
  border: 2px solid var(--line); border-radius: var(--r-full);
  background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 15px;
  transition: all var(--t-fast) var(--ease-out);
}
.back-btn svg { width: 18px; height: 18px; transition: transform var(--t-fast) var(--ease-out); }
.back-btn:hover { border-color: var(--grape); background: var(--grape-tint); color: var(--grape-deep); }
.back-btn:hover svg { transform: translateX(-2px); }
.back-btn:active { transform: scale(.96); }
@media (max-width: 430px) { .back-btn span { display: none; } .back-btn { width: 44px; padding: 0; justify-content: center; border-radius: 50%; } }

.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface); border: 2px solid var(--line);
  color: var(--ink);
  transition: all var(--t-fast) var(--ease-out);
}
.icon-btn svg { width: 19px; height: 19px; }
.icon-btn:hover { border-color: var(--grape); background: var(--grape-tint); color: var(--grape-deep); }
.icon-btn:active { transform: rotate(-45deg) scale(.94); }
.icon-btn.muted { opacity: .55; }

.stage {
  flex: 1; overflow: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: var(--sp-4); gap: var(--sp-4);
  touch-action: manipulation;
}

/* loading & error states */
.load-dots { display: inline-flex; gap: 8px; }
.load-dots span { width: 12px; height: 12px; border-radius: 50%; animation: dot-bounce 1s ease-in-out infinite; }
.load-dots span:nth-child(1) { background: var(--grape); }
.load-dots span:nth-child(2) { background: var(--pink); animation-delay: .15s; }
.load-dots span:nth-child(3) { background: var(--sun); animation-delay: .3s; }
.load-msg { font-family: var(--font-display); font-weight: 600; font-size: 17px; color: var(--ink); }
.error-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl);
  padding: var(--sp-5); max-width: 340px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center;
  box-shadow: var(--shadow-md);
}
.error-card .err-emoji { font-size: 40px; }
.error-card .err-title { font-family: var(--font-display); font-weight: 600; font-size: 19px; }
.error-card p { font-size: var(--fs-sm); color: var(--ink-soft); line-height: 1.5; }
.error-card .row { display: flex; gap: 10px; margin-top: 6px; }

/* ---------- shared game widgets ---------- */
/* canvas frame recipe: white mat + inner radius */
.gcanvas {
  width: 100%; height: auto; display: block;
  border-radius: var(--r-lg);
  background: var(--bg2);
  border: 10px solid var(--surface);
  box-shadow: var(--shadow-md);
  touch-action: none;
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 24px;
  background: var(--grape); color: #fff;
  border: none; border-radius: var(--r-full);
  font-weight: 600; font-size: 15px;
  box-shadow: 0 4px 12px rgba(124, 92, 255, .35);
  transition: all var(--t-fast) var(--ease-out);
}
.btn:hover { background: var(--grape-deep); transform: translateY(-2px); box-shadow: 0 8px 20px rgba(124, 92, 255, .42); }
.btn:active { transform: scale(.96); background: #5A3FD0; }
.btn:disabled { background: var(--line); color: #A9A1BE; box-shadow: none; transform: none; }
.btn.ghost { background: transparent; color: var(--ink); border: 2px solid #E5DCCC; box-shadow: none; }
.btn.ghost:hover { border-color: var(--grape); color: var(--grape-deep); background: var(--grape-tint); }
.hint { color: var(--ink-soft); font-size: var(--fs-sm); text-align: center; max-width: 440px; line-height: 1.5; }
.big-msg { font-size: var(--fs-xl); text-align: center; }
.stat-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.stat {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 12px 18px; text-align: center; min-width: 92px;
}
.stat b { display: block; font-family: var(--font-display); font-weight: 600; font-size: var(--fs-xl); color: var(--ink); }
.stat span { font-size: 11px; font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .07em; }

/* generic board grid */
.board { display: grid; gap: 8px; touch-action: manipulation; }
.cellbtn {
  display: grid; place-items: center;
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--r-md);
  font-weight: 800; transition: all var(--t-fast) var(--ease-out);
  user-select: none;
}
.cellbtn:hover { border-color: var(--grape); }
.cellbtn:active { transform: scale(.94); }

/* on-screen keyboard — color + corner glyph, never color alone */
.kb { display: flex; flex-direction: column; gap: 6px; align-items: center; width: 100%; max-width: 500px; }
.kb-row { display: flex; gap: 5px; justify-content: center; width: 100%; }
.kb-key {
  position: relative;
  flex: 1; max-width: 44px; height: 48px;
  background: var(--surface); border: 2px solid #E5DCCC; border-radius: var(--r-sm);
  font-weight: 700; font-size: var(--fs-md); text-transform: uppercase;
  display: grid; place-items: center; transition: all var(--t-fast) var(--ease-out);
}
.kb-key.wide { max-width: 70px; flex: 1.6; font-size: 12px; }
.kb-key:active { transform: translateY(2px); background: var(--grape-tint); border-color: var(--grape); }
.kb-key.ok, .kb-key.near, .kb-key.no { border-color: transparent; }
.kb-key.ok { background: var(--leaf); color: #fff; }
.kb-key.near { background: var(--sun); color: var(--ink); }
.kb-key.no { background: #DDD8E4; color: #8A8399; }
.kb-key.ok::after, .kb-key.near::after, .kb-key.no::after {
  position: absolute; bottom: 2px; right: 4px; font-size: 9px;
}
.kb-key.ok::after { content: '✓'; }
.kb-key.near::after { content: '•'; }
.kb-key.no::after { content: '✕'; }

/* touch d-pad */
.dpad { display: grid; grid-template-columns: repeat(3, 60px); gap: 7px; justify-content: center; }
.dpad button {
  height: 52px; font-size: 18px; border-radius: 14px;
  background: var(--surface); border: 2px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.dpad button:active { background: var(--grape); border-color: var(--grape); color: #fff; transform: translateY(2px); box-shadow: none; }
.dpad .void { visibility: hidden; }
@media (hover: hover) and (pointer: fine) { .dpad { display: none; } }

/* results banners — win / lose (kind!) / new best */
.banner {
  padding: var(--sp-4) var(--sp-5); border-radius: 20px; text-align: center;
  font-size: var(--fs-xl);
  background: var(--surface); border: 2px solid var(--line);
  animation: pop-in var(--t-slow) var(--ease-spring);
}
.banner.win { background: var(--leaf-tint); border-color: var(--leaf); }
.banner.lose { background: var(--pink-tint); border-color: var(--pink); }
.banner.best { background: var(--sun-tint); border-color: var(--sun); }

/* confetti burst */
.confetti-box { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 70; }
.confetti-box span { position: absolute; top: -14px; border-radius: 2px; }

/* ---------- standalone game pages ---------- */
.game-page .page-main { position: relative; z-index: 1; max-width: 900px; margin: 0 auto; padding: 10px clamp(16px, 4vw, 36px) 40px; }
.game-page h1 { font-size: clamp(28px, 5vw, var(--fs-h1)); line-height: 1.1; text-align: center; margin-bottom: 12px; }
.game-page .tagline { text-align: center; margin: 0 auto 20px; max-width: 640px; }
.page-hud {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  max-width: 640px; margin: 0 auto 20px; height: 56px; padding: 0 10px 0 24px;
  background: var(--surface); border-radius: var(--r-full); box-shadow: var(--shadow-sm);
}
.page-hud span { font-family: var(--font-display); font-weight: 600; font-size: var(--fs-md); color: var(--ink); }
.stage-page {
  background: transparent; border: none; border-radius: var(--r-xl);
  min-height: 340px; padding: 8px 0 16px; box-shadow: none;
}
.page-section { margin-top: var(--sp-6); color: var(--ink-soft); line-height: 1.6; max-width: 720px; margin-left: auto; margin-right: auto; }
.page-section h2 { color: var(--ink); font-size: 26px; margin-bottom: 12px; }
.page-section ul { padding-left: 22px; }
.page-section li { margin-bottom: 8px; font-size: var(--fs-md); }
.rel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.rel-card {
  display: flex; flex-direction: column; align-items: center; gap: 7px; text-align: center;
  background: var(--surface); border: 2px solid transparent; border-radius: 20px; padding: 18px 12px 14px;
  color: var(--ink); text-decoration: none; box-shadow: var(--shadow-sm);
  transition: all var(--t-med) var(--ease-out);
}
.rel-card:hover { transform: translateY(-4px); border-color: var(--grape); box-shadow: 0 10px 24px rgba(124, 92, 255, .18); }
.rel-card span { width: 52px; height: 52px; border-radius: var(--r-lg); background: var(--grape-tint); display: flex; align-items: center; justify-content: center; font-size: 28px; }
.rel-card b { font-family: var(--font-display); font-weight: 600; font-size: 15px; }

/* reserved ad slot — hard-sized, zero layout shift */
.ad-slot {
  position: relative; width: 728px; height: 90px; max-width: 100%;
  margin: 28px auto 0;
  background: #FBF4E7; border: 1px dashed #E3D6BE; border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: #B7A98C;
}
.ad-slot::before { content: 'AD'; position: absolute; top: 6px; left: 10px; font-size: 10px; font-weight: 700; letter-spacing: .1em; }
@media (max-width: 768px) { .ad-slot { width: 320px; height: 100px; } }

@media (max-width: 560px) {
  .grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stage { padding: 10px; }
  .overlay-bar { height: 56px; }
}
@media (prefers-reduced-motion: reduce) {
  :root { --t-fast: 1ms; --t-med: 1ms; --t-slow: 1ms; }
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
  #bg3d { display: none; }
  .confetti-box { display: none; }
}
