/* the detached window (🪟, index.html?win=1): a real app window, not the 400x600 popup.
   Narrow (< 820px): the popup layout, filling the window.  Wide (>= 820px): an app - side rail, wide content, grids. */
html.hx-win, html.hx-win body { width: 100% !important; height: 100vh !important; max-width: none !important; }
html.hx-win .h-\[600px\] { height: 100vh !important; }
html.hx-win .w-\[400px\] { width: 100% !important; max-width: 1000px; margin: 0 auto; box-shadow: 0 0 0 1px rgba(99,102,241,.12), 0 0 60px rgba(0,0,0,.45); background: var(--color-bg); }
html.hx-win body { background-color: #080720 !important; }

@keyframes hxwFade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes hxwSlide { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }

@media (min-width: 820px) {
  /* full width: no empty side margins on a big screen */
  html.hx-win .w-\[400px\] { max-width: none !important; margin: 0 !important; box-shadow: none !important; background: transparent !important; }
  html.hx-win .w-\[400px\] > div { background: transparent !important; }

  /* ---- decoration: drifting colour glows + faint grid behind everything ---- */
  html.hx-win body {
    background-image:
      radial-gradient(1200px 700px at 8% -10%, rgba(99, 102, 241, .22), transparent 60%),
      radial-gradient(900px 600px at 105% 8%, rgba(236, 72, 153, .16), transparent 60%),
      radial-gradient(900px 700px at 60% 115%, rgba(59, 130, 246, .14), transparent 60%),
      linear-gradient(rgba(255, 255, 255, .025) 1px, transparent 1px),
      linear-gradient(90deg, rgba(255, 255, 255, .025) 1px, transparent 1px) !important;
    background-size: auto, auto, auto, 38px 38px, 38px 38px !important;
    background-attachment: fixed !important;
  }
  html.hx-win body::before, html.hx-win body::after {
    content: ""; position: fixed; z-index: 0; pointer-events: none; border-radius: 50%; filter: blur(90px); opacity: .5;
  }
  html.hx-win body::before { width: 520px; height: 520px; left: 30%; top: 22%; background: rgba(99, 102, 241, .28); animation: hxwDriftA 22s ease-in-out infinite alternate; }
  html.hx-win body::after { width: 440px; height: 440px; right: 8%; bottom: 6%; background: rgba(236, 72, 153, .22); animation: hxwDriftB 26s ease-in-out infinite alternate; }
  html.hx-win #root { position: relative; z-index: 1; }

  /* glass header + rail */
  html.hx-win .w-\[400px\] > div > :first-child { background: rgba(17, 24, 39, .62) !important; backdrop-filter: blur(14px); border-bottom: 1px solid rgba(99, 102, 241, .22); position: relative; }
  html.hx-win .w-\[400px\] > div > :first-child::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; background: linear-gradient(90deg, transparent, #6366f1, #ec4899, transparent); opacity: .7; animation: hxwShine 6s linear infinite; background-size: 200% 100%; }
  html.hx-win .w-\[400px\] > div > nav.hx-rail { background: rgba(17, 24, 39, .55) !important; backdrop-filter: blur(14px); }
  html.hx-win nav.hx-rail::after {
    content: "HEXA STORE · APP"; margin-top: auto; padding: 14px 8px 4px; text-align: center; font-size: 10px; font-weight: 800; letter-spacing: .16em;
    background: linear-gradient(90deg, #818cf8, #f472b6); -webkit-background-clip: text; background-clip: text; color: transparent;
    border-top: 1px solid rgba(255, 255, 255, .07); animation: hxwFade .8s .5s both;
  }
  /* cards: soft gradient + glow, staggered entrance */
  html.hx-win .hx-list > * { background-image: linear-gradient(135deg, rgba(99, 102, 241, .07), rgba(236, 72, 153, .04)) !important; animation: hxwFade .45s cubic-bezier(.2, .8, .2, 1) both; }
  html.hx-win .hx-list > button:hover { border-color: rgba(129, 140, 248, .7) !important; box-shadow: 0 10px 30px rgba(0, 0, 0, .4), 0 0 24px rgba(99, 102, 241, .22); }
  html.hx-win .hx-list > :nth-child(2) { animation-delay: .03s; } html.hx-win .hx-list > :nth-child(3) { animation-delay: .06s; }
  html.hx-win .hx-list > :nth-child(4) { animation-delay: .09s; } html.hx-win .hx-list > :nth-child(5) { animation-delay: .12s; }
  html.hx-win .hx-list > :nth-child(6) { animation-delay: .15s; } html.hx-win .hx-list > :nth-child(7) { animation-delay: .18s; }
  html.hx-win .hx-list > :nth-child(8) { animation-delay: .21s; } html.hx-win .hx-list > :nth-child(n+9) { animation-delay: .24s; }
  html.hx-win main { background: transparent; }
  html.hx-win main input, html.hx-win main select { backdrop-filter: blur(6px); }
  /* header on top across everything, rail on the left, the page fills the rest */
  html.hx-win .w-\[400px\] > div { display: grid !important; grid-template-columns: 220px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  html.hx-win .w-\[400px\] > div > :first-child { grid-column: 1 / -1; grid-row: 1; }
  html.hx-win .w-\[400px\] > div > main { grid-column: 2; grid-row: 2; min-height: 0; overflow: hidden; }
  html.hx-win .w-\[400px\] > div > main > * { animation: hxwFade .32s cubic-bezier(.2, .8, .2, 1) both; }
  html.hx-win .w-\[400px\] > div > nav.hx-rail {
    grid-column: 1; grid-row: 2; display: flex; flex-direction: column; gap: 6px; padding: 14px 10px; overflow-y: auto;
    border-top: 0; border-right: 1px solid var(--color-line); background: var(--color-panel);
  }
  html.hx-win nav.hx-rail .hx-tab {
    position: relative; flex-direction: row !important; justify-content: flex-start !important; align-items: center; gap: 14px;
    width: 100%; height: 48px; padding: 0 16px; border-radius: 12px; font-size: 14px; font-weight: 700;
    animation: hxwSlide .4s cubic-bezier(.2, .8, .2, 1) both; transition: background .18s ease, transform .18s ease;
  }
  html.hx-win nav.hx-rail .hx-tab:nth-child(1) { animation-delay: .02s; }
  html.hx-win nav.hx-rail .hx-tab:nth-child(2) { animation-delay: .06s; }
  html.hx-win nav.hx-rail .hx-tab:nth-child(3) { animation-delay: .10s; }
  html.hx-win nav.hx-rail .hx-tab:nth-child(4) { animation-delay: .14s; }
  html.hx-win nav.hx-rail .hx-tab:nth-child(5) { animation-delay: .18s; }
  html.hx-win nav.hx-rail .hx-tab:nth-child(6) { animation-delay: .22s; }
  html.hx-win nav.hx-rail .hx-tab:nth-child(7) { animation-delay: .26s; }
  html.hx-win nav.hx-rail .hx-tab:hover { background: rgba(255, 255, 255, .06); transform: translateX(3px); }
  html.hx-win nav.hx-rail .hx-tab.on { background: linear-gradient(90deg, rgba(99, 102, 241, .28), rgba(236, 72, 153, .14)); }
  html.hx-win nav.hx-rail .hx-tab-bar { position: absolute; left: 0; top: 22%; bottom: 22%; width: 3px; height: auto; border-radius: 3px; }
  /* every list becomes a responsive grid of cards */
  html.hx-win .hx-list { display: grid !important; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; align-content: start; padding: 4px 22px 22px !important; }
  html.hx-win .hx-list > * { margin: 0 !important; }
  html.hx-win .hx-list > .py-16, html.hx-win .hx-list > .py-10, html.hx-win .hx-list > :only-child { grid-column: 1 / -1; }
  html.hx-win .hx-list > button { transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
  html.hx-win .hx-list > button:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(0, 0, 0, .35); }
  html.hx-win main .overflow-y-auto { scrollbar-width: thin; }
}

/* preview in a normal browser tab (not the extension): drop the centred demo card */
html.hx-win .hexa-grid, html.hx-win .hexa-grid > div { display: block !important; padding: 0 !important; min-height: 0 !important; width: 100% !important; }
html.hx-win .hexa-grid p { display: none; }

@keyframes hxwDriftA { from { transform: translate(0, 0) scale(1); } to { transform: translate(140px, 90px) scale(1.25); } }
@keyframes hxwDriftB { from { transform: translate(0, 0) scale(1); } to { transform: translate(-160px, -70px) scale(1.2); } }
@keyframes hxwShine { from { background-position: 0 0; } to { background-position: 200% 0; } }
@media (prefers-reduced-motion: reduce) { html.hx-win body::before, html.hx-win body::after, html.hx-win * { animation: none !important; } }

/* ---- game page, wide window: the panel on the left, store cover + "is it profitable?" card on the right ---- */
@media (min-width: 820px) {
  html.hx-win .hx-gamegrid { display: grid; grid-template-columns: minmax(380px, 520px) minmax(0, 1fr); gap: 26px; align-items: start; padding: 6px 12px 22px; }
  html.hx-win .hx-ginfo { display: flex; flex-direction: column; gap: 16px; animation: hxwFade .5s .1s cubic-bezier(.2,.8,.2,1) both; }
  html.hx-win .hx-gcover { position: relative; border-radius: 18px; overflow: hidden; border: 1px solid rgba(129,140,248,.28); background: #0c1020; box-shadow: 0 18px 50px rgba(0,0,0,.45), 0 0 40px rgba(99,102,241,.16); min-height: 220px; }
  html.hx-win .hx-gcover img { display: block; width: 100%; max-height: 420px; object-fit: cover; }
  html.hx-win .hx-gcover-ph { display: flex; align-items: center; justify-content: center; height: 220px; font-size: 54px; opacity: .55; }
  html.hx-win .hx-gcover-meta { position: absolute; left: 0; right: 0; bottom: 0; padding: 40px 16px 14px; background: linear-gradient(transparent, rgba(5,7,13,.92)); }
  html.hx-win .hx-gtitle { font-size: 18px; font-weight: 800; color: #fff; }
  html.hx-win .hx-gchips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
  html.hx-win .hx-gchip { font-size: 11px; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: rgba(255,255,255,.1); color: #e2e8f0; }
  html.hx-win .hx-gprice { background: rgba(99,102,241,.4); } html.hx-win .hx-gsale { background: rgba(52,211,153,.3); color: #6ee7b7; } html.hx-win .hx-gwas { text-decoration: line-through; opacity: .7; }
  html.hx-win .hx-gverdict { position: relative; padding: 18px 20px; border-radius: 16px; border: 1px solid rgba(255,255,255,.1); background: linear-gradient(135deg, rgba(99,102,241,.12), rgba(236,72,153,.06)); }
  html.hx-win .hx-gverdict.good { border-color: rgba(52,211,153,.5); box-shadow: 0 0 34px rgba(52,211,153,.14); }
  html.hx-win .hx-gverdict.thin { border-color: rgba(251,191,36,.5); } html.hx-win .hx-gverdict.bad { border-color: rgba(248,113,113,.55); }
  html.hx-win .hx-gverdict-t { font-size: 20px; font-weight: 900; color: #fff; }
  html.hx-win .hx-gverdict-n { position: absolute; top: 14px; right: 20px; font-size: 34px; font-weight: 900; }
  html.hx-win .hx-grow { display: flex; justify-content: space-between; padding: 8px 0; border-top: 1px solid rgba(255,255,255,.07); font-size: 13px; color: #94a3b8; margin-top: 8px; }
  html.hx-win .hx-grow b { color: #fff; font-size: 15px; }
  html.hx-win .hx-gnote { margin-top: 8px; font-size: 11px; color: #64748b; }
}

/* ---- Confirm page, wide window: a focused, larger column in the middle instead of a 2000px-wide strip ---- */
@media (min-width: 820px) {
  html.hx-win .hx-page { height: 100%; overflow: hidden; display: flex; justify-content: center; }
  html.hx-win .hx-page > div { width: 100%; max-width: 940px; height: calc(100% / 1.2); zoom: 1.2; }
  html.hx-win .hx-page > div > div:first-child { padding-top: 22px; }
  html.hx-win .hx-page .rounded-xl.border, html.hx-win .hx-page .rounded-2xl.border { background-image: linear-gradient(135deg, rgba(99,102,241,.09), rgba(236,72,153,.04)); border-color: rgba(129,140,248,.28); box-shadow: 0 10px 30px rgba(0,0,0,.28); }
  html.hx-win .hx-page button { transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease; }
  html.hx-win .hx-page button:not(:disabled):hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(0,0,0,.3); }
}

/* every page wrapper must be exactly as tall as the area it sits in (popup and window alike), or the page's own scrolling has nothing to scroll inside */
.hx-page { height: 100%; min-height: 0; }

/* The Back row stays on screen while the page scrolls (popup, window, phone apps). It is the row that holds the Back button. */
main div:has(> button[title="رجوع"]), main div:has(> button[title="Back"]) {
  position: sticky; top: 0; z-index: 14; padding-top: .45rem; padding-bottom: .45rem;
  background: linear-gradient(rgba(10, 14, 23, .96) 80%, rgba(10, 14, 23, 0));
  backdrop-filter: blur(6px);
}
