@font-face { font-family: 'Fredoka'; src: url(../fonts/fredoka.woff2) format('woff2'); font-weight: 300 700; font-display: swap; }
@font-face { font-family: 'Baloo 2'; src: url(../fonts/baloo2-deva.woff2) format('woff2'); font-weight: 400 800; font-display: swap; unicode-range: U+0900-097F, U+1CD0-1CF9, U+200C-200D, U+20A8, U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FF; }

:root {
  --bg1: #4c6dff; --bg2: #3a3fc9; --bg3: #2a2387;
  --panel: rgba(44, 48, 96, .72); --panel-b: rgba(160, 170, 255, .14);
  --text: #f4f5ff; --muted: #d3d8ff;
  --cyan: #38d6ff; --cyan2: #0fa3e6;
  --red: #ff4d5e; --green: #5fe06b; --yellow: #ffd23f; --blue: #3fb6ff;
  --font: 'Fredoka', 'Baloo 2', system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--font); color: var(--text); font-weight: 500;
  background: radial-gradient(circle at 12% 18%, rgba(255,255,255,.18) 0 2px, transparent 3px) 0 0 / 46px 46px,
              radial-gradient(circle at 70% 60%, rgba(255,255,255,.12) 0 1.5px, transparent 2.5px) 0 0 / 63px 63px,
              radial-gradient(120% 70% at 15% 0%, #7fa0ff 0%, transparent 55%),
              radial-gradient(90% 60% at 100% 100%, #8a4dff 0%, transparent 60%),
              linear-gradient(170deg, var(--bg1), var(--bg2) 55%, var(--bg3));
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
button { font-family: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input { font-family: inherit; }
svg { width: 100%; height: 100%; display: block; }

#app { position: relative; height: 100%; max-width: 520px; margin: 0 auto; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
.screen { position: absolute; inset: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); display: none; flex-direction: column; padding: 12px 14px 16px; overflow-y: auto; }
.screen.active { display: flex; animation: fadein .35s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.glass { background: var(--panel); border: 1px solid var(--panel-b); border-radius: 26px; box-shadow: 0 18px 40px rgba(8, 10, 40, .45), inset 0 1px 0 rgba(255,255,255,.08); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.round-btn { width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.1); display: grid; place-items: center; color: #dfe2ff; box-shadow: 0 6px 16px rgba(0,0,0,.25); flex: none; }
.round-btn svg { width: 22px; height: 22px; }
.round-btn:active, .big-btn:active, .pill-btn:active { transform: scale(.95); }
.pill-btn { padding: 10px 18px; border-radius: 999px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.14); font-weight: 600; font-size: 15px; }
.pill-btn.wa { background: #25d366; color: #063; border-color: transparent; }

.bar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.bar h2 { flex: 1; text-align: center; margin: 0; font-size: 22px; font-weight: 700; }
.bar .sp { width: 44px; }

/* ---------- HOME ---------- */
#s-home { align-items: center; justify-content: center; gap: 6px; }
.home-top { position: absolute; top: 12px; left: 14px; right: 14px; display: flex; justify-content: space-between; }
.hero-avatars { display: flex; gap: 10px; margin-bottom: 6px; }
.ha { width: 62px; height: 62px; border-radius: 18px; border: 3px solid; object-fit: cover; animation: bob 3s ease-in-out infinite; }
.ha1 { border-color: var(--blue); box-shadow: 0 0 18px var(--blue); }
.ha2 { border-color: var(--red); box-shadow: 0 0 18px var(--red); animation-delay: .4s; }
.ha3 { border-color: var(--yellow); box-shadow: 0 0 18px var(--yellow); animation-delay: .8s; }
.ha4 { border-color: var(--green); box-shadow: 0 0 18px var(--green); animation-delay: 1.2s; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-2deg); } }
.logo { font-size: clamp(76px, 26vw, 120px); line-height: .9; margin: 8px 0 0; font-weight: 700; letter-spacing: 2px; color: #fff;
  text-shadow: 0 3px 0 #d9dcf7, 0 6px 0 #b9bde8, 0 10px 18px rgba(0,0,0,.45); }
.logo span { display: inline-block; color: var(--lc); -webkit-text-stroke: 3px #fff; paint-order: stroke fill; text-shadow: 0 5px 0 var(--ld), 0 10px 18px rgba(0,0,0,.4); animation: bob 3s ease-in-out infinite; }
.logo span:nth-child(2) { animation-delay: .25s; } .logo span:nth-child(3) { animation-delay: .5s; } .logo span:nth-child(4) { animation-delay: .75s; }
.brand { margin: 4px 0 22px; color: var(--muted); font-size: 16px; text-align: center; }
.brand span { display: block; color: #dfe1ff; }
.menu-btns { display: flex; flex-direction: column; gap: 14px; width: min(340px, 100%); }
.big-btn { height: 58px; border-radius: 20px; font-size: 20px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 0 18px;
  color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.18); transition: transform .1s; }
.big-btn .ico { width: 26px; height: 26px; flex: none; }
.big-btn.cyan { background: linear-gradient(180deg, #5fe3ff, #12a6e8); box-shadow: 0 6px 0 #0b78ad, 0 12px 26px rgba(56, 214, 255, .4); }
.big-btn.violet { background: linear-gradient(180deg, #a08bff, #6b4fe0); box-shadow: 0 6px 0 #4a33a8, 0 12px 26px rgba(130, 100, 255, .35); }
.big-btn.green { background: linear-gradient(180deg, #7ff08a, #2fb84a); box-shadow: 0 6px 0 #1f8434, 0 12px 26px rgba(95, 224, 107, .35); }
.big-btn.wide { width: 100%; margin-top: 16px; }
.big-btn:disabled { filter: grayscale(.7) brightness(.7); }
.dots-deco { display: flex; gap: 10px; margin-top: 26px; }
.dots-deco i { width: 14px; height: 14px; border-radius: 50%; }
.dots-deco .b { background: var(--blue); box-shadow: 0 0 10px var(--blue); } .dots-deco .r { background: var(--red); box-shadow: 0 0 10px var(--red); }
.dots-deco .g { background: var(--green); box-shadow: 0 0 10px var(--green); } .dots-deco .y { background: var(--yellow); box-shadow: 0 0 10px var(--yellow); }

/* ---------- SETUP / ONLINE / LOBBY ---------- */
.card { padding: 18px; margin-bottom: 14px; }
.card.center { display: flex; flex-direction: column; align-items: center; text-align: center; }
.lbl { display: block; color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.seg { display: flex; background: rgba(0,0,0,.2); border-radius: 16px; padding: 4px; gap: 4px; margin-bottom: 14px; }
.seg button { flex: 1; height: 42px; border-radius: 12px; font-size: 20px; font-weight: 700; color: var(--muted); }
.seg button.on { background: linear-gradient(180deg, #5fe3ff, #12a6e8); color: #fff; }
.seat-list { display: flex; flex-direction: column; gap: 10px; }
.seat-row { display: flex; align-items: center; gap: 12px; background: rgba(0,0,0,.16); border-radius: 18px; padding: 8px; }
.seat-row .mini { width: 52px; height: 52px; border-radius: 15px; border: 3px solid; object-fit: cover; flex: none; }
.seat-row .nm { flex: 1; min-width: 0; font-size: 18px; font-weight: 600; background: transparent; border: 0; color: #fff; outline: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat-row input.nm { border-bottom: 1px dashed rgba(255,255,255,.2); padding: 4px 0; }
.seat-row .tag { font-size: 13px; padding: 5px 10px; border-radius: 99px; background: rgba(255,255,255,.1); color: var(--muted); flex: none; }
.seat-row .tag.cpu { background: rgba(56,214,255,.15); color: var(--cyan); }
.seat-row .dot { width: 10px; height: 10px; border-radius: 50%; background: #666; flex: none; }
.seat-row .dot.on { background: var(--green); box-shadow: 0 0 8px var(--green); }
.hint { color: var(--muted); font-size: 14px; margin: 10px 0 4px; }
.avatar-pick img { width: 108px; height: 108px; border-radius: 30px; border: 4px solid var(--cyan); box-shadow: 0 0 26px rgba(56,214,255,.6); object-fit: cover; }
.field { width: 100%; height: 52px; border-radius: 16px; border: 1px solid rgba(255,255,255,.14); background: rgba(0,0,0,.22); color: #fff; font-size: 20px; text-align: center; font-weight: 600; outline: none; margin-top: 10px; }
.field:focus { border-color: var(--cyan); }
.field.code { letter-spacing: 6px; text-transform: uppercase; margin: 0; }
.or { color: var(--muted); margin: 18px 0 10px; }
.join-row { display: flex; gap: 10px; width: 100%; }
.join-row .big-btn { height: 52px; flex: none; }
.err { color: #ff8a95; min-height: 20px; margin: 10px 0 0; font-size: 15px; }
.room-code { font-size: 44px; font-weight: 700; letter-spacing: 8px; margin: 6px 0 14px; color: #fff; text-shadow: 0 0 18px rgba(56,214,255,.6); }
.row2 { display: flex; gap: 10px; }

/* overlays */
.overlay { position: fixed; inset: 0; background: rgba(10, 12, 35, .6); display: none; align-items: center; justify-content: center; z-index: 50; padding: 20px; backdrop-filter: blur(4px); }
.overlay.show { display: flex; animation: fadein .25s; }
.sheet { width: min(380px, 100%); padding: 22px; text-align: center; max-height: 90vh; overflow-y: auto; }
.sheet h3 { margin: 0 0 12px; font-size: 26px; }
.sheet p { color: #d6d8f7; line-height: 1.45; }
.sheet .big-btn { width: 100%; margin-top: 12px; }
.sheet .opt { display: flex; justify-content: space-between; align-items: center; padding: 12px 4px; border-bottom: 1px solid rgba(255,255,255,.08); font-size: 18px; }
.net-banner { position: fixed; top: calc(env(safe-area-inset-top) + 64px); left: 50%; transform: translateX(-50%); background: #ff8a3d; color: #fff; padding: 6px 16px; border-radius: 999px; font-weight: 600; display: none; z-index: 40; font-size: 14px; }
.net-banner.show { display: block; }
/* ---------- CHESS: home hero ---------- */
.home-top .row2 { gap: 8px; }
.hero { position: relative; width: 210px; height: 120px; margin-bottom: 2px; }
.hero-board { position: absolute; left: 50%; top: 52px; width: 150px; height: 60px; transform: translateX(-50%) perspective(300px) rotateX(48deg); display: grid; grid-template-columns: repeat(9, 1fr); border-radius: 8px; overflow: hidden; box-shadow: 0 14px 24px rgba(0,0,0,.35); border: 3px solid #7a4a22; }
.hero-board i:nth-child(odd) { background: #f3dcb2; } .hero-board i:nth-child(even) { background: #b97d4b; }
.hp { position: absolute; width: 76px; height: 76px; filter: drop-shadow(0 6px 8px rgba(0,0,0,.35)) drop-shadow(0 0 14px rgba(255,255,255,.35)); animation: bob 3s ease-in-out infinite; }
.hp1 { left: 8px; top: 18px; width: 70px; height: 70px; animation-delay: .4s; }
.hp2 { left: 64px; top: 0; width: 86px; height: 86px; }
.hp3 { left: 132px; top: 20px; width: 68px; height: 68px; animation-delay: .8s; }
.logo { font-size: clamp(60px, 19vw, 96px); }
.adda { margin-top: -4px; font-size: 26px; font-weight: 700; letter-spacing: 12px; padding-left: 12px; color: #fff; background: linear-gradient(180deg, #ffb347, #ff6f3c); border-radius: 999px; padding: 2px 18px 2px 30px; box-shadow: 0 4px 0 #c04a1c, 0 8px 18px rgba(255,111,60,.45); text-shadow: 0 2px 0 rgba(0,0,0,.2); }
.brand { margin: 12px 0 20px; color: #e8eaff; }

/* setup bits */
.seg img { width: 26px; height: 26px; vertical-align: middle; margin-right: 2px; }
.seg button { display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 16px; }
.seg button span { font-size: 15px; }
.seg.full { width: 100%; margin: 0 0 4px; }
.seat-row + .seat-row { margin-top: 10px; }
.tag-w, .tag-b { padding: 2px 6px !important; background: rgba(255,255,255,.85) !important; } .tag-b { background: rgba(0,0,0,.35) !important; }
.tag-w img, .tag-b img { width: 28px; height: 28px; display: block; }
.lbl-c { margin-top: 16px; }
.mini { cursor: pointer; }
.wait::after { content: ''; display: inline-block; width: 1em; text-align: left; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* ---------- GAME ---------- */
#s-game { padding: 8px 10px 10px; overflow: hidden; }
.game-bar { margin-bottom: 4px; }
.g-title { flex: 1; text-align: center; font-size: 18px; font-weight: 600; color: #e6e8ff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gsp { flex: 1 1 0; min-height: 0; }

.pcard { display: flex; align-items: center; gap: 10px; padding: 6px 8px; margin: 6px 0; border-radius: 18px; background: rgba(30, 34, 110, .45); border: 1px solid rgba(255,255,255,.12); transition: box-shadow .25s, background .25s; min-height: 58px; }
.pcard.active { background: rgba(255,255,255,.16); box-shadow: 0 0 0 2px #ffd23f, 0 0 22px rgba(255,210,63,.55); }
.pcard .pav { position: relative; width: 46px; height: 46px; flex: none; }
.pcard .pav img.a { width: 46px; height: 46px; border-radius: 14px; object-fit: cover; border: 3px solid #fff; background: #2b2f60; display: block; }
.pcard .pav img.k { position: absolute; right: -8px; bottom: -6px; width: 24px; height: 24px; border-radius: 50%; background: radial-gradient(circle, #fff, #dfe3ff); padding: 1px; box-shadow: 0 2px 4px rgba(0,0,0,.35); }
.pcard[data-c=b] .pav img.k { background: radial-gradient(circle, #6b6f9a, #2c2f55); }
.pcard.offline .pav img.a { filter: grayscale(1) brightness(.6); }
.pcard .pinfo { flex: 1; min-width: 0; }
.pcard .pname { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .pname small { font-weight: 500; font-size: 12px; color: #ffd27a; margin-left: 6px; }
.pcard .caps { display: flex; align-items: center; height: 20px; margin-top: 2px; }
.pcard .caps img { width: 18px; height: 18px; margin-right: -6px; filter: drop-shadow(0 1px 1px rgba(0,0,0,.4)); }
.pcard .caps img.gap { margin-left: 8px; }
.pcard .caps b { margin-left: 10px; font-size: 13px; color: #7dffa0; font-weight: 700; }
.pcard .pclock { flex: none; min-width: 74px; text-align: center; font-size: 22px; font-weight: 700; padding: 4px 10px; border-radius: 12px; background: rgba(0,0,0,.3); color: #cfd2ff; font-variant-numeric: tabular-nums; }
.pcard.active .pclock { background: #fff; color: #23264d; }
.pcard .pclock.low { background: #ff4d5e !important; color: #fff !important; animation: pulse-low 1s infinite; }
@keyframes pulse-low { 50% { transform: scale(1.06); } }
.pcard .think { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: middle; }
.pcard .think i { width: 6px; height: 6px; border-radius: 50%; background: #ffd23f; animation: bob 0.9s infinite; }
.pcard .think i:nth-child(2) { animation-delay: .15s; } .pcard .think i:nth-child(3) { animation-delay: .3s; }

/* board + themes */
.board-wrap { flex: none; display: grid; place-items: center; position: relative; z-index: 1; }
.board-frame { padding: var(--fr, 8px); border-radius: 16px; background: var(--frame, linear-gradient(145deg, #a8683a, #6e3f1d 55%, #8a5229)); box-shadow: 0 16px 34px rgba(10,14,60,.5), inset 0 2px 0 rgba(255,255,255,.25), inset 0 -3px 0 rgba(0,0,0,.25); }
.board { position: relative; width: var(--bs, 336px); height: var(--bs, 336px); display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); border-radius: 6px; overflow: hidden; touch-action: none; }
:root { --light: #f3dcb2; --dark: #b97d4b; --coord-l: #b97d4b; --coord-d: #f3dcb2; }
body[data-theme=green] { --light: #eeeed2; --dark: #6fa35a; --coord-l: #6fa35a; --coord-d: #eeeed2; --frame: linear-gradient(145deg, #4f8a3c, #2d5a22); }
body[data-theme=blue] { --light: #e4efff; --dark: #6b97d8; --coord-l: #6b97d8; --coord-d: #e4efff; --frame: linear-gradient(145deg, #4c6fd6, #27409a); }
body[data-theme=pink] { --light: #fff1d9; --dark: #f08aa6; --coord-l: #e0708f; --coord-d: #fff1d9; --frame: linear-gradient(145deg, #ff7aa8, #b63f7a); }
.sq { position: relative; background: var(--light); cursor: pointer; }
.sq.d { background: var(--dark); }
.sq.last::before { content: ''; position: absolute; inset: 0; background: rgba(255, 226, 60, .55); pointer-events: none; }
.sq.sel::before { content: ''; position: absolute; inset: 0; background: rgba(60, 210, 255, .6); pointer-events: none; }
.sq.chk::after { content: ''; position: absolute; inset: 0; background: radial-gradient(circle, rgba(255,40,40,.95) 0, rgba(255,40,40,.55) 40%, transparent 72%); pointer-events: none; animation: chk 1s ease-in-out infinite; }
@keyframes chk { 50% { opacity: .6; } }
.sq .pc { position: absolute; inset: 4%; width: 92%; height: 92%; z-index: 2; pointer-events: none; transition: transform .2s ease-out; filter: drop-shadow(0 2px 1.5px rgba(0,0,0,.35)); will-change: transform; }
.sq .pc.lift { transform: scale(1.12) translateY(-4%); }
.sq .pc.ghosted { opacity: .35; }
.sq .dot { position: absolute; left: 50%; top: 50%; width: 30%; height: 30%; margin: -15% 0 0 -15%; border-radius: 50%; background: rgba(30, 40, 90, .38); z-index: 3; pointer-events: none; box-shadow: 0 0 0 2px rgba(255,255,255,.25); }
.sq .ring { position: absolute; inset: 3%; border-radius: 50%; border: 5px solid rgba(30, 40, 90, .38); z-index: 3; pointer-events: none; }
.sq .co { position: absolute; font-size: 10px; font-weight: 700; line-height: 1; pointer-events: none; z-index: 1; color: var(--coord-l); }
.sq.d .co { color: var(--coord-d); }
.sq .co.f { right: 3px; bottom: 2px; } .sq .co.r { left: 3px; top: 2px; }
.drag-ghost { position: fixed; z-index: 30; pointer-events: none; filter: drop-shadow(0 8px 8px rgba(0,0,0,.4)); transform: translate(-50%, -60%) scale(1.25); }

.toast { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.6); padding: 10px 22px; border-radius: 999px; background: rgba(20, 22, 50, .9); border: 1px solid rgba(255,255,255,.15); font-weight: 700; font-size: 22px; opacity: 0; pointer-events: none; transition: .25s; z-index: 20; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.toast.red { background: #ff4d5e; }

.promo { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; flex-direction: column; z-index: 25; background: rgba(10,12,40,.55); border-radius: 16px; }
.promo.show { display: flex; }
.promo .row { display: flex; gap: 8px; padding: 12px; border-radius: 20px; background: #fff; box-shadow: 0 10px 30px rgba(0,0,0,.4); }
.promo button.pp { width: 66px; height: 66px; border-radius: 14px; background: linear-gradient(180deg, #f3f5ff, #d9ddf7); box-shadow: 0 3px 0 #a9afd6; }
.promo button.pp img { width: 100%; height: 100%; }
.promo p { margin: 0 0 10px; font-size: 20px; font-weight: 700; text-shadow: 0 2px 4px rgba(0,0,0,.4); }
.promo .pill-btn { margin-top: 12px; }

.status { text-align: center; font-size: 24px; font-weight: 700; min-height: 32px; margin: 4px 0 6px; color: #fff; text-shadow: 0 2px 0 rgba(0,0,0,.2), 0 6px 14px rgba(0,0,0,.3); }
.status.chk { color: #ffdf5e; animation: bob 1s ease-in-out infinite; }
.actions { display: flex; justify-content: center; gap: 10px; }
.act { flex: 1; max-width: 84px; height: 60px; border-radius: 18px; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.16); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 13px; font-weight: 600; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.act svg { width: 24px; height: 24px; }
.act:active { transform: scale(.94); }
.act:disabled { opacity: .35; }
.act[hidden] { display: none; }
.sheet .result-ico { font-size: 64px; line-height: 1; filter: drop-shadow(0 0 20px rgba(255,210,63,.7)); animation: bob 2s ease-in-out infinite; }
.sheet .reason { color: #d6d8f7; margin: -4px 0 8px; }
.sheet .credits { font-size: 13px; color: #c6c9ef; text-align: left; }
.sheet a { color: #7fe7ff; }
.theme-row { display: flex; gap: 6px; }
.theme-row button { width: 34px; height: 34px; border-radius: 10px; border: 2px solid transparent; background: linear-gradient(135deg, var(--a) 50%, var(--b) 50%); }
.theme-row button.on { border-color: #fff; box-shadow: 0 0 10px #fff; }
.draw-bar { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 90px); transform: translateX(-50%); z-index: 45; display: flex; gap: 8px; align-items: center; background: rgba(20,22,60,.95); padding: 10px 12px; border-radius: 18px; box-shadow: 0 10px 30px rgba(0,0,0,.4); font-weight: 600; white-space: nowrap; }
@media (max-height: 680px) { .pcard { min-height: 50px; margin: 3px 0; } .pcard .pav, .pcard .pav img.a { width: 40px; height: 40px; } .act { height: 50px; } .status { font-size: 20px; min-height: 26px; } }
.sheet .result-ico { display: flex; justify-content: center; gap: 4px; height: 76px; }
.sheet .result-ico img, .sheet .result-ico svg { width: 72px; height: 72px; filter: drop-shadow(0 4px 10px rgba(0,0,0,.35)); }
.sheet .result-ico svg.trophy-svg { filter: drop-shadow(0 0 18px rgba(255,210,63,.75)); }
.sheet .result-ico img.fallen { transform: rotate(-75deg) translateY(10px); animation: none; }
