:root {
  --bg: #1e1b4b;
  --bg2: #312e81;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #7c3aed;
  --primary2: #a78bfa;
  --danger: #ef4444;
  --ok: #10b981;
  --radius: 18px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: linear-gradient(160deg, var(--bg), var(--bg2));
  color: #fff;
  min-height: 100vh;
  overscroll-behavior: none;
}
#app { max-width: 720px; margin: 0 auto; padding: 16px; }
h1 { font-size: 26px; margin: 8px 0 20px; }
h2 { font-size: 20px; margin: 0 0 12px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 12px; padding: 12px 18px; font-size: 16px; font-weight: 600;
  background: var(--primary); color: #fff; cursor: pointer;
}
.btn:active { transform: scale(0.97); }
.btn.ghost { background: transparent; color: var(--primary); border: 2px solid var(--primary2); }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.danger { background: var(--danger); }
.btn.ok { background: var(--ok); }
.btn.light { background: rgba(255,255,255,.15); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 16px; }
.topbar .who { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; }
.topbar .avatar { font-size: 32px; }
.icon-btn { position: relative; background: rgba(255,255,255,.15); border: 0; color: #fff;
  font-size: 20px; width: 44px; height: 44px; border-radius: 12px; cursor: pointer; }
.badge { position: absolute; top: -4px; right: -4px; background: var(--danger); color: #fff;
  font-size: 11px; min-width: 18px; height: 18px; border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 4px; }

/* 프로필 선택 */
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.profile { background: rgba(255,255,255,.1); border: 2px solid transparent; border-radius: var(--radius);
  padding: 20px 10px; text-align: center; cursor: pointer; color: #fff; font-size: 17px; font-weight: 600; }
.profile:hover { border-color: var(--primary2); }
.profile .avatar { font-size: 56px; display: block; margin-bottom: 8px; }
.profile.admin { background: rgba(250, 204, 21, .15); }

/* PIN */
.pin-wrap { text-align: center; max-width: 320px; margin: 30px auto; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 20px 0; }
.pin-dots span { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #fff; }
.pin-dots span.on { background: #fff; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.pin-pad button { height: 64px; font-size: 26px; border-radius: 16px; border: 0;
  background: rgba(255,255,255,.12); color: #fff; cursor: pointer; }
.pin-pad button:active { background: rgba(255,255,255,.3); }
.pin-err { color: #fca5a5; min-height: 22px; }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px) } 75% { transform: translateX(8px) } }

/* 카드 */
.card { background: var(--card); color: var(--text); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.time-card .bar { height: 14px; background: #e5e7eb; border-radius: 7px; overflow: hidden; margin-top: 10px; }
.time-card .bar > div { height: 100%; background: linear-gradient(90deg, var(--ok), #34d399); transition: width .4s; }
.time-card .bar > div.low { background: linear-gradient(90deg, #f59e0b, var(--danger)); }
.time-big { font-size: 28px; font-weight: 800; }

.games { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.game-card { border-radius: var(--radius); padding: 22px; cursor: pointer; color: #fff; min-height: 140px;
  display: flex; flex-direction: column; justify-content: space-between; border: 0; text-align: left; }
.game-card .emoji { font-size: 44px; }
.game-card .title { font-size: 20px; font-weight: 800; }
.game-card.soon { opacity: .45; cursor: default; }

/* 탭 */
.tabs { display: flex; gap: 6px; margin-bottom: 14px; overflow-x: auto; }
.tabs button { flex: 1; white-space: nowrap; border: 0; padding: 12px; border-radius: 12px; font-size: 15px; font-weight: 700;
  background: rgba(255,255,255,.1); color: #fff; cursor: pointer; }
.tabs button.on { background: #fff; color: var(--primary); }

/* 폼 */
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea { width: 100%; padding: 10px 12px; font-size: 16px; border: 1px solid #d1d5db; border-radius: 10px; font-family: inherit; }
textarea { resize: vertical; min-height: 70px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.user-row { display: flex; align-items: center; gap: 12px; }
.user-row .avatar { font-size: 36px; }
.user-row .info { flex: 1; min-width: 0; }
.user-row .name { font-weight: 700; font-size: 17px; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #ede9fe; color: var(--primary); margin-right: 4px; }
.pill.red { background: #fee2e2; color: #b91c1c; }
.pill.green { background: #d1fae5; color: #047857; }

/* 메시지 */
.msg { padding: 10px 12px; border-radius: 14px; margin: 8px 0; max-width: 85%; }
.msg.in { background: #f3f4f6; }
.msg.out { background: #ede9fe; margin-left: auto; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.msg.unread { border: 2px solid var(--primary2); }

/* 기록 */
.chart { display: flex; align-items: flex-end; gap: 8px; height: 160px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.chart .stack { width: 100%; display: flex; flex-direction: column-reverse; border-radius: 6px 6px 0 0; overflow: hidden; }
.chart .day { font-size: 11px; color: var(--muted); margin-top: 4px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; }
.log { font-size: 14px; }
.log div { padding: 8px 0; border-bottom: 1px solid #f3f4f6; display: flex; gap: 8px; }
.log .t { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* 오버레이 */
.overlay { position: fixed; inset: 0; background: rgba(15, 10, 40, .85); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.lock-card { background: #fff; color: var(--text); border-radius: 24px; padding: 30px 24px; text-align: center; max-width: 360px; width: 100%; }
.lock-card .btn { width: 100%; margin-top: 10px; position: relative; }
.lock-emoji { font-size: 64px; }
.toast { position: fixed; left: 50%; top: 16px; transform: translateX(-50%); background: #111827; color: #fff;
  padding: 12px 18px; border-radius: 12px; z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.3); max-width: 90vw; }

/* ---------- Block Blast ---------- */
.bb { touch-action: none; user-select: none; -webkit-user-select: none; }
.bb-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.bb-score { text-align: center; }
.bb-score .now { font-size: 40px; font-weight: 900; line-height: 1; }
.bb-score .best { font-size: 13px; opacity: .8; }
.bb-board { --n: 8; display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 3px; padding: 6px;
  background: #0f0c2e; border-radius: 14px; width: min(100%, 440px); aspect-ratio: 1; margin: 0 auto; }
.bb-cell { border-radius: 5px; background: #24205a; }
.bb-cell.filled, .bb-mini .filled, .bb-drag .filled {
  box-shadow: inset 0 -4px 0 rgba(0,0,0,.25), inset 0 3px 0 rgba(255,255,255,.35); }
.bb-cell.ghost { opacity: .45; }
.bb-cell.will-clear { filter: brightness(1.5); }
.bb-cell.pop { animation: pop .4s ease-out both; }
@keyframes pop {
  0% { transform: scale(1); filter: brightness(1); }
  35% { transform: scale(1.2); filter: brightness(2.2); box-shadow: 0 0 18px #fff; }
  100% { transform: scale(0); opacity: 0; filter: brightness(2); }
}
.bb-tray { display: flex; justify-content: space-around; align-items: center; height: 130px; margin-top: 16px; width: min(100%, 440px); margin-left: auto; margin-right: auto; }
.bb-slot { flex: 1; height: 100%; display: flex; align-items: center; justify-content: center; }
.bb-mini { display: grid; gap: 2px; cursor: grab; touch-action: none; }
.bb-mini.disabled { opacity: .3; }
.bb-mini > div, .bb-drag > div { border-radius: 4px; }
.bb-drag { position: fixed; display: grid; gap: 3px; pointer-events: none; z-index: 40; }
.bb-over { text-align: center; }
.bb-over .big { font-size: 48px; font-weight: 900; color: var(--primary); }

/* ---------- 2048 ---------- */
.g2 { user-select: none; -webkit-user-select: none; }
.g2-board { --gap: 10px; --cell: calc((min(100vw - 32px, 440px) - 5 * var(--gap)) / 4);
  position: relative; width: min(100%, 440px); aspect-ratio: 1; margin: 0 auto; padding: var(--gap);
  background: #bbada0; border-radius: 14px; touch-action: none; }
.g2-bg { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); height: 100%; }
.g2-bg > div { background: rgba(238, 228, 218, .35); border-radius: 8px; }
.g2-tiles { position: absolute; inset: var(--gap); }
.g2-tile { position: absolute; top: 0; left: 0; z-index: 1; width: var(--cell); height: var(--cell); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; font-weight: 900;
  transition: transform .11s ease-in-out; }
.g2-tile.new { animation: g2-appear .2s ease-out .08s backwards; }
.g2-tile.merged { animation: g2-bump .18s ease-out; }
@keyframes g2-appear { from { opacity: 0; scale: .2; } }
@keyframes g2-bump { 50% { scale: 1.18; } }
.g2-msg { position: absolute; inset: 0; z-index: 5; border-radius: 14px; background: rgba(237, 194, 46, .6);
  display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 32px; font-weight: 900; color: #fff; }
.g2-help { text-align: center; font-size: 13px; opacity: .75; margin-top: 14px; }

/* ---------- Block Blast 이펙트 ---------- */
.bb-score .now.bump { animation: bump .3s ease-out; }
@keyframes bump { 40% { transform: scale(1.25); color: #fde047; } }
.bb-stage { position: relative; }
.bb-fx { position: fixed; inset: 0; pointer-events: none; z-index: 46; }

.bb-float { position: fixed; transform: translate(-50%, -50%); font-weight: 900; font-size: 28px; pointer-events: none; z-index: 47;
  color: #fde047; text-shadow: 0 2px 0 #b45309, 0 4px 12px rgba(0,0,0,.5); white-space: nowrap; animation: floatup 1.1s ease-out forwards; }
.bb-float.big { font-size: 40px; }
.bb-float.combo { font-size: 20px; color: #67e8f9; text-shadow: 0 2px 0 #0e7490, 0 4px 12px rgba(0,0,0,.5); }
@keyframes floatup {
  0% { transform: translate(-50%, -50%) scale(.5); opacity: 0; }
  20% { transform: translate(-50%, -60%) scale(1.15); opacity: 1; }
  100% { transform: translate(-50%, -160%) scale(1); opacity: 0; }
}

/* 2/3/4/5줄 칭찬 문구 */
.bb-praise { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 3; }
.bb-praise > div { font-weight: 900; white-space: nowrap; animation: praise 1.3s cubic-bezier(.2, 1.6, .4, 1) forwards;
  -webkit-text-stroke: 2px rgba(0,0,0,.25); text-shadow: 0 6px 20px rgba(0,0,0,.5); }
.bb-praise .t1 { font-size: 30px; color: #67e8f9; }
.bb-praise .t2 { font-size: min(44px, 12vw); color: #4ade80; }
.bb-praise .t3 { font-size: min(52px, 13vw); color: #fb923c; }
.bb-praise .t4, .bb-praise .t5 { font-size: min(56px, 13vw); color: transparent; -webkit-text-stroke: 0;
  background: linear-gradient(90deg, #f43f5e, #facc15, #22c55e, #06b6d4, #a855f7, #f43f5e) 0 0 / 200% 100%;
  -webkit-background-clip: text; background-clip: text; filter: drop-shadow(0 4px 10px rgba(0,0,0,.6));
  animation: praise 1.3s cubic-bezier(.2, 1.6, .4, 1) forwards, rainbow .6s linear infinite; }
.bb-praise .t5 { font-size: min(62px, 14vw); }
@keyframes praise {
  0% { transform: scale(0) rotate(-12deg); opacity: 0; }
  25% { transform: scale(1.1) rotate(3deg); opacity: 1; }
  40% { transform: scale(1) rotate(0); }
  80% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.3) translateY(-20px); opacity: 0; }
}
@keyframes rainbow { to { background-position: 200% 0; } }

/* 여러 줄을 지울 때 보드 흔들림 / 번쩍임 */
.bb-board.shake-2 { animation: shake2 .3s; }
.bb-board.shake-3 { animation: shake3 .45s; }
.bb-board.shake-4 { animation: shake4 .6s; }
@keyframes shake2 { 25% { transform: translate(-3px, 2px); } 75% { transform: translate(3px, -2px); } }
@keyframes shake3 { 20% { transform: translate(-6px, 3px) rotate(-.5deg); } 40% { transform: translate(6px, -3px) rotate(.5deg); }
  60% { transform: translate(-4px, 2px); } 80% { transform: translate(4px, -1px); } }
@keyframes shake4 { 10% { transform: translate(-10px, 5px) rotate(-1deg) scale(1.02); } 25% { transform: translate(10px, -5px) rotate(1deg); }
  40% { transform: translate(-8px, 4px) rotate(-.6deg); } 55% { transform: translate(8px, -3px) rotate(.6deg); }
  70% { transform: translate(-4px, 2px); } 85% { transform: translate(3px, -1px); } }
.bb-board.flash { box-shadow: 0 0 0 3px #fde047, 0 0 40px 10px rgba(253, 224, 71, .6); transition: box-shadow .1s; }

/* 올 클리어 */
.bb-allclear { position: fixed; inset: 0; z-index: 45; display: flex; align-items: center; justify-content: center; overflow: hidden;
  background: radial-gradient(circle, rgba(124, 58, 237, .55), rgba(15, 10, 40, .8)); animation: acIn .35s ease-out; }
.bb-allclear.out { animation: acOut .5s ease-in forwards; }
.bb-allclear .rays { position: absolute; width: 250vmax; height: 250vmax; left: 50%; top: 50%; margin: -125vmax 0 0 -125vmax;
  background: repeating-conic-gradient(rgba(253, 224, 71, .18) 0 10deg, transparent 10deg 20deg); animation: spin 6s linear infinite; }
.bb-allclear .box { position: relative; text-align: center; animation: acPop .7s cubic-bezier(.2, 1.8, .4, 1); }
.bb-allclear .title { font-size: 34px; font-weight: 900; color: #fde047; text-shadow: 0 4px 0 #b45309, 0 8px 24px rgba(0,0,0,.5); }
.bb-allclear .praise { margin-top: 12px; font-size: min(46px, 11vw); font-weight: 900; line-height: 1.2; padding: 0 12px;
  color: transparent; background: linear-gradient(90deg, #f43f5e, #facc15, #22c55e, #06b6d4, #a855f7, #f43f5e) 0 0 / 200% 100%;
  -webkit-background-clip: text; background-clip: text; filter: drop-shadow(0 4px 12px rgba(0,0,0,.6));
  animation: rainbow .8s linear infinite, wiggle 1s ease-in-out infinite; }
.bb-allclear .bonus { margin-top: 10px; font-size: 30px; font-weight: 900; color: #fff; text-shadow: 0 4px 16px rgba(0,0,0,.6); }
@keyframes acIn { from { opacity: 0; } }
@keyframes acOut { to { opacity: 0; } }
@keyframes acPop { 0% { transform: scale(0) rotate(-20deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes wiggle { 50% { transform: scale(1.08) rotate(-2deg); } }

@media (prefers-reduced-motion: reduce) {
  .bb-board.shake-2, .bb-board.shake-3, .bb-board.shake-4 { animation: none; }
  .bb-allclear .rays { animation: none; }
}
