/* Domino Topple: a quick toy in the Favabeans look (see ../APP_DESIGN.md).
   Accent: warm tangerine. Light by default, dark when the system (or the shared prefs) asks.
   No dark green or dark teal anywhere. */
:root {
  --canvas: #F7F5F2;
  --surface: #FFFFFF;
  --surface-2: #F1EFEA;
  --surface-3: #E7E5E0;
  --ink: #1D1D1F;
  --ink-2: #57575F;
  --line: rgb(29 29 31 / .09);
  --line-2: rgb(29 29 31 / .17);
  --shadow-1: 0 1px 2px rgb(0 0 0 / .04), 0 16px 36px -26px rgb(0 0 0 / .25);
  --shadow-2: 0 1px 2px rgb(0 0 0 / .05), 0 26px 50px -28px rgb(0 0 0 / .32);
  --ease: cubic-bezier(.22, 1, .36, 1);
  --r-card: 32px;
  --r-md: 20px;
  --r-sm: 14px;
  --gutter: clamp(16px, 4vw, 40px);
  --font: "Atkinson Hyperlegible Next", "Atkinson Hyperlegible", "IBM Plex Sans Arabic", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Instrument Serif", Georgia, serif;

  /* This toy's accent: tangerine #FFCB8F → #F28A2E */
  --accent: #C2410C;
  --accent-ink: #FFFFFF;
  --accent-soft: #FFEBDD;
  --accent-text: #A8380A;
  --focus: #C2410C;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    --canvas: #121214;
    --surface: #1D1D21;
    --surface-2: #26262B;
    --surface-3: #303036;
    --ink: #F2F1EC;
    --ink-2: #C2C1BC;
    --line: rgb(255 255 255 / .10);
    --line-2: rgb(255 255 255 / .22);
    --shadow-1: 0 1px 0 rgb(255 255 255 / .04) inset, 0 8px 24px -12px rgb(0 0 0 / .6);
    --shadow-2: 0 1px 0 rgb(255 255 255 / .05) inset, 0 28px 56px -22px rgb(0 0 0 / .8);
    --accent: #FFB27A;
    --accent-ink: #2A1306;
    --accent-soft: #33231A;
    --accent-text: #FFC79E;
    --focus: #FFC79E;
    color-scheme: dark;
  }
}
:root:where([data-theme="dark"]) {
  --canvas: #121214;
  --surface: #1D1D21;
  --surface-2: #26262B;
  --surface-3: #303036;
  --ink: #F2F1EC;
  --ink-2: #C2C1BC;
  --line: rgb(255 255 255 / .10);
  --line-2: rgb(255 255 255 / .22);
  --shadow-1: 0 1px 0 rgb(255 255 255 / .04) inset, 0 8px 24px -12px rgb(0 0 0 / .6);
  --shadow-2: 0 1px 0 rgb(255 255 255 / .05) inset, 0 28px 56px -22px rgb(0 0 0 / .8);
  --accent: #FFB27A;
  --accent-ink: #2A1306;
  --accent-soft: #33231A;
  --accent-text: #FFC79E;
  --focus: #FFC79E;
  color-scheme: dark;
}
:root[lang="ar"] { --font: "Atkinson Hyperlegible Next", "IBM Plex Sans Arabic", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 16px; }
body {
  margin: 0; color: var(--ink); font: 400 1.0625rem/1.6 var(--font);
  background:
    radial-gradient(1100px 520px at 88% -12%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%),
    radial-gradient(900px 480px at -10% 110%, color-mix(in srgb, #E5508C 8%, transparent), transparent 70%),
    var(--canvas);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased; overflow-x: clip;
}
:root[lang="ar"] body { line-height: 1.7; }
:root[lang="ar"] body *:not(svg):not(svg *) { letter-spacing: normal !important; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
a { color: inherit; text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Drawn icons: 24×24, round strokes, a soft fill */
.ico { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; overflow: visible; }
.ico .f { fill: color-mix(in srgb, var(--c, var(--accent)) 50%, transparent); }
.ico .k { fill: currentColor; stroke: none; }
.ico .w { fill: var(--surface); }

/* ---------- Header ---------- */
.top { position: relative; z-index: 20; }
.top-in { max-width: 1180px; margin: 0 auto; padding: 0 var(--gutter); min-height: 88px; display: flex; flex-wrap: wrap; align-items: center; gap: 0 12px; }
.brand { display: flex; align-items: center; gap: 14px; margin-inline-end: auto; min-width: 0; }
.brand img { width: 52px; height: 52px; border-radius: 15px; transform: rotate(-6deg); box-shadow: 0 12px 24px -12px rgb(0 0 0 / .45); flex: none; }
.brand h1 { margin: 0; display: flex; align-items: center; font: italic 400 clamp(1.9rem, 4vw, 2.75rem)/1 var(--serif); letter-spacing: -0.01em; white-space: nowrap; }
body .top .fbk-beta {
  margin-inline-start: 10px; padding: .32em .62em; border: 0; border-radius: 999px; box-shadow: none;
  font: 700 max(.66rem, 11px)/1.1 var(--font); font-style: normal; letter-spacing: .06em;
  color: var(--accent-text); background: var(--accent-soft);
}
.fb-lang { display: flex; align-items: center; color: var(--line-2); font-size: .875rem; }
.fb-lang button { min-height: 44px; display: inline-flex; align-items: center; padding: 0 10px; border: 0; border-radius: 12px; background: none; color: var(--ink-2); font: 700 .875rem/1 var(--font); cursor: pointer; }
.fb-lang button:hover, .fb-lang button[aria-pressed="true"] { color: var(--ink); }
.fb-lang button[lang="ar"] { font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif; font-size: .95rem; }
.fb-lang button:focus-visible { outline-offset: -2px; }
.home-link, .fava-share-btn { min-height: 44px; min-width: 44px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 700; text-decoration: none; }
.home-link { padding-inline: 18px; background: var(--ink); color: var(--canvas); font-size: .9375rem; white-space: nowrap; }
.home-link:hover { filter: brightness(1.25); }
.fava-share-btn { padding: 0; background: var(--surface); border: 1.5px solid var(--line-2); color: var(--ink); cursor: pointer; }
.fava-share-btn svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.sound-btn {
  display: inline-grid; place-items: center; flex: none; width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%;
  color: var(--ink); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); cursor: pointer;
}
.sound-btn:hover { box-shadow: inset 0 0 0 1px var(--line-2); }
.sound-btn .snd-off { display: none; }
.sound-btn[data-on="false"] { color: var(--ink-2); }
.sound-btn[data-on="false"] .snd-on { display: none; }
.sound-btn[data-on="false"] .snd-off { display: inline; }
.sound-btn[data-on="false"] .ico .f { fill: none; }

main { max-width: 1180px; margin: 0 auto; padding: 8px var(--gutter) 24px; display: grid; gap: 22px; }

/* ---------- The table ---------- */
.play { display: grid; gap: 14px; }
.stage {
  position: relative; height: clamp(420px, calc(100svh - 230px), 660px);
  border-radius: var(--r-card); overflow: hidden;
  box-shadow: var(--shadow-2), inset 0 0 0 1px var(--line);
  background: #FFF6EC;
}
:root:where([data-theme="dark"]) .stage { background: #1B1624; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .stage { background: #1B1624; } }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
.stage canvas.over { cursor: pointer; }
.stage canvas:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; border-radius: var(--r-card); }
.hint {
  position: absolute; top: 14px; left: 14px; right: 14px; z-index: 2; pointer-events: none;
  width: fit-content; margin: 0 auto; padding: 9px 18px; border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line);
  font-weight: 700; font-size: .9375rem; line-height: 1.35; text-align: center; color: var(--ink);
  opacity: 0; transform: translateY(-6px); transition: opacity .5s var(--ease), transform .5s var(--ease);
}
.hint.on { opacity: 1; transform: none; }

/* ---------- Tools ---------- */
.tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.tools-main, .tools-side { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border: 0; border-radius: 999px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line);
  font: 700 .9375rem/1.2 var(--font); cursor: pointer; white-space: nowrap;
  transition: background-color .2s, transform .2s var(--ease), box-shadow .2s;
}
.btn:hover { background: color-mix(in srgb, var(--ink) 5%, var(--surface)); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 12px 24px -14px var(--accent); --c: #fff; }
.btn.primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn.primary .ico .f { fill: currentColor; }
.btn.icon { width: 48px; padding: 0; }
.btn.glow { background: var(--accent-soft); color: var(--accent-text); box-shadow: inset 0 0 0 2px var(--accent); }
.btn[disabled] { opacity: .45; cursor: default; transform: none; }
.tool-sep { width: 1px; height: 28px; background: var(--line-2); margin-inline: 4px; }
.swatches { display: flex; gap: 4px; }
.sw {
  width: 44px; height: 44px; padding: 0; border: 0; border-radius: 50%; background: none; cursor: pointer;
  display: grid; place-items: center;
}
.sw span { width: 30px; height: 30px; border-radius: 50%; background: var(--g); box-shadow: inset 0 0 0 1px rgb(0 0 0 / .08), 0 2px 6px -2px rgb(0 0 0 / .25); transition: transform .2s var(--ease); }
.sw[aria-checked="true"] span { transform: scale(1.08); box-shadow: 0 0 0 2.5px var(--surface), 0 0 0 4.5px var(--ink); }
.sw:hover span { transform: scale(1.08); }
.sw:focus-visible { outline-offset: 0; }

/* ---------- Tips ---------- */
.tips { padding: clamp(18px, 2.6vw, 28px); border-radius: var(--r-card); background: var(--surface); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line); }
.tips h2 { margin: 0 0 12px; font: italic 400 clamp(1.6rem, 3vw, 2.1rem)/1.1 var(--serif); letter-spacing: -0.01em; }
:root[dir="rtl"] .tips h2 { font: 700 1.375rem/1.3 var(--font); }
.tips ul { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px 22px; }
.tips li { display: flex; align-items: center; gap: 12px; color: var(--ink-2); line-height: 1.45; }
.tip-ico { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--ink); background: color-mix(in srgb, var(--c) 22%, var(--surface)); }

/* ---------- About, questions, footer, feedback ---------- */
.fb-about { max-width: 46rem; margin: 12px auto 0; padding: 26px var(--gutter) 6px; color: var(--ink-2); }
.fb-about h2 { margin: 0 0 10px; color: var(--ink); font: italic 400 clamp(2rem, 3.6vw, 2.75rem)/1.05 var(--serif); letter-spacing: -0.01em; }
:root[dir="rtl"] .fb-about h2 { font: 700 clamp(1.5rem, 2.6vw, 2rem)/1.3 var(--font); }
.fb-about > p { margin: 0 0 14px; line-height: 1.7; }
.fb-faq { display: grid; gap: 0; }
.fb-faq h3 { margin: 10px 0 4px; font-size: .9375rem; color: var(--ink); }
.fb-faq details { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; margin-block: 6px; }
.fb-faq summary { min-height: 56px; padding: 14px 20px; font-weight: 700; color: var(--ink); cursor: pointer; }
.fb-faq summary:focus-visible { outline-offset: 2px; border-radius: 22px; }
.fb-faq details[open] summary { border-bottom: 1px solid var(--line); }
.fb-faq details p { margin: 0; padding: 12px 20px 16px; line-height: 1.7; }
.foot { max-width: 1180px; margin: 0 auto; padding: 8px var(--gutter) 28px; color: var(--ink-2); font-size: .875rem; text-align: center; }
.foot p { margin: 0 auto 6px; max-width: 70ch; }
body .fbk {
  width: min(760px, calc(100% - 2 * var(--gutter)));
  margin: 24px auto 40px; padding: 24px 26px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 30px; box-shadow: var(--shadow-1);
}
body .fbk-q { font-weight: 700; font-size: 1.25rem; line-height: 1.3; }
body .fbk-q svg { stroke: var(--accent); }
body .fbk-hint { color: var(--accent-text); }
body .fbk-send { background: var(--accent); color: var(--accent-ink); font-weight: 700; min-height: 44px; padding: 0 22px; border-radius: 999px; }
body .fbk textarea, body .fbk input[type=email] { background: var(--surface); border-color: var(--line-2); border-radius: var(--r-sm); }
body .fbk .fbk-beta { color: var(--accent-text); background: var(--accent-soft); border: 0; box-shadow: none; }
body .fbk .fbk-star { background: none; min-width: 44px; min-height: 44px; border-radius: 12px; }
.fb-suggest { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin: 0; padding: 12px 16px; border-radius: 20px; background: var(--surface); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line); }
.fb-suggest p { margin: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.fb-suggest [lang="ar"] { font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif; font-weight: 600; }
.fb-suggest-acts { display: flex; flex-wrap: wrap; gap: 8px; }
.fb-suggest button { min-height: 44px; padding: 0 16px; border: 0; border-radius: 999px; cursor: pointer; font-weight: 700; background: var(--surface-2); }
.fb-suggest .fb-ar { background: var(--accent); color: var(--accent-ink); font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif; }

/* ---------- Shared prefs ---------- */
:root[data-text="large"] { font-size: 120%; }
:root[data-contrast="high"] { --ink-2: var(--ink); --line: rgb(29 29 31 / .45); --line-2: rgb(29 29 31 / .6); }
@media (prefers-color-scheme: dark) { :root[data-contrast="high"]:where(:not([data-theme="light"])) { --line: rgb(255 255 255 / .45); --line-2: rgb(255 255 255 / .6); } }
:root[data-contrast="high"]:where([data-theme="dark"]) { --line: rgb(255 255 255 / .45); --line-2: rgb(255 255 255 / .6); }
:root[data-contrast="high"] .btn { box-shadow: inset 0 0 0 1.5px var(--line-2); }
:root[data-motion="reduce"] *, :root[data-motion="reduce"] *::before, :root[data-motion="reduce"] *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }

/* ---------- Phones ---------- */
@media (max-width: 1023px) { .top-in { padding-top: 12px; } }
@media (max-width: 640px) {
  .top-in { min-height: 64px; row-gap: 0; }
  .brand img { width: 38px; height: 38px; border-radius: 11px; }
  .brand h1 { font-size: 1.6rem; }
  .home-link { font-size: 0; width: 44px; padding: 0; }
  .home-link::before { content: '←'; font-size: 1.1rem; line-height: 1; }
  :root[dir="rtl"] .home-link::before { content: '→'; }
  main { padding-top: 4px; gap: 18px; }
  .stage { height: min(64svh, 560px); min-height: 360px; border-radius: 26px; }
  .stage canvas:focus-visible { border-radius: 26px; }
  .tools { justify-content: center; }
  .tools-main { width: 100%; display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 8px; }
  .tools-main .btn { padding: 0 10px; gap: 6px; font-size: .875rem; min-width: 0; }
  .tools-main .btn span { overflow: hidden; text-overflow: ellipsis; }
  .tools-side { width: 100%; justify-content: space-between; gap: 4px; }
  .swatches { gap: 0; }
  .tool-sep { display: none; }
  .btn.icon { width: 46px; min-height: 46px; }
}
@media (max-width: 440px) {
  .top-in { flex-wrap: wrap; gap: 0 6px; }
  .brand { gap: 10px; }
  .fb-lang button { padding: 0 6px; }
  .sound-btn { background: none; box-shadow: none; }
}
@media (max-width: 360px) {
  .tools-main .btn .ico { display: none; }
  .sw { width: 40px; }
  .btn.icon { width: 44px; min-height: 44px; }
}

/* Until app.js has drawn the toy, keep the page below the header hidden (no layout jump). */
html.fb-wait body > :not(.top) { visibility: hidden; }
