/* Bean Stack: a bean stacking toy in the Favabeans look (see ../APP_DESIGN.md, 2026 refresh).
   Light by default, dark when the system asks or the shared prefs force it. Accent: periwinkle.
   No dark green or dark teal anywhere. */
:root {
  --canvas: #F7F6F2;
  --surface: #FFFFFF;
  --surface-2: #EFEDE6;
  --surface-3: #E6E3DA;
  --ink: #18181B;
  --ink-2: #46464E;
  --line: rgb(24 24 27 / .09);
  --line-2: rgb(24 24 27 / .18);
  --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;

  /* Accent: periwinkle */
  --accent: #5146D8;
  --accent-ink: #FFFFFF;
  --accent-soft: #E9E7FF;
  --accent-text: #4136B8;
  --focus: #5146D8;

  /* The stage (the sky itself is painted by app.js) */
  --box-0: #C4E6FF;
  --box-1: #FFE6F0;
  --box-rim: rgb(60 40 90 / .10);
  --sheen: rgb(255 255 255 / .28);
  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: #ADA6FF; --accent-ink: #17133D; --accent-soft: #25223F; --accent-text: #C8C3FF; --focus: #C8C3FF;
    --box-0: #17172E; --box-1: #2A1E3E; --box-rim: rgb(255 255 255 / .08); --sheen: rgb(255 255 255 / .05);
    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: #ADA6FF; --accent-ink: #17133D; --accent-soft: #25223F; --accent-text: #C8C3FF; --focus: #C8C3FF;
  --box-0: #17172E; --box-1: #2A1E3E; --box-rim: rgb(255 255 255 / .08); --sheen: rgb(255 255 255 / .05);
  color-scheme: dark;
}

*, *::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);
  -webkit-font-smoothing: antialiased; overflow-x: clip;
  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, #FF8FB8 12%, transparent), transparent 70%),
    var(--canvas);
  background-attachment: fixed;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
a { color: inherit; text-underline-offset: 3px; }
h1, h2, h3 { font-weight: 700; letter-spacing: -0.02em; }
: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; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; overflow: visible; flex: none; }
.ico .f { fill: color-mix(in srgb, var(--c, var(--accent)) 45%, transparent); }
.ico .k { fill: currentColor; stroke: none; }

/* ---------- Header (same pattern as the other apps) ---------- */
.top { position: relative; z-index: 20; }
.top-in { max-width: 1180px; margin: 0 auto; padding-inline: 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-inline: 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[aria-pressed="false"] { font-weight: 500; }
.fb-lang button[lang="ar"] { font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif; font-size: .95rem; }
.home-link, .fava-share-btn, .sound-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); white-space: nowrap; font-size: .9rem; }
.home-link:hover { filter: brightness(1.25); }
.fava-share-btn, .sound-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 .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: 6px var(--gutter) 28px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }

/* ---------- The stage ---------- */
.play { display: grid; gap: 14px; }
.box {
  position: relative; height: clamp(380px, 66vh, 660px); border-radius: var(--r-card); overflow: hidden;
  background: linear-gradient(180deg, var(--box-0), var(--box-1));
  box-shadow: var(--shadow-2), inset 0 0 0 1.5px var(--box-rim);
}
.box::after { /* soft glass sheen and rim on top */
  content: ''; position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  background: linear-gradient(160deg, var(--sheen), transparent 30%);
  box-shadow: inset 0 0 0 1.5px var(--box-rim);
}
.box canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  touch-action: none; cursor: pointer; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.box canvas:focus-visible { outline: none; }
.box:has(canvas:focus-visible) { outline: 3px solid var(--focus); outline-offset: 3px; }
.hint, .toast {
  position: absolute; inset-inline: 12px; margin: 0; display: flex; justify-content: center; pointer-events: none; text-align: center;
  transition: opacity .6s var(--ease), transform .6s var(--ease);
}
.hint { top: 36%; }
.toast { bottom: 18px; }
.hint span, .toast span {
  padding: 12px 22px; border-radius: 999px; background: var(--ink); color: var(--canvas);
  font-weight: 700; font-size: 1.0625rem; box-shadow: var(--shadow-2);
}
.toast span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-2), inset 0 0 0 1.5px var(--accent-soft); }
.hint.gone, .toast.gone { opacity: 0; transform: translateY(-6px); }
.toast.gone { transform: translateY(6px); }

/* ---------- Tools and actions ---------- */
.tools { display: flex; gap: 4px; padding: 4px; border-radius: 22px; background: var(--surface); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line); }
.tool {
  flex: 1 1 0; min-width: 0; min-height: 52px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 14px; border: 0; border-radius: 18px; background: transparent; color: var(--ink);
  font: 700 .9375rem/1.1 var(--font); cursor: pointer;
  transition: background-color .2s var(--ease), color .2s, transform .2s var(--ease);
}
.tool:hover { background: var(--surface-2); }
.tool:active { transform: scale(.97); }
.tool[aria-pressed="true"] { background: var(--ink); color: var(--canvas); }
.tool[aria-pressed="true"] .ico .f { fill: color-mix(in srgb, var(--c) 75%, transparent); }
#turnBtn { --c: #FF7EB0; }
#wobbleBtn { --c: #FFC93C; }
#freshBtn { --c: #4CB4FF; }
#bookBtn { --c: #9B7BFF; }
#turnBtn .ico rect { transition: transform .3s var(--ease); transform-origin: 12px 10.5px; }
#turnBtn[aria-pressed="true"] .ico rect { transform: rotate(90deg); }

.acts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.best {
  margin: 0; margin-inline-end: auto; min-height: 48px; display: inline-flex; align-items: center; gap: 8px;
  padding: 0 18px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); font-weight: 700;
  --c: #FFC93C;
}
.best .ico { color: var(--accent-text); }
.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(--btn, var(--surface)); color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line-2);
  font: 700 .9375rem/1.2 var(--font); cursor: pointer; white-space: nowrap;
  transition: background-color .2s, transform .2s var(--ease), filter .2s;
}
.btn:hover { background: color-mix(in srgb, var(--ink) 6%, var(--btn, var(--surface))); }
.btn:active { transform: scale(.98); }
.btn.primary { --c: #fff; background: var(--accent); color: var(--accent-ink); box-shadow: 0 12px 24px -14px var(--accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.primary .ico .f { fill: color-mix(in srgb, var(--accent-ink) 25%, transparent); }

/* ---------- Bean book (a dialog; a bottom sheet on phones) ---------- */
.book {
  width: min(640px, calc(100% - 32px)); max-height: min(86vh, 760px); padding: 22px 22px 24px; border: 0; border-radius: 26px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-2);
}
.book::backdrop { background: rgb(20 16 40 / .38); }
.book-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.book h2 { margin: 0; font: italic 400 clamp(1.8rem, 3vw, 2.2rem)/1.1 var(--serif); }
:root[dir="rtl"] .book h2 { font: 700 1.5rem/1.3 var(--font); }
.book-x { width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 50%; background: var(--surface-2); color: var(--ink); cursor: pointer; }
.book-note { margin: 6px 0 16px; color: var(--ink-2); }
.book-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.book-grid li { display: grid; justify-items: center; gap: 4px; padding: 12px 10px 14px; border-radius: 20px; background: var(--surface-2); text-align: center; }
.book-grid img { width: 100px; height: 64px; object-fit: contain; }
.book-grid b { font-size: .98rem; line-height: 1.25; }
.book-grid small { color: var(--ink-2); font-size: .84rem; line-height: 1.4; }
.book-grid li.locked b { color: var(--ink-2); }
.book-grid .dots { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin-top: 4px; }
.book-grid .dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1.5px rgb(58 42 23 / .55); }
.book-grid .dots i.off { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line-2); }
.book-grid .dots + small { margin-top: 2px; }

/* ---------- Settings card ---------- */
.card { background: var(--surface); border-radius: var(--r-card); box-shadow: var(--shadow-1), inset 0 0 0 1px var(--line); padding: clamp(18px, 2.6vw, 28px); }
.prefs { display: grid; gap: 12px; justify-items: start; }
.prefs-title { margin: 0; font: italic 400 clamp(1.7rem, 3vw, 2.2rem)/1.05 var(--serif); }
:root[dir="rtl"] .prefs-title { font: 700 1.5rem/1.3 var(--font); }
.prefs [data-fava-howto] { margin: 0; }
.pref-note { margin: 0; color: var(--ink-2); font-size: .9375rem; }
.theme-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.theme-l { font-weight: 700; }
.theme-seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 999px; background: var(--surface-2); }
.theme-opt { position: relative; }
.theme-opt input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.theme-opt span { display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: 999px; color: var(--ink-2); font-weight: 700; font-size: .9375rem; }
.theme-opt input:checked + span { background: var(--ink); color: var(--canvas); }
.theme-opt input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- About, FAQ, 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; font-size: 1.0625rem; line-height: 1.7; }
.fb-faq h3 { margin: 18px 0 6px; font-size: .9375rem; color: var(--ink); }
.fb-faq details { background: var(--surface); border: 1px solid var(--line); border-radius: 22px; margin-block: 10px; }
.fb-faq summary { min-height: 56px; padding: 14px 20px; font-size: 1.0625rem; font-weight: 700; color: var(--ink); cursor: pointer; }
.fb-faq details[open] summary { border-bottom: 1px solid var(--line); }
.fb-faq summary:focus-visible { border-radius: 22px; }
.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-family: var(--font); font-style: normal; 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 { min-height: 44px; padding: 0 22px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); font-weight: 700; }
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; font-family: var(--font); font-weight: 700; letter-spacing: .06em; }
body .fbk .fbk-star { min-width: 44px; min-height: 44px; background: none; padding: 8px; border-radius: 12px; }
body .fbk .fbk-link { background: none; min-height: 44px; padding: 4px 0; border-radius: 0; }
body .fbk button:focus-visible, body .fbk textarea:focus-visible, body .fbk input:focus-visible { outline-color: var(--focus); }

/* ---------- Arabic ---------- */
:root[lang="ar"] { --font: "Atkinson Hyperlegible Next", "IBM Plex Sans Arabic", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
:root[lang="ar"] body { line-height: 1.7; }
:root[lang="ar"] body *:not(svg):not(svg *) { letter-spacing: normal !important; }
:root[dir="rtl"] .brand h1 { font: 700 1.75rem/1.1 var(--font); }
:root[dir="rtl"] .brand h1 > span { font: italic 400 clamp(1.9rem, 4vw, 2.6rem)/1 var(--serif); }
.fb-suggest { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; 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-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; }
.fb-suggest .fb-ar { background: var(--accent); color: var(--accent-ink); font-family: 'IBM Plex Sans Arabic', system-ui, sans-serif; }
.fb-suggest .fb-en { background: var(--surface-2); color: var(--ink); }

/* ---------- Shared comfort settings (prefs.js) ---------- */
:root[data-text="large"] { font-size: 120%; }
:root[data-contrast="high"] { --ink-2: var(--ink); --line: rgb(24 24 27 / .45); --line-2: rgb(24 24 27 / .6); --box-rim: rgb(24 24 27 / .5); }
@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); --box-rim: rgb(255 255 255 / .5); } }
:root[data-contrast="high"]:where([data-theme="dark"]) { --line: rgb(255 255 255 / .45); --line-2: rgb(255 255 255 / .6); --box-rim: rgb(255 255 255 / .5); }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
:root[data-motion="reduce"] *, :root[data-motion="reduce"] *::before, :root[data-motion="reduce"] *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }

/* ---------- Desktop: tools and actions share one dock under the box ---------- */
@media (min-width: 900px) {
  .play { grid-template-columns: auto 1fr; grid-template-areas: "box box" "tools acts"; align-items: center; gap: 14px 16px; }
  .box { grid-area: box; }
  .tools { grid-area: tools; }
  .tool { flex: none; }
  .acts { grid-area: acts; justify-content: flex-end; }
  .best { margin-inline-end: 0; }
}

/* ---------- Phones ---------- */
@media (max-width: 1023px) { .top-in { padding-top: 12px; } }
@media (max-width: 640px) {
  .top-in { min-height: 64px; row-gap: 0; gap: 0 8px; }
  .brand { gap: 10px; }
  .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: '→'; }
  .fb-lang button { padding-inline: 6px; font-size: .8125rem; }
  main { gap: 16px; }
  .play { gap: 10px; }
  .box { height: min(58vh, 540px); height: min(58svh, 540px); border-radius: 26px; }
  .tool { flex-direction: column; gap: 3px; min-height: 60px; padding: 6px 2px; border-radius: 16px; font-size: .78rem; text-align: center; }
  .acts { flex-wrap: nowrap; }
  .best { padding: 0 14px; min-width: 0; }
  .acts .btn { flex: 1 1 auto; min-width: 0; padding: 0 14px; }
  .hint span, .toast span { font-size: 1rem; padding: 11px 18px; }
  .book { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 26px 26px 0 0; padding: 14px 16px 22px; max-height: 88vh; }
  .book::before { content: ''; display: block; width: 36px; height: 4px; margin: 0 auto 10px; border-radius: 4px; background: var(--line-2); }
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 440px) {
  .top-in { flex-wrap: wrap; }
  body .top .fbk-beta { margin-inline-start: 6px; padding: .3em .5em; }
  .sound-btn, .fava-share-btn { border: 0; background: none; }
}
@media (max-width: 370px) {
  .acts .btn .ico { display: none; }
  .best { padding: 0 12px; font-size: .9rem; }
}
