:root {
  --bg: #fff7dc;
  --panel: rgba(255, 255, 255, 0.78);
  --ink: #2f2a23;
  --muted: #766b5d;
  --green: #72c97a;
  --yellow: #f4c95d;
  --gray: #c8c2b7;
  --pink: #ff8fb3;
  --blue: #8cc7ff;
  --shadow: 0 22px 60px rgba(97, 67, 28, 0.16);
  font-family: ui-rounded, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; color: var(--ink);
  background: var(--stage-bg, radial-gradient(circle at 12% 12%, #fff 0 9rem, transparent 9.2rem), linear-gradient(135deg, #fff7dc, #ffe5ef 52%, #e8f5ff));
  overflow-x: hidden;
  transition: background .55s ease;
}
body::before {
  content: var(--stage-emoji, "🌱");
  position: fixed; right: clamp(10px, 5vw, 42px); top: clamp(10px, 5vw, 42px);
  font-size: clamp(3rem, 16vw, 9rem); opacity: .12; transform: rotate(10deg); pointer-events: none; z-index: -1;
}
.bg-orb { position: fixed; width: 18rem; height: 18rem; border-radius: 50%; filter: blur(10px); opacity: .45; pointer-events: none; }
.orb-a { background: #ffd166; left: -6rem; bottom: 5rem; }
.orb-b { background: #8ecae6; right: -6rem; top: 4rem; }
.app-shell { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: 32px 0; }
.panel { background: var(--panel); border: 2px solid rgba(255,255,255,.9); border-radius: 28px; box-shadow: var(--shadow); backdrop-filter: blur(16px); }
.hidden { display: none !important; }
.hero, .result { max-width: 720px; margin: 7vh auto 0; padding: 42px; text-align: center; }
.mascot { width: 86px; height: 86px; margin: 0 auto 12px; display: grid; place-items: center; border-radius: 28px; background: #fff3c4; font-size: 52px; transform: rotate(-5deg); }
.mascot.small { width: 62px; height: 62px; font-size: 38px; }
.eyebrow { margin: 0 0 6px; color: #d16b8f; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; font-size: .78rem; }
h1 { margin: 0; font-size: clamp(3rem, 9vw, 6rem); line-height: .92; }
h2, h3 { margin: 0; }
.hero-copy { margin: 18px auto 28px; color: var(--muted); font-size: 1.08rem; line-height: 1.7; max-width: 520px; }
.start-form { text-align: left; max-width: 520px; margin: 0 auto; }
label { display: block; margin: 0 0 8px 10px; font-weight: 800; }
.inline-input, .guess-form { display: flex; gap: 10px; }
input { width: 100%; border: 0; border-radius: 18px; padding: 16px 18px; font: inherit; font-weight: 800; background: #fff; color: var(--ink); outline: 3px solid transparent; }
input:focus { outline-color: rgba(255, 143, 179, .42); }
button { border: 0; border-radius: 18px; padding: 0 22px; font: inherit; font-weight: 900; color: #fff; background: linear-gradient(135deg, #ff7aaa, #ffb24d); cursor: pointer; box-shadow: 0 10px 20px rgba(255, 122, 170, .25); white-space: nowrap; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary { background: #fff; color: var(--ink); border: 2px solid #ffe0a5; box-shadow: none; }
button.ghost { background: #fff8; color: var(--muted); border: 2px dashed #ead8ba; box-shadow: none; padding: 10px 14px; }
.start-actions { display: flex; justify-content: center; margin: 14px 0 0; }
.start-actions button { min-height: 46px; padding: 0 18px; }
.start-leaderboard { margin-top: 16px; }
.mini-rules { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 26px; }
.mini-rules div { background: #fff8; border-radius: 18px; padding: 14px; }
.mini-rules strong { display: block; }
.mini-rules span { color: var(--muted); font-size: .9rem; }
.game { display: grid; grid-template-columns: 1fr; grid-template-areas: "top" "main"; gap: 18px; max-width: 820px; margin: 0 auto; }
.topbar { grid-area: top; padding: 22px 26px; display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.stats { display: flex; gap: 10px; }
.stats div { min-width: 86px; padding: 12px 14px; border-radius: 20px; text-align: center; background: #fff; }
.stats span { display: block; font-size: 1.8rem; font-weight: 1000; }
.stats small { color: var(--muted); font-weight: 800; }
.tower-wrap { grid-area: main; padding: 26px; }
.tower-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 18px; }
.stage-badge { padding: 10px 14px; border-radius: 999px; background: linear-gradient(135deg, rgba(255,255,255,.9), rgba(255,255,255,.55)); font-weight: 1000; color: #b94f75; box-shadow: inset 0 -3px rgba(0,0,0,.04); white-space: nowrap; }
.board { display: flex; flex-direction: column; gap: 8px; min-height: 260px; margin-bottom: 18px; }
.row { --label-w: 5.5rem; --cell-gap: 6px; --gaps-w: 42px; display: flex; gap: var(--cell-gap); flex-wrap: wrap; width: 100%; }
.tile { width: clamp(34px, 7vw, 52px); height: clamp(34px, 7vw, 52px); border-radius: 14px; display: grid; place-items: center; background: #fff; font-size: 1.35rem; font-weight: 1000; box-shadow: inset 0 -4px rgba(0,0,0,.05); transition: transform .12s ease, background .18s ease; }
.tile.pending { outline: 3px solid rgba(255, 143, 179, .32); transform: translateY(-1px); }
.tile.o { background: var(--green); color: #fff; }
.tile.c { background: var(--yellow); color: #fff; }
.tile.x { background: var(--gray); color: #fff; }
.word-label { min-width: var(--label-w); width: var(--label-w); align-self: center; font-weight: 1000; color: var(--muted); }
.keyboard { margin: 18px 0 14px; display: flex; flex-direction: column; gap: 7px; touch-action: manipulation; }
.key-row { display: flex; justify-content: center; gap: 6px; }
.key { min-width: 0; height: 44px; padding: 0; flex: 1 1 0; max-width: 54px; border-radius: 13px; background: #fff; color: var(--ink); box-shadow: inset 0 -4px rgba(0,0,0,.08), 0 6px 12px rgba(97,67,28,.08); border: 1px solid rgba(255,255,255,.8); font-size: 1.05rem; }
.key:active { transform: translateY(2px); box-shadow: inset 0 -2px rgba(0,0,0,.08); }
.key.wide { flex: 1.7 1 0; max-width: 86px; font-size: .9rem; }
.key.o { background: var(--green); color: #fff; }
.key.c { background: var(--yellow); color: #fff; }
.key.x { background: var(--gray); color: #fff; }
.message { min-height: 1.4em; color: var(--muted); font-weight: 800; }
.hint { color: var(--muted); line-height: 1.6; }
.share-card { padding: 24px; border-radius: 24px; background: linear-gradient(180deg, #fffaf0, #fff); border: 2px dashed #ffd597; }
.big-floor { margin: 12px 0; font-size: clamp(3rem, 14vw, 7rem); font-weight: 1000; color: #ff7aaa; text-shadow: 0 5px #ffe0ec; }
.result-tier { display: inline-block; margin: 0 0 8px; padding: 8px 14px; border-radius: 999px; background: #fff0f6; color: #b94f75; font-weight: 1000; }
.result-grid { display: flex; justify-content: center; flex-wrap: wrap; gap: 7px; margin-top: 18px; }
.badge { padding: 8px 12px; border-radius: 999px; background: #fff0f6; font-weight: 900; color: #b94f75; }
.actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; margin-top: 20px; }
.rank-card { margin: 16px auto 6px; padding: 16px; max-width: 460px; border-radius: 22px; background: linear-gradient(180deg, #fff, #fff7fb); border: 2px solid #ffe0ec; box-shadow: inset 0 -4px rgba(255,122,170,.08); }
.rank-head { display: flex; align-items: baseline; justify-content: center; gap: 10px; color: var(--muted); font-weight: 1000; }
.rank-head strong { color: #ff6fa5; font-size: clamp(2rem, 8vw, 3.2rem); line-height: 1; text-shadow: 0 4px #ffe0ec; }
.rank-track { height: 18px; margin: 12px 0 10px; border-radius: 999px; background: #f0e6da; overflow: hidden; box-shadow: inset 0 2px 6px rgba(0,0,0,.08); }
.rank-track span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #ffd166, #ff8fb3, #8cc7ff); animation: climbBar .9s cubic-bezier(.2,.8,.2,1) both; }
.rank-meta { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.rank-meta span { padding: 6px 10px; border-radius: 999px; background: #fff0f6; color: #b94f75; font-size: .82rem; font-weight: 900; }
.rank-card small { display: block; margin-top: 10px; color: var(--muted); font-size: .74rem; line-height: 1.45; }
.rank-notice { min-height: 1.2em; margin: 8px 0 0; color: #b94f75; font-weight: 1000; font-size: .9rem; }
.rank-notice.muted { color: var(--muted); }
@keyframes climbBar { from { width: 4%; filter: saturate(.5); } }
.tier-map { max-width: 560px; margin: 14px auto 0; padding: 14px; border-radius: 22px; background: rgba(255,255,255,.68); border: 2px dashed #ffd597; text-align: left; }
.tier-step { display: grid; grid-template-columns: 42px 1fr; gap: 10px; align-items: center; padding: 10px; border-radius: 16px; }
.tier-step.active { background: linear-gradient(135deg, #fff0f6, #fff7dc); outline: 2px solid rgba(255,143,179,.38); }
.tier-emoji { font-size: 1.8rem; }
.tier-step strong { display: block; font-size: .98rem; }
.tier-step small { display: block; color: var(--muted); line-height: 1.35; }
.leaderboard { max-width: 560px; margin: 16px auto 0; padding: 16px; border-radius: 24px; background: rgba(255,255,255,.76); border: 2px solid rgba(255,255,255,.9); text-align: left; }
.league-tabs { display: flex; justify-content: center; gap: 8px; margin-bottom: 10px; }
.league-tabs button { min-height: 38px; padding: 0 14px; border-radius: 999px; background: #fff; color: var(--muted); border: 2px solid #ffe0a5; box-shadow: none; font-size: .86rem; }
.league-tabs button.active { color: #fff; border-color: transparent; background: linear-gradient(135deg, #ff7aaa, #ffb24d); box-shadow: 0 8px 16px rgba(255,122,170,.18); }
.leader-callout { margin-bottom: 10px; padding: 12px 14px; border-radius: 18px; background: linear-gradient(135deg, #fff3c4, #fff0f6); text-align: center; font-weight: 1000; color: #b94f75; }
.leaderboard ol { list-style: none; padding: 0; margin: 0; display: grid; gap: 7px; }
.leaderboard li { display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; align-items: center; padding: 10px 12px; border-radius: 16px; background: #fff; }
.leaderboard li.current { outline: 2px solid rgba(255,143,179,.55); background: #fff7fb; }
.leaderboard li.podium { background: linear-gradient(135deg, #fff, #fff7dc); }
.leaderboard li.rank-1 { outline: 2px solid rgba(245,158,11,.45); box-shadow: inset 0 -4px rgba(245,158,11,.10); }
.leaderboard li.rank-2 { outline: 2px solid rgba(148,163,184,.45); }
.leaderboard li.rank-3 { outline: 2px solid rgba(180,83,9,.35); }
.leaderboard li span em { display: inline-block; margin-left: 6px; padding: 3px 7px; border-radius: 999px; background: #fff0f6; color: #b94f75; font-size: .68rem; font-style: normal; vertical-align: middle; }
.leaderboard li.rank-1 span em { background: #fff3c4; color: #a16207; }
.leaderboard li b { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: #ffeff6; color: #b94f75; }
.leaderboard li span { font-weight: 1000; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.leaderboard li strong { color: #ff6fa5; white-space: nowrap; }
.leaderboard li small { grid-column: 2 / 4; color: var(--muted); font-weight: 800; }
.leaderboard p { margin: 10px 4px 0; color: var(--muted); font-size: .78rem; line-height: 1.45; text-align: center; }
.adfit-slot { width: 100%; max-width: 360px; min-height: 124px; margin: 18px auto 0; padding: 10px 0 14px; display: grid; place-items: center; border-radius: 18px; background: rgba(255,255,255,.48); border: 1px dashed rgba(185,79,117,.22); overflow: hidden; }
.adfit-dock { position: fixed; left: 50%; bottom: max(10px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; margin: 0; background: rgba(255,255,255,.9); box-shadow: 0 12px 32px rgba(97,67,28,.16); backdrop-filter: blur(12px); }
.adfit-slot.ad-empty { display: none !important; }
body.adfit-visible .app-shell { padding-bottom: 154px; }
.ad-label { margin-bottom: 6px; color: var(--muted); font-size: .72rem; font-weight: 900; opacity: .72; }
@media (max-width: 820px) {
  body { overscroll-behavior: none; }
  .app-shell { width: min(100% - 20px, 720px); padding: 16px 0; }
  .hero, .result { padding: 28px 18px; margin-top: 2vh; }
  .adfit-slot { max-width: 340px; min-height: 120px; margin-top: 14px; }
  .adfit-dock { width: min(340px, calc(100% - 20px)); margin: 0; }
  .start-leaderboard { margin-top: 14px; }
  .mini-rules, .game { grid-template-columns: 1fr; }
  .game { grid-template-areas: "top" "main"; }
  .topbar, .inline-input, .guess-form { flex-direction: column; align-items: stretch; }
  .stats { width: 100%; }
  .stats div { flex: 1; min-width: 0; }
  button { min-height: 52px; }
  .guess-form { display: none; }
  .tower-wrap { padding: 18px 12px; }
  .board { min-height: 226px; }
  .key { height: 46px; border-radius: 12px; font-size: 1rem; }
  .key-row { gap: 4px; }
}
@media (min-width: 821px) {
  .guess-form { margin-bottom: 4px; }
}

/* Mobile portrait tuning: keep the board + touch keyboard usable above the fold. */
@media (max-width: 480px) {
  .app-shell { width: min(100% - 12px, 720px); padding: 8px 0; }
  .panel { border-radius: 22px; }
  .topbar { padding: 16px; gap: 10px; }
  .topbar h2 { font-size: clamp(1.45rem, 9vw, 2.15rem); line-height: 1.12; }
  .stats { gap: 6px; }
  .stats div { padding: 8px 6px; border-radius: 16px; }
  .stats span { font-size: 1.55rem; line-height: 1.05; }
  .stats small { font-size: .78rem; }
  .tower-wrap { padding: 14px 10px; }
  .tower-header { margin-bottom: 10px; align-items: flex-start; }
  .stage-badge { padding: 7px 9px; font-size: .78rem; }
  .tower-header h3 { font-size: clamp(1.25rem, 7vw, 1.75rem); }
  .board { min-height: 188px; gap: 5px; margin-bottom: 8px; }
  .row { --label-w: 34px; --cell-gap: 4px; --gaps-w: 28px; flex-wrap: nowrap; align-items: center; }
  .word-label { font-size: .86rem; line-height: 1; letter-spacing: -.04em; }
  .tile {
    width: clamp(36px, 10.7vw, 46px);
    height: clamp(36px, 10.7vw, 46px);
    border-radius: 12px;
    font-size: clamp(1.22rem, 6vw, 1.55rem);
  }
  .keyboard { margin: 8px 0 8px; gap: 5px; }
  .key-row { gap: 4px; }
  .key { height: 40px; border-radius: 11px; font-size: .95rem; }
  .key.wide { max-width: 96px; }
  .message { font-size: .95rem; line-height: 1.35; }
  .rank-card { padding: 13px 10px; }
  .rank-meta span { font-size: .76rem; }
  .leaderboard { padding: 12px; }
  .leaderboard li { grid-template-columns: 28px 1fr auto; padding: 9px; }
  .adfit-slot { max-width: 326px; min-height: 118px; }
  .adfit-dock { width: min(326px, calc(100% - 16px)); }
}

@media (max-width: 360px) {
  .row { --label-w: 30px; --cell-gap: 3px; --gaps-w: 21px; }
  .word-label { font-size: .76rem; }
  .tile {
    width: clamp(33px, 10.7vw, 41px);
    height: clamp(33px, 10.7vw, 41px);
    font-size: clamp(1.08rem, 5.6vw, 1.34rem);
  }
  .key { height: 38px; font-size: .9rem; }
}

/* Very small portrait phones, e.g. iPhone SE with browser chrome. */
@media (max-width: 480px) and (max-height: 700px) {
  .app-shell { padding: 6px 0; }
  .game { gap: 8px; }
  .topbar { padding: 12px; }
  .topbar h2 { font-size: clamp(1.25rem, 8vw, 1.65rem); }
  .eyebrow { font-size: .68rem; margin-bottom: 3px; }
  .stats div { padding: 6px 4px; border-radius: 14px; }
  .stats span { font-size: 1.3rem; }
  .stats small { font-size: .68rem; }
  .tower-wrap { padding: 10px 8px; }
  .tower-header { margin-bottom: 6px; }
  .stage-badge { padding: 5px 7px; font-size: .68rem; }
  .tower-header h3 { font-size: clamp(1.05rem, 6vw, 1.35rem); }
  .board { min-height: 150px; gap: 3px; margin-bottom: 5px; }
  .row { --label-w: 30px; --cell-gap: 3px; --gaps-w: 21px; }
  .word-label { font-size: .72rem; }
  .tile {
    width: clamp(32px, 9.8vw, 39px);
    height: clamp(32px, 9.8vw, 39px);
    border-radius: 9px;
    font-size: clamp(1.04rem, 5.4vw, 1.25rem);
  }
  .keyboard { margin: 5px 0; gap: 3px; }
  .key-row { gap: 3px; }
  .key { height: 32px; border-radius: 9px; font-size: .82rem; }
  .key.wide { max-width: 82px; min-height: 38px; }
  .message { font-size: .82rem; line-height: 1.25; min-height: 1.1em; }
  .rank-card small, .leaderboard p { font-size: .68rem; }
  .tier-map, .leaderboard { padding: 10px; }
  .tier-step { grid-template-columns: 34px 1fr; gap: 7px; padding: 8px; }
  .tier-emoji { font-size: 1.45rem; }
  .adfit-slot { margin-top: 10px; }
  body.adfit-visible .app-shell { padding-bottom: 136px; }
}

@media (max-width: 360px) and (max-height: 700px) {
  .topbar { padding: 10px; }
  .topbar h2 { font-size: clamp(1.12rem, 7.4vw, 1.45rem); }
  .stats span { font-size: 1.18rem; }
  .tower-wrap { padding: 8px; }
  .board { min-height: 126px; }
  .row { --label-w: 28px; --cell-gap: 2px; --gaps-w: 14px; }
  .tile {
    width: clamp(31px, 9.7vw, 37px);
    height: clamp(31px, 9.7vw, 37px);
  }
  .key { height: 30px; }
  .key.wide { min-height: 34px; }
}
