/* Nakama app surface. Tokens come from the native theme (ui/theme/Theme.kt) so web and native screens match; the
   composition follows the redesign canvas (glass panels over imagery, one clear primary action, 44px targets). */
:root, [data-theme="galaxy"] {
  --bg: #05020F; --bg2: #0D0A24; --surf: #14102E; --surf2: #1C1540; --line: #2A2160; --line2: #3B2E80;
  --fg: #EDE9FF; --fg2: #CBBFE8; --fg3: #B8ACE0; --fg4: #9D92C9;
  --pri: #A78BFA; --onpri: #1A0A4A; --pric: #3D1FA8; --onpric: #EDE9FF; --act: #7C3AED; --onact: #FFFFFF;
  --sec: #F472B6; --secc: #7B1450; --onsecc: #FFD8EE; --ter: #22D3EE; --terc: #0E4F5F; --onterc: #A5F3FC;
  --err: #FFB4AB; --errc: #93000A; --onerrc: #FFDAD6; --ok: #86EFAC; --warn: #FDE68A; --gold: #FCD34D;
  --topbar: rgba(5,2,15,0.88); --secbg: rgba(244,114,182,0.18); --tagbg: rgba(61,31,168,0.45); --tagline: rgba(167,139,250,0.35); --errbg: rgba(147,0,10,0.3);
  --glass: rgba(13,10,36,0.84); --glass2: rgba(20,16,46,0.88); --glassline: rgba(167,139,250,0.22); --scrim: rgba(5,2,15,0.6);
  color-scheme: dark;
}
[data-theme="dark"] {
  --bg: #0F0D1C; --bg2: #151226; --surf: #1A1730; --surf2: #252140; --line: #2E2A48; --line2: #48454E;
  --fg: #E5E0F8; --fg2: #C8C4DA; --fg3: #B3AFC6; --fg4: #918EA3;
  --pri: #BDB4FE; --onpri: #2D2570; --pric: #433D8A; --onpric: #E3DFFF; --act: #5B52C9; --onact: #FFFFFF;
  --sec: #EFB8CA; --secc: #633A4D; --onsecc: #FFD8E6; --ter: #EBC97E; --terc: #5A4200; --onterc: #FFDE9C;
  --topbar: rgba(15,13,28,0.9); --tagbg: rgba(67,61,138,0.45); --tagline: rgba(189,180,254,0.35);
  --glass: rgba(15,13,28,0.86); --glass2: rgba(26,23,48,0.9); --glassline: rgba(189,180,254,0.2);
}
[data-theme="light"] {
  --bg: #FCF8FF; --bg2: #F4EFFA; --surf: #FFFFFF; --surf2: #E5E0EF; --line: #E2DCEE; --line2: #C9C3D6;
  --fg: #1C1B22; --fg2: #48454E; --fg3: #5C5966; --fg4: #6F6C78;
  --pri: #4F3FA0; --onpri: #FFFFFF; --pric: #E5DFFF; --onpric: #160458; --act: #5B3FD0; --onact: #FFFFFF;
  --sec: #7A3560; --secc: #FFD8E6; --onsecc: #31001F; --ter: #6E5600; --terc: #FFDE9C; --onterc: #221B00;
  --err: #BA1A1A; --errc: #FFDAD6; --onerrc: #410002; --ok: #15803D; --warn: #92400E; --gold: #A16207;
  --topbar: rgba(252,248,255,0.9); --secbg: rgba(122,53,96,0.12); --tagbg: rgba(229,223,255,0.8); --tagline: rgba(79,63,160,0.3); --errbg: rgba(255,218,214,0.8);
  --glass: rgba(255,255,255,0.86); --glass2: rgba(255,255,255,0.92); --glassline: rgba(79,63,160,0.18); --scrim: rgba(28,27,34,0.4);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--fg); }
body {
  /* The phone's own font, as the native screens use (FontFamily.Default); web fonts would not load in mainland China. */
  font-family: system-ui, -apple-system, Roboto, 'Noto Sans', 'Segoe UI', 'Noto Sans CJK SC', 'Noto Sans JP', sans-serif;
  font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none; user-select: none; -webkit-user-select: none;
}
input, textarea, [contenteditable] { user-select: text; -webkit-user-select: text; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 2px solid var(--pri); outline-offset: 2px; }
.display { font-weight: 800; letter-spacing: 0.1px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--fg3); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Screens: every visited screen stays mounted (hidden) so back is instant and keeps its scroll. */
#app { height: var(--nk-viewport-height, 100%); top: var(--nk-viewport-top, 0px); position: relative; }
/* No `contain` here: size/layout containment makes the screen the containing block of position:fixed sheets and dialogs,
   which then scroll with the page. */
/* 11-10: the page's own bottom bar (core/app-bar.js), only when the app asks for it. #app ends above it, as the native
   bar's Scaffold padding did, so no screen needs changing. */
.has-appbar #app { height: calc(var(--nk-viewport-height, 100%) - 64px); }
#nk-appbar .appbar { position: fixed; left: 0; right: 0; bottom: 0; height: 64px; z-index: 30; display: flex; justify-content: center;
  background: var(--surf); border-top: 1px solid var(--line); }
.appbar-tab { flex: 1; max-width: 140px; min-width: 0; border: 0; background: transparent; color: var(--fg3); display: flex;
  flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 0; font: 600 10px/1.1 inherit; }
.appbar-tab.on { color: var(--fg); }
.appbar-ico { position: relative; display: grid; place-items: center; width: 56px; height: 28px; border-radius: 14px; }
.appbar-tab.on .appbar-ico { background: var(--pric); color: var(--onpric); }
.appbar-tab.create .appbar-ico { width: 36px; height: 36px; border-radius: 18px; background: var(--pri); color: var(--onpri); }
.appbar-ico .badge { top: -4px; right: 6px; }
.appbar-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.screen { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; background: var(--bg); }
.screen[hidden] { display: none !important; }
.screen.enter { animation: enter 120ms ease-out; }
.native-shell .screen.enter { animation: none; }
/* Fade only: transforming the screen moves fixed sheets and compounds the native transition. */
@keyframes enter { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .screen.enter { animation: none; } }
.pad { padding: 0 16px; }
.stack { display: flex; flex-direction: column; gap: var(--gap, 10px); }
.row { display: flex; align-items: center; gap: var(--gap, 10px); }
.grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.bottom-space { height: 24px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 2px; min-height: 56px; padding: 6px 6px 4px 6px;
  background: var(--topbar); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.topbar h1 { margin: 0; font-size: 21px; flex: 1; min-width: 0; padding-left: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back + h1 { padding-left: 2px; }
.icon-btn { width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center; border-radius: 14px; color: var(--fg2); position: relative; }
.icon-btn:active { background: var(--surf2); }
.icon-btn.on-image { background: rgba(5,2,15,0.55); color: #EDE9FF; border-radius: 22px; backdrop-filter: blur(10px); }
.badge { position: absolute; top: 6px; right: 6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--sec); color: #3B0A24;
  font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.dot { position: absolute; top: 9px; right: 9px; width: 8px; height: 8px; border-radius: 4px; background: var(--sec); }

/* Buttons */
.btn { height: 46px; padding: 0 18px; border-radius: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 15px; font-weight: 800; transition: transform 80ms, filter 80ms; white-space: nowrap; }
.btn:active { transform: scale(0.98); filter: brightness(1.08); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn.primary { background: var(--act); color: var(--onact); }
.btn.tonal { background: var(--surf2); color: var(--fg); border: 1px solid var(--line2); }
.btn.outline { border: 1px solid var(--line2); color: var(--fg); }
.btn.ghost { color: var(--pri); padding: 0 10px; height: 40px; font-weight: 700; font-size: 14px; }
.btn.danger { color: var(--err); border: 1px solid var(--err); }
.btn.sm { height: 36px; padding: 0 14px; border-radius: 12px; font-size: 13px; }
.btn.block { width: 100%; }
.pill { border-radius: 999px; }

/* Chips and segmented controls */
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 0 16px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 34px; padding: 0 14px; border-radius: 17px; border: 1px solid var(--line2); color: var(--fg2); font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.chip.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.chip.accent.on { background: var(--secbg); color: var(--sec); border-color: var(--sec); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: var(--bg2); border: 1px solid var(--surf2); }
.seg button { height: 34px; border-radius: 10px; color: var(--fg3); font-size: 13px; font-weight: 700; padding: 0 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seg button.on { background: var(--pric); color: var(--onpric); }
.tag { height: 28px; padding: 0 10px; border-radius: 14px; background: var(--tagbg); border: 1px solid var(--tagline);
  font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; max-width: 100%; overflow: hidden; white-space: nowrap; }
.label { font-size: 11px; font-weight: 800; letter-spacing: 0.9px; color: var(--fg4); text-transform: uppercase; margin: 0; }
.h2 { font-size: 16px; font-weight: 800; margin: 0; }

/* Surfaces */
.card { background: var(--surf); border: 1px solid var(--line); border-radius: 18px; }
.card.pad16 { padding: 14px; }
.tile { background: var(--surf); border: 1px solid var(--surf2); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 4px; color: var(--fg); text-align: left; }
.tile:active, .card.tap:active, .list-row:active { filter: brightness(1.15); }
.glass { background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--glassline); }
.list { display: flex; flex-direction: column; border-radius: 16px; background: var(--surf); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 14px; text-align: left; width: 100%; color: var(--fg); }
.list-row + .list-row { border-top: 1px solid var(--line); }
.list-row .meta { font-size: 13px; color: var(--fg3); }
.avatar { flex: none; border-radius: 50%; background: var(--pric); color: var(--onpric); display: inline-flex; align-items: center; justify-content: center; font-weight: 800; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.art { position: relative; background: var(--surf2); overflow: hidden; }
.art img { width: 100%; height: 100%; object-fit: cover; }
.art.blur img { filter: blur(18px) brightness(0.8); transform: scale(1.1); }
.skel { background: linear-gradient(90deg, var(--surf) 0%, var(--surf2) 50%, var(--surf) 100%); background-size: 200% 100%; animation: skel 1.2s infinite linear; border-radius: 12px; }
@keyframes skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 48px 24px; text-align: center; color: var(--fg3); }
.err-box { margin: 16px; padding: 14px; border-radius: 16px; background: var(--errbg); color: var(--onerrc); display: flex; gap: 10px; align-items: center; }

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 700; color: var(--fg2); }
.input { width: 100%; min-height: 46px; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line2); background: var(--bg2); color: var(--fg); font-size: 15px; font-weight: 500; outline: none; }
.input:focus { border-color: var(--pri); }
textarea.input { resize: vertical; line-height: 1.45; }
.input::placeholder { color: var(--fg4); }
.switch { flex: none; width: 46px; height: 28px; border-radius: 14px; background: var(--line2); position: relative; transition: background 120ms; }
.switch::after { content: ''; position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 10px; background: var(--fg); transition: transform 140ms; }
.switch.on { background: var(--act); }
.switch.on::after { transform: translateX(18px); background: #fff; }

/* Sheets, dialogs, toasts */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 40; animation: fade 140ms; }
@keyframes fade { from { opacity: 0; } }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; max-height: 88%; z-index: 41; border-radius: 26px 26px 0 0; background: var(--surf);
  border-top: 1px solid var(--glassline); display: flex; flex-direction: column; animation: up 200ms cubic-bezier(.2,.8,.2,1); }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line2); margin: 8px auto 0; flex: none; }
.sheet .body { overflow-y: auto; padding: 8px 16px 24px; }
.dialog { position: fixed; left: 24px; right: 24px; top: 50%; transform: translateY(-50%); z-index: 41; max-width: 420px; margin: 0 auto; padding: 20px;
  border-radius: 24px; background: var(--surf); border: 1px solid var(--glassline); display: flex; flex-direction: column; gap: 12px; animation: fade 140ms; }
.dialog h2 { margin: 0; font-size: 18px; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.toast { position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 60; margin: 0 auto; max-width: 480px; padding: 12px 16px; border-radius: 14px;
  background: var(--fg); color: var(--bg); font-size: 14px; font-weight: 600; display: flex; gap: 10px; align-items: center; animation: up 180ms; }
.toast button { color: var(--act); font-weight: 800; margin-left: auto; }

/* Character card (Discover and every grid) */
.cgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; padding: 0 16px; }
.ccard { position: relative; aspect-ratio: 0.65; border-radius: 18px; overflow: hidden; background: var(--surf2); border: 1px solid var(--line); }
.ccard > a { position: absolute; inset: 0; color: #EDE9FF; }
.ccard .art { position: absolute; inset: 0; }
.ccard .cap { position: absolute; left: 6px; right: 6px; bottom: 6px; padding: 9px 10px; border-radius: 13px; background: rgba(13,10,36,0.5);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); text-shadow: 0 1px 3px rgba(0,0,0,0.85); border: 1px solid rgba(167,139,250,0.18); display: flex; flex-direction: column; gap: 2px; color: #EDE9FF; }
.ccard .cap .name { font-size: 15px; line-height: 1.2; }
.ccard .cap .by { font-size: 11px; color: #B8ACE0; }
.ccard .cap .bio { font-size: 12px; line-height: 16px; color: #DCD3F5; }
.ccard .cap .stats { display: flex; gap: 10px; margin-top: 3px; font-size: 11px; font-weight: 700; color: #CBBFE8; }
.ccard .cap .stats span { display: inline-flex; align-items: center; gap: 4px; }
.ccard .badges { position: absolute; top: 8px; left: 8px; display: flex; gap: 4px; }
.ccard .badges span { height: 22px; padding: 0 8px; border-radius: 11px; background: rgba(5,2,15,0.72); color: #F9A8D4; font-size: 11px; font-weight: 800; display: flex; align-items: center; }
.ccard .corner { position: absolute; top: 6px; right: 6px; }
.ccard .corner .icon-btn { width: 36px; height: 36px; background: rgba(5,2,15,0.6); color: #EDE9FF; border-radius: 12px; }

/* Right-to-left (Arabic): direction-bearing icons and switches mirror. */
[dir="rtl"] .rtl-flip { transform: scaleX(-1); }
[dir="rtl"] .switch::after { left: auto; right: 4px; }
[dir="rtl"] .switch.on::after { transform: translateX(-18px); }
