:root {
  --water: #1f7a86;
  --water-deep: #155c66;
  --ink: #1e2a3a;
  --cream: #fff6e5;
  --cream-2: #ffe9c4;
  --wood: #b5733f;
  --wood-dark: #8a5230;
  --accent: #ffd23f;
  --pink: #ff7ab6;
  --red: #ff5a5f; --yellow: #ffd23f; --green: #43c465; --blue: #3f8efc;
  --radius: 20px;
  --shadow: 0 6px 0 rgba(0,0,0,.25);
  --font: Fredoka, 'Baloo 2', 'Varela Round', ui-rounded, system-ui, -apple-system, 'Segoe UI', sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); color: var(--ink);
  background: var(--water);
  background-image:
    radial-gradient(ellipse at 50% 0%, rgba(255,255,255,.12), transparent 60%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='40' viewBox='0 0 120 40'%3E%3Cpath d='M0 20 Q15 5 30 20 T60 20 T90 20 T120 20' fill='none' stroke='rgba(255,255,255,0.08)' stroke-width='4' stroke-linecap='round'/%3E%3C/svg%3E");
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button, input { font-family: inherit; font-size: inherit; }
#app { display: flex; flex-direction: column; min-height: 100dvh; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; height: 52px; color: #fff; }
.brand { font-weight: 700; font-size: 26px; color: var(--accent); text-decoration: none; -webkit-text-stroke: 1.5px var(--ink); letter-spacing: 1px; text-shadow: 2px 2px 0 var(--ink); }
.topbar-mid { flex: 1; text-align: center; font-weight: 600; letter-spacing: 2px; opacity: .95; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.conn { color: #ffd23f; font-size: 14px; transition: color .3s; }
.conn.open { color: #7CFC9B; } .conn.closed { color: #ff5a5f; }
.icon-btn { background: rgba(255,255,255,.15); border: 2px solid rgba(255,255,255,.4); color: #fff; border-radius: 12px; width: 38px; height: 38px; cursor: pointer; font-size: 18px; }
.icon-btn:hover { background: rgba(255,255,255,.28); }

/* ---------- generic ---------- */
main#screen { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.center-screen { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; }
.panel { background: var(--cream); border: 4px solid var(--ink); border-radius: 28px; box-shadow: var(--shadow); padding: 22px 24px; width: min(560px, 100%); }
.panel h1, .panel h2 { margin: 0 0 12px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); color: var(--ink); border: 3px solid var(--ink); border-radius: 16px;
  padding: 10px 18px; font-weight: 700; font-size: 17px; cursor: pointer; box-shadow: 0 4px 0 var(--ink);
  transition: transform .08s, box-shadow .08s, opacity .2s; min-height: 46px; text-decoration: none;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: 0 4px 0 var(--ink); }
.btn.secondary { background: #fff; }
.btn.danger { background: var(--red); color: #fff; }
.btn.pink { background: var(--pink); }
.btn.green { background: var(--green); }
.btn.blue { background: var(--blue); color: #fff; }
.btn.big { font-size: 22px; padding: 14px 26px; border-radius: 20px; }
.btn.small { font-size: 14px; padding: 6px 10px; min-height: 34px; border-width: 2px; box-shadow: 0 3px 0 var(--ink); border-radius: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 14px; opacity: .8; }
input.text { border: 3px solid var(--ink); border-radius: 14px; padding: 10px 14px; font-size: 18px; background: #fff; width: 100%; font-weight: 600; }
input.text.code { text-transform: uppercase; letter-spacing: 6px; text-align: center; font-size: 24px; }
.muted { opacity: .7; font-size: 14px; }
.hr { height: 3px; background: var(--ink); opacity: .12; border-radius: 3px; margin: 16px 0; }

/* ---------- home ---------- */
.logo { display: flex; justify-content: center; gap: 6px; margin: 6px 0 14px; }
.logo span { display: inline-block; width: 54px; height: 72px; line-height: 72px; text-align: center; font-size: 44px; font-weight: 700; color: #fff; border: 4px solid var(--ink); border-radius: 12px; box-shadow: 0 4px 0 var(--ink); -webkit-text-stroke: 1.5px var(--ink); }
.logo span:nth-child(1) { background: var(--red); transform: rotate(-6deg); }
.logo span:nth-child(2) { background: var(--yellow); transform: rotate(4deg); }
.logo span:nth-child(3) { background: var(--green); transform: rotate(-3deg); }
.logo span:nth-child(4) { background: var(--blue); transform: rotate(6deg); }
.mascots { display: flex; justify-content: center; gap: 10px; margin: -6px 0 8px; }
.mascots .otter { width: 84px; height: 84px; }
.tagline { text-align: center; margin: 0 0 16px; font-weight: 600; opacity: .8; }

.avatars { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.avatar-opt { width: 84px; border: 0; background: none; padding: 4px 2px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; border-radius: 14px; transition: transform .1s; }
.avatar-opt .avatar-pic { width: 62px; height: 62px; border-radius: 50%; border: 3px solid var(--ink); background: #cfe9ec; overflow: hidden; display: block; transition: box-shadow .15s; }
.avatar-opt .otter { width: 100%; height: 100%; display: block; }
.avatar-opt .avatar-name { font-size: 12px; font-weight: 600; line-height: 1.1; text-align: center; opacity: .75; }
.avatar-opt:hover { transform: scale(1.05); }
.avatar-opt.selected .avatar-pic { background: #fff; box-shadow: 0 0 0 4px var(--accent); }
.avatar-opt.selected .avatar-name { opacity: 1; color: var(--ink); background: var(--accent); border-radius: 8px; padding: 1px 6px; }
.avatar-opt.taken { opacity: .35; cursor: not-allowed; }

/* ---------- lobby ---------- */
.code-box { text-align: center; margin: 6px 0 14px; }
.code { font-size: 46px; font-weight: 700; letter-spacing: 12px; padding-left: 12px; color: var(--ink); background: #fff; border: 3px dashed var(--ink); border-radius: 18px; display: inline-block; padding: 4px 16px 4px 28px; }
.seats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.seat-card { display: flex; align-items: center; gap: 12px; background: #fff; border: 3px solid var(--ink); border-radius: 18px; padding: 10px; min-height: 86px; position: relative; }
.seat-card.empty { border-style: dashed; opacity: .6; justify-content: center; font-weight: 600; }
.seat-card .avatar-frame { width: 60px; height: 60px; flex: 0 0 auto; }
.seat-card .name { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 6px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 10px; background: var(--ink); color: #fff; margin-right: 4px; }
.badge.bot { background: var(--blue); } .badge.host { background: var(--accent); color: var(--ink); } .badge.off { background: #999; } .badge.you { background: var(--pink); }
.seat-card .x { position: absolute; top: 6px; right: 6px; }
.avatar-frame { width: 64px; height: 64px; border-radius: 50%; border: 3px solid #fff; background: #cfe9ec; overflow: hidden; box-shadow: 0 0 0 3px var(--ink); }
.avatar-frame .otter { width: 100%; height: 100%; display: block; }

/* ---------- table ---------- */
.table { position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0; }
.arena { position: relative; flex: 1; min-height: 300px; }
.felt { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(82vw, 560px); height: min(56vw, 320px); border-radius: 50%; background: radial-gradient(ellipse at 50% 40%, #c98950, var(--wood) 60%, var(--wood-dark)); border: 5px solid var(--ink); box-shadow: inset 0 0 40px rgba(0,0,0,.25), 0 8px 0 rgba(0,0,0,.25); }
.felt::after { content: ''; position: absolute; inset: 14px; border-radius: 50%; border: 3px dashed rgba(255,255,255,.25); }
.seat { position: absolute; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 4px; width: 130px; text-align: center; z-index: 2; }
.seat.pos-top { left: 50%; top: 13%; }
.seat.pos-left { left: 12%; top: 46%; }
.seat.pos-right { left: 88%; top: 46%; }
.seat .name { font-weight: 700; color: #fff; text-shadow: 1px 1px 0 var(--ink); font-size: 15px; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seat .cards { display: flex; justify-content: center; height: 30px; }
.seat .cards .mini { width: 20px; height: 30px; margin-left: -12px; border-radius: 3px; background: #2c4a6b; border: 2px solid var(--ink); }
.seat .cards .mini:first-child { margin-left: 0; }
.seat .count { position: absolute; top: -6px; right: 10px; background: var(--accent); border: 2px solid var(--ink); border-radius: 12px; font-weight: 700; font-size: 13px; padding: 1px 7px; }
.seat .uno-badge { position: absolute; top: -6px; left: 10px; background: var(--red); color: #fff; border: 2px solid var(--ink); border-radius: 12px; font-weight: 700; font-size: 12px; padding: 1px 6px; display: none; }
.seat.uno .uno-badge { display: block; }
.seat .avatar-frame { transition: box-shadow .2s; }
.seat.turn .avatar-frame { box-shadow: 0 0 0 3px var(--ink), 0 0 0 8px var(--accent), 0 0 24px 6px rgba(255,210,63,.75); animation: pulse 1.2s ease-in-out infinite; }
.seat.offline .avatar-frame { filter: grayscale(.9); opacity: .7; }
.seat .status { font-size: 12px; color: #fff; opacity: .85; min-height: 14px; }
.seat .catch { display: none; }
.seat.catchable .catch { display: inline-flex; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.05); } }

.center { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; gap: 28px; align-items: center; z-index: 2; }
.pile { width: 88px; height: 132px; position: relative; }
.pile .card-svg { position: absolute; inset: 0; width: 100%; height: 100%; filter: drop-shadow(0 3px 2px rgba(0,0,0,.3)); }
.drawpile { cursor: pointer; }
.drawpile.can:hover .card-svg:last-child { transform: translateY(-4px); }
.drawpile .card-svg:nth-child(1) { transform: translate(-4px, 4px); }
.drawpile .card-svg:nth-child(2) { transform: translate(-2px, 2px); }
.drawpile .n { position: absolute; bottom: -10px; left: 50%; transform: translateX(-50%); background: #fff; border: 2px solid var(--ink); border-radius: 10px; font-size: 12px; font-weight: 700; padding: 0 6px; }
.discard-wrap { position: relative; padding: 6px; border-radius: 16px; border: 5px solid transparent; transition: border-color .3s, box-shadow .3s; }
.discard-wrap[data-color="red"] { border-color: var(--red); box-shadow: 0 0 18px var(--red); }
.discard-wrap[data-color="yellow"] { border-color: var(--yellow); box-shadow: 0 0 18px var(--yellow); }
.discard-wrap[data-color="green"] { border-color: var(--green); box-shadow: 0 0 18px var(--green); }
.discard-wrap[data-color="blue"] { border-color: var(--blue); box-shadow: 0 0 18px var(--blue); }
.dir { position: absolute; left: 50%; top: 50%; width: 300px; height: 190px; transform: translate(-50%, -50%); pointer-events: none; z-index: 1; opacity: .9; }
.dir svg { width: 100%; height: 100%; }
.dir .arrows { transform-origin: 50% 50%; animation: spin 9s linear infinite; }
.dir.ccw .arrows { animation-direction: reverse; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner { position: absolute; left: 50%; top: 4px; transform: translateX(-50%); background: var(--cream); border: 3px solid var(--ink); border-radius: 14px; padding: 4px 14px; font-weight: 700; z-index: 3; box-shadow: 0 3px 0 var(--ink); white-space: nowrap; }
.banner.yours { background: var(--accent); animation: bob 1s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translate(-50%, 0); } 50% { transform: translate(-50%, -3px); } }
.log { position: absolute; left: 10px; bottom: 6px; font-size: 13px; color: #fff; text-shadow: 1px 1px 0 rgba(0,0,0,.6); max-width: 46%; z-index: 3; line-height: 1.25; }
.log div { opacity: .55; } .log div:last-child { opacity: 1; font-weight: 600; }

.me { display: flex; flex-direction: column; align-items: center; padding: 4px 8px 10px; gap: 6px; position: relative; }
.me-row { display: flex; align-items: center; gap: 12px; width: min(100%, 720px); justify-content: center; }
.me .seat { position: static; transform: none; width: auto; flex-direction: row; gap: 8px; }
.me .seat .avatar-frame { width: 54px; height: 54px; }
.me .seat .name { color: #fff; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; min-height: 48px; align-items: center; }
.emotes { display: flex; gap: 4px; }
.emotes button { background: #fff; border: 2px solid var(--ink); border-radius: 10px; width: 34px; height: 34px; cursor: pointer; font-size: 17px; padding: 0; }
.hand { display: flex; justify-content: flex-start; width: 100%; overflow-x: auto; overflow-y: visible; padding: 38px 16px 6px; gap: 0; scrollbar-width: thin; }
.hand-inner { display: flex; margin: 0 auto; padding: 0 10px; }
.hand .card { width: 86px; height: 129px; margin-left: -34px; flex: 0 0 auto; transition: transform .2s; border: 0; background: none; padding: 0; cursor: default; position: relative; }
.hand .card:first-child { margin-left: 0; }
.hand .card .card-svg { width: 100%; height: 100%; filter: drop-shadow(0 3px 2px rgba(0,0,0,.35)); }
.hand .card.playable { cursor: pointer; transform: translateY(-30px); z-index: 2; }
.hand .card.playable:hover { transform: translateY(-38px) scale(1.06); z-index: 5; }
.hand .card.arriving { visibility: hidden; }
.hand .card.drawn::after { content: 'new'; position: absolute; top: -10px; left: 50%; transform: translateX(-50%); background: var(--pink); border: 2px solid var(--ink); border-radius: 10px; font-size: 11px; font-weight: 700; padding: 0 6px; }
.uno-btn { background: var(--red); color: #fff; font-size: 22px; padding: 8px 22px; animation: wiggle .6s ease-in-out infinite; }
@keyframes wiggle { 0%,100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }

/* overlays */
.overlay { position: absolute; inset: 0; background: rgba(20,40,50,.55); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.overlay .panel { width: min(440px, 100%); text-align: center; }
.color-picker { display: flex; justify-content: center; gap: 14px; margin: 12px 0 4px; }
.color-blob { width: 72px; height: 72px; border-radius: 50%; border: 4px solid var(--ink); cursor: pointer; box-shadow: 0 5px 0 var(--ink); transition: transform .1s; }
.color-blob:hover { transform: scale(1.1); }
.color-blob:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.color-blob.red { background: var(--red); } .color-blob.yellow { background: var(--yellow); } .color-blob.green { background: var(--green); } .color-blob.blue { background: var(--blue); }
.tally { width: 100%; border-collapse: collapse; margin: 10px 0; }
.tally td { padding: 6px 8px; border-bottom: 2px solid rgba(0,0,0,.1); text-align: left; }
.tally td:last-child { text-align: right; font-weight: 700; }
.tally tr.win td { background: rgba(255,210,63,.35); }
.winner-otter { width: 120px; height: 120px; margin: 0 auto; animation: bounce .8s ease-in-out infinite; }
.winner-otter .otter { width: 100%; height: 100%; }
@keyframes bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
.reveal { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; margin: 8px 0; }
.reveal .card-svg { width: 44px; height: 66px; }

/* fx */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 50; overflow: hidden; }
.fly { position: absolute; width: 86px; height: 129px; transition: transform .45s cubic-bezier(.2,.8,.3,1), opacity .3s; will-change: transform; }
.fly .card-svg { width: 100%; height: 100%; filter: drop-shadow(0 6px 4px rgba(0,0,0,.35)); }
.bubble { position: absolute; transform: translate(-50%, -100%); background: #fff; border: 3px solid var(--ink); border-radius: 14px; padding: 4px 10px; font-weight: 700; font-size: 16px; white-space: nowrap; animation: pop 2.6s ease-out forwards; }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -10px; margin-left: -6px; border: 6px solid transparent; border-top-color: var(--ink); }
.bubble.uno { background: var(--red); color: #fff; font-size: 22px; }
.bubble.bad { background: var(--ink); color: #fff; }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, -80%) scale(.6); } 12% { opacity: 1; transform: translate(-50%, -110%) scale(1.1); } 20% { transform: translate(-50%, -105%) scale(1); } 80% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -130%); } }
.shake { animation: shake .5s; }
@keyframes shake { 0%,100% { transform: translate(0); } 20% { transform: translate(-6px, 2px); } 40% { transform: translate(6px, -2px); } 60% { transform: translate(-4px, 1px); } 80% { transform: translate(4px, -1px); } }

#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none; }
.toast { background: var(--ink); color: #fff; border-radius: 14px; padding: 8px 14px; font-weight: 600; border: 2px solid #fff; animation: toast 3s forwards; }
.toast.err { background: var(--red); }
@keyframes toast { 0% { opacity: 0; transform: translateY(10px); } 10%,85% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; } }
.ribbon { position: fixed; top: 0; left: 0; right: 0; background: var(--red); color: #fff; text-align: center; font-weight: 700; padding: 4px; z-index: 70; display: none; }
.ribbon.on { display: block; }

@media (max-width: 640px) {
  .panel { padding: 16px; border-radius: 22px; }
  .logo span { width: 44px; height: 60px; line-height: 60px; font-size: 36px; }
  .seats-grid { grid-template-columns: 1fr; }
  .seat { width: 96px; }
  .seat .name { font-size: 13px; max-width: 96px; }
  .avatar-frame { width: 52px; height: 52px; }
  .seat.pos-left { left: 12%; top: 40%; }
  .seat.pos-right { left: 88%; top: 40%; }
  .seat.pos-top { top: 12%; }
  .pile { width: 64px; height: 96px; }
  .center { gap: 18px; }
  .felt { width: 94vw; height: 60vw; }
  .dir { width: 240px; height: 150px; }
  .hand .card { width: 72px; height: 108px; margin-left: -30px; }
  .log { font-size: 12px; max-width: 60%; }
  .btn { font-size: 15px; padding: 8px 14px; }
  .color-blob { width: 60px; height: 60px; }
}
