/* Hand in Hand — the frame, the shared art classes and the screens.
   Parts of the game keep their own sheets in /css/ (skill, logic, scenes,
   rooms); everything shares the tokens below. */

:root {
  color-scheme: light;
  --bg: #fff6ef;
  --bg2: #ffe9ee;
  --surface: #ffffff;
  --surface2: #fff8f3;
  --text: #3b2a2f;
  --muted: #86707a;
  --line: rgba(75, 51, 40, 0.13);
  --accent: #ff7a9a;
  --accent-soft: #ffe0e8;
  --btn: #c23a6b; /* white text on it: 5.7:1 */
  --btn-hover: #ad2f5d;
  --gold: #ffcf5a;
  --mint: #8fd18a;
  --sky: #a9daf0;
  --ok: #2f8a4a;
  --shadow: 0 14px 34px -16px rgba(130, 60, 80, 0.45);
  --shadow-sm: 0 4px 12px -6px rgba(130, 60, 80, 0.4);
  --radius: 22px;
  --ca-accent: #c23a6b; /* the accounts SDK's sheets and chip */
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bar-h: 58px;
}
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { color-scheme: dark; }
}
:root[data-theme="dark"],
:root.dark-auto {
  --bg: #1b1624;
  --bg2: #241c31;
  --surface: #2a2237;
  --surface2: #31283f;
  --text: #f7ebf1;
  --muted: #bba7b5;
  --line: rgba(255, 255, 255, 0.11);
  --accent: #ff8fae;
  --accent-soft: #4a2c40;
  --ok: #7fd49a;
  --shadow: 0 16px 40px -18px rgba(0, 0, 0, 0.7);
  --shadow-sm: 0 4px 14px -6px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
/* no double-tap zoom on iOS: js/touch-guard.js adds the same rule plus a JS
   fallback; this copy covers Safari before 16.4 under the strict CSP */
:where(html, body, body *) { touch-action: manipulation; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0; height: 100%; min-height: 100dvh; display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 16px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
/* a game page: no text selection or long-press callouts anywhere, HUD and
   menus included; form fields and long text (the Help sheet) opt back in */
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
input, textarea, [contenteditable], .sheet p { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ top bar */
.bar { position: relative; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 10px; height: var(--bar-h); padding: 0 12px 0 14px; flex: none; }
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; background: none; border: 0; padding: 4px 6px 4px 0; cursor: pointer; border-radius: 14px; }
.brand svg { width: 34px; height: 34px; flex: none; }
.title { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-tools { display: flex; align-items: center; gap: 6px; flex: none; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  display: inline-grid; place-items: center; cursor: pointer; box-shadow: var(--shadow-sm); transition: transform 0.15s ease, background 0.15s;
  flex: none; padding: 0;
}
.icon-btn:hover { background: var(--surface2); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn[disabled] { opacity: 0.4; cursor: default; }
#account-chip { min-width: 44px; display: flex; justify-content: flex-end; }

/* ------------------------------------------------------------ buttons, cards */
.btn {
  min-height: 48px; padding: 0 22px; border-radius: 16px; border: 0; background: var(--btn); color: #fff; font-weight: 800; font-size: 16px;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; box-shadow: 0 6px 0 -1px #8f2649, var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s;
}
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: translateY(3px); box-shadow: 0 3px 0 -1px #8f2649, var(--shadow-sm); }
.btn.soft { background: var(--surface); color: var(--text); box-shadow: 0 5px 0 -1px var(--line), var(--shadow-sm); border: 1px solid var(--line); }
.btn.soft:hover { background: var(--surface2); }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 14px; border-radius: 13px; }
.btn svg { width: 20px; height: 20px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.muted { color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--text); font-size: 13px; font-weight: 700; }

/* ------------------------------------------------------------ screens */
#app { position: relative; flex: 1; min-height: 0; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; overflow: hidden; animation: screen-in 0.35s cubic-bezier(.2,.8,.3,1) both; }
.screen.leaving { animation: screen-out 0.22s ease both; pointer-events: none; }
.scroll { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
@keyframes screen-in { from { opacity: 0; transform: translateY(14px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes screen-out { to { opacity: 0; transform: translateY(-8px) scale(0.99); } }

/* ------------------------------------------------------------ dialogs */
.sheet {
  border: 0; border-radius: 26px; padding: 22px; width: min(92vw, 440px); max-height: min(86dvh, 720px); overflow: auto;
  background: var(--surface); color: var(--text); box-shadow: 0 30px 80px -30px rgba(0,0,0,.55);
}
.sheet::backdrop { background: rgba(30, 14, 24, 0.42); backdrop-filter: blur(6px); }
.sheet[open] { animation: sheet-in 0.3s cubic-bezier(.2,.9,.3,1.2) both; }
@keyframes sheet-in { from { opacity: 0; transform: translateY(20px) scale(0.96); } }
.sheet h2 { margin: 0 0 14px; font-size: 21px; font-weight: 800; }
.sheet p { margin: 0 0 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.row:last-of-type { border-bottom: 0; }
.row select { min-height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface2); color: var(--text); padding: 0 10px; font: inherit; max-width: 60%; }
.switch { appearance: none; -webkit-appearance: none; width: 52px; height: 32px; border-radius: 99px; background: var(--line); position: relative; cursor: pointer; transition: background 0.2s; flex: none; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.25); transition: transform 0.2s cubic-bezier(.3,.7,.4,1.3); }
.switch:checked { background: var(--btn); }
.switch:checked::after { transform: translateX(20px); }
.sheet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }
.link-btn { background: none; border: 0; color: var(--btn); font-weight: 700; cursor: pointer; padding: 10px 0; min-height: 44px; text-align: left; }
:root[data-theme="dark"] .link-btn, :root.dark-auto .link-btn { color: var(--accent); }
.version { color: var(--muted); font-size: 13px; }
.help-list { padding-left: 1.1em; margin: 0 0 8px; }
.help-list li { margin-bottom: 8px; }

/* ------------------------------------------------------------ the challenge frame (games and rooms) */
.host { position: absolute; inset: 0; display: flex; flex-direction: column; }
.host-bar { display: flex; align-items: center; gap: 8px; padding: 6px 12px 8px; flex: none; }
.host-title { flex: 1; min-width: 0; }
.host-title b { display: block; font-size: 17px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.host-title span { display: block; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.hint-btn { width: auto; padding: 0 14px 0 10px; border-radius: 22px; gap: 6px; display: inline-flex; font-weight: 800; font-size: 14px; }
.hint-btn .count { min-width: 20px; height: 20px; border-radius: 10px; background: var(--accent-soft); font-size: 12px; display: inline-grid; place-items: center; }
.host-stage { position: relative; flex: 1; min-height: 0; margin: 0 10px 10px; border-radius: 24px; overflow: hidden; background: var(--surface2); box-shadow: inset 0 0 0 1px var(--line); isolation: isolate; }
.host-stage > .game { position: absolute; inset: 0; }
.overlay { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px; background: rgba(255, 246, 239, 0.62); backdrop-filter: blur(5px); animation: fade-in 0.25s ease both; }
:root[data-theme="dark"] .overlay, :root.dark-auto .overlay { background: rgba(27, 22, 36, 0.66); }
.overlay .card { width: min(100%, 430px); padding: 20px 20px 22px; text-align: center; max-height: 100%; overflow: auto; animation: pop-in 0.42s cubic-bezier(.2,.9,.3,1.25) both; }
.overlay h2 { margin: 4px 0 6px; font-size: 24px; font-weight: 900; letter-spacing: -0.01em; }
.overlay p { margin: 0 0 12px; color: var(--muted); }
.overlay .how { text-align: left; color: var(--text); background: var(--surface2); border-radius: 16px; padding: 12px 14px; margin: 10px 0 16px; font-size: 15px; }
.overlay .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.overlay .pair-art { width: 210px; height: 130px; margin: -4px auto 0; display: block; }
.overlay .tag { display: inline-flex; gap: 6px; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(18px) scale(0.92); } }
.toast {
  position: absolute; left: 50%; bottom: 18px; z-index: 30; transform: translateX(-50%); max-width: min(92%, 440px);
  background: var(--surface); color: var(--text); border-radius: 18px; padding: 10px 16px; box-shadow: var(--shadow); border: 1px solid var(--line);
  font-weight: 700; text-align: center; animation: toast-in 0.3s cubic-bezier(.2,.9,.3,1.2) both; pointer-events: none;
}
.toast.out { animation: toast-out 0.25s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 14px) scale(0.95); } }
@keyframes toast-out { to { opacity: 0; transform: translate(-50%, 8px); } }

/* speech bubbles over characters (HTML, positioned by JS) */
.bubble {
  position: absolute; z-index: 15; max-width: min(260px, 70vw); padding: 10px 14px; border-radius: 18px; background: var(--surface); color: var(--text);
  box-shadow: var(--shadow); border: 2px solid #4b3328; font-weight: 700; font-size: 15px; line-height: 1.35; transform: translate(-50%, -100%);
  animation: bubble-in 0.3s cubic-bezier(.2,.9,.3,1.3) both; pointer-events: none;
}
.bubble::after { content: ""; position: absolute; left: 50%; bottom: -10px; width: 16px; height: 16px; background: inherit; border: 2px solid #4b3328; border-top: 0; border-left: 0; transform: translateX(-50%) rotate(45deg); }
@keyframes bubble-in { from { opacity: 0; transform: translate(-50%, -88%) scale(0.85); } }

/* confetti hearts (fx.js) */
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 25; overflow: hidden; }
.fx svg { position: absolute; width: 26px; height: 26px; left: 0; top: 0; will-change: transform, opacity; }

/* ------------------------------------------------------------ the art: lines and animations */
.o { stroke: #4b3328; stroke-width: 3.5; stroke-linejoin: round; stroke-linecap: round; }
.ln { fill: none; stroke: #4b3328; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.lw { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.t15 { stroke-width: 1.5; } .t2 { stroke-width: 2; } .t22 { stroke-width: 2.2; } .t25 { stroke-width: 2.5; } .t3 { stroke-width: 3; } .t32 { stroke-width: 3.2; } .t4 { stroke-width: 4; }

.chr .eh, .chr .ez, .chr .mg, .chr .mo, .chr .md { display: none; }
.x-happy .eo, .x-sleep .eo { display: none; }
.x-happy .eh { display: inline; }
.x-sleep .ez { display: inline; }
.x-happy .ms, .x-wow .ms, .x-sad .ms { display: none; }
.x-happy .mg { display: inline; }
.x-wow .mo { display: inline; }
.x-sad .md { display: inline; }
.chr-bup.x-sleep .eo { display: inline; } /* Bup's heart eyes never close */

.br { animation: br 2.6s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 100%; }
.bl { animation: bl 4.2s infinite; transform-box: fill-box; transform-origin: center; }
.fl { animation: fl 3.2s ease-in-out infinite; }
.ht { animation: ht 3s ease-in infinite; transform-box: fill-box; transform-origin: center; }
.tw { animation: tw 2.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.tg { animation: tg 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: 0% 100%; }
.tg2 { animation-duration: 0.45s; }
.pl { animation: pl 1.1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.an { animation: an 1.6s steps(1) infinite; }
.wg { animation: wg 0.22s ease-in-out infinite; transform-box: fill-box; transform-origin: 50% 100%; }
.rt { animation: rt 9s linear infinite; transform-box: fill-box; transform-origin: center; }
.glow { animation: glow 2.2s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.jp { animation: jp 0.7s cubic-bezier(.3,.6,.4,1); }
.wiggle { animation: wiggle 0.5s ease-in-out; transform-box: fill-box; transform-origin: 50% 100%; }
.d1 { animation-delay: -0.4s; } .d2 { animation-delay: -0.8s; } .d3 { animation-delay: -1.2s; } .d4 { animation-delay: -1.6s; } .d5 { animation-delay: -2s; } .d6 { animation-delay: -2.4s; }
.chr + .chr .br, .lb .br { animation-delay: -1.3s; }
.lb .bl { animation-delay: -1.7s; }
.lb .ht { animation-delay: -1.5s; }

@keyframes br { 0%, 100% { transform: scale(1, 1); } 50% { transform: scale(0.985, 1.03); } }
@keyframes bl { 0%, 90%, 100% { transform: scaleY(1); } 94% { transform: scaleY(0.1); } }
@keyframes fl { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes ht { 0% { transform: translateY(10px) scale(0.5); opacity: 0; } 25% { opacity: 1; } 100% { transform: translateY(-28px) scale(1.05); opacity: 0; } }
@keyframes tw { 0%, 100% { opacity: 0.35; transform: scale(0.7); } 50% { opacity: 1; transform: scale(1.1); } }
@keyframes tg { 0%, 100% { transform: rotate(-10deg); } 50% { transform: rotate(12deg); } }
@keyframes pl { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }
@keyframes an { 0% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes wg { 0%, 100% { transform: scaleY(1); } 50% { transform: scaleY(0.6); } }
@keyframes rt { to { transform: rotate(360deg); } }
@keyframes glow { 0%, 100% { opacity: 0.45; transform: scale(0.92); } 50% { opacity: 0.8; transform: scale(1.08); } }
@keyframes jp { 0% { transform: translateY(0); } 35% { transform: translateY(-16px); } 70% { transform: translateY(0); } 85% { transform: translateY(-4px); } 100% { transform: translateY(0); } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }

/* less motion: the setting, or the device's own choice */
.reduce .br, .reduce .bl, .reduce .fl, .reduce .ht, .reduce .tw, .reduce .tg, .reduce .pl, .reduce .an, .reduce .wg, .reduce .rt, .reduce .glow { animation: none !important; }
.reduce .screen, .reduce .sheet[open], .reduce .overlay, .reduce .overlay .card, .reduce .bubble, .reduce .toast { animation-duration: 0.01s !important; }
/* the device asks for less motion and the player has not chosen "full motion" in Settings */
@media (prefers-reduced-motion: reduce) {
  :root:not(.full) .br, :root:not(.full) .bl, :root:not(.full) .fl, :root:not(.full) .ht, :root:not(.full) .tw, :root:not(.full) .tg,
  :root:not(.full) .pl, :root:not(.full) .an, :root:not(.full) .wg, :root:not(.full) .rt, :root:not(.full) .glow { animation: none !important; }
  :root:not(.full) .screen, :root:not(.full) .sheet[open], :root:not(.full) .overlay, :root:not(.full) .overlay .card { animation-duration: 0.01s !important; }
}
.reduce .jp, .reduce .wiggle { animation: none !important; }
