:root {
  --bg: #eaf6e4;
  --ink: #232b2f;
  --soft: #5b6b63;
  --card: #fffdf6;
  --back: #c9d8cc;
  --gold: #ffd75e;
  --gold-ink: #6a4b00;
  --good: #a9e08f;
  --good-ink: #1d4d10;
  --bad: #ff8d7a;
  --line: #232b2f;
  --cw: 62px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif; }
body { min-height: 100vh; }
#app { max-width: 520px; margin: 0 auto; padding: 14px 14px calc(24px + env(safe-area-inset-bottom)); }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3, p { margin: 0; }

/* 버튼 */
.btn { display: block; width: 100%; border: 2px solid var(--line); border-radius: 14px; background: #fff; padding: 12px 10px; font-weight: 700; font-size: 16px; box-shadow: 0 3px 0 var(--line); margin: 0 0 10px; text-align: center; }
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--line); }
.btn small { display: block; font-weight: 400; font-size: 12px; color: var(--soft); margin-top: 2px; }
.btn.green { background: var(--good); }
.btn.dark { background: var(--ink); color: #fff; }
.btn.ghost { box-shadow: none; border-width: 1.5px; font-weight: 500; font-size: 14px; background: transparent; }
.btn.small { width: auto; display: inline-block; padding: 6px 12px; font-size: 13px; margin: 0; box-shadow: 0 2px 0 var(--line); }
.row2 { display: flex; gap: 8px; margin-bottom: 10px; }
.row2 > * { flex: 1; margin: 0; }

/* 홈 */
.topbar { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.logo { text-align: center; margin: 10px 0 16px; }
.logo .crown { font-size: 44px; line-height: 1; }
.logo h1 { font-size: 28px; margin-top: 4px; letter-spacing: -0.5px; }
.logo p { color: var(--soft); font-size: 14px; margin-top: 4px; }
.label { font-size: 13px; color: var(--soft); font-weight: 700; margin: 14px 0 6px; }
.chips { display: flex; gap: 6px; }
.chip { flex: 1; border: 2px solid var(--line); border-radius: 12px; background: #fff; padding: 9px 4px; font-size: 14px; font-weight: 700; text-align: center; }
.chip small { display: block; font-weight: 400; font-size: 11px; color: var(--soft); }
.chip.on { background: var(--good); }
.note { font-size: 12.5px; color: var(--soft); text-align: center; margin: -4px 0 12px; line-height: 1.5; }
.divider { height: 2px; background: #cfe3c7; margin: 16px 0; border-radius: 2px; }
footer { text-align: center; font-size: 12px; color: var(--soft); margin-top: 18px; line-height: 1.7; }

/* 게임 화면 */
.gbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 8px; }
.gbar .turns { font-weight: 800; font-size: 17px; }
.gbar .turns.low { color: #c0392b; }
.slots { display: grid; gap: 6px; margin-bottom: 10px; }
.slot { border: 2px dashed #8aa595; border-radius: 12px; min-height: 58px; padding: 6px 4px; text-align: center; font-size: 12px; color: var(--soft); display: flex; flex-direction: column; justify-content: center; }
.slot.open { border: 2px solid var(--line); border-style: solid; background: var(--gold); color: var(--gold-ink); }
.slot.open b { font-size: 15px; }
.slot.open .dots { letter-spacing: 3px; font-size: 13px; }
.slot.flash { animation: flash .6s; }
.donebar { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; min-height: 0; }
.donechip { font-size: 12px; font-weight: 700; background: var(--good); color: var(--good-ink); border: 1.5px solid var(--good-ink); border-radius: 99px; padding: 2px 8px; }
.tab { display: grid; gap: 6px; align-items: start; margin-bottom: 12px; }
.col { position: relative; min-height: 46px; border-radius: 10px; }
.col.empty { border: 1.5px dashed #b6cbbd; min-height: 46px; }
.card { position: absolute; left: 0; right: 0; height: 44px; border: 2px solid var(--line); border-radius: 9px; background: var(--card); font-weight: 700; font-size: clamp(11px, 3.4vw, 14px); display: flex; align-items: center; justify-content: center; text-align: center; padding: 0 2px; line-height: 1.15; word-break: keep-all; box-shadow: 0 2px 0 rgba(35,43,47,.35); user-select: none; }
.card.label { background: var(--gold); color: var(--gold-ink); }
.card.label::before { content: '👑'; font-size: 10px; position: absolute; top: -1px; left: 3px; line-height: 1; }
.card.down { background: repeating-linear-gradient(45deg, var(--back), var(--back) 6px, #bccdc0 6px, #bccdc0 12px); color: transparent; box-shadow: none; }
.card.down::before { content: none; }
.card.hint-src { outline: 3px solid #2d7ff9; outline-offset: 1px; animation: pulse 1s infinite; z-index: 5; }
.card.shake { animation: shake .35s; }
.col.hint-dst, .slot.hint-dst, .stock.hint-dst { outline: 3px solid #2d7ff9; outline-offset: 2px; animation: pulse 1s infinite; }
.draw { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.stock, .wastebox { position: relative; width: var(--cw); height: 46px; flex: 0 0 var(--cw); }
.stock .card { position: relative; width: 100%; height: 44px; font-size: 12px; }
.stock .card.down { color: var(--soft); background: repeating-linear-gradient(45deg, var(--back), var(--back) 6px, #bccdc0 6px, #bccdc0 12px); }
.stock .empty-s { border: 1.5px dashed #b6cbbd; border-radius: 9px; width: 100%; height: 44px; display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--soft); }
.wastebox .card { position: relative; width: 100%; }
.draw .hintline { flex: 1; font-size: 12px; color: var(--soft); text-align: right; line-height: 1.4; }
.tools { display: flex; gap: 6px; }
.tool { flex: 1; border: 2px solid var(--line); border-radius: 12px; background: #fff; padding: 8px 2px; font-size: 13px; font-weight: 700; text-align: center; box-shadow: 0 2px 0 var(--line); }
.tool:active { transform: translateY(1px); }
.tool small { display: block; font-weight: 400; font-size: 11px; color: var(--soft); }
.tool.on { background: #cfe5ff; }
.tool[aria-disabled="true"] { opacity: .45; }
.banner { background: #fff3cd; border: 2px solid #c9a227; border-radius: 12px; padding: 8px 10px; font-size: 13px; margin-bottom: 10px; line-height: 1.45; }
.banner.bad { background: #ffe1db; border-color: #c0392b; }

/* 결과 */
.result { text-align: center; padding-top: 18px; }
.result h2 { font-size: 24px; }
.stars { font-size: 38px; letter-spacing: 6px; margin: 8px 0 12px; color: #e6a700; }
.stars .off { color: #c8d3cb; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0 14px; }
.stat { background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 8px; }
.stat small { display: block; font-size: 12px; color: var(--soft); }
.stat b { font-size: 20px; }
.sharebox { background: #fff; border: 1.5px dashed var(--soft); border-radius: 12px; padding: 10px; font-size: 13px; text-align: left; line-height: 1.6; margin-bottom: 12px; white-space: pre-line; }

/* 도움말 */
.help { background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 14px; font-size: 14px; line-height: 1.7; margin-bottom: 12px; }
.help h3 { font-size: 16px; margin: 10px 0 4px; }
.help h3:first-child { margin-top: 0; }
.help ul { margin: 4px 0; padding-left: 20px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw; text-align: center; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.loading { text-align: center; padding: 80px 0; font-weight: 700; color: var(--soft); }

@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes flash { 0% { background: #fff; transform: scale(1.06); } 100% { background: var(--gold); transform: scale(1); } }
@keyframes pulse { 0%,100% { outline-color: #2d7ff9; } 50% { outline-color: #9cc4ff; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* 대결방 */
.field { display: block; width: 100%; border: 2px solid var(--line); border-radius: 12px; padding: 11px 12px; font: inherit; font-size: 16px; background: #fff; margin-bottom: 10px; }
.join { display: flex; gap: 8px; align-items: stretch; margin-bottom: 8px; }
.join .field { margin: 0; flex: 1; }
.join .btn.small { padding: 0 16px; }
.codebox { text-align: center; background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 10px; margin-bottom: 10px; }
.codebox small { display: block; font-size: 12px; color: var(--soft); }
.codebox b { font-size: 34px; letter-spacing: 8px; padding-left: 8px; }
.plist { display: flex; flex-direction: column; gap: 6px; }
.prow { display: flex; justify-content: space-between; align-items: center; background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 8px 12px; font-size: 15px; }
.prow.off { opacity: .55; }
.prow small { color: var(--soft); }
.rstrip { margin-bottom: 8px; }
.rrow { display: flex; align-items: center; gap: 6px; font-size: 12px; height: 20px; }
.rrow .rname { width: 74px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rrow.me .rname { font-weight: 800; }
.rrow .rbar { flex: 1; height: 8px; background: #d3e2d6; border-radius: 99px; overflow: hidden; border: 1px solid #a9bfae; }
.rrow .rbar i { display: block; height: 100%; background: #5fb04a; transition: width .3s; }
.rrow.me .rbar i { background: #2d7ff9; }
.rrow .rnum { width: 52px; text-align: right; color: var(--soft); }
.rrow.off { opacity: .5; }
.sboard { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; text-align: left; }
.srow { display: flex; align-items: center; gap: 8px; background: #fff; border: 2px solid var(--line); border-radius: 12px; padding: 9px 12px; }
.srow.me { background: #e5f0ff; }
.srow .medal { width: 26px; text-align: center; font-size: 20px; }
.srow b { flex: 1; font-size: 15px; }
.srow small { color: var(--soft); font-size: 12.5px; text-align: right; }

/* 협동방 */
.pchips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.pchip { font-size: 12px; background: #fff; border: 1.5px solid var(--line); border-radius: 99px; padding: 2px 8px; }
.pchip small { color: var(--soft); }
.pchip.hot { background: #cfe5ff; border-color: #2d7ff9; }
.pchip.off { opacity: .5; }
.lastby { font-size: 12px; color: var(--soft); margin: 0 0 8px; }
.says { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.say { flex: 1 1 30%; border: 1.5px solid var(--line); border-radius: 99px; background: #fff; padding: 6px 4px; font-size: 12px; }
.say:active { background: var(--good); }

/* 누림랩 상단 막대·다른 게임 팝업 */
.sitebar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 0 0 8px; }
.sitelink { font: inherit; font-size: 14px; font-weight: 800; color: var(--ink); background: #fff; border: 2px solid var(--line); border-radius: 999px; padding: 5px 12px; min-height: 36px; text-decoration: none; cursor: pointer; white-space: nowrap; }
.modal { position: fixed; inset: 0; background: rgba(35, 43, 47, .55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal .sheet { background: var(--bg); width: 100%; max-width: 520px; max-height: 88dvh; overflow: auto; border-radius: 22px 22px 0 0; padding: 18px 14px calc(18px + env(safe-area-inset-bottom)); border: 2px solid var(--line); border-bottom: 0; }
.modal h2 { font-size: 18px; margin-bottom: 10px; }
.roomlist { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.roomitem { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 10px 14px; border: 2px solid var(--line); border-radius: 14px; background: #fff; box-shadow: 0 3px 0 var(--line); text-decoration: none; color: inherit; }
.roomitem b { font-size: 16px; }
.roomitem small { color: var(--soft); font-weight: 600; font-size: 12.5px; line-height: 1.4; }
.roomitem.here { opacity: .55; box-shadow: none; }

/* 겹쳐 쌓인 앞면 카드는 보이는 윗줄에 글자가 오게 한다(맨 위 카드는 가운데) */
.col .card:not(:last-child) { align-items: flex-start; padding-top: 3px; }
