/* Palette and radii come from GevaTalk: neutral surfaces, one accent, small corners. */
@font-face { font-family: 'GevaHandwriting'; src: url('../assets/fonts/GevaHandwriting-Regular.ttf') format('truetype'); font-display: swap; }
/* Digits, punctuation and Latin, drawn to match: GevaHandwriting itself holds only Hebrew letters. */
@font-face { font-family: 'GevaExtras'; src: url('../assets/fonts/GevaExtras.otf') format('opentype'); font-display: swap; }
@font-face { font-family: 'Suez One'; src: url('../assets/fonts/suez-hebrew.woff2') format('woff2'); unicode-range: U+0590-05FF, U+200C-2010, U+20AA, U+25CC, U+FB1D-FB4F; font-display: block; }
@font-face { font-family: 'Suez One'; src: url('../assets/fonts/suez-latin.woff2') format('woff2'); unicode-range: U+0000-00FF, U+2000-206F; font-display: block; }

:root {
  --accent: #e8553e; --accent-ink: #fff;
  --bg: #161718; --panel: #1c1d1f; --raised: #232427; --input: #121314;
  --hover: rgba(255,255,255,.055); --selected: rgba(255,255,255,.09);
  --line: #2b2c2f; --line-strong: #38393d;
  --text: #e8e8e6; --text-2: #a9abb0; --muted: #85878c;
  --danger: #f0616a; --shadow: 0 6px 18px rgba(0,0,0,.4);
  --r1: 4px; --r2: 6px; --r3: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
  --hand: 'GevaHandwriting', 'GevaExtras', 'Noteworthy', 'Chalkboard SE', 'Comic Sans MS', -apple-system, sans-serif;
  --paper: #fdfcf8; --ink: #1b1b1d; --rule: #d4dbe6; --gridline: #dde3ec;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f3f1; --panel: #fbfbfa; --raised: #fff; --input: #fff;
    --hover: rgba(0,0,0,.045); --selected: rgba(0,0,0,.08);
    --line: #e3e3e1; --line-strong: #d2d2cf;
    --text: #1b1b1d; --text-2: #4a4b50; --muted: #6b6c70;
    --accent: #d6432c; --danger: #c7323a; --shadow: 0 6px 18px rgba(0,0,0,.13);
    color-scheme: light;
  }
}
@media (prefers-contrast: more) { :root { --muted: var(--text-2); --line: var(--line-strong); } }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font: 17px/1.4 var(--font); overscroll-behavior: none; }
body { overflow: hidden; }
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
.ic { width: 22px; height: 22px; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app { position: fixed; inset: 0; overflow: hidden; }
.view { position: absolute; inset: 0; display: flex; flex-direction: column; background: var(--bg); will-change: transform, opacity; }

/* ---------- Opening card: copied from GevaTalk styles.css ---------- */
.studio-intro { position: fixed; inset: 0; z-index: 2000; display: grid; place-items: center; background: #161718; color: #e8e8e6; cursor: default; transition: opacity .45s ease; }
.studio-intro.out { opacity: 0; pointer-events: none; }
.studio-mark { display: flex; flex-direction: column; align-items: center; gap: 14px; transition: transform .45s ease; }
.studio-intro.out .studio-mark { transform: scale(1.04); }
.studio-word { display: flex; overflow: hidden; padding: .12em .1em; font-family: 'Suez One', var(--font); font-size: clamp(40px, 7vw, 76px); line-height: 1.15; color: #e8e8e6; }
.studio-letter { display: inline-block; opacity: 0; transform: translateY(105%); animation: studio-letter .55s cubic-bezier(.2,.8,.2,1) forwards; }
.studio-rule { width: 72%; height: 3px; background: #e8553e; transform: scaleX(0); animation: studio-rule .6s cubic-bezier(.6,0,.2,1) forwards; }
@keyframes studio-letter { to { opacity: 1; transform: none; } }
@keyframes studio-rule { to { transform: scaleX(1); } }
@media (prefers-reduced-motion: reduce) {
  .studio-letter, .studio-rule { animation-duration: .01s !important; animation-delay: 0s !important; }
}

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; min-width: 44px; padding: 0 14px; border-radius: var(--r2); background: var(--raised); border: 1px solid var(--line); font-weight: 500; white-space: nowrap; transition: background .12s; }
.btn:hover { background: var(--line-strong); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.icon-btn { display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: var(--r2); color: var(--text-2); flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* ---------- Home ---------- */
.home { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: max(20px, env(safe-area-inset-top)) max(28px, env(safe-area-inset-right)) 40px max(28px, env(safe-area-inset-left)); }
.home-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; margin-bottom: 26px; }
.home-title { flex: 1 1 auto; margin: 0; font-family: 'Suez One', var(--font); font-weight: 400; font-size: 38px; line-height: 1.15; }
.home-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.search { display: flex; align-items: center; gap: 8px; height: 44px; padding: 0 12px; background: var(--input); border: 1px solid var(--line); border-radius: var(--r2); color: var(--muted); min-width: 210px; }
.search:focus-within { border-color: var(--line-strong); }
.search input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--text); -webkit-appearance: none; }
.search input::placeholder { color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(216px, 1fr)); gap: 26px 22px; }
.card { min-width: 0; }
.card-open { display: block; width: 100%; text-align: start; border-radius: var(--r3); transition: transform .18s cubic-bezier(.2,.8,.2,1); }
@media (hover: hover) { .card-open:hover { transform: translateY(-3px); } }
.card-open:active { transform: scale(.98); }
.mini { position: relative; aspect-ratio: 3 / 4; overflow: hidden; border-radius: var(--r3); background-color: var(--paper); color: var(--ink); box-shadow: 0 0 0 1px rgba(0,0,0,.2), var(--shadow); pointer-events: none; }
.mini-in { position: absolute; top: 0; left: 0; width: 820px; min-height: 1094px; transform-origin: top left; padding: 56px 64px; }
.card-meta { display: flex; align-items: flex-start; gap: 4px; margin-top: 8px; }
.card-text { flex: 1; min-width: 0; padding-top: 2px; }
.card-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-rename { width: 100%; height: 30px; padding: 0 6px; background: var(--input); border: 1px solid var(--accent); border-radius: var(--r1); outline: 0; }
.card-date { font-size: 13px; color: var(--muted); }
.empty { grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; text-align: center; padding: 8vh 20px; gap: 6px; }
.empty h2 { margin: 12px 0 0; font-family: 'Suez One', var(--font); font-weight: 400; font-size: 26px; }
.empty p { margin: 0 0 16px; color: var(--text-2); }
.empty-page { width: 110px; height: 146px; border-radius: var(--r2); background: repeating-linear-gradient(var(--paper) 0 17px, var(--rule) 17px 18px); box-shadow: var(--shadow); transform: rotate(-3deg); }

/* ---------- Menus & popovers ---------- */
.pop { position: fixed; z-index: 500; background: var(--raised); border: 1px solid var(--line-strong); border-radius: var(--r3); box-shadow: var(--shadow); animation: pop .14s cubic-bezier(.2,.8,.2,1); max-width: calc(100vw - 20px); }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.menu { display: flex; flex-direction: column; padding: 5px; min-width: 190px; }
.menu button { min-height: 44px; padding: 0 12px; text-align: start; border-radius: var(--r1); }
.menu button:hover { background: var(--hover); }
.danger { color: var(--danger) !important; }
.swatches { display: flex; gap: 6px; padding: 8px; }
.sw { width: 40px; height: 40px; border-radius: var(--r2); background: var(--c); box-shadow: inset 0 0 0 1px rgba(128,128,128,.4); }
.sw.none { background: linear-gradient(to top right, transparent 47%, var(--danger) 47% 53%, transparent 53%), #fff; }
.sw:hover { transform: scale(1.08); }
.symbols { display: grid; grid-template-columns: repeat(7, 44px); padding: 6px; }
.symbols button { height: 44px; font-size: 21px; border-radius: var(--r1); }
.symbols button:hover { background: var(--hover); }
.settings { width: 280px; padding: 14px; display: flex; flex-direction: column; gap: 9px; }
.set-label { font-size: 14px; color: var(--text-2); }
.seg { display: flex; background: var(--input); border-radius: var(--r2); padding: 3px; gap: 2px; }
.seg button { flex: 1; min-height: 38px; border-radius: var(--r1); color: var(--text-2); }
.seg .on { background: var(--raised); color: var(--text); box-shadow: 0 0 0 1px var(--line-strong); }
.settings input[type=range] { width: 100%; accent-color: var(--accent); height: 30px; direction: ltr; }
.set-sep { height: 1px; background: var(--line); margin: 3px 0; }
.linkish { min-height: 40px; text-align: start; color: var(--text); }
.help { width: 350px; max-width: calc(100vw - 20px); padding: 16px; }
.help h3 { margin: 0 0 10px; font-size: 17px; }
.help dl { display: grid; grid-template-columns: auto 1fr; gap: 9px 14px; margin: 0; font-size: 15px; align-items: baseline; }
.help dt { white-space: nowrap; color: var(--text-2); }
.help dd { margin: 0; }
kbd { display: inline-block; direction: ltr; padding: 1px 6px; font: 13px/1.5 var(--font); background: var(--input); border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: var(--r1); color: var(--text); }
#toasts { position: fixed; bottom: max(22px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 900; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 14px; padding: 10px 16px; background: var(--raised); border: 1px solid var(--line-strong); border-radius: var(--r3); box-shadow: var(--shadow); animation: toast .24s cubic-bezier(.2,.8,.2,1); white-space: nowrap; }
@keyframes toast { from { opacity: 0; transform: translateY(12px); } }
.toast-act { color: var(--accent); font-weight: 700; min-height: 30px; }

/* ---------- Editor ---------- */
.ed-bar { flex: none; z-index: 5; background: var(--panel); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); animation: bar-in .42s cubic-bezier(.2,.8,.2,1) both; }
.entering .ed-bar { animation-delay: .1s; }
@keyframes bar-in { from { opacity: 0; transform: translateY(-16px); } }
.ed-top { display: flex; align-items: center; gap: 6px; padding: 6px 12px 0; }
.ed-title { flex: 1; min-width: 0; height: 44px; padding: 0 8px; font-family: 'Suez One', var(--font); font-size: 22px; background: none; border: 0; outline: 0; border-radius: var(--r2); }
.ed-title:hover { background: var(--hover); }
.ed-title::placeholder { color: var(--muted); }
.ed-status { font-size: 13px; color: var(--muted); white-space: nowrap; }
.ed-tools { display: flex; flex-wrap: wrap; gap: 2px 3px; padding: 2px 8px 6px; }
.tg { display: flex; flex: none; padding-inline-end: 3px; border-inline-end: 1px solid var(--line); }
.tg:last-child { border: 0; }
.tb { display: grid; place-items: center; min-width: 37px; height: 44px; padding: 0 3px; border-radius: var(--r2); color: var(--text-2); transition: background .1s; }
.tb:hover { background: var(--hover); color: var(--text); }
.tb:active { background: var(--selected); }
.tb.on { background: var(--selected); color: var(--accent); }
.t-h1 { font-weight: 700; font-size: 16px; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 3px; }
.t-h2 { font-weight: 600; font-size: 15px; }
.t-p { font-size: 15px; }
.t-a { font-size: 22px; font-weight: 600; } .t-a.s { font-size: 15px; }
.t-f { font-size: 19px; font-family: Georgia, 'Times New Roman', serif; }
.t-small { font-size: 15px; font-family: var(--font); font-weight: 600; direction: ltr; }
.t-color { border-bottom: 3px solid var(--accent); line-height: 1.05; font-family: var(--font); font-weight: 600; }
.t-mark { background: #ffe873; color: #1b1b1d; padding: 0 5px; border-radius: 2px; font-family: var(--font); font-weight: 600; font-size: 16px; }
.t-frac { display: inline-flex; flex-direction: column; align-items: center; font-size: 12px; line-height: 1.15; font-weight: 700; color: var(--accent); }
.t-frac i { font-style: normal; padding: 0 3px; } .t-frac i:first-child { border-bottom: 1.5px solid currentColor; }
.t-frac.s { font-size: 10px; }
.t-mixed { display: inline-flex; align-items: center; gap: 2px; direction: ltr; font-weight: 700; color: var(--accent); font-size: 15px; }
.t-vert { font-size: 11px; line-height: 1.15; font-weight: 600; text-align: right; direction: ltr; }

.ed-scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 22px max(16px, env(safe-area-inset-right)) 70px max(16px, env(safe-area-inset-left)); }
.paper { max-width: 900px; min-height: calc(100% - 4px); margin: 0 auto; border-radius: var(--r3); box-shadow: 0 0 0 1px rgba(0,0,0,.2), var(--shadow); background-color: var(--paper); color: var(--ink); cursor: text; display: flex; flex-direction: column; }
.paper > .sheet { flex: 1; border-radius: var(--r3); }

/* The page itself. Line height is one unit, headings take whole units so the ruled lines stay aligned. */
.sheet { --size: 28px; --lh: calc(var(--size) * 1.5); font-family: var(--hand); font-size: var(--size); line-height: var(--lh); caret-color: var(--accent); color: var(--ink); text-align: right; outline: 0; padding: var(--lh) clamp(22px, 6vw, 64px) calc(var(--lh) * 4); min-height: 100%; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.paper-lined .sheet { --rw: 1px; background: repeating-linear-gradient(transparent 0 calc(var(--lh) - var(--rw)), var(--rule) calc(var(--lh) - var(--rw)) var(--lh)); }
.paper-grid .sheet { --rw: 1px; background-image: linear-gradient(var(--gridline) var(--rw), transparent var(--rw)), linear-gradient(90deg, var(--gridline) var(--rw), transparent var(--rw)); background-size: calc(var(--lh) / 1.5) calc(var(--lh) / 1.5); }
.mini .sheet { --rw: 3px !important; } /* thicker so the rules survive being scaled down */
.sheet * { font-family: inherit !important; }
.sheet { padding-top: 0; }
.page-date { --size: 28px; flex: none; font-family: var(--hand); font-size: calc(var(--size) * .82); line-height: calc(var(--size) * 1.5); height: calc(var(--size) * 1.5); margin-top: calc(var(--size) * .75); padding: 0 clamp(22px, 6vw, 64px); text-align: right; color: var(--ink); direction: rtl; }
.paper-lined .page-date { box-shadow: inset 0 -1px var(--rule); }
.sheet p, .sheet h1, .sheet h2, .sheet ul, .sheet ol { margin: 0; }
.solving { color: #6b6c70; animation: solving 1s ease-in-out infinite alternate; }
@keyframes solving { from { opacity: .35; } }
.solve-btn { position: fixed; z-index: 21; min-height: 44px; padding: 0 16px; background: var(--accent); color: var(--accent-ink); font-weight: 700; border-radius: var(--r2); box-shadow: var(--shadow); white-space: nowrap; animation: pop .14s cubic-bezier(.2,.8,.2,1); }
.solve-btn[hidden] { display: none; }
.tablew { width: 100%; }
.tbl-h { position: fixed; z-index: 19; width: 32px; height: 32px; background: var(--accent); border: 2px solid #fff; border-radius: 50%; box-shadow: var(--shadow); touch-action: none; }
.tbl-h[hidden] { display: none; }
.tbl-h.active { transform: scale(1.2); }
.tbl-move { cursor: grab; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border-radius: var(--r2); }
.tbl-move i { display: block; width: 14px; height: 2px; background: #fff; }
.tbl-size { width: 28px; height: 28px; cursor: nesw-resize; }
.modal { position: fixed; inset: 0; z-index: 600; display: grid; place-items: center; padding: 20px; background: rgba(0,0,0,.5); animation: fade .16s; }
.modal-card { background: var(--raised); border: 1px solid var(--line-strong); border-radius: var(--r3); box-shadow: var(--shadow); animation: panel .26s cubic-bezier(.2,.8,.2,1); }
.key-card { width: min(420px, 100%); padding: 20px; }
.key-card h2 { margin: 0; font-size: 22px; }
.key-card p { margin: 6px 0 14px; color: var(--text-2); }
.key-msg:empty { display: none; }
.t-solve { font-weight: 700; font-size: 15px; color: var(--accent); }
.toast { white-space: normal !important; max-width: min(620px, calc(100vw - 32px)); }
.key-card .key-msg { margin: 10px 0 0; font-size: 15px; overflow-wrap: anywhere; }
.key-card input { width: 100%; height: 44px; padding: 0 12px; background: var(--input); border: 1px solid var(--line-strong); border-radius: var(--r2); outline: 0; }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.gallery { width: min(900px, 100%); height: min(760px, 100%); display: flex; flex-direction: column; overflow: hidden; }
.gal-head { flex: none; display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); }
.gal-head .search { flex: 1 1 240px; }
.gal-body { flex: 1; overflow-y: auto; padding: 4px 14px 18px; }
.gal-title { margin: 14px 0 8px; font-size: 15px; color: var(--text-2); font-weight: 600; }
.gal-note { color: var(--text-2); margin: 16px 0; }
.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.gal-tile { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r2); overflow: hidden; text-align: center; font-size: 14px; }
.gal-tile img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; background: #fff; }
.gal-tile span { padding: 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
/* Subjects look like the real notebooks in a schoolbag: a coloured cover with a white name label. */
.shelf { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 24px 22px; }
.shelf[hidden], .grid[hidden] { display: none; }
.book { position: relative; aspect-ratio: 3 / 4; }
.book-open { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; width: 100%; height: 100%; padding: 18px 18px 18px 30px; background: var(--cover); border-radius: 5px 10px 10px 5px; box-shadow: var(--shadow); color: #fff; overflow: hidden; transition: transform .18s cubic-bezier(.2,.8,.2,1); }
html[dir=rtl] .book-open { border-radius: 10px 5px 5px 10px; padding: 18px 30px 18px 18px; }
.book-open::before { content: ''; position: absolute; top: 0; bottom: 0; right: 0; width: 18px; background: rgba(0,0,0,.25); }
.book-open:active { transform: scale(.98); }
@media (hover: hover) { .book-open:hover { transform: translateY(-4px) rotate(-.6deg); } }
.book-label { display: block; width: 100%; padding: 12px 8px; background: #fdfcf8; color: #1b1b1d; border-radius: 4px; font-family: var(--hand); font-size: 32px; line-height: 1.25; text-align: center; overflow-wrap: anywhere; }
.book-count { font-weight: 600; font-size: 15px; }
.book-input { width: 100%; height: 56px; padding: 0 8px; background: #fdfcf8; color: #1b1b1d; border: 0; border-radius: 4px; outline: 2px solid #fff; font: 28px var(--hand); text-align: center; }
.book-more { position: absolute; top: 6px; left: 6px; color: #fff; }
.book-more:hover { background: rgba(0,0,0,.2); color: #fff; }
.subject-dot { display: inline-block; width: 18px; height: 18px; margin-inline-end: 10px; border-radius: 4px; background: var(--cover); }
.subject .home-head { gap: 12px 8px; }
.home-name { flex: 1 1 auto; min-width: 200px; }
.home-date { color: var(--text-2); font-size: 15px; }
.g-load { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; padding: 20px; }
.g-load h2 { margin: 0; font: 400 34px 'Suez One', var(--font); }
.g-load p { margin: 0 0 8px; color: #a9abb0; }
.player:focus { outline: 0; }
.sheet h1 { font-size: 1.7em; font-weight: 400; line-height: calc(var(--lh) * 2); text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: .16em; text-decoration-color: var(--accent); text-align: center; }
.sheet h2 { font-size: 1.28em; font-weight: 400; line-height: calc(var(--lh) * 1); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: .14em; }
.sheet b, .sheet strong { font-weight: 700; -webkit-text-stroke: .4px currentColor; }
.sheet ul, .sheet ol { padding-inline-start: 1.3em; }
.sheet ul.checks { list-style: none; padding-inline-start: 0; }
.sheet ul.checks > li { position: relative; padding-inline-start: 1.25em; }
.sheet ul.checks > li::before { content: ''; position: absolute; inset-inline-start: 0; top: calc((var(--lh) - .78em) / 2); width: .78em; height: .78em; border: 2px solid #6b6c70; border-radius: 4px; cursor: pointer; }
.sheet ul.checks > li.done { color: #6b6c70; text-decoration: line-through; }
.sheet ul.checks > li.done::before { background: var(--accent); border-color: var(--accent); }
.sheet hr { border: 0; border-top: 2px solid var(--ink); margin: calc(var(--lh) / 2 - 1px) 0; }
.mx { unicode-bidi: isolate; direction: ltr; }

/* Fractions: real stacked numbers with a line between them. */
.frac { display: inline-flex; align-items: center; gap: .14em; vertical-align: middle; margin: 0 .12em; line-height: 1; direction: ltr; unicode-bidi: isolate; }
.stack { display: inline-flex; flex-direction: column; align-items: stretch; text-align: center; font-size: .78em; }
.frac .n, .frac .d, .frac .w, .rootx .r, .vl { outline: 0; min-width: .75em; -webkit-user-select: text; user-select: text; caret-color: var(--accent); }
.frac .n { display: block; padding: 0 .16em .04em; border-bottom: 2px solid currentColor; line-height: 1.05; }
.frac .d { display: block; padding: .06em .16em 0; line-height: 1.05; }
.frac .w { display: inline-block; text-align: center; }
.frac [contenteditable]:empty::before, .rootx [contenteditable]:empty::before, .vl:empty::before { content: '\25a1'; color: #a9abb0; }
.frac [contenteditable]:focus { background: rgba(232,85,62,.13); border-radius: 2px; }
.rootx { display: inline-flex; align-items: flex-start; vertical-align: baseline; direction: ltr; unicode-bidi: isolate; margin: 0 .08em; }
.rootx .rad { font-size: 1em; line-height: 1.2; }
.rootx .r { display: inline-block; border-top: 2px solid currentColor; padding: 0 .12em; line-height: 1.2; }
.sheet sup { font-size: .62em; line-height: 0; }

.vert { display: inline-flex; flex-direction: column; min-width: 4.5em; margin: calc(var(--lh) / 2) 0; float: none; direction: ltr; text-align: right; letter-spacing: .06em; }
.vl { display: block; padding: 0 .3em; line-height: var(--lh); }
.vl.res { border-top: 2px solid var(--ink); }

.tablew { margin: calc(var(--lh) / 2) 0; overflow-x: auto; }
.sheet table { border-collapse: collapse; width: 100%; background: rgba(255,255,255,.55); }
.sheet td { border: 1.5px solid var(--ink); padding: .1em .4em; min-width: 2em; vertical-align: top; text-align: right; }

.pic { display: block; margin: calc(var(--lh) / 2) auto; position: relative; line-height: 0; }
.pic[data-side=right] { float: right; margin: .3em 0 .3em 1em; }
.pic[data-side=left] { float: left; margin: .3em 1em .3em 0; }
.pic img { width: 100%; height: auto; border-radius: var(--r2); display: block; }
.pic.selected { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: var(--r2); }
.pic.selected::after { content: ''; position: absolute; left: -8px; bottom: -8px; width: 18px; height: 18px; background: var(--accent); border: 2px solid #fff; border-radius: 50%; pointer-events: none; }
.float-bar { position: fixed; z-index: 20; display: flex; align-items: center; gap: 2px; padding: 4px; background: var(--raised); border: 1px solid var(--line-strong); border-radius: var(--r3); box-shadow: var(--shadow); }
.float-bar[hidden] { display: none; }
.float-bar button { min-height: 40px; padding: 0 10px; border-radius: var(--r1); font-size: 15px; white-space: nowrap; }
.float-bar button:hover { background: var(--hover); }
.float-bar .sep { width: 1px; height: 22px; background: var(--line-strong); margin: 0 3px; }

/* ---------- Games shelf ---------- */
.games { overflow-y: auto; padding: max(14px, env(safe-area-inset-top)) max(28px, env(safe-area-inset-right)) 44px max(28px, env(safe-area-inset-left)); }
.games-head { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; }
.games-head h1 { margin: 0; font-family: 'Suez One', var(--font); font-weight: 400; font-size: 34px; }
.shelf-title { margin: 24px 0 12px; font-size: 15px; font-weight: 600; color: var(--text-2); }
.g3d { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.g2d { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.gcard { display: flex; flex-direction: column; text-align: start; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r3); overflow: hidden; transition: transform .16s cubic-bezier(.2,.8,.2,1), border-color .12s; }
/* Hover only with a real pointer: on a touch iPad the first tap could get spent on it. */
@media (hover: hover) { .gcard:hover { transform: translateY(-3px); border-color: var(--line-strong); } }
.gcard:active { transform: scale(.985); }
.gart { display: block; width: 100%; aspect-ratio: 16 / 9; }
.g2d .gart { aspect-ratio: 3 / 2; }
.gart svg { width: 100%; height: 100%; display: block; }
.ginfo { padding: 10px 12px 12px; }
.gname { font-weight: 700; font-size: 18px; }
.g2d .gname { font-size: 16px; }
.gdesc { color: var(--text-2); font-size: 14px; line-height: 1.3; margin-top: 2px; }
.gbest { color: var(--muted); font-size: 13px; margin-top: 5px; }
.g-tabs { margin-inline-start: auto; width: 220px; }
.learn-note { margin: 4px 0 14px; color: var(--text-2); font-size: 15px; }
.glearn { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }

/* Learning games: grade and language picker on the start panel */
.lp-lang { margin: 18px auto 0; width: 240px; background: #121314; }
.lp-lang button { color: #a9abb0; }
.lp-lang .on { background: #2c2d31; color: #fff; box-shadow: 0 0 0 1px #4a4b50; }
.lp-label { margin: 18px 0 10px; font-weight: 700; font-size: 17px; color: #e8e8e6; }
.lp-grades { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.lp-grades button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 0 8px; border-radius: var(--r2); background: #fff; color: #2b2f36; box-shadow: 0 5px 0 #c9c2b6; transition: transform .1s, box-shadow .1s; }
.lp-grades button b { font: 400 30px/1 'Suez One', var(--font); }
.lp-grades button i { font-style: normal; font-size: 12px; color: #7a7f88; }
.lp-grades button:nth-child(-n+2) { background: #e6f7e1; box-shadow: 0 5px 0 #9fd18f; }
.lp-grades button:nth-child(n+5) { background: #ffe6e2; box-shadow: 0 5px 0 #eaa59a; }
@media (hover: hover) { .lp-grades button:hover { transform: translateY(-2px); box-shadow: 0 7px 0 #b0a99d; } }
.lp-grades button:active { transform: translateY(4px); box-shadow: 0 1px 0 #b0a99d; }
.lp-stars { display: block; font-size: 44px; letter-spacing: 4px; color: #f4b400; line-height: 1.1; margin: 4px 0; }
.lp-stars i { font-style: normal; color: #3a3b40; }
.lp-rec { font-size: 14px; }
.g-btns { flex-wrap: wrap; }

/* ---------- Game player ---------- */
.player { background: #0b0c0d; color: #e8e8e6; user-select: none; -webkit-user-select: none; }
.stage { position: absolute; inset: 0; display: grid; place-items: center; overflow: hidden; touch-action: none; }
.stage canvas { display: block; }
.stage canvas.fit2d { max-width: 100%; max-height: 100%; }
.stage canvas.fit3d { width: 100%; height: 100%; }
.g-hud { position: absolute; inset: 0; pointer-events: none; }
.g-top { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 12px; right: 12px; display: flex; align-items: center; gap: 6px; z-index: 6; }
.g-top .icon-btn { color: #e8e8e6; background: rgba(0,0,0,.42); }
.g-top .icon-btn:hover { background: rgba(0,0,0,.7); color: #fff; }
.g-score { margin-inline-start: auto; padding: 4px 12px; background: rgba(0,0,0,.42); border-radius: var(--r2); font-weight: 700; font-size: 20px; font-variant-numeric: tabular-nums; direction: ltr; }
.g-over { position: absolute; inset: 0; z-index: 8; display: grid; place-items: center; background: rgba(10,11,12,.76); animation: fade .2s; padding: 20px; overflow: auto; }
@keyframes fade { from { opacity: 0; } }
.g-panel { width: min(470px, 100%); padding: 26px; background: #1c1d1f; border: 1px solid #38393d; border-radius: var(--r3); text-align: center; animation: panel .3s cubic-bezier(.2,.8,.2,1); }
@keyframes panel { from { opacity: 0; transform: translateY(16px) scale(.98); } }
.g-panel h2 { margin: 0; font-family: 'Suez One', var(--font); font-weight: 400; font-size: 34px; }
.g-panel p { color: #a9abb0; margin: 6px 0 0; }
.g-big { font-size: 58px; font-weight: 800; color: #e8553e; line-height: 1.15; margin-top: 6px; font-variant-numeric: tabular-nums; }
.g-keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 18px 0; text-align: start; align-items: center; font-size: 15px; color: #d6d6d4; }
.g-keys > span:nth-child(odd) { text-align: end; white-space: nowrap; }
.g-panel kbd { background: #121314; border-color: #38393d; color: #e8e8e6; }
.g-btns { display: flex; gap: 8px; justify-content: center; margin-top: 18px; }
.g-panel .btn { background: #232427; border-color: #38393d; color: #e8e8e6; }
.g-panel .btn.primary { background: #e8553e; border-color: transparent; color: #fff; }
.vignette { position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 120px 30px rgba(220,30,20,.75); opacity: 0; transition: opacity .25s; }
.crosshair { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; margin: -11px 0 0 -11px; }
.crosshair::before, .crosshair::after { content: ''; position: absolute; background: rgba(255,255,255,.85); box-shadow: 0 0 2px #000; }
.crosshair::before { left: 10px; top: 0; width: 2px; height: 22px; clip-path: polygon(0 0,100% 0,100% 30%,0 30%,0 70%,100% 70%,100% 100%,0 100%); }
.crosshair::after { top: 10px; left: 0; height: 2px; width: 22px; clip-path: polygon(0 0,30% 0,30% 100%,70% 100%,70% 0,100% 0,100% 100%,0 100%); }
.hud-row { position: absolute; bottom: max(16px, env(safe-area-inset-bottom)); left: 18px; right: 18px; display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; direction: ltr; text-shadow: 0 1px 3px #000; font-weight: 700; }
.hud-stat { font-size: 15px; color: #d6d6d4; } .hud-stat b { display: block; font-size: 34px; color: #fff; line-height: 1; font-variant-numeric: tabular-nums; }
.hud-bar { width: 190px; height: 10px; background: rgba(0,0,0,.55); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.hud-bar i { display: block; height: 100%; background: #e8553e; }
.hud-msg { position: absolute; top: 18%; left: 0; right: 0; text-align: center; font: 400 40px 'Suez One', var(--font); color: #fff; text-shadow: 0 2px 10px #000; animation: msg 1.8s both; }
@keyframes msg { 0% { opacity: 0; transform: translateY(10px); } 12%, 75% { opacity: 1; transform: none; } 100% { opacity: 0; } }
.hud-tip { position: absolute; top: 74px; left: 0; right: 0; text-align: center; font-size: 15px; color: #d6d6d4; text-shadow: 0 1px 3px #000; }

@media (prefers-reduced-motion: reduce) {
  .ed-bar, .pop, .toast, .g-over, .g-panel, .hud-msg { animation-duration: .01s !important; animation-delay: 0s !important; }
  .card-open, .gcard { transition: none; }
}

@media (max-width: 720px) {
  .home, .games { padding-left: 16px; padding-right: 16px; }
  .search { flex: 1 1 100%; }
  .btn span { display: inline; }
  .g3d { grid-template-columns: 1fr; }
}

/* Print / PDF: the page only, no chrome. */
@media print {
  html, body { overflow: visible; height: auto; background: #fff; }
  #app, .view, .ed-scroll { position: static; overflow: visible; display: block; height: auto; }
  .ed-bar, #toasts, .float-bar, .pop, .home-head { display: none !important; }
  .ed-scroll { padding: 0; }
  .paper { box-shadow: none; max-width: none; }
}
