* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
    background: #141414;
    color: #fff;
    font-family: "Heebo", system-ui, sans-serif;
    overflow: hidden;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

/* ---------- hub ---------- */
.hub {
    height: 100dvh;
    overflow-y: auto;
    padding: max(4dvh, env(safe-area-inset-top)) 5vw calc(4dvh + env(safe-area-inset-bottom));
    max-width: 40rem;
    margin: 0 auto;
}
.hub h1 { font-family: "Oxanium", system-ui, sans-serif; font-size: clamp(1.3rem, 5vw, 1.8rem); }
.hub .sub { color: rgba(255,255,255,0.55); margin-top: 0.5rem; font-size: clamp(0.85rem, 3.4vw, 1rem); line-height: 1.45; }
.hub .cards { display: flex; flex-direction: column; gap: 0.9rem; margin-top: 1.6rem; }
.card {
    display: block; width: 100%; text-align: left;
    background: #1e1e24; border: 1px solid #33333e; border-radius: 0.9rem;
    padding: 1rem 1.1rem; transition: transform 0.08s ease;
}
.card:active { transform: scale(0.985); }
.card .row { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; }
.card .name { font-family: "Oxanium", system-ui, sans-serif; font-weight: 600; font-size: clamp(1rem, 4vw, 1.15rem); }
.card .tag {
    flex-shrink: 0; font-family: "Oxanium", system-ui, sans-serif; font-size: 0.7rem; font-weight: 700;
    padding: 0.25em 0.7em; border-radius: 999px; background: rgba(142,78,198,0.22); color: #dccbff;
}
.card .tag.slow { background: rgba(229,72,77,0.2); color: #ffb3b5; }
.card .desc { color: rgba(255,255,255,0.6); font-size: clamp(0.82rem, 3.2vw, 0.95rem); margin-top: 0.45rem; line-height: 1.45; }
.hub .foot { color: rgba(255,255,255,0.35); font-size: 0.78rem; margin-top: 1.6rem; line-height: 1.6; }

/* ---------- player shell ---------- */
.player { position: fixed; inset: 0; background: #141414; display: flex; flex-direction: column; overflow: hidden; }
.player .frame {
    position: relative; z-index: 20; pointer-events: none;
    margin: 0 auto; display: flex; flex-direction: column; height: 100%; width: 100%;
    max-width: min(100vw, 62dvh);
    padding: max(2dvh, env(safe-area-inset-top)) 4vw max(2dvh, env(safe-area-inset-bottom));
}
.progress { display: flex; gap: 0.3rem; padding-right: 22vw; }
.progress .seg { height: 0.24rem; flex: 1; border-radius: 999px; background: rgba(255,255,255,0.2); overflow: hidden; }
.progress .seg > i { display: block; height: 100%; width: 0%; border-radius: 999px; background: #8e4ec6; transition: width 0.25s; }
.latency {
    align-self: flex-start; margin-top: 0.7dvh; font-family: "Oxanium", system-ui, sans-serif;
    font-size: 0.66rem; color: rgba(255,255,255,0.45); min-height: 1em;
}
.latency b { color: #ffd578; font-weight: 600; }
.callout {
    margin-top: 1dvh; display: flex; flex-direction: column; gap: 0.35em; overflow: hidden;
    height: 8.4em; flex-shrink: 0;
    border: 1px solid #33333e; background: #1e1e24; border-radius: 0.9rem;
    padding: 0.7em 1em; font-size: clamp(0.78rem, 2.3dvmin, 0.96rem);
    box-shadow: 0 0.5rem 1.5rem rgba(0,0,0,0.45);
}
.callout .badge-row { display: flex; align-items: center; justify-content: space-between; gap: 0.75em; }
.callout .badge {
    display: inline-flex; border-radius: 999px; background: rgba(255,255,255,0.1); color: #dccbff;
    padding: 0.2em 0.7em; font-size: clamp(0.58rem, 1.7dvmin, 0.72rem); font-weight: 600;
    text-transform: uppercase; font-family: "Oxanium", system-ui, sans-serif;
}
.callout .text { font-weight: 500; line-height: 1.35; overflow: hidden; }
.callout .text.fade { animation: calloutIn 0.14s ease-out; }
@keyframes calloutIn { from { opacity: 0.2; transform: translateY(0.2em); } to { opacity: 1; transform: none; } }
.board-slot { display: flex; flex-direction: column; justify-content: flex-start; padding-top: 1.2dvh; min-height: 0; flex: 1; }
.hint {
    position: absolute; left: 8vw; right: 8vw; bottom: max(1.2dvh, env(safe-area-inset-bottom));
    text-align: center; font-size: 0.66rem; color: rgba(255,255,255,0.4); transition: opacity 0.3s;
}
.tap-zones { position: absolute; inset: 0; z-index: 10; display: flex; }
.tap-zones .back { width: 25%; height: 100%; }
.tap-zones .next { flex: 1; height: 100%; }
.exit {
    position: absolute; right: 4vw; top: max(2dvh, env(safe-area-inset-top)); z-index: 50;
    border-radius: 999px; background: rgba(0,0,0,0.35); padding: 0.6rem; line-height: 0;
    backdrop-filter: blur(4px); pointer-events: auto;
}

/* ---------- board ---------- */
.board { position: relative; margin: 0 auto; width: 100%; aspect-ratio: 1; border-radius: 4px; }
.board .clip { position: absolute; inset: 0; overflow: hidden; border-radius: 4px; }
.board .grid { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); }
.board .sq { position: relative; }
.board .sq.light { background: #efe9ff; }
.board .sq.dark { background: #8777b6; }
.board .coord { position: absolute; font-size: clamp(0.5rem, 1.6dvmin, 0.68rem); font-weight: 600; }
.board .coord.file { bottom: 2%; right: 6%; }
.board .coord.rank { left: 6%; top: 2%; }
.board .layer { position: absolute; inset: 0; pointer-events: none; }
.board .hl { position: absolute; width: 12.5%; height: 12.5%; left: 0; top: 0; }
.board .piece {
    position: absolute; z-index: 3; width: 12.5%; height: 12.5%; left: 0; top: 0;
    pointer-events: none; will-change: transform;
    transition-property: transform, opacity, filter; transition-timing-function: linear; transition-duration: 0s;
}
.board .piece.carried { z-index: 5; transform-origin: center; }
.board .piece.pop { animation: capturePop 0.18s ease-out forwards; }
@keyframes capturePop { to { opacity: 0; scale: 1.35; } }
.board .piece-box { position: absolute; inset: 0; transition: opacity 0.3s ease-out; }
.board svg.arrows { position: absolute; inset: 0; z-index: 4; width: 100%; height: 100%; }
.board .focus {
    position: absolute; width: 12.5%; height: 12.5%; left: 0; top: 0; border-radius: 8%;
    animation: focusPulse 1.5s ease-in-out infinite;
}
@keyframes focusPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,199,84,0), inset 0 0 0 0.15rem rgba(255,210,110,0.9); }
    50% { box-shadow: 0 0 1rem 0.3rem rgba(255,199,84,0.6), inset 0 0 0 0.22rem rgba(255,224,150,1); }
}
.board .land {
    position: absolute; width: 12.5%; height: 12.5%; left: 0; top: 0; border-radius: 12%; z-index: 4;
    animation: landPulse 0.34s ease-out forwards;
}
@keyframes landPulse {
    from { box-shadow: inset 0 0 0 0.3rem rgba(255,224,150,0.95); opacity: 1; }
    to { box-shadow: inset 0 0 0 0.05rem rgba(255,224,150,0); opacity: 0; }
}
.board .hand {
    position: absolute; z-index: 6; width: 12.5%; height: 12.5%; left: 0; top: 0;
    pointer-events: none; will-change: transform;
    transition-property: transform; transition-timing-function: linear; transition-duration: 0s;
}
.board .hand .flip { position: absolute; inset: 0; }
.board .hand .flip.mirror { transform: scaleX(-1); }
.board .hand .stick {
    position: absolute; left: 50%; top: 44%; height: 17%; width: 108%;
    transform-origin: 0% 50%; transform: rotate(30deg);
    filter: drop-shadow(0 0.25rem 0.5rem rgba(0,0,0,0.45));
}
.board .hand.tapping .stick { animation: handTap 0.6s cubic-bezier(0.45,0.05,0.55,0.95); }
@keyframes handTap { 0%,100% { transform: rotate(30deg); } 50% { transform: rotate(37deg); } }
.board .hand.wake .stick { animation: handWake 0.26s cubic-bezier(0.3,0.7,0.3,1); }
@keyframes handWake { 0% { transform: rotate(30deg); } 35% { transform: rotate(39.5deg); } 100% { transform: rotate(30deg); } }
.board .hand, .board .piece { backface-visibility: hidden; }

/* ---------- end screen ---------- */
.end {
    position: absolute; inset: 0; z-index: 40; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: clamp(1rem, 3dvh, 2rem);
    background: rgba(20,20,20,0.94); padding: 0 8vw; text-align: center;
    animation: calloutIn 0.3s ease-out; pointer-events: auto;
}
.end img { max-height: 34dvh; width: min(44vw, 22dvh); object-fit: contain; }
.end .stats { font-size: clamp(0.85rem, 3.4vw, 1rem); color: rgba(255,255,255,0.75); line-height: 1.6; }
.end .stats b { color: #ffd578; }
.end .buttons { display: flex; flex-direction: column; gap: 0.8rem; width: min(86vw, 42dvh); }
.end .primary {
    width: 100%; border-radius: 0.8rem; background: #8e4ec6; padding: 0.8em 1em;
    font-weight: 800; text-transform: uppercase; box-shadow: 0 0.35rem 0 #5f3a96;
}
.end .secondary {
    width: 100%; border-radius: 0.8rem; border: 1px solid rgba(255,255,255,0.25);
    background: rgba(255,255,255,0.1); padding: 0.8em 1em; font-weight: 700; text-transform: uppercase;
}

/* ---------- scrub variant ---------- */
.scrub-track { position: absolute; left: 4vw; right: 4vw; bottom: max(2.4dvh, env(safe-area-inset-bottom)); z-index: 30; pointer-events: auto; }
.scrub-track .rail { position: relative; height: 2.6rem; display: flex; align-items: center; }
.scrub-track .line { position: absolute; left: 0.4rem; right: 0.4rem; height: 0.28rem; border-radius: 999px; background: rgba(255,255,255,0.18); }
.scrub-track .fill { position: absolute; left: 0.4rem; height: 0.28rem; border-radius: 999px; background: #8e4ec6; }
.scrub-track .dot { position: absolute; width: 0.5rem; height: 0.5rem; border-radius: 50%; background: rgba(255,255,255,0.45); transform: translate(-50%, 0); }
.scrub-track .dot.move { background: #ffd578; }
.scrub-track .knob {
    position: absolute; width: 1.7rem; height: 1.7rem; border-radius: 50%;
    background: #fff; box-shadow: 0 0.15rem 0.6rem rgba(0,0,0,0.6); transform: translate(-50%, 0);
}

/* ---------- chat variant ---------- */
.chat-player { position: fixed; inset: 0; background: #141414; display: flex; flex-direction: column; }
.chat-top {
    flex-shrink: 0; padding: max(2dvh, env(safe-area-inset-top)) 4vw 0;
    max-width: min(100vw, 56dvh); width: 100%; margin: 0 auto;
}
.chat-feed {
    flex: 1; min-height: 0; overflow-y: auto; padding: 1.2dvh 4vw calc(9dvh + env(safe-area-inset-bottom));
    display: flex; flex-direction: column; gap: 0.55rem; max-width: 40rem; width: 100%; margin: 0 auto;
    overscroll-behavior: contain;
}
.bubble { display: flex; gap: 0.5rem; align-items: flex-end; animation: bubbleIn 0.16s ease-out; }
@keyframes bubbleIn { from { opacity: 0; transform: translateY(0.5rem); } to { opacity: 1; transform: none; } }
.bubble .avatar { width: 1.7rem; height: 1.7rem; border-radius: 50%; object-fit: cover; background: #1e1e24; flex-shrink: 0; }
.bubble .msg {
    background: #1e1e24; border: 1px solid #33333e; border-radius: 1rem 1rem 1rem 0.25rem;
    padding: 0.55em 0.85em; font-size: clamp(0.82rem, 3.4vw, 0.95rem); line-height: 1.4; max-width: 82%;
}
.bubble .msg .kind {
    display: inline-block; font-family: "Oxanium", system-ui, sans-serif; font-size: 0.62rem; font-weight: 700;
    text-transform: uppercase; color: #dccbff; margin-bottom: 0.2em;
}
.bubble .msg .movechip {
    display: inline-flex; margin-top: 0.35em; font-family: "Oxanium", system-ui, sans-serif;
    font-size: 0.7rem; font-weight: 700; color: #ffd578; background: rgba(255,213,120,0.12);
    border-radius: 0.4rem; padding: 0.15em 0.5em;
}
.bubble.user { justify-content: flex-end; }
.bubble.user .msg { background: #8e4ec6; border-color: #8e4ec6; border-radius: 1rem 1rem 0.25rem 1rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.45rem; padding-left: 2.2rem; }
.chips button {
    border: 1px solid rgba(184,117,255,0.7); color: #c9a2ff; border-radius: 999px;
    padding: 0.35em 0.8em; font-size: 0.76rem; background: rgba(142,78,198,0.12);
}
.chat-continue {
    position: fixed; left: 50%; transform: translateX(-50%);
    bottom: max(2dvh, env(safe-area-inset-bottom)); z-index: 30;
    border-radius: 999px; background: #8e4ec6; padding: 0.6em 1.6em; font-weight: 800;
    box-shadow: 0 0.3rem 0 #5f3a96, 0 0.6rem 1.4rem rgba(0,0,0,0.5); text-transform: uppercase;
    font-size: 0.85rem;
}
.chat-continue:active { transform: translateX(-50%) translateY(0.15rem); }

/* auto variant pause chip */
.pause-chip {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 30;
    font-family: "Oxanium", system-ui, sans-serif; font-weight: 700; letter-spacing: 0.08em;
    background: rgba(0,0,0,0.55); border-radius: 999px; padding: 0.5em 1.2em; font-size: 0.8rem;
    backdrop-filter: blur(3px);
}
