:root {
    --bg1: #c7f3ff;
    --bg2: #ffe3f1;
    --ink: #2b2347;
    --ink-soft: #6b6390;
    --panel: #ffffffd9;
    --line: #2b234722;
    --pink: #ff6fa8;
    --blue: #3aa9ff;
    --yellow: #ffd23f;
    --red: #ff4d5e;
    --p1: #7ec8ff;
    --p2: #c08cff;
    --p3: #ffb84d;
    --radius: 18px;
    --safe-t: env(safe-area-inset-top);
    --safe-b: env(safe-area-inset-bottom);
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg1: #1d2a4a; --bg2: #3a2147; --ink: #fff4fb; --ink-soft: #c9bfe6; --panel: #2b2347e6; --line: #ffffff22;
    }
}
:root[data-theme="dark"] { --bg1: #1d2a4a; --bg2: #3a2147; --ink: #fff4fb; --ink-soft: #c9bfe6; --panel: #2b2347e6; --line: #ffffff22; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body {
    font-family: 'Fredoka', system-ui, sans-serif;
    color: var(--ink);
    background: linear-gradient(160deg, var(--bg1), var(--bg2)) fixed;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none; user-select: none;
    touch-action: manipulation;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: 'Baloo 2', 'Fredoka', sans-serif; margin: 0; }
input, select, button { font: inherit; color: inherit; }
input, select {
    background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 0;
}
input { -webkit-user-select: text; user-select: text; }

.screen { min-height: 100dvh; padding: calc(var(--safe-t) + 12px) 16px calc(var(--safe-b) + 16px); max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

/* ---------- buttons ---------- */
.btn {
    border: 0; border-radius: 999px; padding: 10px 18px; font-weight: 700; cursor: pointer;
    box-shadow: 0 4px 0 #0002; transition: transform .08s, box-shadow .08s; background: var(--panel);
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #0002; }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-primary { background: linear-gradient(180deg, #ff8fc0, var(--pink)); color: #fff; text-shadow: 0 1px 0 #0003; }
.btn-secondary { background: linear-gradient(180deg, #7fd0ff, var(--blue)); color: #fff; text-shadow: 0 1px 0 #0003; }
.btn-ghost { background: transparent; box-shadow: none; color: var(--ink-soft); }
.btn-big { font-size: 1.2rem; padding: 14px 22px; }
.btn-danger { background: linear-gradient(180deg, #ff7f8a, var(--red)); color: #fff; }
.icon-btn { border: 0; background: var(--panel); border-radius: 12px; width: 38px; height: 38px; font-size: 18px; display: grid; place-items: center; cursor: pointer; flex: none; padding: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1; }
.hint { color: var(--ink-soft); margin: 0; font-size: .95rem; }
.error { color: var(--red); font-weight: 600; margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.bar { display: flex; align-items: center; gap: 8px; }
.bar h2 { flex: 1; font-size: 1.4rem; }
.or { text-align: center; color: var(--ink-soft); font-size: .9rem; }

/* ---------- title ---------- */
#title { justify-content: center; text-align: center; }
.title-art img { width: 100%; max-width: 460px; border-radius: 28px; box-shadow: 0 10px 30px #0003; border: 4px solid #fff; animation: bob 4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-.6deg); } }
.logo { font-size: clamp(3rem, 15vw, 4.6rem); line-height: .9; color: #fff; text-shadow: 0 4px 0 var(--blue), 0 8px 0 #2b234733, 0 0 2px var(--blue); letter-spacing: 1px; }
.logo span { color: var(--yellow); margin-left: .2em; text-shadow: 0 4px 0 var(--pink), 0 8px 0 #2b234733; display: inline-block; animation: wobble 2.4s ease-in-out infinite; }
@keyframes wobble { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(5deg) translateY(-3px); } }
.tagline { color: var(--ink-soft); margin: 0 auto; max-width: 360px; }
.title-buttons { display: flex; flex-direction: column; gap: 10px; }
.howto { text-align: left; background: var(--panel); border-radius: var(--radius); padding: 10px 14px; }
.howto summary { font-weight: 700; cursor: pointer; }
.howto-body h3 { margin-top: 12px; }
.howto-body p, .howto-body li { line-height: 1.45; }
.p1 { color: #2a8ee0; } .p2 { color: #8a4fe0; } .p3 { color: #e08a10; }
.fam { display: inline-block; border: 3px solid var(--c); border-radius: 8px; padding: 0 6px; margin: 2px; font-size: .85rem; font-weight: 600; }

/* ---------- seats ---------- */
.seat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.seat-list li { display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: 16px; padding: 6px 10px; }
.seat-list li input { flex: 1; }
.seat-list li .name { flex: 1; font-weight: 600; }
.seat-list li.offline { opacity: .5; }
.avatar-btn { width: 52px; height: 52px; border-radius: 50%; border: 3px solid #fff; padding: 0; overflow: hidden; background: var(--c, #fff); box-shadow: 0 3px 0 #0002; cursor: pointer; flex: none; }
.avatar-btn img, .av img { width: 100%; height: 100%; object-fit: cover; display: block; }
.me-row { display: flex; gap: 10px; align-items: center; }
.me-row input { flex: 1; font-size: 1.1rem; }
#code-input { text-transform: uppercase; letter-spacing: 3px; max-width: 120px; }

/* ---------- game layout ---------- */
#game { padding: calc(var(--safe-t) + 6px) 8px calc(var(--safe-b) + 6px); height: 100dvh; min-height: 0; gap: 6px; max-width: 640px; }
.topbar { display: flex; align-items: center; gap: 6px; flex: none; }
.ticker { flex: 1; min-width: 0; background: var(--panel); border-radius: 12px; padding: 7px 10px; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.players { display: flex; gap: 6px; overflow-x: auto; flex: none; padding: 2px 2px 4px; scrollbar-width: none; }
.players::-webkit-scrollbar { display: none; }
.pchip { flex: 1 0 auto; min-width: 70px; max-width: 120px; background: var(--panel); border-radius: 14px; padding: 4px 6px; display: flex; flex-direction: column; align-items: center; position: relative; border: 3px solid transparent; transition: border-color .2s, transform .2s; }
.pchip.cur { border-color: var(--yellow); transform: translateY(-2px); box-shadow: 0 0 0 3px #ffd23f55; }
.pchip.lost { filter: grayscale(.8); }
.pchip.hit { animation: hitflash .5s ease-in-out 4; }
@keyframes hitflash { 50% { border-color: var(--red); background: #ffd0d6; } }
.av { display: inline-block; vertical-align: middle; width: 34px; height: 34px; border-radius: 50%; overflow: hidden; border: 2px solid #fff; background: var(--c, #fff); flex: none; }
.pchip .pname { font-size: .78rem; font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pchip .pmeta { font-size: .72rem; color: var(--ink-soft); display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; }
.pchip .turns { position: absolute; top: -6px; right: -4px; background: var(--red); color: #fff; font-weight: 800; border-radius: 999px; font-size: .75rem; padding: 0 6px; }
.pchip .dir { position: absolute; top: 12px; left: -9px; font-size: .8rem; color: var(--ink-soft); }
.hits { letter-spacing: -2px; }

.piles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; flex: none; }
.pile { position: relative; border-radius: 14px; overflow: hidden; height: 74px; border: 3px solid var(--pc); background: var(--pc); cursor: pointer; transition: transform .2s; }
.pile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .55; }
.pile .pinfo { position: relative; padding: 4px 6px; display: flex; flex-direction: column; height: 100%; justify-content: space-between; text-shadow: 0 1px 2px #fff, 0 0 6px #fff; color: #2b2347; }
.pile .pname { font-weight: 800; font-size: .85rem; font-family: 'Baloo 2'; }
.pile .pcount { font-size: .8rem; font-weight: 700; }
.pile .prep { font-size: .95rem; font-weight: 800; }
.pile .pknown { font-size: .7rem; font-weight: 700; color: #b0003a; }
.pile.zone { transform: translateY(-3px); box-shadow: 0 0 0 3px #fff, 0 0 16px var(--pc); }
.pile.drawn { animation: pulse .6s ease-out; }
@keyframes pulse { 30% { transform: scale(1.08); } }

.table-wrap { position: relative; flex: 1 1 auto; min-height: 170px; border-radius: 22px; overflow: hidden; box-shadow: inset 0 0 0 3px #fff8, 0 6px 20px #0002; }
#table { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.float-layer { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.floater { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); font-family: 'Baloo 2'; font-weight: 800; font-size: 1.6rem; color: #fff; text-shadow: 0 3px 0 var(--pink), 0 0 10px #0005; white-space: nowrap; animation: floatup 1.6s ease-out forwards; }
@keyframes floatup { 0% { opacity: 0; transform: translate(-50%, -20%) scale(.6); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.15); } 70% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -140%) scale(1); } }

.action { flex: none; display: flex; gap: 8px; align-items: center; min-height: 58px; }
.action .msg { flex: 1; font-weight: 600; font-size: .95rem; text-align: center; }
.pour-btn { flex: 1; height: 58px; border-radius: 999px; border: 0; font-family: 'Baloo 2'; font-size: 1.5rem; font-weight: 800; color: #fff; cursor: pointer;
    background: linear-gradient(180deg, #6fd0ff, #1f8fff); box-shadow: 0 5px 0 #0b5fb0; text-shadow: 0 2px 0 #0003; touch-action: none; }
.pour-btn.pouring { background: linear-gradient(180deg, #ff8fa8, #ff3f6c); box-shadow: 0 5px 0 #b01e44; animation: throb .5s ease-in-out infinite; }
.pour-btn.forced { background: linear-gradient(180deg, #4fe3ff, #00a6d6); animation: throb 1s ease-in-out infinite; }
@keyframes throb { 50% { transform: scale(1.03); } }
.pour-btn:disabled { filter: grayscale(.6); opacity: .6; animation: none; }

.hand { flex: none; display: flex; gap: 8px; overflow-x: auto; padding: 6px 2px 4px; scrollbar-width: none; min-height: 132px; align-items: flex-end; }
.hand::-webkit-scrollbar { display: none; }
.hand .empty { color: var(--ink-soft); margin: auto; font-size: .9rem; }

/* ---------- cards ---------- */
.card { --edge: #ccc; position: relative; flex: none; width: 92px; height: 124px; border-radius: 12px; background: #fff; border: 5px solid var(--edge); box-shadow: 0 4px 0 #0002, 0 6px 14px #0002; overflow: hidden; display: flex; flex-direction: column; cursor: pointer; transition: transform .15s; color: #2b2347; }
.card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; flex: none; }
.card .cname { font-family: 'Baloo 2'; font-weight: 800; font-size: .74rem; line-height: 1; padding: 3px 3px 0; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .cemoji { position: absolute; top: 2px; left: 3px; font-size: .9rem; filter: drop-shadow(0 1px 1px #fff); }
.card .ctext { display: none; }
.card.dim { opacity: .55; }
.card.playable { transform: translateY(-6px); }
.card.new { animation: newcard .7s ease-out; }
@keyframes newcard { 0% { transform: translateY(-60px) scale(.6) rotate(-10deg); opacity: 0; } }
.card.big { width: min(240px, 62vw); height: auto; border-width: 8px; border-radius: 20px; cursor: default; }
.card.big .cname { font-size: 1.4rem; padding: 6px 8px 0; }
.card.big .cemoji { font-size: 1.6rem; top: 6px; left: 8px; }
.card.big .ctext { display: block; font-size: .92rem; padding: 4px 10px 10px; text-align: center; line-height: 1.3; }
.card.big .cfam { display: block; text-align: center; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; color: var(--edge); filter: brightness(.8); }
.card .cfam { display: none; }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 16px); background: #2b234799; backdrop-filter: blur(3px); overflow-y: auto; }
.overlay .panel { background: var(--panel); border-radius: 22px; padding: 16px; width: min(440px, 100%); display: flex; flex-direction: column; gap: 10px; box-shadow: 0 10px 40px #0005; }
.overlay h2 { text-align: center; font-size: 1.5rem; }
.overlay .who { color: #fff; font-family: 'Baloo 2'; font-weight: 800; font-size: 1.3rem; text-align: center; text-shadow: 0 2px 0 #0004; }
.overlay .btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.react { background: #2b2347b3; }
.react .card.big { animation: slam .35s cubic-bezier(.2, 1.6, .5, 1); }
@keyframes slam { 0% { transform: scale(1.8) rotate(8deg); opacity: 0; } }
.react.me .card.big { animation: slam .35s cubic-bezier(.2, 1.6, .5, 1), redflash .45s ease-in-out .35s infinite; }
@keyframes redflash { 50% { border-color: #ff2340; box-shadow: 0 0 0 6px #ff234088, 0 0 40px #ff2340; } }
.react .stamp { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%) rotate(-14deg); font-family: 'Baloo 2'; font-weight: 800; font-size: 2.6rem; color: #ff2340; border: 6px solid #ff2340; border-radius: 16px; padding: 0 14px; background: #fff9; animation: stamp .3s ease-out; pointer-events: none; }
.react .stamp.yes { color: #1aa84f; border-color: #1aa84f; }
@keyframes stamp { 0% { transform: translate(-50%, -50%) rotate(-14deg) scale(2.4); opacity: 0; } }
.react .cardwrap { position: relative; }
.timer { width: min(300px, 80vw); height: 12px; border-radius: 999px; background: #fff5; overflow: hidden; }
.timer i { display: block; height: 100%; background: linear-gradient(90deg, var(--yellow), var(--red)); border-radius: 999px; }
.timer.paused i { background: #9ad; }
.curtain { background: linear-gradient(160deg, #7fd0ff, #ff8fc0); }
.curtain .av { width: 120px; height: 120px; border-width: 5px; }
.curtain .who { font-size: 2rem; }
.sheet .opts { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.opt { border: 3px solid transparent; background: #fff; border-radius: 14px; padding: 8px 10px; display: flex; align-items: center; gap: 6px; cursor: pointer; font-weight: 700; color: #2b2347; }
.opt.sel { border-color: var(--pink); box-shadow: 0 0 0 3px #ff6fa855; }
.opt .av { width: 30px; height: 30px; }
.cards-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.cards-row .card { cursor: pointer; }
.cards-row .card.sel { outline: 4px solid var(--pink); outline-offset: 2px; }
.order-num { position: absolute; bottom: 22px; right: 4px; background: var(--pink); color: #fff; font-weight: 800; border-radius: 999px; width: 22px; height: 22px; display: grid; place-items: center; font-size: .8rem; }
.depth { width: 100%; }
.log .panel { max-height: 80dvh; overflow-y: auto; }
.log ol { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; font-size: .9rem; }
.gameover h2 { font-size: 2.6rem; color: #fff; text-shadow: 0 4px 0 var(--blue); }
.gameover > .av { width: 110px; height: 110px; border-width: 5px; animation: soaked 1s ease-in-out infinite; }
.score .av { width: 30px; height: 30px; }
.score td:first-child { width: 40px; }
@keyframes soaked { 50% { transform: rotate(-6deg) translateY(4px); } }
.score { width: 100%; border-collapse: collapse; font-size: .95rem; }
.score td { padding: 4px 6px; border-bottom: 1px solid var(--line); }
.net-banner { position: fixed; top: calc(var(--safe-t) + 4px); left: 50%; transform: translateX(-50%); background: var(--red); color: #fff; border-radius: 999px; padding: 4px 14px; z-index: 80; font-weight: 700; }
.toast { position: fixed; bottom: calc(var(--safe-b) + 150px); left: 50%; transform: translateX(-50%); background: #2b2347ee; color: #fff; padding: 10px 16px; border-radius: 14px; z-index: 90; font-weight: 600; max-width: calc(100vw - 32px); text-align: center; }

@media (max-height: 680px) {
    .card { width: 78px; height: 106px; }
    .hand { min-height: 112px; }
    .pile { height: 62px; }
}
