@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.min.css');
:root {
  --paper: #f6f1e7; --ink: #15130f; --ink-2: #5c574d; --line: #15130f;
  --card: #fffdf8; --yellow: #ffe24d; --green: #5be37d; --red: #ff6b6b; --blue: #7cc4ff;
  --r: 16px; --shadow: 4px 4px 0 var(--ink);
  font-family: "Pretendard Variable", Pretendard, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); -webkit-font-smoothing: antialiased; overscroll-behavior: none; touch-action: manipulation; line-height: 1.45; }
body::before { content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none; background-image: radial-gradient(rgba(21,19,15,.08) 1px, transparent 1.2px); background-size: 18px 18px; }
button, input { font-family: inherit; }
a { color: inherit; text-decoration: none; }
b, strong { font-weight: 800; }

#top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); background: var(--paper); border-bottom: 2px solid var(--ink); }
.brand { font-weight: 900; font-size: 18px; letter-spacing: -.5px; }
.brand mark { background: var(--yellow); padding: 0 4px; }
.nick { background: var(--card); color: var(--ink); border: 2px solid var(--ink); border-radius: 999px; padding: 5px 12px; font-size: 13px; font-weight: 700; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; box-shadow: 2px 2px 0 var(--ink); }
.nick:active { transform: translate(1px,1px); box-shadow: 1px 1px 0 var(--ink); }

#app { max-width: 520px; margin: 0 auto; padding: 18px 16px 60px; }
.screen { animation: pop .22s ease both; }
@keyframes pop { from { opacity: 0; transform: translateY(6px) } to { opacity: 1; transform: none } }
h1 { font-size: 30px; margin: 10px 0 6px; letter-spacing: -1px; line-height: 1.15; font-weight: 900; }
h2 { font-size: 20px; margin: 6px 0; letter-spacing: -.3px; font-weight: 900; }
h3 { font-size: 14px; margin: 22px 0 10px; font-weight: 800; color: var(--ink-2); text-transform: uppercase; letter-spacing: .5px; }
.lead { color: var(--ink-2); margin: 0 0 8px; font-size: 15px; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; }

/* home */
.games { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.game-card { display: block; background: var(--c, var(--card)); border: 2px solid var(--ink); border-radius: var(--r); padding: 14px 14px 12px; min-height: 150px; position: relative; box-shadow: var(--shadow); transition: transform .08s, box-shadow .08s; }
.game-card:active { transform: translate(3px,3px); box-shadow: 1px 1px 0 var(--ink); }
.game-card .tag { font-size: 11px; font-weight: 800; background: var(--ink); color: #fff; padding: 2px 7px; border-radius: 6px; display: inline-block; }
.game-card .name { font-weight: 900; font-size: 20px; margin-top: 8px; letter-spacing: -.5px; line-height: 1.15; }
.game-card .desc { font-size: 12px; margin-top: 6px; line-height: 1.4; color: rgba(21,19,15,.75); }
.game-card .best { position: absolute; bottom: 10px; right: 12px; font-size: 11px; font-weight: 800; background: #fff; border: 1.5px solid var(--ink); border-radius: 999px; padding: 1px 8px; }
.game-card.wide { grid-column: 1 / -1; min-height: auto; }
.today { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink-2); margin: 4px 0 10px; }
.today b { color: var(--ink); }

/* buttons */
.btn { appearance: none; border: 2px solid var(--ink); border-radius: 12px; padding: 13px 18px; font-size: 16px; font-weight: 800; cursor: pointer; background: var(--card); color: var(--ink); width: 100%; box-shadow: var(--shadow); transition: transform .06s, box-shadow .06s; }
.btn:active { transform: translate(3px,3px); box-shadow: 1px 1px 0 var(--ink); }
.btn.primary { background: var(--yellow); }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.sm { padding: 8px 12px; font-size: 13px; width: auto; border-radius: 10px; box-shadow: 2px 2px 0 var(--ink); }
.btn.sm:active { transform: translate(1px,1px); box-shadow: 1px 1px 0 var(--ink); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.linkish { background: none; border: 0; color: var(--ink-2); font-weight: 700; font-size: 13px; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* play area */
.hud { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--ink-2); margin: 6px 2px 8px; font-variant-numeric: tabular-nums; }
.hud b { color: var(--ink); font-size: 16px; }
.hud .timer.low { color: var(--red); }
.arena { position: relative; background: var(--card); border: 2px solid var(--ink); border-radius: var(--r); box-shadow: var(--shadow); min-height: 62vh; display: flex; align-items: center; justify-content: center; flex-direction: column; text-align: center; user-select: none; -webkit-user-select: none; overflow: hidden; padding: 16px; }
.arena.full { min-height: 70vh; }
.arena .big { font-size: 60px; font-weight: 900; letter-spacing: -2px; line-height: 1; }
.arena .msg { font-size: 20px; font-weight: 800; margin-top: 12px; }
.arena .sub { color: var(--ink-2); margin-top: 8px; font-size: 14px; max-width: 300px; }
.arena.wait { background: #ff6b6b; }
.arena.go { background: #5be37d; }
.arena.early { background: #ffb347; }
.bar { height: 10px; background: var(--card); border: 2px solid var(--ink); border-radius: 99px; overflow: hidden; margin-bottom: 10px; }
.bar > i { display: block; height: 100%; background: var(--ink); width: 100%; transition: width .2s linear; }

/* grids */
.grid { display: grid; gap: 6px; width: 100%; max-width: 420px; aspect-ratio: 1; }
.grid > button { border: 2px solid var(--ink); border-radius: 10px; padding: 0; cursor: pointer; }
.grid.num > button { background: #fff; color: var(--ink); font-size: 22px; font-weight: 900; transition: opacity .1s; }
.grid.num > button.done { opacity: .15; pointer-events: none; }
.grid.num > button.wrong { background: var(--red); }

/* result */
.card { background: var(--card); border: 2px solid var(--ink); border-radius: var(--r); padding: 16px; margin-top: 12px; box-shadow: var(--shadow); }
.result { text-align: center; }
.result .score { font-size: 56px; font-weight: 900; letter-spacing: -2px; line-height: 1.05; }
.result .rank-line { margin-top: 10px; font-size: 15px; }
.result .rank-line b { background: var(--yellow); padding: 0 4px; }
.stamp { display: inline-block; font-size: 12px; font-weight: 900; border: 2px solid var(--ink); border-radius: 6px; padding: 1px 8px; transform: rotate(-3deg); background: var(--green); }

/* leaderboard */
.lb { list-style: none; margin: 0; padding: 0; }
.lb li { display: flex; align-items: center; gap: 10px; padding: 10px 6px; border-bottom: 1.5px dashed rgba(21,19,15,.2); font-size: 15px; }
.lb li:last-child { border-bottom: 0; }
.lb .pos { width: 30px; text-align: center; font-weight: 900; color: var(--ink-2); }
.lb li:nth-child(1) .pos { color: #d4a000 } .lb li:nth-child(2) .pos { color: #8a8a8a } .lb li:nth-child(3) .pos { color: #b5651d }
.lb .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.lb .val { font-variant-numeric: tabular-nums; font-weight: 900; }
.lb li.me { background: var(--yellow); border-radius: 10px; }
.lb li.me .name::after { content: " 나"; font-size: 11px; background: var(--ink); color: #fff; padding: 1px 5px; border-radius: 4px; margin-left: 4px; }
.empty { text-align: center; color: var(--ink-2); padding: 20px 0; font-size: 14px; }

/* inputs */
.input { width: 100%; background: #fff; border: 2px solid var(--ink); color: var(--ink); border-radius: 12px; padding: 12px 14px; font-size: 18px; outline: none; }
.input:focus { box-shadow: 3px 3px 0 var(--ink); }
.input-row { display: flex; gap: 8px; }
.input-row .input { flex: 1; min-width: 0; }
.input-row .btn { width: auto; padding-inline: 16px; box-shadow: var(--shadow); }

/* 초성 */
.cho { font-size: 46px; font-weight: 900; letter-spacing: 10px; margin: 8px 0 2px; }
.cat { display: inline-block; background: var(--ink); color: #fff; border-radius: 999px; padding: 3px 12px; font-size: 13px; font-weight: 800; }
.flash-ok { animation: ok .35s; } .flash-no { animation: no .3s; }
@keyframes ok { 0% { background: var(--green) } 100% { background: var(--card) } }
@keyframes no { 0%,100% { transform: translateX(0) } 25% { transform: translateX(-6px) } 75% { transform: translateX(6px) } }

/* 뜨거워 차가워 */
.guesses { list-style: none; margin: 12px 0 0; padding: 0; }
.guesses li { display: grid; grid-template-columns: 30px 1fr 60px 78px; align-items: center; gap: 8px; padding: 8px 8px; border-bottom: 1.5px dashed rgba(21,19,15,.2); font-size: 15px; font-variant-numeric: tabular-nums; }
.guesses li.latest { background: var(--card); border: 2px solid var(--ink); border-radius: 10px; box-shadow: 3px 3px 0 var(--ink); margin-bottom: 8px; }
.guesses .n { color: var(--ink-2); font-size: 12px; }
.guesses .w { font-weight: 800; }
.guesses .s { text-align: right; font-weight: 900; }
.guesses .r { text-align: right; font-size: 12px; color: var(--ink-2); }
.guesses .r.hot { color: var(--ink); font-weight: 900; background: var(--yellow); border-radius: 6px; padding: 1px 6px; }
.temp { height: 12px; border: 2px solid var(--ink); border-radius: 99px; background: linear-gradient(90deg, #7cc4ff, #5be37d 40%, #ffe24d 70%, #ff6b6b); position: relative; margin: 10px 0 4px; }
.temp > i { position: absolute; top: -7px; width: 20px; height: 20px; border-radius: 50%; background: #fff; border: 2px solid var(--ink); transform: translateX(-50%); transition: left .3s; }
.howto ol { padding-left: 20px; margin: 8px 0; } .howto li { margin: 6px 0; font-size: 15px; }
.howto .ex > :first-child { text-align: left; }
.howto .ex { display: grid; grid-template-columns: 1fr 60px 80px; text-align: right; gap: 6px; font-size: 14px; padding: 4px 8px; background: #fff; border: 1.5px solid var(--ink); border-radius: 8px; margin: 4px 0; }

/* 자모 야구 */
.board { display: grid; gap: 6px; justify-content: center; margin: 10px auto; }
.board .tile { width: 48px; height: 52px; border: 2px solid var(--ink); border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 26px; font-weight: 900; background: #fff; }
.board .tile.cur { border-style: dashed; }
.board .tile.typing { background: #fff; }
.tile.g, .key.g { background: var(--green) !important; }
.tile.y, .key.y { background: var(--yellow) !important; }
.tile.x, .key.x { background: #cfc9bd !important; color: rgba(21,19,15,.5); }
.tile.flip { animation: flip .35s ease; }
@keyframes flip { 0% { transform: rotateX(0) } 50% { transform: rotateX(90deg) } 100% { transform: rotateX(0) } }
.keys { display: flex; flex-direction: column; gap: 5px; align-items: center; margin-top: 10px; }
.keys .krow { display: flex; gap: 4px; }
.key { width: 30px; height: 36px; border: 1.5px solid var(--ink); border-radius: 6px; background: #fff; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800; }
.stage-tabs { display: flex; gap: 6px; margin: 4px 0 8px; }
.stage-tabs span { flex: 1; text-align: center; font-size: 12px; font-weight: 800; padding: 6px; border: 2px solid var(--ink); border-radius: 8px; background: #fff; opacity: .45; }
.stage-tabs span.on { opacity: 1; background: var(--yellow); }
.stage-tabs span.done { opacity: 1; background: var(--green); }
.stage-tabs span.fail { opacity: 1; background: #cfc9bd; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(21,19,15,.55); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal .sheet { background: var(--paper); width: 100%; max-width: 520px; border: 2px solid var(--ink); border-bottom: 0; border-radius: 20px 20px 0 0; padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); animation: up .2s ease; max-height: 88vh; overflow: auto; }
@keyframes up { from { transform: translateY(30px); opacity: 0 } }

#toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 700; opacity: 0; transition: .2s; pointer-events: none; z-index: 99; white-space: nowrap; }
#toast.show { opacity: 1; transform: translateX(-50%); }
footer.foot { text-align: center; color: var(--ink-2); font-size: 12px; margin-top: 34px; line-height: 1.7; }

.top-right { display: flex; align-items: center; gap: 10px; }
.toplink { font-weight: 800; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; }
.rank-block { padding: 12px 14px; border-left: 10px solid var(--c); }
.rank-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.rank-head b { font-size: 17px; }
.rank-head .tag { font-size: 11px; font-weight: 800; background: var(--ink); color: #fff; padding: 2px 7px; border-radius: 6px; }
.rank-block .lb li { padding: 7px 4px; font-size: 14px; }
.tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.tabs button { flex: 1; background: #fff; border: 2px solid var(--ink); color: var(--ink-2); border-radius: 10px; padding: 8px; font-size: 13px; font-weight: 800; cursor: pointer; }
.tabs button.on { color: var(--ink); background: var(--yellow); box-shadow: 2px 2px 0 var(--ink); }
