:root {
  --bg: #f1f8ec;
  --ink: #2d2a3e;
  --muted: #7a7590;
  --card: #fcfffa;
  --line: #d6e5cb;
  --accent: #9be26b;
  --accent-d: #5fae35;
  --green: #6cc644;
  --yellow: #f5c53d;
  --red: #ef5b5b;
  --empty: #ffffff;
  --radius: 16px;
  --gutter: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  word-break: keep-all;
  min-height: 100dvh;
}
button, input { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }

#app { max-width: 560px; margin: 0 auto; padding: 0 var(--gutter) calc(24px + env(safe-area-inset-bottom)); min-height: 100dvh; }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 10px 18px;
  background: var(--card); color: var(--ink);
  border: 2px solid var(--ink); border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  font-weight: 800; cursor: pointer;
  transition: transform .06s, box-shadow .06s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); }
.btn.big { min-height: 56px; font-size: 1.1rem; width: 100%; }
.btn.small { min-height: 42px; padding: 6px 12px; font-size: .95rem; }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; text-decoration: underline; width: 100%; color: var(--muted); }
a.btn { text-decoration: none; display: flex; box-sizing: border-box; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* 누림랩 상단 막대 */
.sitebar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding-top: 10px; }
.sitelink { font: inherit; font-size: .85rem; font-weight: 800; color: var(--ink); background: var(--card); border: 2px solid var(--ink); border-radius: 999px; padding: 5px 12px; min-height: 36px; text-decoration: none; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; }

/* 홈 */
.logo { text-align: center; padding: 30px 0 22px; }
.logo .ball { font-size: 76px; line-height: 1; }
.logo h1 { font-size: 2.2rem; letter-spacing: -1px; margin-top: 8px; }
.logo p { color: var(--muted); margin-top: 4px; font-weight: 600; }
.soon-tag { font-size: .78rem; background: var(--ink); color: #fff; border-radius: 999px; padding: 2px 8px; }
.footer { text-align: center; color: var(--muted); font-size: .85rem; margin-top: 22px; line-height: 1.6; }

/* 상단 바(게임 안) */
.top { display: flex; align-items: center; gap: 8px; padding: 12px 0 8px; }
.top .title { flex: 1; text-align: center; font-weight: 800; }
.icon-btn { width: 44px; height: 44px; border-radius: 12px; border: 2px solid var(--ink); background: var(--card); font-weight: 900; cursor: pointer; font-size: 1.1rem; }

/* 난이도 */
.levels { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.levels .btn { justify-content: space-between; }
.levels .btn small { font-weight: 700; color: var(--muted); }
.note { margin-top: 12px; padding: 10px 12px; background: #fff; border: 2px dashed var(--line); border-radius: 12px; color: var(--muted); font-size: .9rem; }

/* 판 */
.sub { text-align: center; color: var(--muted); font-weight: 700; font-size: .92rem; margin: 2px 0 8px; }
.board { display: flex; flex-direction: column; gap: 5px; margin: 6px auto 12px; }
.row { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 5px; margin: 0 auto; width: 100%; max-width: calc(var(--n) * 54px + (var(--n) - 1) * 5px); }
.cell { text-transform: uppercase;
  position: relative; aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  background: var(--empty); border: 2px solid #c9d3c0; border-radius: 10px;
  font-size: clamp(1rem, 5.5vw, 1.6rem); font-weight: 900; user-select: none;
}
.cell.filled { border-color: var(--ink); }
.cell.green { background: var(--green); border-color: var(--ink); }
.cell.yellow { background: var(--yellow); border-color: var(--ink); }
.cell.red { background: var(--red); border-color: var(--ink); color: #fff; }
.cell .sym { position: absolute; top: 1px; right: 3px; font-size: .5em; font-weight: 900; line-height: 1; opacity: .8; }
.cell.active { border-color: var(--accent-d); box-shadow: 0 0 0 2px var(--accent); }

/* 키보드 */
.kb { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.kb .krow { display: flex; gap: 5px; justify-content: center; }
.key { text-transform: uppercase;
  flex: 1; max-width: 44px; min-height: 46px; border-radius: 10px; border: 2px solid var(--ink); background: var(--card);
  font-weight: 800; font-size: 1.1rem; cursor: pointer; padding: 0; position: relative;
}
.key:active { transform: translateY(2px); }
.key.wide { max-width: 88px; flex: 2; font-size: .95rem; }
.key.green { background: var(--green); }
.key.yellow { background: var(--yellow); }
.key.red { background: var(--red); color: #fff; opacity: .75; }
.key.enter { background: var(--accent); }
.kb-sym { position: absolute; top: 0; right: 2px; font-size: .55rem; }

/* 결과 */
.result { text-align: center; margin: 8px 0 14px; }
.result h2 { font-size: 1.6rem; }
.result p { color: var(--muted); font-weight: 700; margin-top: 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* 팝업 */
.modal { position: fixed; inset: 0; background: rgba(45, 42, 62, .55); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal .sheet { background: var(--card); width: 100%; max-width: 560px; max-height: 88dvh; overflow: auto; border-radius: 22px 22px 0 0; padding: 20px var(--gutter) calc(20px + env(safe-area-inset-bottom)); border: 2px solid var(--ink); border-bottom: 0; }
.modal h2 { margin-bottom: 10px; }
.modal ol { padding-left: 22px; margin: 0 0 12px; }
.modal li { margin-bottom: 8px; }
.modal .sheet > .btn { margin-top: 10px; }
.legend { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.legend div { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.legend .sw { width: 28px; height: 28px; border: 2px solid var(--ink); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: .75rem; font-weight: 900; }
.roomitem { display: block; padding: 10px 12px; margin-bottom: 8px; background: #fff; border: 2px solid var(--ink); border-radius: 12px; text-decoration: none; color: inherit; }
.roomitem b { display: block; }
.roomitem small { color: var(--muted); font-weight: 600; }
.roomitem.here { opacity: .55; }

.textin { display: block; width: 100%; height: 52px; margin: 6px 0 12px; padding: 0 14px; background: #fff; border: 2px solid var(--ink); border-radius: 14px; font-size: 1.05rem; }
.boardrow { display: grid; grid-template-columns: 34px 1fr auto 70px; gap: 8px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line); font-weight: 700; }
.boardrow.me { background: var(--accent); border-radius: 10px; border-bottom-color: transparent; }
.boardrow .rk { text-align: center; font-weight: 900; }
.boardrow .nk { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.boardrow .tm { color: var(--muted); font-size: .82rem; text-align: right; }
.btn.small.primary { background: var(--accent); }
/* 같이 하기 */
.joinrow { display: flex; gap: 10px; }
.joinrow .btn { min-width: 84px; }
.textin.code { text-transform: uppercase; letter-spacing: 3px; text-align: center; font-weight: 800; margin: 0; }
button.roomitem { width: 100%; text-align: left; font: inherit; cursor: pointer; }
.card { background: #fff; border: 2px solid var(--ink); border-radius: var(--radius); padding: 12px; margin: 14px 0; }
.card h3 { margin-bottom: 6px; }
.lvls { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.lvls .btn.small { flex-direction: column; gap: 0; min-height: 52px; padding: 4px 2px; }
.lvls small { font-size: .62rem; font-weight: 700; color: var(--muted); }
.plist { display: flex; flex-direction: column; gap: 6px; margin: 6px 0; }
.pl { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; background: #fff; border: 2px solid var(--ink); border-radius: 12px; }
.pl.off { opacity: .5; }
.tag { font-size: .8rem; font-weight: 800; border-radius: 999px; padding: 2px 10px; color: #fff; }
.tag.A, .tbtn.A.on { background: #3d8bfd; }
.tag.B, .tbtn.B.on { background: #a06cd5; }
.tbtn { font: inherit; font-size: .85rem; font-weight: 800; border: 2px solid var(--ink); border-radius: 999px; padding: 2px 10px; background: #fff; cursor: pointer; min-height: 32px; }
.tbtn.on { color: #fff; }
.linkbtn { font: inherit; font-size: .85rem; font-weight: 800; background: none; border: 0; text-decoration: underline; color: var(--ink); cursor: pointer; padding: 0 4px; }
.plr { display: flex; align-items: center; gap: 6px; }
.kickbtn { font: inherit; font-weight: 900; width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--ink); background: #fff; color: #c43d3d; cursor: pointer; padding: 0; }
.tag.W, .tbtn.W.on { background: #7a7590; }
.tbtn.A.on { background: #3d8bfd; }
.teamsel { display: flex; gap: 6px; }
.pchips { display: flex; flex-wrap: wrap; gap: 5px; margin: 4px 0 8px; }
.pchip { font-size: .8rem; font-weight: 800; padding: 2px 9px; border-radius: 999px; border: 2px solid var(--ink); background: #fff; }
.pchip.A { border-color: #3d8bfd; }
.pchip.B { border-color: #a06cd5; }
.pchip.cur { background: var(--accent); }
.pchip.out { opacity: .4; text-decoration: line-through; }
.turnbar { text-align: center; font-weight: 800; padding: 8px; border-radius: 12px; border: 2px solid var(--ink); background: #fff; margin-bottom: 6px; }
.turnbar.mine { background: var(--accent); }
.turnbar b { margin-left: 6px; font-variant-numeric: tabular-nums; }
.turnbar b.warn { color: #c43d3d; }
.mboard { display: flex; flex-direction: column; gap: 4px; margin: 6px 0 10px; }
.mrow { display: grid; grid-template-columns: 46px 1fr; gap: 4px; align-items: center; }
.mcells { display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 4px; }
.mcells .cell { border-radius: 8px; font-size: clamp(.8rem, 4.2vw, 1.3rem); }
.who { font-size: .68rem; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-left: 4px solid var(--line); padding-left: 3px; }
.who.A { border-left-color: #3d8bfd; }
.who.B { border-left-color: #a06cd5; }
.toast { position: fixed; left: 50%; bottom: 130px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 120; max-width: 90vw; text-align: center; font-weight: 700; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.center { text-align: center; padding-top: 80px; color: var(--muted); font-weight: 700; }
