/* Sunny Games - large, warm, high-contrast.

   The visual language, in one rule a player can learn:
     a dark outline that looks RAISED  = you can press it
     flat colour or plain text         = information
   Each game has its own colour (see "Game colours"); the rule is the same in all of them.

   Text never below ~19px, buttons never below 64px, colour never the only signal,
   nothing moves unless the player caused it, and no hover effects (tablets have no hover). */

/* Baloo 2 (SIL Open Font License, fonts/OFL.txt): one friendly, rounded face for both English
   and Hindi. Bundled, so it works offline and straight from the folder. */
@font-face {
  font-family: "Baloo 2";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("../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: 400 800;
  font-display: swap;
  src: url("../fonts/Baloo2-devanagari.woff2") format("woff2");
  unicode-range: U+0900-097F, U+1CD0-1CF9, U+200C-200D, U+20A8, U+20B9, U+20F0, U+25CC, U+A830-A839, U+A8E0-A8FF, U+11B00-11B09;
}

:root {
  /* Colour - surfaces */
  --color-bg: #FBF7F0;
  --color-surface: #FFFFFF;          /* pressable things and play surfaces */
  --color-surface-info: #F3ECDF;     /* information panels, never pressable */
  /* Colour - text (ratios are against --color-bg) */
  --color-ink: #1F2A44;              /* 13.4:1 */
  --color-ink-soft: #3D4966;         /* 8.4:1 */
  --color-on-action: #FFFFFF;        /* 8.4:1 on --color-action */
  /* Colour - lines */
  --color-line: #D9D0C1;             /* decoration only - never the edge of a control */
  --color-line-strong: #8A7F6D;      /* 3.7:1 - edges that must be seen */
  /* Colour - "you can press this". Navy by default; inside a game these follow its colour. */
  --navy: #1D4E89;
  --navy-pressed: #0F2D52;
  --navy-tint: #C9DAF0;
  --color-action: var(--navy);
  --color-action-pressed: var(--navy-pressed);
  --color-action-tint: var(--navy-tint);   /* pressed fill of white buttons */
  /* A game's own colour (set by [data-game], below):
       --accent        fills, card backs, pictures (>= 3:1 on cream)
       --accent-deep   text, edges, buttons - the only one white text sits on (>= 6:1)
       --accent-tint   surfaces (ink on it >= 11:1)
       --accent-wash   the page behind the game */
  --accent: var(--navy);
  --accent-deep: var(--navy);
  --accent-tint: #E4ECF7;
  --accent-pressed: var(--navy-pressed);
  --accent-wash: var(--color-bg);
  /* Colour - "done" */
  --color-done: #1F6B3F;             /* 6.5:1 with white */
  --color-done-tint: #D7EFDD;
  /* Colour - brand sun */
  --color-sun: #F5B301;
  --color-focus: #C2410C;            /* 4.9:1 */

  /* Type: rem at the 22px root (19px on phones). --text-body is the floor. */
  --font-ui: "Baloo 2", "Segoe UI", system-ui, -apple-system, Roboto, "Nirmala UI", "Kohinoor Devanagari", "Noto Sans Devanagari", Helvetica, Arial, sans-serif;
  --font-emoji: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
  --text-body: 1rem;
  --text-label: 1.1rem;              /* buttons, status, chips */
  --text-lead: 1.2rem;               /* sub-title, topic, panel text */
  --text-title: 1.45rem;             /* bar title, card title, level name */
  --text-heading: 1.8rem;            /* the task on the page: "Choose a level" */
  --text-display: 2.3rem;            /* "Sunny Games", "Well done!" */
  --leading-tight: 1.2;
  --leading-body: 1.5;

  /* Spacing (px on purpose: gaps must not balloon with the text size) */
  --space-1: 4px;  --space-2: 8px;  --space-3: 12px; --space-4: 16px; --space-5: 20px;
  --space-6: 24px; --space-7: 32px; --space-8: 40px;
  --target-min: 64px;
  --target-lg: 72px;

  /* Shape */
  --radius-sm: 8px;                  /* chips, keyboard cursor */
  --radius-md: 20px;                 /* everything pressable, the letter grid */
  --radius-lg: 28px;                 /* containers: cards, panels */
  --radius-xl: 36px;                 /* the big game tiles on the home page */
  --border-thin: 2px;                /* information */
  --border: 3px;                     /* controls */
  --border-thick: 4px;               /* focus, matched */

  /* Elevation - hard edges only. A blurred shadow reads as a smudge with low vision. */
  --raise-action: 0 4px 0 var(--color-action-pressed);
  --raise-surface: 0 4px 0 var(--color-action);
  --raise-card: 0 4px 0 var(--color-line-strong);
  --raise-pressed: 0 1px 0;
  --press-shift: translateY(3px);

  /* Motion - every animation is started by the player, and all are removed by "reduce motion" */
  --motion-press: 80ms;
  --motion-state: 200ms;
  --motion-fade: 600ms;
}

/* ---------- Game colours ----------
   Contrast checked: accent-deep on cream / on its tint and white on accent-deep are all >= 5.3:1,
   accent on cream >= 3.6:1 (edges and pictures only). Setting data-game on an element re-points
   the "press this" colours, so every button, tile and pad in a game takes the game's colour. */

[data-game="wordsearch"] { --accent: #B8720A; --accent-deep: #6B4300; --accent-tint: #FFF1C9; --accent-pressed: #4A2E00; --accent-wash: #FFF9EA; }
[data-game="tilematch"]  { --accent: #1F8A8A; --accent-deep: #0E5C5C; --accent-tint: #D5F0EE; --accent-pressed: #083B3B; --accent-wash: #F2FAF8; }
[data-game="numbers"]    { --accent: #C8552F; --accent-deep: #8F3A1C; --accent-tint: #FFE3D8; --accent-pressed: #5E240F; --accent-wash: #FFF5F0; }
[data-game="pattern"]    { --accent: #7B4FB5; --accent-deep: #4C2A85; --accent-tint: #EADFF7; --accent-pressed: #321A5A; --accent-wash: #F8F3FC; }
[data-game="sorting"]    { --accent: #3A8A3A; --accent-deep: #1F6B3F; --accent-tint: #D7EFDD; --accent-pressed: #124528; --accent-wash: #F3FAF2; }
[data-game="colouring"]  { --accent: #C9457E; --accent-deep: #8E2A5C; --accent-tint: #FBE1EC; --accent-pressed: #5E1A3C; --accent-wash: #FFF5F9; }
[data-game="harmonium"]  { --accent: #A0652A; --accent-deep: #5E3814; --accent-tint: #F5E6D3; --accent-pressed: #3D230B; --accent-wash: #FCF6EF; }
[data-game="rangoli"]    { --accent: #1E86C8; --accent-deep: #0B4F7C; --accent-tint: #D8EDFB; --accent-pressed: #063352; --accent-wash: #F2F9FE; }
[data-game="chai"]       { --accent: #6E7D1F; --accent-deep: #45500F; --accent-tint: #EDF1D2; --accent-pressed: #2C340A; --accent-wash: #F8FAEE; }
[data-game="diya"]       { --accent: #4F57C4; --accent-deep: #2B3190; --accent-tint: #E2E4FA; --accent-pressed: #1B1F63; --accent-wash: #F4F5FD; }
/* The raised edges are re-declared too: a custom property that uses another is worked out where
   it is declared, so these would otherwise stay navy. */
[data-game], .bar-home {
  --raise-action: 0 4px 0 var(--color-action-pressed);
  --raise-surface: 0 4px 0 var(--color-action);
}
[data-game] {
  --color-action: var(--accent-deep);
  --color-action-pressed: var(--accent-pressed);
  --color-action-tint: var(--accent-tint);
}
body[data-game] { background: var(--accent-wash); }

/* Pictures drawn with the game's colours (see each game's illustration()) */
.fill-accent { fill: var(--accent); }
.fill-deep { fill: var(--accent-deep); }
.fill-tint { fill: var(--accent-tint); }
.stroke-deep { stroke: var(--accent-deep); }
.stroke-accent { stroke: var(--accent); }

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html {
  font-size: 137.5%; /* 22px, and still follows the browser's own text-size setting */
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: contain; /* no accidental pull-to-refresh */
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-ink);
  font-family: var(--font-ui);
  font-size: var(--text-body);
  font-weight: 500;
  line-height: var(--leading-body);
  touch-action: manipulation; /* no double-tap zoom surprises */
  -webkit-tap-highlight-color: transparent;
  /* A slow, heavy press must never bring up the system's selection bubble or link preview */
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

a { -webkit-user-drag: none; }

/* The app is a frame exactly the size of the screen, and every page fills it: nothing scrolls.
   Pictures and tiles flex to the space left over; words keep their size. When a page still does
   not fit, it takes away extras step by step (data-fit and .fit-1 ... in app.js / util.js). */
html, body { height: 100%; }
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* the visible screen, without the browser's own bars */
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-4);
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
#view, .screen, .stage { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
.stage[hidden], .screen[hidden] { display: none; }

h1, h2, p { margin: 0; }
h1, h2 { line-height: var(--leading-tight); }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}


.noscript { padding: var(--space-6); text-align: center; }

.icon { width: 1.25em; height: 1.25em; flex: none; }

/* ---------- Focus ---------- */

a:focus, button:focus {
  outline: var(--border-thick) solid var(--color-focus);
  outline-offset: 3px; /* the gap keeps the ring on the cream page, where it has contrast */
}
a:focus:not(:focus-visible), button:focus:not(:focus-visible) { outline: none; }
[tabindex="-1"]:focus { outline: none; }

/* The letter grid only shows a focus ring while it is being played by keyboard */
.ws-board:focus { outline: none; }
.ws-board.keys:focus { outline: var(--border-thick) solid var(--color-focus); outline-offset: 3px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: var(--target-min);
  padding: 10px 28px;
  border: var(--border) solid var(--color-action);
  border-radius: var(--radius-md);
  background: var(--color-action);
  box-shadow: var(--raise-action);
  color: var(--color-on-action);
  font: inherit;
  font-size: var(--text-label);
  font-weight: 700;
  line-height: var(--leading-tight);
  text-decoration: none;
  cursor: pointer;
  transition: transform var(--motion-press), box-shadow var(--motion-press), background-color var(--motion-press);
}
/* A press changes shape as well as colour: the button visibly goes down */
.btn:active, .btn.is-pressed {
  background: var(--color-action-pressed);
  border-color: var(--color-action-pressed);
  box-shadow: var(--raise-pressed) var(--color-action-pressed);
  transform: var(--press-shift);
}

.btn-lg { min-height: var(--target-lg); min-width: 240px; }

.btn-secondary { background: var(--color-surface); color: var(--color-action); box-shadow: var(--raise-surface); }
.btn-secondary:active, .btn-secondary.is-pressed {
  background: var(--color-action-tint);
  border-color: var(--color-action);
  box-shadow: var(--raise-pressed) var(--color-action);
}

/* In-game controls take the whole touch themselves, so a drifting finger is never
   mistaken for the start of a scroll (see SG.onTap) */
.bar-playing .btn, .ws-hint, .panel .btn, .tm-board { touch-action: none; }

/* ---------- Top bar ---------- */

.bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.bar > :first-child { justify-self: start; }
.bar > :last-child { justify-self: end; }
.bar-title { font-size: var(--text-title); text-align: center; }
.bar-home { --color-action: var(--navy); --color-action-pressed: var(--navy-pressed); --color-action-tint: var(--navy-tint); }
.bar-level { max-width: 42vw; }
.bar-level-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Choosers (Sound, playing hand) ---------- */

.chooser { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--space-3) var(--space-4); }
.chooser-label { font-size: var(--text-label); font-weight: 700; }
.chooser-options { display: flex; gap: var(--space-3); }
.chooser .btn { white-space: nowrap; }
.chooser .btn { padding-left: 20px; padding-right: 24px; }
.chooser .icon { visibility: hidden; } /* the tick's space is always kept, so choosing never moves anything */
.chooser [aria-pressed="true"] .icon { visibility: visible; }

/* ---------- Home ---------- */

.home { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: var(--space-4); }
.home-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.home-brand { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.sun { width: 54px; height: 54px; flex: none; }
.home-title { font-size: var(--text-display); font-weight: 800; }

/* One big tile per game: its picture and its name, in the game's own colour. The whole tile is
   the button - nothing else on it to read or aim for. The tiles share the screen: app.js picks
   3 x 2, 2 x 3... to suit its shape, and each picture fills what its tile has left. */
.tiles {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows, 2), minmax(0, 1fr));
  gap: var(--space-5);
  width: 100%;
  max-width: 1068px;
  margin: 0 auto;
  padding-bottom: 6px; /* room for the raised edge */
}
.tile {
  container-type: size; /* a wide, short tile puts its picture beside the name (below) */
  min-width: 0;
  min-height: 0;
  padding: var(--space-3);
  background: var(--accent-tint);
  border: var(--border) solid var(--accent-deep);
  border-radius: var(--radius-xl);
  box-shadow: 0 6px 0 var(--accent-deep);
  color: var(--accent-deep);
  text-align: center;
  text-decoration: none;
  transition: transform var(--motion-press), box-shadow var(--motion-press);
}
.tile:active, .tile.is-pressed { transform: translateY(5px); box-shadow: 0 1px 0 var(--accent-deep); }
.tile-inner { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-1); height: 100%; }
.tile-art { flex: 1 1 0; min-height: 0; width: 100%; max-width: 250px; display: flex; }
.tile-art .illus { width: 100%; height: 100%; }
/* The name is as big as its tile allows, never below reading size */
.tile-title { flex: none; font-size: clamp(19px, min(12cqh, 11cqw), 1.45rem); font-weight: 800; line-height: 1.15; }
@container (min-aspect-ratio: 2 / 1) {
  .tile-inner { flex-direction: row; gap: var(--space-3); }
  .tile-title { font-size: clamp(19px, min(22cqh, 9cqw), 1.45rem); }
  .tile-art { flex: 0 0 auto; width: auto; height: 100%; aspect-ratio: 4 / 3; }
  .tile-title { flex: 1 1 auto; text-align: left; }
}

/* The games' drawn pictures (home tile, How to play) */
.illus { display: block; width: 100%; height: auto; overflow: visible; }
.illus text { font-family: var(--font-ui); }

.home-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--space-3) var(--space-6); }

/* Too tall for the screen: tighter spacing, then fewer words around the tiles */
.home.fit-1 { gap: var(--space-2); }
.home.fit-1 .tiles { gap: var(--space-3); }
.home.fit-1 .sun { width: 40px; height: 40px; }
.home.fit-1 .home-title { font-size: var(--text-heading); }
.home.fit-2 .chooser-label { display: none; }
.home.fit-2 .tile-title { font-size: var(--text-label); }
.home.fit-3 .home-settings .btn-text { display: none; }
.home.fit-3 .tile { padding: var(--space-1) var(--space-2); border-radius: var(--radius-lg); }

/* A drawn hand acting out the move in a game's picture (SG.demoHand). It rests where the move ends;
   on the first-time page and in How to play it plays the move twice, and again when tapped. */
.demo-hand { transform-box: view-box; }
.demo-slide { transform: translate(var(--dx), var(--dy)); }
.demo-run .demo-tap { animation: demo-tap 2.4s ease-in-out 2 both; }
.demo-run .demo-slide { animation: demo-slide 3s ease-in-out 2 both; }
.demo-run .demo-fill { animation: demo-fill 2.4s step-end 2 both; }
.intro-art { cursor: pointer; }

@keyframes demo-tap {
  0% { transform: translate(18px, 22px); opacity: 0; }
  20% { opacity: 1; }
  45% { transform: translate(0, 0) scale(1); }
  55% { transform: translate(0, 0) scale(0.86); }
  68%, 100% { transform: translate(0, 0) scale(1); opacity: 1; }
}
@keyframes demo-slide {
  0% { transform: translate(0, 10px); opacity: 0; }
  15% { transform: translate(0, 0) scale(1); opacity: 1; }
  25% { transform: translate(0, 0) scale(0.9); }
  75% { transform: translate(var(--dx), var(--dy)) scale(0.9); }
  85%, 100% { transform: translate(var(--dx), var(--dy)) scale(1); opacity: 1; }
}
/* Colouring: the petal fills just as the finger presses it */
@keyframes demo-fill {
  0% { fill: #FFFFFF; }
  55%, 100% { fill: #E53935; }
}

/* ---------- Settings ---------- */

.settings { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-8); padding-bottom: var(--space-8); }
.settings .chooser { flex-direction: column; gap: var(--space-3); }
.settings .chooser-label { font-size: var(--text-title); }
.fit-1 .settings { flex-direction: row; flex-wrap: wrap; gap: var(--space-4) var(--space-8); padding-bottom: 0; }
.fit-2 .settings .chooser { flex-direction: row; }
.settings-note { max-width: 520px; color: var(--color-ink-soft); text-align: center; }
.fit-1 .settings-note { flex-basis: 100%; }

/* ---------- How to play (the first time a game is opened, and from its level page) ---------- */

/* The picture takes whatever room the words and the button leave */
.intro { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-4); width: 100%; max-width: 760px; margin: 0 auto; text-align: center; }
.intro-art { flex: 0 1 290px; min-height: 70px; width: 100%; max-width: 390px; display: flex; }
.intro-art .illus { width: 100%; height: 100%; }
.intro-words { flex: none; display: flex; flex-direction: column; align-items: center; gap: var(--space-3); }
.intro-title { font-size: var(--text-heading); color: var(--accent-deep); }
.intro-lines { display: grid; gap: var(--space-2); font-size: var(--text-lead); }
.intro-start { min-width: 280px; margin-top: var(--space-2); }
/* A wide, short screen: picture on one side, words on the other */
@media (orientation: landscape) and (max-height: 620px) {
  .intro { flex-direction: row; max-width: 1060px; gap: var(--space-6); }
  .intro-art { flex: 1 1 45%; max-width: none; height: 100%; min-height: 0; }
  .intro-words { flex: 1 1 55%; }
}
/* Too tall: the heading goes, then the last line of help, then the spacing tightens */
.fit-1 .intro-title { display: none; }
.fit-2 .intro-lines p:nth-child(n + 3) { display: none; }
.fit-3 .intro { gap: var(--space-2); }
.fit-3 .intro-start { min-height: var(--target-min); margin-top: 0; }
.fit-4 .intro-lines p:nth-child(n + 2) { display: none; }

/* ---------- Choose a level ---------- */

.levels-page { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; gap: var(--space-3); width: 100%; max-width: 1000px; margin: 0 auto; }
.levels-head { flex: none; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2) var(--space-4); }
.levels-title { font-size: var(--text-heading); color: var(--accent-deep); }
.levels-howto { margin-left: auto; }

/* The levels share the rest of the screen; app.js picks the columns to suit its shape */
.levels {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows, 3), minmax(0, 1fr));
  gap: var(--space-4);
  padding-bottom: 5px; /* room for the raised edge */
}
.level-btn {
  container-type: size; /* the inside is laid out by the card's own size, below */
  min-width: 0;
  min-height: var(--target-min); /* never squeezed below a button: the page tightens instead */
  background: var(--color-surface);
  border: var(--border) solid var(--color-action);
  border-radius: var(--radius-md);
  box-shadow: var(--raise-surface);
  color: inherit;
  text-decoration: none;
  overflow: hidden;
  transition: transform var(--motion-press), box-shadow var(--motion-press), background-color var(--motion-press);
}
.level-btn:active, .level-btn.is-pressed {
  background: var(--color-action-tint);
  box-shadow: var(--raise-pressed) var(--color-action);
  transform: var(--press-shift);
}
/* A tall card: the picture above the words */
.level-inner {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--space-2);
  height: 100%;
  padding: var(--space-3);
  text-align: center;
}
.level-pic { flex: none; display: flex; align-items: center; justify-content: center; width: min(170px, 42cqh, 70cqw); height: min(170px, 42cqh, 70cqw); }
.level-pic > .level-art { width: 100%; height: 100%; }
.level-inner > .icon { display: none; }
.level-words { display: flex; flex-direction: column; align-items: center; }
/* A wide card: the picture beside the words, and an arrow */
@container (min-aspect-ratio: 8 / 5) {
  .level-inner { flex-direction: row; justify-content: flex-start; gap: var(--space-5); padding: var(--space-3) var(--space-5); text-align: left; }
  .level-pic { width: min(96px, 76cqh); height: min(96px, 76cqh); }
  .level-words { flex: 1 1 auto; align-items: flex-start; }
  .level-inner > .icon { display: block; width: 28px; height: 28px; color: var(--color-action); }
}
/* A small card: only the picture and the level's name (and "Playing now") */
@container (max-height: 150px) and (max-aspect-ratio: 8 / 5) { .level-words .level-detail { display: none; } }
@container (max-height: 108px) { .level-words .level-detail { display: none; } }
@container (max-height: 84px) { .level-words .level-last { display: none; } }
.level-name { font-size: var(--text-title); font-weight: 700; line-height: var(--leading-tight); color: var(--color-action); }
.level-detail { color: var(--color-ink-soft); display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.level-last { font-weight: 700; }

.level-art { width: 88px; height: 88px; }
.level-art-tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8%; align-content: center; }
.level-art-tiles span { background: var(--color-action); border-radius: 22%; aspect-ratio: 1; }
.level-art-tokens { display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 4px; padding: 4px; }
.level-art-tokens span { width: 11px; height: 11px; border-radius: 50%; background: var(--color-action); }

/* A game under way: carry on, or start again */
.levels-resume {
  flex: none;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: var(--color-surface);
  border: var(--border) solid var(--accent-deep);
  border-radius: var(--radius-lg);
  text-align: center;
}
.levels-resume-title { font-size: var(--text-title); color: var(--accent-deep); }
.levels-resume-text { margin-top: var(--space-1); }
.levels-resume .panel-actions { margin-top: var(--space-3); }

/* Colouring Book: the pictures, as a gallery of how each was left */
.levels-gallery .level-pic { width: min(84cqw, 70cqh); height: min(84cqw, 70cqh); }
.levels-gallery .level-detail { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.levels-gallery .level-last { display: none; }
.levels-gallery .level-name { font-size: var(--text-lead); }
@container (min-aspect-ratio: 8 / 5) {
  .levels-gallery .level-pic { width: min(84cqh, 45cqw); height: min(84cqh, 45cqw); }
}

/* Too tall: a shorter "carry on" box, then no heading, then just its buttons */
.levels-screen.fit-1 .levels-resume-title { display: none; }
.levels-screen.fit-1 .levels { gap: var(--space-3); }
.levels-screen.fit-2 .levels-title { display: none; }
.levels-screen.fit-3 .levels-resume-text { display: none; }
.levels-screen.fit-3 .levels-resume .panel-actions { margin-top: 0; }
.levels-screen.fit-4 .levels-resume { padding: var(--space-2); }

/* ---------- The finish screen ---------- */

.panel-wrap { position: relative; overflow: hidden; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; padding: var(--space-1) 0 var(--space-3); }
.panel {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 660px;
  max-height: 100%;
  padding: var(--space-7) var(--space-6);
  background: var(--color-surface);
  border: var(--border) solid var(--color-action);
  border-radius: var(--radius-lg);
  text-align: center;
}
/* In the game's colour, with a warm glow at the top */
.panel-win {
  border-color: var(--accent-deep);
  background: linear-gradient(var(--accent-tint), var(--color-surface) 55%);
  box-shadow: 0 6px 0 var(--accent-deep);
  animation: panel-in 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.panel > * { flex: none; }
/* The picture on top (a star, or the finished colouring) gives way first when space is short */
.panel-art { flex: 0 1 112px; min-height: 48px; display: flex; justify-content: center; }
.panel-art:has(> .col-finished) { flex-basis: 320px; }
.panel-art > svg { height: 100%; width: auto; max-width: 100%; aspect-ratio: 1; }
.star { width: auto; height: 100%; }
.panel-title { font-size: var(--text-display); font-weight: 800; }
.panel-win .panel-title { color: var(--accent-deep); }
.panel-text { font-size: var(--text-lead); margin-top: var(--space-2); }
.panel .panel-trophies { margin-top: var(--space-5); justify-content: center; }
/* Too tall: tighter, then without the list of what was done, then without the picture */
.panel-wrap.fit-1 .panel { padding: var(--space-4) var(--space-5); }
.panel-wrap.fit-1 .panel-art:has(> .star) { flex-basis: 72px; }
.panel-wrap.fit-1 .panel-actions { margin-top: var(--space-4); }
.panel-wrap.fit-1 .panel .panel-trophies { margin-top: var(--space-3); }
.panel-wrap.fit-2 .panel-trophies { display: none; }
.panel-wrap.fit-3 .panel-art { display: none; }
.panel-wrap.fit-4 .panel-text { display: none; }
.panel-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--space-4); margin-top: var(--space-7); padding-bottom: var(--space-1); }

@keyframes panel-in {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: none; }
}

/* Paper confetti: falls once over the finish screen and is gone. Never blocks a tap. */
.confetti { position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 2; pointer-events: none; }
.confetti i {
  position: absolute;
  top: 0;
  left: var(--x);
  width: 12px;
  height: 18px;
  border-radius: 3px;
  background: var(--c);
  animation: confetti 2.4s cubic-bezier(0.25, 0.6, 0.4, 1) var(--d) both;
}
@keyframes confetti {
  0% { opacity: 1; transform: translate(0, -30px) rotate(var(--r)); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--dx), 72vh) rotate(calc(var(--r) + 540deg)); }
}

/* ---------- Status line ---------- */

/* Always two lines tall. A longer message can then never push the grid, tiles or Hint button. */
.status { font-size: var(--text-label); font-weight: 700; line-height: 1.4; min-height: 2.8em; }

/* ---------- Word Search ---------- */

.ws-layout {
  display: grid;
  gap: var(--space-4);
  grid-template-areas: "info" "board" "foot";
}
.ws-info { grid-area: info; }
.ws-board-wrap { grid-area: board; min-width: 0; }
.ws-foot { grid-area: foot; display: grid; grid-template-columns: 1fr auto; align-items: start; gap: var(--space-3) var(--space-5); }

.ws-topic { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-title); margin-bottom: var(--space-2); }
.ws-topic-icon { font-family: var(--font-emoji); font-size: 1.3em; line-height: 1; }
.ws-topic strong { color: var(--accent-deep); font-weight: 800; }

/* The words to find: big and clear, each on its own white card. Found: filled with the colour of
   its band in the grid, ticked (and crossed through, in English). Flat, so they read as a list
   rather than as buttons. */
.ws-words { list-style: none; margin: 0; padding: 9px 9px 0 0; display: flex; flex-wrap: wrap; gap: var(--space-3); } /* room for the tick badges */
.ws-word {
  position: relative;
  display: flex;
  align-items: center;
  padding: 2px 12px;
  background: var(--color-surface);
  border: var(--border-thin) solid var(--color-line-strong);
  border-radius: var(--radius-sm);
  font-size: var(--text-lead);
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.35;
}
.ws-word-mark { display: none; }
.ws-word.found { background: var(--mark); border-color: var(--mark-edge); }
.ws-word.found .ws-word-text { text-decoration: line-through; text-decoration-thickness: 2px; }
.ws-word.found .ws-word-mark {
  /* a tick badge on the corner: it takes no room, so nothing in the list moves */
  display: block;
  position: absolute;
  top: -9px; right: -9px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: #1F2A44 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 12.5l4 4 8-9'/%3E%3C/svg%3E") center / 72% no-repeat;
}
/* Dashed, so the hinted word is marked by shape as well as colour. An outline never changes the chip's size. */
.ws-word.hinting { outline: var(--border) dashed var(--color-action); outline-offset: 0; }

.ws-hint { justify-self: end; }

.ws-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  box-sizing: content-box;
  width: 320px;
  height: 320px;
  margin: 0 auto;
  background: var(--color-surface);
  border: var(--border) solid var(--accent-deep);
  border-radius: var(--radius-md);
  box-shadow: 0 5px 0 var(--accent-deep);
  overflow: hidden;
  cursor: pointer;
  touch-action: none; /* the grid handles every touch itself - no scrolling or zooming mid-word */
}

.ws-marks { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
.ws-preview.fading { opacity: 0; transition: opacity var(--motion-fade) ease-out; }
/* Three gentle pulses to catch the eye, then the ring simply stays until the word is found */
.ws-hint-ring { animation: ws-pulse 1.2s ease-in-out 3; }

@keyframes ws-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; } /* never fades below 3:1 against the grid */
}

.ws-cell {
  position: relative; /* sits above the highlighter marks so letters stay crisp */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--letter, 24px);
  font-weight: 700;
  line-height: 1;
}
.ws-cell.cursor { outline: var(--border-thick) solid var(--color-focus); outline-offset: -4px; border-radius: var(--radius-sm); }

@media (max-width: 640px) {
  /* On a phone the status gets a full row of its own and Hint a full-width button below it */
  .ws-foot { grid-template-columns: 1fr; }
  .ws-hint { justify-self: stretch; }
}

@media (min-width: 640px) and (orientation: landscape) { /* keep in step with SIDE_BY_SIDE in wordsearch.js */
  .ws-layout {
    /* the grid and its side panel are centred together as one group */
    grid-template-columns: auto 340px;
    grid-template-rows: auto 1fr;
    grid-template-areas: "board info" "board foot";
    justify-content: center;
    column-gap: 28px;
  }
  .ws-foot { grid-template-columns: 1fr; align-self: start; }
  .ws-hint { justify-self: stretch; }

  /* Left-handed play: the word list and Hint sit on the left, so nobody reaches across the grid */
  .hand-left .ws-layout { grid-template-columns: 340px auto; grid-template-areas: "info board" "foot board"; }
}

/* ---------- Tile Match ---------- */

.tm-layout { display: flex; flex-direction: column; justify-content: center; }
.tm-status { text-align: center; margin-bottom: var(--space-3); }

.tm-board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), var(--tile, 100px));
  grid-auto-rows: var(--tile, 100px);
  gap: var(--gap, 16px);
  justify-content: center;
  padding: 8px 0 6px; /* room for a lifted tile and the raised edge */
}

/* A picture: a raised white card - it can be pressed */
.tm-tile {
  position: relative;
  padding: 0;
  background: var(--color-surface);
  border: var(--border) solid var(--accent-deep);
  border-radius: 16%;
  box-shadow: 0 5px 0 var(--accent-deep);
  cursor: pointer;
  transition: transform var(--motion-press), box-shadow var(--motion-press), opacity var(--motion-state);
}
.tm-face {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0;
  display: flex; align-items: center; justify-content: center; /* centred by box, not by font baseline */
  font-family: var(--font-emoji);
  font-size: calc(var(--tile, 100px) * 0.62);
  line-height: 1;
}
.tm-tile.is-pressed { transform: translateY(4px); box-shadow: 0 1px 0 var(--accent-deep); }
/* Chosen: lifted, with a thick ring (shape as well as colour) */
.tm-tile.picked { transform: translateY(-6px); box-shadow: 0 11px 0 var(--accent-deep); outline: 5px solid var(--accent-deep); outline-offset: 3px; background: var(--accent-tint); }
/* Matched: settled flat, green, ticked, and faded back, so the pictures still to find stand out */
.tm-tile.matched { background: var(--color-done-tint); border: var(--border-thick) solid var(--color-done); box-shadow: none; transform: translateY(5px); cursor: default; }
.tm-tile.matched .tm-face { opacity: 0.45; }
.tm-tile.matched::after {
  content: "";
  position: absolute;
  top: 4%; right: 4%;
  width: 30%; height: 30%;
  min-width: 26px; min-height: 26px;
  border-radius: 50%;
  background: var(--color-done) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 12.5l4 4 8-9'/%3E%3C/svg%3E") center / 72% no-repeat;
}
/* Not the same: a little shake, and they are let go */
.tm-tile.tm-nope { animation: tm-nope 0.45s ease-in-out; }
@keyframes tm-nope {
  20%, 60% { transform: translateX(-7px) rotate(-3deg); }
  40%, 80% { transform: translateX(7px) rotate(3deg); }
}

.tm-trophies { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); font-family: var(--font-emoji); font-size: 48px; line-height: 1.1; }

/* ---------- Number Hunt ---------- */

.nh-layout { display: grid; gap: var(--space-3); grid-template-areas: "info" "board" "foot"; }
.nh-info { grid-area: info; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: var(--space-2) var(--space-6); }
.nh-board-wrap { grid-area: board; min-width: 0; }
.nh-foot { grid-area: foot; display: grid; justify-content: end; }

/* The number being looked for is the biggest thing on the screen */
.nh-target { display: flex; align-items: baseline; gap: var(--space-3); font-size: var(--text-lead); line-height: 1; white-space: nowrap; }
.nh-target { align-items: center; }
/* Drawn just like the kites in the sky, so "find this one" needs no reading */
.nh-target-kite { position: relative; flex: none; width: 104px; height: 104px; }
.nh-target-number {
  position: absolute;
  left: 50%; top: 41%;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; justify-content: center;
  min-width: 56px; height: 50px;
  padding: 0 6px;
  border: var(--border) solid #1F2A44;
  border-radius: 999px;
  background: #FFFFFF;
  color: var(--color-ink);
  font-size: 2rem; font-weight: 800; line-height: 1;
}

/* The sky. The kites are placed by numbers.js, each inside its own cell, so they never overlap */
.nh-board {
  position: relative;
  margin: 0 auto;
  border-radius: var(--radius-lg);
  background: linear-gradient(#BFE1FB, #E9F5FE);
  box-shadow: 0 0 0 10px #D8ECFC; /* a little more sky round the edge, outside the board's size */
  touch-action: none;
}

/* A kite: the whole square is the button (big to press); the number sits on a white patch */
.nh-tile {
  position: absolute;
  width: var(--token, 80px);
  height: var(--token, 80px);
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: none;
  cursor: pointer;
  transition: transform var(--motion-press), opacity var(--motion-state);
}
.nh-kite { position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: visible; }
.nh-diamond { stroke: #1F2A44; }
.nh-tail { stroke: #1F2A44; }
.nh-num {
  position: absolute;
  left: 50%; top: 41%;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; justify-content: center;
  min-width: 46%; height: 46%;
  padding: 0 4px;
  border: var(--border-thin) solid #1F2A44;
  border-radius: 999px;
  background: #FFFFFF;
  color: var(--color-ink);
  font: inherit;
  font-size: calc(var(--token, 80px) * 0.3);
  font-weight: 800;
  line-height: 1;
}
.nh-tile:active, .nh-tile.is-pressed { transform: translateY(4px) scale(0.96); }
/* Found: the kite fades back, with a green tick - the ones still to find stand out */
.nh-tile.done { opacity: 0.4; cursor: default; transform: translateY(-4px); animation: nh-pop 0.4s ease-out; }
.nh-tile.done .nh-num { background: var(--color-done-tint); border-color: var(--color-done); color: var(--color-done); }
.nh-tile.done::after {
  content: "";
  position: absolute;
  top: 2%; right: 6%;
  width: 30%; height: 30%;
  min-width: 22px; min-height: 22px;
  border-radius: 50%;
  background: var(--color-done) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 12.5l4 4 8-9'/%3E%3C/svg%3E") center / 70% no-repeat;
}
.nh-tile.done:active, .nh-tile.done.is-pressed { transform: translateY(-4px); }
/* Dashed, so the hint is a shape as well as a colour. Three gentle pulses, then it simply stays. */
.nh-tile.hinting { outline: var(--border-thick) dashed var(--accent-deep); outline-offset: 4px; border-radius: 50%; animation: nh-pulse 1.2s ease-in-out 3; }

@keyframes nh-pop {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  40% { transform: translateY(-10px) scale(1.12); opacity: 1; }
  100% { transform: translateY(-4px) scale(1); opacity: 0.4; }
}
@keyframes nh-pulse {
  50% { outline-color: var(--accent); }
}

.nh-trophies { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px; max-width: 540px; margin-left: auto; margin-right: auto; }
.nh-trophy { position: relative; width: 48px; height: 48px; }
.nh-trophy .nh-num { font-size: 15px; }

@media (max-width: 640px) {
  .nh-info { grid-template-columns: 1fr; }
  .nh-foot { justify-content: stretch; }
}

@media (min-width: 640px) and (orientation: landscape) { /* keep in step with SIDE_BY_SIDE in numbers.js */
  .nh-layout {
    grid-template-columns: auto 340px;
    grid-template-rows: auto 1fr;
    grid-template-areas: "board info" "board foot";
    justify-content: center;
    column-gap: 28px;
  }
  .nh-info { grid-template-columns: 1fr; }
  .nh-foot { justify-content: stretch; align-self: start; }
  .hand-left .nh-layout { grid-template-columns: 340px auto; grid-template-areas: "info board" "foot board"; }
}

/* ---------- Repeat the Pattern ---------- */

.pt-layout { display: grid; gap: var(--space-4); justify-items: center; }
.pt-info { display: grid; justify-items: center; gap: var(--space-2); width: 100%; }
.pt-status { text-align: center; }
.pt-board-wrap { width: 100%; }
.pt-foot { display: grid; justify-items: center; width: 100%; }
.pt-watch { width: 100%; max-width: 360px; touch-action: none; }

/* How far through the pattern: a ring still to do, a solid dot once tapped (shape, not just colour) */
.pt-dots { display: flex; gap: var(--space-3); min-height: 28px; align-items: center; }
.pt-dots span { width: 24px; height: 24px; border: var(--border) solid var(--accent-deep); border-radius: 50%; }
.pt-dots .on { background: var(--accent-deep); }

.pt-board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), var(--pad-size, 160px));
  grid-auto-rows: var(--pad-size, 160px);
  gap: var(--gap, 16px);
  justify-content: center;
  touch-action: none;
  padding-bottom: 4px; /* room for the raised edge of the last row */
}

/* A pad: its own colour with a big white shape. Lit: it turns white with the shape in its colour,
   and gains a thick dark ring - a change you can see without telling colours apart. */
.pt-pad {
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  border: var(--border-thick) solid var(--pad);
  border-radius: 22%;
  background: var(--pad);
  box-shadow: 0 5px 0 var(--color-ink);
  color: #FFFFFF;
  cursor: pointer;
  transition: transform var(--motion-press), box-shadow var(--motion-press);
}
.pt-pad.pt-ink { color: var(--color-ink); }
.pt-shape { width: 58%; height: 58%; fill: currentColor; }
.pt-pad.is-pressed { transform: translateY(4px); box-shadow: 0 1px 0 var(--color-ink); }
.pt-pad { position: relative; }
/* Lit: white with the shape in its colour, a thick ring, a warm glow round it, a little bigger -
   and while the pattern is being shown, a badge with its step number (1, 2, 3...) */
.pt-pad.lit {
  z-index: 1;
  background: #FFFFFF;
  color: var(--pad);
  border-color: var(--color-ink);
  outline: 6px solid var(--pad);
  outline-offset: -12px;
  transform: scale(1.07);
  box-shadow: 0 0 0 7px #FFF3C4, 0 0 34px 14px var(--pad);
}
.pt-pad[data-step]::after {
  content: attr(data-step);
  position: absolute;
  top: 7%; left: 7%;
  display: flex; align-items: center; justify-content: center;
  width: 34%; height: 34%;
  border-radius: 50%;
  background: var(--color-ink);
  color: #FFFFFF;
  font-size: calc(var(--pad-size, 160px) * 0.2);
  font-weight: 800;
  line-height: 1;
}
.pt-dots .shown { background: var(--accent-tint); }
.pt-pad.lit .pt-shape { stroke: var(--color-ink); stroke-width: 0.9; stroke-linejoin: round; }
.pt-showing .pt-pad { cursor: default; }

.level-art-pt { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.level-art-pads { display: grid; grid-template-columns: repeat(2, 26px); grid-auto-rows: 26px; gap: 4px; }
.level-art-pads.six { grid-template-columns: repeat(3, 20px); grid-auto-rows: 20px; }
.level-art-pads span { border-radius: 6px; }
.level-art-dots { display: flex; gap: 3px; }
.level-art-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--color-ink); }

/* ---------- Sort into Baskets ---------- */

/* The baskets sit along the bottom edge, where the hand rests; the table fills the space above */
.so-layout { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr auto; gap: var(--space-4); }
.so-status { text-align: center; }

/* The table: a fixed place for each picture, so one leaving never moves the others */
.so-table {
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), var(--card, 180px));
  grid-auto-rows: var(--card, 180px);
  gap: 16px;
  justify-content: center;
  align-content: center;
  touch-action: none;
}
.so-slot { position: relative; border: var(--border-thin) dashed var(--color-line-strong); border-radius: var(--radius-lg); }
.so-slot:not(:empty) { border-color: transparent; } /* the dashed place only shows once the table runs out */

/* A picture: a raised white card - it can be picked up */
.so-card {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0;
  z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--color-surface);
  border: var(--border) solid var(--accent-deep);
  border-radius: var(--radius-lg);
  box-shadow: 0 5px 0 var(--accent-deep);
  cursor: grab;
  touch-action: none;
  transition: translate var(--motion-state), box-shadow var(--motion-state);
  animation: so-arrive 0.35s ease-out;
}
.so-card:focus { outline: none; }
.so-card:focus-visible { outline: var(--border-thick) solid var(--color-focus); outline-offset: 3px; }
/* Picked up: lifted, a much thicker edge and a tick - shape as well as colour */
.so-card.so-selected { translate: 0 -8px; border-width: 6px; box-shadow: 0 12px 0 var(--accent-deep); }
.so-card.so-selected::after {
  content: "";
  position: absolute;
  top: -14px; right: -14px;
  width: 40px; height: 40px;
  border: 3px solid #FFFFFF;
  border-radius: 50%;
  background: var(--accent-deep) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 12.5l4 4 8-9'/%3E%3C/svg%3E") center / 64% no-repeat;
}
.so-card.dragging { z-index: 5; cursor: grabbing; box-shadow: 0 14px 0 rgba(31, 42, 68, 0.25); }
.so-card-pic { font-family: var(--font-emoji); font-size: calc(var(--card, 180px) * 0.46); line-height: 1; }
.so-card-name { font-weight: 700; font-size: var(--text-label); line-height: 1.2; text-align: center; padding: 0 8px; }

@keyframes so-arrive {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: none; }
}

.so-baskets { display: grid; grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr)); gap: var(--space-4); }
.so-basket {
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: var(--space-2);
  min-height: 180px;
  padding: var(--space-3) var(--space-3) var(--space-4);
  background: var(--accent-tint);
  border: var(--border) solid var(--accent-deep);
  border-radius: var(--radius-lg);
  box-shadow: 0 5px 0 var(--accent-deep);
  color: var(--color-ink);
  font: inherit;
  cursor: pointer;
  transition: transform var(--motion-press), box-shadow var(--motion-press), background-color var(--motion-press);
}
.so-basket.is-pressed { box-shadow: 0 1px 0 var(--accent-deep); transform: translateY(4px); }
/* A picture held over a basket: the basket answers before the finger lets go - it rises to meet it */
.so-basket.so-over { border-width: var(--border-thick); transform: translateY(-6px); box-shadow: 0 11px 0 var(--accent-deep); }

/* Each basket stands in its own scene, so land, water and sky (hot and cold...) look different
   before a word is read. The scene is light, so the basket's name stays easy to read on it. */
.so-scene-plain { background: var(--scene, var(--accent-tint)); }
.so-scene-land { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 150' preserveAspectRatio='xMidYMax slice'%3E%3Crect width='200' height='150' fill='%23E6F4FF'/%3E%3Cpath d='M0 92Q55 64 115 84T200 76V150H0Z' fill='%23BFE3A6'/%3E%3Cpath d='M0 116Q90 96 200 112V150H0Z' fill='%2393CC74'/%3E%3C/svg%3E") center bottom / cover no-repeat; }
.so-scene-water { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 150' preserveAspectRatio='xMidYMax slice'%3E%3Crect width='200' height='150' fill='%23E9F6FF'/%3E%3Cpath d='M0 86q12.5 -9 25 0 q12.5 -9 25 0 q12.5 -9 25 0 q12.5 -9 25 0 q12.5 -9 25 0 q12.5 -9 25 0 q12.5 -9 25 0 q12.5 -9 25 0 V150H0Z' fill='%238ED0F2'/%3E%3Cpath d='M0 114q12.5 -9 25 0 q12.5 -9 25 0 q12.5 -9 25 0 q12.5 -9 25 0 q12.5 -9 25 0 q12.5 -9 25 0 q12.5 -9 25 0 q12.5 -9 25 0 ' fill='none' stroke='%23FFFFFF' stroke-width='3' stroke-opacity='.7'/%3E%3C/svg%3E") center bottom / cover no-repeat; }
.so-scene-sky { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 150' preserveAspectRatio='xMidYMax slice'%3E%3Crect width='200' height='150' fill='%23CBE7FD'/%3E%3Cg fill='%23FFFFFF'%3E%3Cellipse cx='62' cy='72' rx='18' ry='8'/%3E%3Cellipse cx='72' cy='66' rx='11' ry='8'/%3E%3Cellipse cx='140' cy='84' rx='17' ry='7'/%3E%3Cellipse cx='132' cy='78' rx='10' ry='7'/%3E%3Cellipse cx='20' cy='120' rx='16' ry='6'/%3E%3Cellipse cx='184' cy='124' rx='14' ry='6'/%3E%3C/g%3E%3C/svg%3E") center bottom / cover no-repeat; }
.so-scene-hot { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 150' preserveAspectRatio='xMidYMax slice'%3E%3Crect width='200' height='150' fill='%23FFE4B0'/%3E%3Cg stroke='%23F5A623' stroke-width='3.5' stroke-linecap='round'%3E%3Cpath d='M146 58v6M146 90v6M130 77h6M156 77h6M134 65l4 4M154 85l4 4M134 89l4-4M154 69l4-4'/%3E%3C/g%3E%3Ccircle cx='146' cy='77' r='9' fill='%23FFC940' stroke='%23F5A623' stroke-width='2.5'/%3E%3C/svg%3E") center bottom / cover no-repeat; }
.so-scene-cold { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 150' preserveAspectRatio='xMidYMax slice'%3E%3Crect width='200' height='150' fill='%23E2F3FB'/%3E%3Cg stroke='%23FFFFFF' stroke-width='3' stroke-linecap='round'%3E%3Cpath d='M58 64v14M51 71h14M53 66l10 10M63 66L53 76M146 70v14M139 77h14M141 72l10 10M151 72l-10 10M100 60v8M96 64h8'/%3E%3C/g%3E%3Cpath d='M0 124Q100 106 200 124V150H0Z' fill='%23FFFFFF'/%3E%3C/svg%3E") center bottom / cover no-repeat; }
.so-scene-garden { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 200 150' preserveAspectRatio='xMidYMax slice'%3E%3Crect width='200' height='150' fill='%23F0F8E6'/%3E%3Cpath d='M0 118Q100 102 200 118V150H0Z' fill='%23A9D98C'/%3E%3Cg fill='%23F48FB1' stroke='%23C2185B' stroke-width='1.5'%3E%3Ccircle cx='24' cy='112' r='6'/%3E%3Ccircle cx='178' cy='108' r='6'/%3E%3C/g%3E%3Cg fill='%23FFD54F' stroke='%23B58500' stroke-width='1.5'%3E%3Ccircle cx='44' cy='118' r='5'/%3E%3Ccircle cx='160' cy='116' r='5'/%3E%3C/g%3E%3C/svg%3E") center bottom / cover no-repeat; }

/* The label on the front of the basket: one of the things that goes in it */
.so-basket-body { position: relative; display: block; }
.so-sign {
  position: absolute;
  left: 50%; top: 62%;
  transform: translate(-50%, -50%);
  display: flex; align-items: center; justify-content: center;
  width: 36%; aspect-ratio: 1;
  min-width: 44px; max-width: 84px;
  border: var(--border) solid #5B3A1A;
  border-radius: 50%;
  background: #FFFFFF;
  font-family: var(--font-emoji);
  font-size: 44px;
  line-height: 1;
}

/* After a second try: a hand points at the right basket (three bobs, then it stays) */
.so-basket { position: relative; }
.so-point { display: none; position: absolute; left: 50%; top: -74px; width: 60px; height: 82px; margin-left: -30px; transform: rotate(180deg); z-index: 3; pointer-events: none; overflow: visible; }
.so-basket.so-hint .so-point { display: block; animation: so-point 0.8s ease-in-out 3; }
@keyframes so-point {
  50% { transform: rotate(180deg) translateY(10px); }
}
/* Shown after a second try: dashed (a shape, not just a colour), three gentle pulses, then it stays */
.so-basket.so-hint { outline: var(--border-thick) dashed var(--accent-deep); outline-offset: 5px; animation: nh-pulse 1.2s ease-in-out 3; }
.so-basket.so-wobble .so-basket-body { animation: so-wobble 0.5s ease-in-out; }
/* Not this basket: it shakes its head, and a big grey cross appears on it for a moment */
.so-basket.so-nope { animation: so-shake 0.5s ease-in-out; }
.so-basket.so-nope::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 84px; height: 84px;
  margin: -42px 0 0 -42px;
  border: 4px solid #FFFFFF;
  border-radius: 50%;
  background: #4A5468 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.6' stroke-linecap='round'%3E%3Cpath d='M7 7l10 10M17 7L7 17'/%3E%3C/svg%3E") center / 60% no-repeat;
  box-shadow: 0 4px 0 rgba(31, 42, 68, 0.3);
  opacity: 0;
  pointer-events: none;
  animation: so-cross 1.4s ease-out;
}
.so-card.so-wobble-card { animation: so-wobble-card 0.45s ease-in-out; }
@keyframes so-shake {
  20%, 60% { transform: translateX(-10px); }
  40%, 80% { transform: translateX(10px); }
}
@keyframes so-cross {
  0% { opacity: 0; transform: scale(0.5); }
  15%, 70% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1); }
}
@keyframes so-wobble-card {
  25% { transform: rotate(-7deg); }
  75% { transform: rotate(7deg); }
}
.so-basket-name {
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.82); /* a little white behind the name keeps it crisp on any scene */
  font-size: var(--text-title); font-weight: 800; line-height: var(--leading-tight); text-align: center; color: var(--color-ink);
}
.so-basket-pic { position: relative; display: block; width: min(100%, 230px); padding-top: 38px; }
.so-basket-body { transform-origin: 50% 90%; }
.so-basket-art { display: block; width: 100%; height: auto; }
/* What is already in the basket, piled on top */
.so-contents {
  position: absolute; left: 6%; right: 6%; top: 0;
  display: flex; flex-wrap: wrap-reverse; justify-content: center;
  font-family: var(--font-emoji); font-size: 32px; line-height: 1;
  max-height: 68px; overflow: hidden;
}
.so-contents span { margin: 0 -3px; }

@keyframes so-wobble {
  25% { transform: rotate(-5deg); }
  60% { transform: rotate(4deg); }
  100% { transform: none; }
}

.so-trophies { display: grid; gap: var(--space-3); text-align: left; }
.so-trophy { display: grid; gap: 2px; }
.so-trophy-name { font-weight: 700; }
.so-trophy-pics { font-family: var(--font-emoji); font-size: 36px; line-height: 1.2; letter-spacing: 4px; }

.level-art-so { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.level-art-things { display: flex; flex-wrap: wrap; justify-content: center; gap: 3px; max-width: 70px; }
.level-art-things span { width: 9px; height: 9px; border-radius: 2px; background: var(--color-action); }
.level-art-baskets { display: flex; gap: 4px; }
.level-art-baskets svg { width: 28px; height: auto; }

@media (max-width: 480px) {
  .so-baskets { gap: var(--space-3); }
  .so-basket { min-height: 140px; padding: var(--space-2) 4px var(--space-3); }
  .so-basket-name { padding: 0 3px; font-size: var(--text-body); hyphens: auto; }
  .so-basket-pic { padding-top: 30px; }
  .so-contents { font-size: 24px; }
  .so-sign { font-size: 26px; }
}

/* ---------- Colouring Book ---------- */

.col-layout { display: grid; gap: var(--space-4); justify-items: center; grid-template-areas: "top" "picture" "side"; }
.col-top { grid-area: top; display: flex; align-items: center; justify-content: center; gap: var(--space-3); width: 100%; }
.col-status { display: flex; align-items: center; text-align: left; } /* the words sit level with the colour pot */
/* The colour on the brush: a big pot of it, beside the words that name it */
.col-current {
  flex: none;
  width: 52px; height: 52px;
  border: var(--border) solid var(--color-ink);
  border-radius: 50%;
  background: var(--swatch, #FFFFFF);
  box-shadow: inset 0 0 0 3px #FFFFFF;
}
.col-picture-box { grid-area: picture; width: 320px; height: 320px; }
.col-picture {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--color-surface);
  border: var(--border) solid var(--accent-deep);
  border-radius: var(--radius-md);
  box-shadow: 0 5px 0 var(--accent-deep);
  touch-action: none; /* every touch on the picture is a tap on a part - never a scroll or zoom */
  cursor: pointer;
}
.col-part:focus { outline: none; }
.col-part:focus-visible { stroke: var(--color-focus); stroke-width: 2.8; }
/* The new colour spreading out from the finger (see spread() in colouring.js) */
.col-hole { transform-box: fill-box; transform-origin: center; animation: col-spread 0.5s ease-out both; }
@keyframes col-spread {
  from { transform: scale(0); }
  to { transform: scale(1); }
}
.col-side { grid-area: side; display: grid; gap: var(--space-4); justify-items: center; }

.col-palette { display: grid; grid-template-columns: repeat(6, 64px); gap: 10px 12px; padding-bottom: 4px; touch-action: none; }
/* A swatch: a raised circle of its colour. The chosen one gets a thick ring AND a tick. */
.col-swatch {
  display: flex; align-items: center; justify-content: center;
  width: 64px; height: 64px;
  padding: 0;
  border: var(--border) solid var(--color-ink-soft);
  border-radius: 50%;
  background: var(--swatch);
  box-shadow: 0 4px 0 var(--color-ink);
  cursor: pointer;
  transition: transform var(--motion-press), box-shadow var(--motion-press);
}
.col-swatch.is-pressed { transform: translateY(3px); box-shadow: 0 1px 0 var(--color-ink); }
.col-swatch .icon {
  visibility: hidden;
  width: 30px; height: 30px;
  padding: 4px;
  border-radius: 50%;
  background: #FFFFFF;
  color: var(--color-ink);
  box-shadow: 0 0 0 2px var(--color-ink);
}
.col-swatch[aria-pressed="true"] { outline: var(--border-thick) solid var(--color-ink); outline-offset: 3px; }
.col-swatch[aria-pressed="true"] .icon { visibility: visible; }

.col-tools { display: flex; gap: var(--space-3); width: 100%; justify-content: center; }
.col-tools .btn { flex: 1 1 0; max-width: 240px; touch-action: none; padding-left: 16px; padding-right: 16px; }

.col-finished { display: block; margin: 0 auto; background: #FFFFFF; border: var(--border) solid var(--color-ink); border-radius: var(--radius-md); }

.level-art-col { background: #FFFFFF; border: var(--border-thin) solid var(--color-ink); border-radius: 10px; }

@media (min-width: 640px) and (orientation: landscape) { /* keep in step with SIDE_BY_SIDE in colouring.js */
  .col-layout {
    grid-template-columns: auto 272px;
    grid-template-areas: "top top" "picture side";
    justify-content: center;
    align-items: start;
    column-gap: 28px;
  }
  .col-palette { grid-template-columns: repeat(3, 72px); gap: 14px; }
  .col-swatch { width: 72px; height: 72px; }
  .col-tools { flex-direction: column; align-items: stretch; }
  .col-tools .btn { max-width: none; }
  .hand-left .col-layout { grid-template-columns: 272px auto; grid-template-areas: "top top" "side picture"; }
}

@media (max-width: 480px) {
  /* Fewer colours per row rather than smaller ones */
  .col-palette { grid-template-columns: repeat(4, 64px); gap: 10px 14px; }
  .col-current { width: 44px; height: 44px; }
}

/* ---------- Harmonium ---------- */

.hm-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); justify-items: center; }
.hm-status { text-align: center; width: 100%; }
/* The phrase to play, in sargam: the next note ringed, the ones played ticked green */
.hm-strip { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px 8px; max-width: 100%; padding: 8px 12px; }
.hm-chip {
  min-width: 46px;
  padding: 0 10px;
  border: var(--border-thin) solid var(--color-line-strong);
  border-radius: 999px;
  background: var(--color-surface);
  box-shadow: inset 0 -5px 0 var(--key);
  font-size: var(--text-label);
  font-weight: 800;
  line-height: 1.7;
  text-align: center;
}
/* The syllable to play now: ringed in its key's colour and a little bigger (drawn bigger, so the
   words beside it never move) */
.hm-chip.next { position: relative; z-index: 1; border: var(--border-thick) solid var(--accent-deep); outline: 4px solid var(--key); transform: scale(1.3); }
.hm-chip.done { border-color: var(--color-done); background: var(--color-done-tint); color: var(--color-done); box-shadow: none; }
.hm-board-wrap { width: 100%; }
/* Room above the keys for the hand that points at the next one */
.hm-board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 8), var(--key-w, 90px));
  grid-auto-rows: var(--key-h, 220px);
  gap: 10px;
  justify-content: center;
  padding: 64px 0 6px;
  touch-action: none;
}
.hm-free .hm-board { padding-top: 0; }
/* A key: white, with its colour across the top and its name big at the bottom */
.hm-key {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  padding: 0 0 18px;
  background: var(--color-surface);
  border: var(--border) solid var(--color-ink);
  border-radius: 14px;
  box-shadow: 0 6px 0 var(--color-ink);
  color: var(--color-ink);
  font: inherit;
  cursor: pointer;
  touch-action: none;
  transition: transform var(--motion-press), box-shadow var(--motion-press), background-color var(--motion-press);
}
.hm-cap { position: absolute; top: 0; left: 0; right: 0; height: 26%; background: var(--key); border-bottom: var(--border) solid var(--color-ink); border-radius: 11px 11px 0 0; }
.hm-name { font-size: clamp(22px, calc(var(--key-w, 90px) * 0.4), 44px); font-weight: 800; line-height: 1.15; }
.hm-other { font-size: var(--text-body); font-weight: 700; color: var(--color-ink-soft); line-height: 1.2; }
/* Written as sargam is written: a dot above a high note, a dot below a low one, a line under a
   komal note and a line over tivra Ma */
.hm-name { position: relative; }
.hm-high .hm-name::before, .hm-low .hm-name::after { content: ""; position: absolute; left: 50%; width: 8px; height: 8px; margin-left: -4px; border-radius: 50%; background: currentColor; }
.hm-high .hm-name::before { top: -8px; }
.hm-low .hm-name::after { bottom: -8px; }
.hm-komal .hm-name { text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 4px; }
.hm-low.hm-komal .hm-name::after { bottom: -14px; }
.hm-tivra .hm-name { text-decoration: overline; text-decoration-thickness: 3px; }
/* A syllable held over from the one before (one syllable, several notes) */
.hm-chip.hm-held { min-width: 30px; color: var(--color-ink-soft); }
/* Sounding: pressed down, and glowing warm */
.hm-key.is-pressed, .hm-key.sounding { transform: translateY(5px); box-shadow: 0 1px 0 var(--color-ink); background: #FFF4CC; }
.hm-key.hm-next { outline: 5px solid var(--accent-deep); outline-offset: 4px; }
.hm-point { display: none; position: absolute; left: 50%; top: -66px; width: 44px; height: 60px; margin-left: -22px; transform: rotate(180deg); pointer-events: none; overflow: visible; z-index: 2; }
.hm-key.hm-next .hm-point { display: block; animation: so-point 0.8s ease-in-out 3; }
.hm-foot { display: grid; justify-items: center; }

/* ---------- Rangoli Mirror ---------- */

.rg-board-box { grid-area: picture; width: 320px; height: 320px; }
.rg-board { display: block; width: 100%; height: 100%; border-radius: var(--radius-md); box-shadow: 0 5px 0 var(--accent-deep); touch-action: none; cursor: pointer; }
.rg-board:focus { outline: none; }
.rg-board:focus-visible { outline: var(--border-thick) solid var(--color-focus); outline-offset: 3px; }
.rg-new { animation: rg-in 0.35s ease-out; }
@keyframes rg-in {
  from { opacity: 0; }
}
/* The shape on the brush, in its colour, beside the words that name it */
.rg-current { flex: none; display: flex; align-items: center; justify-content: center; width: 52px; height: 52px; border: var(--border) solid var(--color-ink); border-radius: 14px; background: #5B2A22; }
.rg-current svg { width: 38px; height: 38px; }
.rg-shapes { display: grid; grid-template-columns: repeat(4, 64px); gap: 10px; }
/* A shape button: the shape in the chosen colour, on the floor's colour. Chosen: ringed and ticked. */
.rg-shape {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 64px; height: 64px;
  padding: 0;
  border: var(--border) solid var(--color-ink-soft);
  border-radius: 16px;
  background: #5B2A22;
  box-shadow: 0 4px 0 var(--color-ink);
  cursor: pointer;
  transition: transform var(--motion-press), box-shadow var(--motion-press);
}
.rg-shape-pic { width: 44px; height: 44px; }
.rg-shape .icon { position: absolute; top: -9px; right: -9px; visibility: hidden; width: 28px; height: 28px; padding: 4px; border-radius: 50%; background: #FFFFFF; color: var(--color-ink); box-shadow: 0 0 0 2px var(--color-ink); }
.rg-shape[aria-pressed="true"] { outline: var(--border-thick) solid var(--color-ink); outline-offset: 3px; }
.rg-shape[aria-pressed="true"] .icon { visibility: visible; }
.rg-shape.is-pressed { transform: translateY(3px); box-shadow: 0 1px 0 var(--color-ink); }
.col-palette.rg-palette { grid-template-columns: repeat(4, 64px); gap: 10px; }
.rg-palette .col-swatch { width: 64px; height: 64px; }
.level-art-rg { border-radius: 10px; }
@media (min-width: 640px) and (orientation: landscape) {
  .col-layout.rg-layout { grid-template-columns: auto auto; }
}

/* ---------- Diya Trail ---------- */

.dy-layout { display: grid; gap: var(--space-3); }
.dy-status { text-align: center; }
.dy-board-wrap { width: 100%; min-width: 0; }
.dy-board { display: block; border-radius: 22px; box-shadow: 0 6px 0 var(--accent-deep); touch-action: none; }
.dy-board:focus { outline: none; }
.dy-board:focus-visible { outline: var(--border-thick) solid var(--color-focus); outline-offset: 3px; }
.dy-sky, .dy-moon-cut { fill: #1E2461; }
/* The path: faint dots still to light; bright ones behind the finger; a white ring on the next */
.dy-dot { fill: #FFD54F; fill-opacity: 0.3; stroke: #FFD54F; stroke-opacity: 0.55; stroke-width: 1.5; transition: fill-opacity var(--motion-state); }
.dy-dot.lit { fill-opacity: 1; stroke: #FFF3C4; stroke-opacity: 1; }
.dy-dot.next { fill-opacity: 0.75; stroke: #FFFFFF; stroke-opacity: 1; stroke-width: 4; }
.dy-trail { stroke: #FFD54F; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; stroke-opacity: 0.85; }
.dy-glow { opacity: 0; }
.dy-diya.lit .dy-glow { opacity: 1; }
.dy-diya.next .dy-glow { opacity: 1; fill: none; stroke: #FFFFFF; stroke-width: 3; stroke-dasharray: 6 6; stroke-opacity: 0.8; }
.dy-flame, .dy-flame-core { opacity: 0; transform-box: fill-box; transform-origin: 50% 100%; }
.dy-flame { fill: #FF9800; stroke: #E65100; stroke-width: 2; }
.dy-flame-core { fill: #FFF3C4; }
.dy-diya.lit .dy-flame, .dy-diya.lit .dy-flame-core { opacity: 1; animation: dy-light 0.5s ease-out; }
@keyframes dy-light {
  from { opacity: 0; transform: scale(0.3); }
}
.dy-trophies { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; }
.dy-trophies svg { width: 64px; height: 58px; }

/* ---------- Making Chai ---------- */

.ch-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); }
.ch-status { text-align: center; }
/* The row the steps go into: numbered places, filled in order */
.ch-row { display: grid; grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr)); gap: var(--space-2); max-width: 820px; width: 100%; margin: 0 auto; }
.ch-slot {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  aspect-ratio: 1;
  max-height: 110px;
  border: var(--border) dashed var(--accent);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}
.ch-slot-num { font-size: 2rem; font-weight: 800; color: var(--accent-deep); line-height: 1; }
.ch-slot.filled { border-style: solid; border-color: var(--color-done); background: var(--color-done-tint); }
.ch-slot.filled .ch-slot-num { position: absolute; top: -10px; left: -10px; display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%; background: var(--color-done); color: #FFFFFF; font-size: 1rem; z-index: 2; }
/* The steps, mixed up: big cards with a picture and a few words */
.ch-pile { display: grid; grid-template-columns: repeat(var(--cols, 3), var(--card, 160px)); grid-auto-rows: var(--card, 160px); gap: 14px; justify-content: center; align-content: center; padding-top: 12px; }
.ch-place { position: relative; border: var(--border-thin) dashed var(--color-line); border-radius: var(--radius-lg); }
.ch-place:not(:empty) { border-color: transparent; }
.ch-card {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  padding: 6px;
  background: var(--color-surface);
  border: var(--border) solid var(--accent-deep);
  border-radius: var(--radius-lg);
  box-shadow: 0 5px 0 var(--accent-deep);
  color: var(--color-ink);
  font: inherit;
  cursor: pointer;
  transition: transform var(--motion-press), box-shadow var(--motion-press);
}
.ch-card.is-pressed { transform: translateY(4px); box-shadow: 0 1px 0 var(--accent-deep); }
.ch-pic { font-family: var(--font-emoji); font-size: calc(var(--card, 160px) * 0.4); line-height: 1; }
.ch-words { font-size: var(--text-label); font-weight: 800; line-height: 1.15; text-align: center; }
/* Placed: small, flat and ticked in its numbered place in the row */
.ch-card.ch-placed { position: absolute; top: 4px; right: 4px; bottom: 4px; left: 4px; padding: 2px; border: 0; box-shadow: none; background: none; cursor: default; }
.ch-card.ch-placed .ch-pic { font-size: min(52px, 5.5vw); }
.ch-card.ch-placed .ch-words { display: none; }
.ch-card.ch-nope { animation: tm-nope 0.45s ease-in-out; }
.ch-point { display: none; position: absolute; left: 50%; top: -50px; width: 44px; height: 60px; margin-left: -22px; transform: rotate(180deg); pointer-events: none; overflow: visible; z-index: 3; }
.ch-card.ch-hint { outline: var(--border-thick) dashed var(--accent-deep); outline-offset: 5px; }
.ch-card.ch-hint .ch-point { display: block; animation: so-point 0.8s ease-in-out 3; }
.ch-trophies { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; text-align: left; justify-content: center; counter-reset: step; }
.ch-trophies li { display: flex; align-items: center; gap: 10px; font-weight: 700; counter-increment: step; }
.ch-trophies li::before { content: counter(step); display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-deep); color: #FFFFFF; font-size: 17px; }
.ch-trophy-pic { font-family: var(--font-emoji); font-size: 28px; }
.level-art-ch { display: flex; flex-wrap: wrap; align-content: center; justify-content: center; gap: 2px; font-family: var(--font-emoji); font-size: 24px; line-height: 1.1; }

/* ---------- A photo with the masterpiece ---------- */

.pb-layout { flex: 1 1 auto; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); gap: var(--space-3); justify-items: center; padding-bottom: 6px; }
.pb-status { text-align: center; }
.pb-view {
  position: relative;
  width: 100%; height: 100%;
  max-width: 900px;
  min-height: 160px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: #1F2A44;
  box-shadow: 0 6px 0 var(--accent-deep);
}
.pb-video { display: block; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); } /* like a mirror */
/* The masterpiece, framed in the corner - where it will be in the photo */
.pb-art { position: absolute; right: 3%; bottom: 4%; width: 34%; max-width: 280px; aspect-ratio: 1; padding: 1.5%; background: #FFFFFF; border-radius: 6px; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35); }
.pb-art svg { display: block; width: 100%; height: 100%; }
.pb-art.pb-art-only { position: static; margin: 4% auto; width: auto; height: 88%; max-width: none; }
.pb-count { position: absolute; top: 0; right: 0; bottom: 0; left: 0; display: flex; align-items: center; justify-content: center; color: #FFFFFF; font-size: min(30vmin, 220px); font-weight: 800; line-height: 1; text-shadow: 0 4px 24px rgba(0, 0, 0, 0.6); pointer-events: none; }
.pb-shot { display: block; width: 100%; height: 100%; object-fit: contain; }
.pb-flash::after { content: ""; position: absolute; top: 0; right: 0; bottom: 0; left: 0; background: #FFFFFF; animation: pb-flash 0.3s ease-out forwards; }
@keyframes pb-flash {
  from { opacity: 0.9; }
  to { opacity: 0; }
}
.pb-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--space-3); }

/* ---------- Hindi (Devanagari) ---------- */

/* Vowel signs sit above and below the line, so lines need more air; and letter-spacing must be
   zero, because it would break the headline that joins the letters of a word. */
:lang(hi) body { line-height: 1.7; }
:lang(hi) h1, :lang(hi) h2, :lang(hi) .btn, :lang(hi) .level-name { line-height: 1.4; }
:lang(hi) .status { line-height: 1.6; min-height: 3.2em; }
:lang(hi) .ws-word { letter-spacing: 0; line-height: 1.5; }
/* A strike-through collides with the headline that joins Devanagari letters and makes the word
   unreadable. The tick, the colour fill and the outline already mark a found word. */
:lang(hi) .ws-word.found .ws-word-text { text-decoration: none; }
:lang(hi) .nh-target { line-height: 1.2; }

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  /* One row: Home, the title (on pages other than a game), and the level. */
  .bar { grid-template-columns: auto minmax(0, 1fr) auto; margin-bottom: var(--space-3); }
  .bar-title { font-size: var(--text-label); }
  .btn { padding: 10px 18px; }
  /* While playing on a small screen the space goes to the game; the title stays for screen readers */
  .bar-playing .bar-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .panel-actions { flex-direction: column; align-items: stretch; }
  .btn-lg { min-width: 0; }
}

@media (max-width: 480px) {
  html { font-size: 118.75%; } /* 19px */
  .sun { width: 44px; height: 44px; }
  .home-title { font-size: 1.7rem; }
  .tiles { gap: var(--space-3); }
  .tile { border-radius: var(--radius-lg); }
  .chooser .btn { padding-left: 14px; padding-right: 18px; }
  .intro-start { min-width: 0; width: 100%; }
}

/* ---------- Short screens ---------- */

@media (max-height: 560px) {
  .app { padding-top: max(8px, env(safe-area-inset-top)); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .bar { margin-bottom: var(--space-2); }
  /* The messages here are short: one line is enough on a wide, short screen */
  .hm-status, .ch-status, .so-status, .tm-status, .pt-status, .dy-status { min-height: 1.4em; }
  .ws-topic { font-size: var(--text-lead); margin-bottom: var(--space-1); }
  .ws-word { font-size: var(--text-body); }
  .ch-slot { max-height: 60px; }
  .ch-slot-num { font-size: 1.4rem; }
  .ch-pile { padding-top: 4px; }
}

/* Sideways phone: the pads in one row with Watch beside them; the baskets in a column beside the
   pictures; the colours in two rows beside the picture */
@media (orientation: landscape) and (max-height: 560px) {
  .pt-layout { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "info info" "board foot"; align-items: center; }
  .pt-info { grid-area: info; }
  .pt-board-wrap { grid-area: board; }
  .pt-foot { grid-area: foot; width: auto; }
  .pt-watch { width: 220px; }

  .so-layout { grid-template-columns: minmax(0, 1fr) minmax(250px, 36%); grid-template-rows: auto 1fr; grid-template-areas: "status status" "table baskets"; }
  .so-status { grid-area: status; }
  .so-table { grid-area: table; }
  .so-baskets { grid-area: baskets; grid-template-columns: 1fr; grid-auto-rows: minmax(0, 1fr); gap: var(--space-2); }
  .so-basket { min-height: 0; flex-direction: row; justify-content: space-between; padding: var(--space-1) var(--space-3); }
  .so-basket-name { font-size: var(--text-body); white-space: nowrap; }
  .so-basket-pic { width: 88px; padding-top: 0; }
  .so-sign { min-width: 34px; border-width: 2px; font-size: 20px; }
  .so-contents { display: none; }

  .col-layout { grid-template-columns: auto auto; }
  .col-palette { grid-template-columns: repeat(6, 64px); gap: 8px; }
  .col-swatch { width: 64px; height: 64px; }
  .col-tools { flex-direction: row; }
  .col-tools .btn { white-space: nowrap; }
  .rg-side { grid-template-columns: auto auto; grid-template-areas: "shapes palette" "tools tools"; align-items: start; }
  .rg-shapes { grid-area: shapes; grid-template-columns: repeat(2, 64px); }
  .rg-palette { grid-area: palette; }
  .rg-side .col-tools { grid-area: tools; }
  .hm-board { padding-top: 52px; }
  .hm-layout { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "status status" "strip foot" "board board"; align-items: center; }
  .hm-status { grid-area: status; }
  .hm-strip { grid-area: strip; }
  .hm-foot { grid-area: foot; }
  .hm-board-wrap { grid-area: board; }
  .hm-strip { gap: 4px; }
  .hm-chip { min-width: 40px; padding: 0 6px; }
  .hm-other { display: none; }
  .hm-key { padding-bottom: 6px; }
  .hm-cap { height: 22%; }
  .hm-point { top: -54px; width: 38px; height: 52px; margin-left: -19px; }
}
/* A laptop or tablet with little height: four colours to a row, so the tools stay in view */
@media (orientation: landscape) and (max-height: 760px) and (min-height: 561px) {
  .col-palette { grid-template-columns: repeat(4, 64px); gap: 10px; }
  .col-swatch { width: 64px; height: 64px; }
  .col-layout { grid-template-columns: auto auto; }
}

/* ---------- Calm mode ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .confetti { display: none; }
  .so-basket.so-nope::after { opacity: 1; } /* the cross stays until the next move */
  .demo-run .demo-fill { fill: #E53935; }
}
