/* squigo.css — the paper-craft design system for the kid-facing surface (home, categories,
   games, the grown-ups gate, and the shell-owned game chrome that sits on the play surface).
   This is Squigo's own identity. AppCaddy tokens are NOT used here; they live in shell.css and
   apply only to the grown-up settings panel. Recreated from the Paper-craft design handoff. */

/* Baloo 2, self-hosted. Latin subset is a variable woff2 spanning weights 500-800. No CDN. */
@font-face {
  font-family: 'Baloo 2';
  font-style: normal;
  font-weight: 500 800;
  font-display: swap;
  src: url('../../assets/fonts/Baloo2-Latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Baloo 2';
  font-style: normal;
  font-weight: 500 800;
  font-display: swap;
  src: url('../../assets/fonts/Baloo2-LatinExt.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* Paper surface (light) */
  --sq-bg: #f1e6d3;
  --sq-grain: rgba(150, 120, 80, 0.06);
  --sq-ink: #463a2d;
  --sq-ink-2: #5c4d3d;
  --sq-muted: #8a7358;
  --sq-faint: #a08a6e;
  --sq-cream: #f7efe0;
  --sq-cream-2: #f8f2e6;
  --sq-cream-3: #f8f0e1;
  --sq-cream-deep: #efe3cd;
  --sq-cream-deeper: #e3d4b8;
  --sq-hairline: #d8cbb4;
  --sq-dashed: #b7a184;
  --sq-badge-cream: #f7efe0;

  --sq-shadow-card: 0 8px 14px rgba(70, 58, 45, 0.22);
  --sq-shadow-sm: 0 3px 5px rgba(70, 58, 45, 0.18);
  --sq-shadow-chip: 0 3px 6px rgba(70, 58, 45, 0.14);
  --sq-inset-hi: inset 0 1.5px 0 rgba(255, 255, 255, 0.28);

  /* Category accents (base only; tints/darks are set per tile class below) */
  --sq-coral: #e88a6a;
  --sq-mustard: #e6b23e;
  --sq-sage: #86a86f;
  --sq-plum: #9d6f9e;
  --sq-blue: #6d96b8;
  --sq-teal: #4fa88f;

  --sq-radius-tile: 22px;
  --sq-font: 'Baloo 2', system-ui, -apple-system, sans-serif;
}

/* Bedtime / wind-down (dark) — forced */
[data-theme='dark'] {
  --sq-bg: #241f19;
  --sq-grain: rgba(255, 235, 200, 0.05);
  --sq-ink: #f0e6d5;
  --sq-ink-2: #cbb896;
  --sq-muted: #c9b799;
  --sq-faint: #7d6b52;
  --sq-cream: #332b22;
  --sq-cream-2: #2e2820;
  --sq-cream-3: #332b22;
  --sq-cream-deep: #332b22;
  --sq-cream-deeper: #3a3026;
  --sq-hairline: #3a3026;
  --sq-dashed: #5f513c;
  --sq-badge-cream: #f0e2cc;

  --sq-shadow-card: 0 8px 16px rgba(0, 0, 0, 0.4);
  --sq-shadow-sm: 0 3px 5px rgba(0, 0, 0, 0.3);
  --sq-shadow-chip: 0 3px 6px rgba(0, 0, 0, 0.35);
  --sq-inset-hi: inset 0 1.5px 0 rgba(255, 255, 255, 0.18);
}
/* Dark — automatic when no explicit theme is forced */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']):not([data-theme='dark']) {
    --sq-bg: #241f19;
    --sq-grain: rgba(255, 235, 200, 0.05);
    --sq-ink: #f0e6d5;
    --sq-ink-2: #cbb896;
    --sq-muted: #c9b799;
    --sq-faint: #7d6b52;
    --sq-cream: #332b22;
    --sq-cream-2: #2e2820;
    --sq-cream-3: #332b22;
    --sq-cream-deep: #332b22;
    --sq-cream-deeper: #3a3026;
    --sq-hairline: #3a3026;
    --sq-dashed: #5f513c;
    --sq-badge-cream: #f0e2cc;
    --sq-shadow-card: 0 8px 16px rgba(0, 0, 0, 0.4);
    --sq-shadow-sm: 0 3px 5px rgba(0, 0, 0, 0.3);
    --sq-shadow-chip: 0 3px 6px rgba(0, 0, 0, 0.35);
    --sq-inset-hi: inset 0 1.5px 0 rgba(255, 255, 255, 0.18);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #d9cdb4;
  color: var(--sq-ink);
  font-family: var(--sq-font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
[data-theme='dark'] body { background: #17130e; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']):not([data-theme='dark']) body { background: #17130e; }
}

/* The app is a single portrait canvas, centered and phone-width on larger screens. */
#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background-color: var(--sq-bg);
  background-image: radial-gradient(var(--sq-grain) 1px, transparent 1.4px);
  background-size: 9px 9px;
}

.sq-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(22px + env(safe-area-inset-top)) 20px calc(16px + env(safe-area-inset-bottom));
}

/* ---- Wordmark + squiggle ---- */
.sq-wordmark-name {
  font-weight: 800;
  font-size: 32px;
  line-height: 0.9;
  letter-spacing: -0.5px;
  color: var(--sq-ink);
}
.sq-squiggle { display: block; margin-top: 2px; }
.sq-home-head .sq-squiggle,
.sq-gate .sq-squiggle { animation: sqwob 5s ease-in-out infinite; }

/* ---- Home ---- */
.sq-home-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
}
.sq-trust {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--sq-cream-3);
  border-radius: 20px;
  padding: 6px 10px;
  box-shadow: var(--sq-shadow-chip);
  transform: rotate(2deg);
}
.sq-trust-check {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--sq-teal); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 800;
}
.sq-trust-text { font-weight: 700; font-size: 9.5px; color: var(--sq-ink-2); }

.sq-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  flex: 1;
  align-content: start;
}

.sq-tile {
  border: 0;
  cursor: pointer;
  font-family: inherit;
  background: var(--tile-accent);
  border-radius: 22px 20px 24px 21px;
  padding: 15px 10px 13px;
  box-shadow: var(--sq-shadow-card), var(--sq-inset-hi);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  transition: transform 120ms ease-out;
}
/* Hand-placed rotations + varied corners for the cut-paper feel. */
.sq-tile:nth-child(1) { transform: rotate(-1.4deg); border-radius: 22px 20px 24px 21px; }
.sq-tile:nth-child(2) { transform: rotate(1.3deg); border-radius: 20px 23px 20px 24px; }
.sq-tile:nth-child(3) { transform: rotate(1.1deg); border-radius: 23px 20px 21px 23px; }
.sq-tile:nth-child(4) { transform: rotate(-1.2deg); border-radius: 20px 24px 20px 22px; }
.sq-tile:nth-child(5) { transform: rotate(1.4deg); border-radius: 24px 20px 22px 20px; }
.sq-tile:nth-child(6) { transform: rotate(-1.3deg); border-radius: 21px 23px 20px 24px; }
.sq-tile:active { transform: scale(0.96); }

.sq-badge {
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--sq-badge-cream);
  box-shadow: var(--sq-shadow-sm);
  display: flex; align-items: center; justify-content: center;
  animation: sqbob 4.2s ease-in-out infinite;
}
.sq-tile:nth-child(1) .sq-badge { animation-delay: 0s; }
.sq-tile:nth-child(2) .sq-badge { animation-delay: 0.4s; }
.sq-tile:nth-child(3) .sq-badge { animation-delay: 0.8s; }
.sq-tile:nth-child(4) .sq-badge { animation-delay: 1.2s; }
.sq-tile:nth-child(5) .sq-badge { animation-delay: 1.6s; }
.sq-tile:nth-child(6) .sq-badge { animation-delay: 2s; }

.sq-tile-label {
  font-weight: 700;
  font-size: 14.5px;
  color: #fbf5ea;
  text-shadow: 0 1px 1px rgba(70, 58, 45, 0.25);
}

/* Category accent triples used by tiles and icons. */
.tile--coral   { --tile-accent: #e88a6a; --tile-tint: #f0a98f; --tile-dark: #d9795c; }
.tile--mustard { --tile-accent: #e6b23e; --tile-tint: #f0c968; --tile-dark: #c99a1f; }
.tile--sage    { --tile-accent: #86a86f; --tile-tint: #a7c493; --tile-dark: #6c8f57; }
.tile--plum    { --tile-accent: #9d6f9e; --tile-tint: #bb93bc; --tile-dark: #82577f; }
.tile--blue    { --tile-accent: #6d96b8; --tile-tint: #93b6d1; --tile-dark: #547b9a; }
.tile--teal    { --tile-accent: #4fa88f; --tile-tint: #7cc3ad; --tile-dark: #3a8d75; }
[data-theme='dark'] .tile--coral   { --tile-accent: #d9795c; --tile-tint: #e79a80; --tile-dark: #b5644a; }
[data-theme='dark'] .tile--mustard { --tile-accent: #d19b34; --tile-tint: #e0b45a; --tile-dark: #a87c1f; }
[data-theme='dark'] .tile--sage    { --tile-accent: #6f9060; --tile-tint: #93b183; --tile-dark: #58734b; }
[data-theme='dark'] .tile--plum    { --tile-accent: #8a5f8c; --tile-tint: #a87faa; --tile-dark: #6f4b70; }
[data-theme='dark'] .tile--blue    { --tile-accent: #5c84a6; --tile-tint: #7ea3c1; --tile-dark: #476a86; }
[data-theme='dark'] .tile--teal    { --tile-accent: #3f9079; --tile-tint: #63b099; --tile-dark: #2f735f; }

.sq-home-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
}
.sq-grownups-link {
  border: 0; background: transparent; cursor: pointer;
  font-family: inherit; font-weight: 700; font-size: 11px;
  color: var(--sq-faint);
  padding: 4px 10px;
}
.sq-credit {
  text-align: center;
  font-weight: 700; font-size: 10px; letter-spacing: 0.02em;
  color: var(--sq-faint);
}

/* ---- Category screen ---- */
.sq-cat-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.sq-cat-title {
  flex: 1;
  background: var(--tile-accent);
  border-radius: 16px;
  padding: 10px 16px;
  color: #fbf5ea;
  font-weight: 700; font-size: 18px;
  text-shadow: 0 1px 1px rgba(70, 58, 45, 0.2);
  transform: rotate(-0.6deg);
  box-shadow: var(--sq-shadow-sm);
}
.sq-game-list {
  display: flex; flex-direction: column; gap: 12px; flex: 1;
  overflow-y: auto;
  padding: 2px 2px 12px; /* room for card shadows and rotation inside the scroll clip */
  -webkit-overflow-scrolling: touch;
}
.sq-game-card {
  display: flex; align-items: center; gap: 14px;
  border: 0; cursor: pointer; text-align: left;
  font-family: inherit;
  background: var(--sq-cream-2);
  border-radius: 18px;
  padding: 14px 16px;
  box-shadow: 0 6px 12px rgba(70, 58, 45, 0.14);
  transition: transform 120ms ease-out;
}
[data-theme='dark'] .sq-game-card { box-shadow: 0 6px 12px rgba(0, 0, 0, 0.35); }
.sq-game-card:active { transform: scale(0.98); }
.sq-game-dot {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  background: var(--tile-accent, var(--sq-teal));
  box-shadow: var(--sq-inset-hi), var(--sq-shadow-sm);
}
.sq-game-title { font-weight: 700; font-size: 16px; color: var(--sq-ink); }
.sq-game-blurb { font-weight: 600; font-size: 12px; color: var(--sq-muted); }
.accent--coral   { --tile-accent: #e88a6a; }
.accent--mustard { --tile-accent: #e6b23e; }
.accent--sage    { --tile-accent: #86a86f; }
.accent--plum    { --tile-accent: #9d6f9e; }
.accent--blue    { --tile-accent: #6d96b8; }
.accent--teal    { --tile-accent: #4fa88f; }

.sq-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 6px; }
.sq-empty-title { font-weight: 800; font-size: 18px; color: var(--sq-ink); }
.sq-empty-sub { font-weight: 600; font-size: 13px; color: var(--sq-muted); }

/* ---- Exit control (matches the in-game exit position/style) ---- */
.sq-exit, .gh-exit {
  flex: none;
  width: 46px; height: 46px; border-radius: 50%;
  border: 0; cursor: pointer;
  background: var(--sq-cream-3);
  color: var(--sq-muted);
  box-shadow: 0 5px 9px rgba(70, 58, 45, 0.2), inset 0 1.5px 0 rgba(255, 255, 255, 0.4);
  font-size: 24px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  padding-right: 3px;
}
[data-theme='dark'] .sq-exit, [data-theme='dark'] .gh-exit {
  box-shadow: 0 5px 9px rgba(0, 0, 0, 0.4), inset 0 1.5px 0 rgba(255, 255, 255, 0.12);
}

/* ---- Game host chrome (shell-owned, on the play surface -> paper-craft) ---- */
.gh-root { position: absolute; inset: 0; }
.gh-stage { position: absolute; inset: 0; touch-action: none; }
.gh-exit {
  position: absolute;
  top: calc(18px + env(safe-area-inset-top));
  left: calc(16px + env(safe-area-inset-left));
  /* Above the loading/error layer (4) and the pause overlay (5): the way out must always be
     tappable, including on the "game did not open" error screen and during a slow load. */
  z-index: 6;
}
.gh-pause-btn {
  position: absolute;
  top: calc(18px + env(safe-area-inset-top));
  right: calc(16px + env(safe-area-inset-right));
  z-index: 3;
  width: 46px; height: 46px; border-radius: 50%;
  border: 0; cursor: pointer;
  background: var(--sq-cream-3); color: var(--sq-muted);
  box-shadow: 0 5px 9px rgba(70, 58, 45, 0.2), inset 0 1.5px 0 rgba(255, 255, 255, 0.4);
  font-size: 18px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
[data-theme='dark'] .gh-pause-btn { box-shadow: 0 5px 9px rgba(0, 0, 0, 0.4), inset 0 1.5px 0 rgba(255, 255, 255, 0.12); }

.gh-loading {
  position: absolute; inset: 0; z-index: 4;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background-color: var(--sq-bg);
  background-image: radial-gradient(var(--sq-grain) 1px, transparent 1.4px);
  background-size: 9px 9px;
  text-align: center; padding: 24px;
}
.gh-loading[hidden] { display: none; }
.gh-loading-title { font-weight: 800; font-size: 22px; color: var(--sq-ink); }
.gh-loading-sub { font-weight: 600; font-size: 13px; color: var(--sq-muted); }
.gh-bar { width: 160px; height: 10px; border-radius: 6px; background: var(--sq-cream-deep); overflow: hidden; }
.gh-bar-fill { height: 100%; width: 100%; transform: scaleX(0); transform-origin: left; background: var(--sq-teal); transition: transform 120ms ease-out; }

.gh-overlay {
  position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center;
  background: rgba(35, 30, 24, 0.55);
  padding: 24px;
}
.gh-overlay[hidden] { display: none; }
.gh-overlay-card {
  background: var(--sq-cream-2);
  border-radius: 24px;
  padding: 28px 24px;
  box-shadow: var(--sq-shadow-card);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  width: 100%; max-width: 280px;
}
.gh-overlay-title { font-weight: 800; font-size: 22px; color: var(--sq-ink); }
.gh-resume {
  border: 0; cursor: pointer; font-family: inherit;
  background: var(--sq-teal); color: #fff;
  font-weight: 800; font-size: 17px;
  border-radius: 16px; padding: 14px 22px; width: 100%;
  box-shadow: var(--sq-shadow-sm);
}
.gh-overlay-exit {
  border: 0; cursor: pointer; font-family: inherit;
  background: transparent; color: var(--sq-muted);
  font-weight: 700; font-size: 14px; padding: 6px 12px;
}

/* ---- Grown-ups gate ---- */
.sq-gate-head { display: flex; align-items: center; margin-bottom: 8px; }
.sq-gate-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; }
.sq-gate-lock {
  width: 44px; height: 30px; border-radius: 7px;
  background: var(--sq-mustard); position: relative; margin-bottom: 8px;
  box-shadow: 0 4px 8px rgba(70, 58, 45, 0.2);
}
.sq-gate-lock::before {
  content: ''; position: absolute; left: 50%; top: -18px; transform: translateX(-50%);
  width: 22px; height: 22px; border: 5px solid #c99a1f; border-bottom: none;
  border-radius: 12px 12px 0 0; box-sizing: border-box;
}
.sq-gate-lock::after {
  content: ''; position: absolute; left: 50%; top: 9px; transform: translateX(-50%);
  width: 7px; height: 9px; border-radius: 4px; background: #7a5f1a;
}
.sq-gate-title { font-weight: 800; font-size: 22px; color: var(--sq-ink); }
.sq-gate-sub { font-weight: 600; font-size: 13px; color: var(--sq-muted); max-width: 210px; line-height: 1.45; margin-bottom: 8px; }
.sq-gate-ring {
  width: 130px; height: 130px; border-radius: 50%;
  background: conic-gradient(var(--sq-coral) 0 var(--hold, 0%), var(--sq-cream-deeper) var(--hold, 0%) 100%);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 16px rgba(70, 58, 45, 0.2);
  cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: none;
}
.sq-gate-inner {
  width: 104px; height: 104px; border-radius: 50%;
  background: var(--sq-cream); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  box-shadow: inset 0 2px 5px rgba(70, 58, 45, 0.12);
}
.sq-gate-hold { font-weight: 800; font-size: 16px; color: #8a6a44; }
[data-theme='dark'] .sq-gate-hold { color: var(--sq-ink); }
.sq-gate-secs { font-weight: 600; font-size: 10px; color: var(--sq-faint); }
.sq-gate-help { font-weight: 600; font-size: 11px; color: var(--sq-faint); max-width: 200px; line-height: 1.45; margin-top: 14px; }

/* ---- Game kit (games/_kit/kit.js) ---- */
/* Platform-owned classes the kit base classes rely on, so every game gets them without
   spending its single injected stylesheet on boilerplate. */
.kit-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.kit-root { position: absolute; inset: 0; touch-action: manipulation; }
.kit-celebrate {
  position: absolute; left: 50%; top: 45%;
  pointer-events: none; z-index: 2;
}
.kit-celebrate-star {
  position: absolute; left: 0; top: 0;
  font-size: 26px; color: var(--sq-mustard);
  text-shadow: 0 1px 2px rgba(70, 58, 45, 0.3);
  animation: kitstar 1.1s ease-out forwards;
}
@keyframes kitstar {
  0% { transform: translate(0, 0) scale(0.4); opacity: 1; }
  100% { transform: translate(var(--dx, 0), var(--dy, -80px)) scale(1.2); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .kit-celebrate-star { animation: none; opacity: 1; transform: translate(0, -40px); }
}

/* ---- Focus ---- */
/* Visible keyboard focus everywhere, including the role="button" gate ring, which Safari never
   rings on its own. Pointer taps do not trigger :focus-visible, so the play surface stays clean. */
:focus-visible {
  outline: 3px solid var(--sq-teal);
  outline-offset: 3px;
}

/* ---- Motion ---- */
@keyframes sqwob { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }
@keyframes sqbob { 0%, 100% { transform: translateY(0) rotate(-1.5deg); } 50% { transform: translateY(-4px) rotate(1.5deg); } }

@media (prefers-reduced-motion: reduce) {
  .sq-squiggle, .sq-badge, .sq-home-head .sq-squiggle, .sq-gate .sq-squiggle { animation: none !important; }
  .sq-tile, .sq-game-card, .gh-bar-fill { transition: none !important; }
}
