/* 고양이 타워 — 디자인 토큰
 * 방향성: 코지 레트로 일본 인디게임. 베이지+코랄+진브라운 팔레트.
 * 그라데이션/소프트 블러 최소화, 하드섀도우 + 뚜렷한 보더로 수제감. */
:root {
  --bg: #F5E9D4;
  --bg-soft: #FBF2E0;
  --card: #FFFBF1;
  --ink: #2E1F17;
  --ink-soft: #5A4535;
  --accent: #E85A4F;
  --accent-dark: #B73E35;
  --yellow: #F2B43A;
  --sage: #90A583;
  --line: #3A2920;
  --shadow: 0 3px 0 0 var(--line);
  --shadow-deep: 0 5px 0 0 var(--line);
  --radius: 14px;
  --radius-sm: 10px;
  --mobile-browser-bottom-gap: 24px;
  --screen-max-width: 420px;
  --screen-max-height: 900px;
  --menu-pad-y: 32px;
  --menu-pad-x: 24px;
  --menu-gap: 28px;
  --title-emoji-size: 72px;
  --title-size: 40px;
  --tagline-size: 15px;
  --best-pad-y: 16px;
  --best-pad-x: 28px;
  --best-min-width: 220px;
  --best-label-size: 12px;
  --best-value-size: 32px;
  --menu-btn-max-width: 280px;
  --btn-font-size: 17px;
  --btn-pad-y: 14px;
  --btn-pad-x: 20px;
  --modal-shell-pad: 24px;
  --modal-body-max-width: 360px;
  --modal-body-pad-y: 24px;
  --modal-body-pad-x: 20px;
  --modal-gap: 14px;
  --modal-title-size: 24px;
  --final-value-size: 48px;
  --rank-row-font-size: 14px;
  --field-max-width: 400px;
  --field-fit-width: var(--field-max-width);
  --ui-icons: image-set(url("assets/ui/ui-icons.webp") type("image/webp"), url("assets/ui/ui-icons.png") type("image/png"));
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
}
body {
  font-family: 'Pretendard Variable', Pretendard, -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  /* 은은한 점묘 패턴 — AI 그라데이션 느낌 제거, 종이 질감 */
  background-image:
    radial-gradient(rgba(58, 41, 32, 0.07) 1px, transparent 1.2px),
    radial-gradient(rgba(58, 41, 32, 0.05) 1px, transparent 1.2px);
  background-size: 22px 22px, 22px 22px;
  background-position: 0 0, 11px 11px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.rotate-lock {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  text-align: center;
  overflow: hidden;
  background-color: #F4DFBE;
  background-image:
    radial-gradient(rgba(58, 41, 32, 0.07) 1px, transparent 1.2px),
    radial-gradient(rgba(58, 41, 32, 0.05) 1px, transparent 1.2px),
    linear-gradient(180deg, rgba(255,255,255,0.52), rgba(242,180,58,0.16));
  background-size: 22px 22px, 22px 22px, auto;
  background-position: 0 0, 11px 11px, 0 0;
}

.rotate-lock::before {
  content: "";
  position: absolute;
  inset: -12vh -8vw;
  background:
    radial-gradient(circle at 28% 36%, rgba(255,255,255,0.62), transparent 16%),
    radial-gradient(circle at 76% 64%, rgba(242,180,58,0.22), transparent 18%);
  pointer-events: none;
}

.rotate-lock > * {
  position: relative;
}

.rotate-lock__mascot {
  width: clamp(58px, 13vh, 88px);
  height: clamp(58px, 13vh, 88px);
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 5px 0 rgba(58, 41, 32, 0.16));
}

.rotate-lock__mascot img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.rotate-lock__phone {
  width: clamp(70px, 18vh, 112px);
  height: clamp(70px, 18vh, 112px);
  display: grid;
  place-items: center;
}

.rotate-lock__phone::before {
  content: "";
  width: 42%;
  height: 66%;
  display: block;
  border: 4px solid var(--line);
  border-radius: 15px;
  background: rgba(255,251,241,0.88);
  box-shadow: 0 4px 0 0 var(--line), inset 0 2px 0 rgba(255,255,255,0.58);
  transform: rotate(-90deg);
  animation: phoneRotate 1.85s ease-in-out infinite;
}

.rotate-lock__phone span {
  position: absolute;
  width: 68%;
  height: 68%;
  border: 4px solid transparent;
  border-top-color: var(--accent);
  border-right-color: var(--accent);
  border-radius: 999px;
  transform: rotate(40deg);
}

.rotate-lock__phone span::after {
  content: "";
  position: absolute;
  right: -7px;
  top: 8px;
  width: 0;
  height: 0;
  border-left: 9px solid var(--accent);
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  transform: rotate(24deg);
}

.rotate-lock h2 {
  font-size: clamp(20px, 6vh, 30px);
  line-height: 1.12;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--ink);
}

.rotate-lock p {
  max-width: min(420px, 78vw);
  color: var(--ink-soft);
  font-size: clamp(13px, 3.2vh, 16px);
  line-height: 1.35;
  font-weight: 700;
  letter-spacing: 0;
}

@keyframes phoneRotate {
  0%, 20% { transform: rotate(-90deg); }
  55%, 78% { transform: rotate(0deg); }
  100% { transform: rotate(-90deg); }
}

/* ---------- 상단 전역 바 ---------- */
#topbar {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  z-index: 30;
}
#topbar > * { pointer-events: auto; }
/* 게임 중에는 숨김 (ArcherLab 링크/언어 토글) — 몰입도 우선 */
body:has(#game:not(.hidden)) #topbar { display: none; }
.topbar-btn {
  background: rgba(255, 251, 241, 0.92);
  color: var(--ink);
  border: 2px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-decoration: none;
  box-shadow: 0 2px 0 0 var(--line);
  transition: transform 0.08s, box-shadow 0.08s;
}
.topbar-btn:hover { transform: translateY(-1px); box-shadow: 0 3px 0 0 var(--line); }
.topbar-btn:active { transform: translateY(2px); box-shadow: none; }
.lang-switch {
  display: flex;
  gap: 0;
  background: rgba(255, 251, 241, 0.92);
  border: 2px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  box-shadow: 0 2px 0 0 var(--line);
  padding: 0;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.08s, box-shadow 0.08s;
}
.lang-switch:hover { transform: translateY(-1px); box-shadow: 0 3px 0 0 var(--line); }
.lang-switch:active { transform: translateY(2px); box-shadow: none; }
.lang-btn {
  display: inline-block;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  letter-spacing: 0;
  pointer-events: none;
}
.lang-btn.active {
  background: var(--accent);
  color: #FFF5EC;
}

.screen {
  width: 100%;
  max-width: var(--screen-max-width);
  height: 100%;
  max-height: var(--screen-max-height);
  display: flex;
  flex-direction: column;
}
.hidden { display: none !important; }

/* ---------- 메인 메뉴 ---------- */
#menu {
  padding: var(--menu-pad-y) var(--menu-pad-x);
  align-items: center;
  justify-content: space-evenly;
  gap: var(--menu-gap);
  text-align: center;
}

.title-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.title-emoji {
  width: var(--title-emoji-size);
  height: var(--title-emoji-size);
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 5px 0 rgba(58, 41, 32, 0.14));
  animation: bob 3.2s ease-in-out infinite;
}
.title-mascot {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}
.title-mascot img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50%      { transform: translateY(-6px) rotate(2deg); }
}
h1 {
  font-size: var(--title-size);
  font-weight: 800;
  letter-spacing: 0;
  color: var(--ink);
}
.tagline {
  color: var(--ink-soft);
  font-size: var(--tagline-size);
  letter-spacing: 0;
}

.best-card {
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  padding: var(--best-pad-y) var(--best-pad-x);
  box-shadow: var(--shadow-deep);
  min-width: var(--best-min-width);
}
.best-label {
  font-size: var(--best-label-size);
  font-weight: 700;
  letter-spacing: 0;
  color: var(--accent);
  margin-bottom: 4px;
}
.best-value {
  font-size: var(--best-value-size);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.menu-btns {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: var(--menu-btn-max-width);
}

.btn {
  font: inherit;
  font-weight: 700;
  font-size: var(--btn-font-size);
  letter-spacing: 0;
  padding: var(--btn-pad-y) var(--btn-pad-x);
  border-radius: var(--radius);
  cursor: pointer;
  border: 3px solid var(--line);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  box-shadow: var(--shadow);
}
.btn:not(:disabled):hover { transform: translate(-1px, -1px); box-shadow: 0 4px 0 0 var(--line); }
.btn:not(:disabled):active {
  transform: translate(0, 3px);
  box-shadow: 0 0 0 0 var(--line);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #FFF5EC; }
.btn-secondary { background: var(--card); color: var(--ink); }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: rgba(58, 41, 32, 0.25); box-shadow: none; }
.btn-ghost:not(:disabled):hover { color: var(--ink); border-color: var(--line); box-shadow: var(--shadow); }
.btn-with-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.ui-icon {
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  display: inline-block;
  background-image: var(--ui-icons);
  background-repeat: no-repeat;
  background-size: 144px 24px;
}
.ui-icon--home { background-position: 0 0; }
.ui-icon--sound-on { background-position: -24px 0; }
.ui-icon--sound-off { background-position: -48px 0; }
.ui-icon--rank { background-position: -72px 0; }
.ui-icon--replay { background-position: -96px 0; }
.ui-icon--paw { background-position: -120px 0; }

.credit {
  font-size: 11px;
  color: var(--ink-soft);
  opacity: 0.65;
  letter-spacing: 0;
}

/* ---------- 게임 화면 ---------- */
#game {
  --game-pad-top: 10px;
  --game-pad-x: 12px;
  --game-pad-bottom: 10px;
  --game-gap: 4px;
  --hud-pad-y: 10px;
  --hud-pad-x: 14px;
  --hud-border: 3px;
  --hud-gap: 10px;
  --icon-size: 42px;
  --next-cat-size: 46px;
  --stat-label-size: 10px;
  --stat-value-size: 24px;
  --chip-font-size: 10px;
  --chip-pad-y: 2px;
  --chip-pad-x: 7px;
  --next-name-font-size: 9px;
  --strip-gap: 5px;
  --strip-padding: 6px;
  --tier-icon-size: 18px;
  --tier-num-size: 9px;
  --tier-name-size: 8px;
  --tier-cell-gap: 3px;
  --tier-cell-pad-y: 3px;
  --tier-cell-pad-x: 4px;
  --game-hint-font-size: 12px;
  --game-hint-clearance: 8px;
  padding: var(--game-pad-top) var(--game-pad-x) calc(var(--game-pad-bottom) + env(safe-area-inset-bottom));
  gap: var(--game-gap);
  overflow: hidden;
  overscroll-behavior: contain;
}

.hud {
  display: flex;
  align-items: center;
  gap: var(--hud-gap);
  background: var(--card);
  border: var(--hud-border) solid var(--line);
  border-radius: var(--radius);
  padding: var(--hud-pad-y) var(--hud-pad-x);
  box-shadow: var(--shadow);
}
.stat { display: flex; flex-direction: column; }
.score-stat { flex: 1; }
.cat-name-chip {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  min-height: 18px;
  max-width: 148px;
  margin-top: 3px;
  padding: var(--chip-pad-y) var(--chip-pad-x);
  border: 1px solid rgba(58, 41, 32, 0.20);
  border-radius: 999px;
  background: rgba(251, 242, 224, 0.86);
  color: var(--ink-soft);
  font-size: var(--chip-font-size);
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stat-label {
  font-size: var(--stat-label-size);
  font-weight: 700;
  letter-spacing: 0;
  color: var(--accent);
}
.stat-value {
  font-size: var(--stat-value-size);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  line-height: 1.1;
}
.next-stat { align-items: center; }
.next-stat canvas {
  width: var(--next-cat-size);
  height: var(--next-cat-size);
  background: var(--bg-soft);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  margin-top: 2px;
}
.next-cat-name {
  width: 64px;
  min-height: 13px;
  margin-top: 2px;
  color: var(--ink-soft);
  font-size: var(--next-name-font-size);
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: var(--icon-size);
  height: var(--icon-size);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft);
  border: var(--hud-border) solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  letter-spacing: 0;
  color: var(--ink);
  font-weight: 700;
  font-size: 0;
  box-shadow: var(--shadow);
  transition: transform 0.08s, box-shadow 0.08s;
}
.icon-btn::before {
  content: "";
  width: 24px;
  height: 24px;
  display: block;
  background-image: var(--ui-icons);
  background-repeat: no-repeat;
  background-size: 144px 24px;
}
.icon-btn--home::before { background-position: 0 0; }
.icon-btn--sound::before { background-position: -24px 0; }
.icon-btn--sound.muted::before { background-position: -48px 0; }
.icon-btn:active { transform: translateY(3px); box-shadow: 0 0 0 0 var(--line); }
.icon-btn.muted { color: var(--ink-soft); background: rgba(58, 41, 32, 0.06); opacity: 0.75; }

.game-tier-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--strip-gap);
  width: 100%;
  max-width: var(--field-max-width);
  align-self: center;
  padding: var(--strip-padding);
  background: rgba(255, 251, 241, 0.88);
  border: 2px solid rgba(58, 41, 32, 0.28);
  border-radius: var(--radius-sm);
  box-shadow: 0 2px 0 rgba(58, 41, 32, 0.24);
  margin-bottom: 0;
}
.game-tier-cell {
  min-width: 0;
  display: grid;
  grid-template-columns: var(--tier-icon-size) 1fr;
  align-items: center;
  gap: var(--tier-cell-gap);
  padding: var(--tier-cell-pad-y) var(--tier-cell-pad-x);
  border: 1px solid rgba(58, 41, 32, 0.14);
  border-radius: 8px;
  background: var(--bg-soft);
}
.game-tier-cell canvas {
  width: var(--tier-icon-size);
  height: var(--tier-icon-size);
}
.game-tier-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1;
}
.game-tier-num {
  color: var(--accent);
  font-size: var(--tier-num-size);
  font-weight: 900;
}
.game-tier-name {
  color: var(--ink-soft);
  font-size: var(--tier-name-size);
  font-weight: 800;
  line-height: 1.05;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.field-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
#canvas {
  width: min(100%, var(--field-max-width), var(--field-fit-width));
  height: auto;
  aspect-ratio: 400 / 540;
  background: var(--bg-soft);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-deep);
  display: block;
  margin: 0 auto;
  touch-action: none;
  cursor: grab;
}
#canvas:active { cursor: grabbing; }

.game-hint {
  position: relative;
  z-index: 1;
  min-height: calc(var(--game-hint-font-size) * 1.3);
  margin-top: var(--game-hint-clearance);
  text-align: center;
  font-size: var(--game-hint-font-size);
  line-height: 1.3;
  font-weight: 700;
  color: var(--ink-soft);
  opacity: 0.86;
  letter-spacing: 0;
}

.combo-flash {
  position: fixed;
  top: 32%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: var(--yellow);
  color: var(--ink);
  font-weight: 800;
  font-size: 26px;
  padding: 8px 18px;
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-deep);
  pointer-events: none;
  opacity: 0;
  z-index: 20;
}
.combo-flash.pop {
  animation: comboPop 0.8s cubic-bezier(0.2, 0.9, 0.3, 1.15) forwards;
}
.combo-flash.legend {
  background: linear-gradient(135deg, #F2B43A 0%, #FFD46E 50%, #F2B43A 100%);
  font-size: 30px;
  padding: 12px 26px;
  box-shadow: 0 5px 0 0 var(--line), 0 0 24px rgba(242, 180, 58, 0.65);
}
.combo-flash.legend.pop {
  animation: legendPop 1.8s cubic-bezier(0.2, 0.9, 0.3, 1.15) forwards;
}
@keyframes comboPop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.6) rotate(-5deg); }
  20%  { opacity: 1; transform: translate(-50%, -50%) scale(1.1) rotate(3deg); }
  60%  { opacity: 1; transform: translate(-50%, -60%) scale(1) rotate(-1deg); }
  100% { opacity: 0; transform: translate(-50%, -85%) scale(0.95) rotate(0); }
}
@keyframes legendPop {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.5) rotate(-8deg); }
  15%  { opacity: 1; transform: translate(-50%, -50%) scale(1.25) rotate(4deg); }
  30%  { opacity: 1; transform: translate(-50%, -50%) scale(1.05) rotate(-2deg); }
  70%  { opacity: 1; transform: translate(-50%, -55%) scale(1.05) rotate(1deg); }
  100% { opacity: 0; transform: translate(-50%, -80%) scale(1) rotate(0); }
}

/* ---------- 모달 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(46, 31, 23, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: var(--modal-shell-pad);
  animation: fadeIn 0.18s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-body {
  width: 100%;
  max-width: var(--modal-body-max-width);
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-deep);
  padding: var(--modal-body-pad-y) var(--modal-body-pad-x) calc(var(--modal-body-pad-y) - 4px);
  display: flex;
  flex-direction: column;
  gap: var(--modal-gap);
  text-align: center;
  animation: slideUp 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
@keyframes slideUp {
  from { transform: translateY(16px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
.modal-body h2 { font-size: var(--modal-title-size); font-weight: 800; letter-spacing: 0; }
.modal-body h3 { font-size: 14px; font-weight: 700; color: var(--accent); letter-spacing: 0; margin-top: 4px; }

.gameover-body {
  align-items: center;
}
.gameover-visual {
  width: min(176px, 58vw);
  aspect-ratio: 256 / 160;
  margin: -10px auto -4px;
  background: image-set(url("assets/ui/gameover-cats.webp") type("image/webp"), url("assets/ui/gameover-cats.png") type("image/png")) center / contain no-repeat;
  filter: drop-shadow(0 5px 0 rgba(58, 41, 32, 0.16));
}
.final-block { padding: 8px 0; }
.final-label {
  font-size: 11px;
  letter-spacing: 0;
  color: var(--accent);
  font-weight: 700;
}
.final-value {
  font-size: var(--final-value-size);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  line-height: 1.1;
}
.new-record {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  background: var(--yellow);
  color: var(--ink);
  font-weight: 800;
  padding: 4px 14px 4px 8px;
  border-radius: 999px;
  border: 2px solid var(--line);
  box-shadow: 0 3px 0 0 var(--line), inset 0 1px 0 rgba(255,255,255,0.34);
}
.new-record__medal {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  margin: -8px 0 -7px -3px;
  background: image-set(url("assets/ui/new-record-medal.webp") type("image/webp"), url("assets/ui/new-record-medal.png") type("image/png")) center / contain no-repeat;
}

.how-body { max-width: 420px; max-height: 90vh; overflow-y: auto; }
.how-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  padding: 0 4px;
}
.how-list li {
  padding-left: 22px;
  position: relative;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink-soft);
}
.how-list li::before {
  content: '🐾';
  position: absolute;
  left: 0;
  top: 1px;
  font-size: 12px;
}

/* ---------- 랭킹 모달 ---------- */
.rank-body {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  max-width: 410px;
  max-height: calc(100vh - 48px);
  padding: 28px 22px 20px;
  background-color: #FFF7E9;
  background-image:
    linear-gradient(180deg, rgba(255, 251, 241, 0.36), rgba(255, 247, 233, 0.72)),
    url("assets/ui/rank-popup-frame.webp");
  background-size: cover;
  background-position: center;
  border-color: var(--line);
  box-shadow:
    0 6px 0 0 var(--line),
    0 16px 28px rgba(58, 41, 32, 0.24),
    inset 0 1px 0 rgba(255,255,255,0.65);
}
.rank-body > * {
  position: relative;
  z-index: 1;
}
.rank-body::before {
  content: "";
  position: absolute;
  z-index: 0;
  inset: 82px 19px 72px;
  border: 2px solid rgba(58, 41, 32, 0.16);
  border-radius: 12px;
  background: rgba(255, 251, 241, 0.58);
  box-shadow:
    inset 0 2px 0 rgba(255,255,255,0.58),
    inset 0 -8px 18px rgba(232, 90, 79, 0.06);
  pointer-events: none;
}
.rank-content {
  min-height: 240px;
  max-height: 60vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px 8px;
  border: 2px solid rgba(58, 41, 32, 0.12);
  border-radius: 12px;
  background: rgba(255, 251, 241, 0.66);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.65);
  scrollbar-width: thin;
  scrollbar-color: rgba(58, 41, 32, 0.28) transparent;
}
.rank-loading, .rank-empty, .rank-error {
  display: grid;
  min-height: 168px;
  place-items: center;
  padding: 28px 12px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.45;
}
.rank-error { color: var(--accent-dark); }
.rank-title {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  gap: 9px;
  min-height: 42px;
  padding: 7px 18px 8px;
  border: 2px solid rgba(58, 41, 32, 0.2);
  border-radius: 999px;
  background: rgba(255, 244, 214, 0.82);
  box-shadow:
    0 3px 0 rgba(58, 41, 32, 0.16),
    inset 0 1px 0 rgba(255,255,255,0.72);
}
.rank-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 8px 12px 8px 8px;
  background: rgba(255, 251, 241, 0.88);
  border: 2px solid rgba(58, 41, 32, 0.11);
  border-radius: 12px;
  font-size: var(--rank-row-font-size);
  box-shadow:
    0 2px 0 rgba(58, 41, 32, 0.11),
    inset 0 1px 0 rgba(255,255,255,0.65);
}
.rank-row.top1 { background: rgba(255, 244, 214, 0.95); border-color: var(--yellow); }
.rank-row.top2 { background: rgba(242, 245, 241, 0.95); border-color: #A9B7A2; }
.rank-row.top3 { background: rgba(251, 226, 213, 0.95); border-color: #D78A52; }
.rank-row.me { border-color: var(--accent); background: rgba(255, 240, 236, 0.96); }
.rank-pos {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 28px;
  margin-inline: auto;
  border: 2px solid rgba(58, 41, 32, 0.18);
  border-radius: 999px;
  background: rgba(245, 233, 212, 0.82);
  font-weight: 800;
  font-size: 16px;
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.55);
}
.rank-row.top1 .rank-pos {
  width: 36px;
  background: var(--yellow);
  border-color: var(--line);
  box-shadow: 0 2px 0 rgba(58, 41, 32, 0.2), inset 0 1px 0 rgba(255,255,255,0.42);
}
.rank-row.top2 .rank-pos { background: #DDE7D8; }
.rank-row.top3 .rank-pos { background: #F1C0A4; }
.rank-row.me .rank-pos { background: #FFD8D2; border-color: var(--accent); }
.rank-row.top1 .rank-name,
.rank-row.top1 .rank-score {
  color: #3B2517;
}
.rank-name {
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}
.rank-score {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: var(--ink);
  padding-left: 8px;
}

/* ---------- 랭킹 제출 (게임오버) ---------- */
.rank-submit-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 0 4px;
  border-top: 1px dashed rgba(58, 41, 32, 0.15);
  border-bottom: 1px dashed rgba(58, 41, 32, 0.15);
  margin: 4px 0;
}
.rank-submit-row input {
  font: inherit;
  font-size: 15px;
  padding: 10px 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--ink);
  text-align: center;
  font-weight: 700;
  letter-spacing: 0;
}
.rank-submit-row input:focus {
  outline: none;
  border-color: var(--accent);
}
.rank-submit-buttons {
  display: flex;
  gap: 8px;
}
.rank-submit-buttons .btn { flex: 1; padding: 10px 14px; font-size: 14px; }
.rank-submit-buttons .btn-ghost { flex: 0 0 72px; }
.submit-status {
  min-height: 18px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}
.submit-status.ok { color: var(--sage); }
.submit-status.fail { color: var(--accent-dark); }
.rank-submit-progress {
  position: relative;
  height: 8px;
  overflow: hidden;
  border: 1px solid rgba(114, 72, 37, 0.22);
  border-radius: 999px;
  background: rgba(255, 250, 226, 0.78);
  box-shadow: inset 0 0 14px rgba(89, 47, 25, 0.12);
}
.rank-submit-progress span {
  position: absolute;
  inset: -1px auto -1px 0;
  width: 42%;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, var(--accent) 28%, var(--gold) 72%, transparent);
  filter: drop-shadow(0 0 8px rgba(196, 117, 42, 0.5));
  animation: rankSubmitBar 0.92s ease-in-out infinite;
}
.rank-submit-row.is-submitting input {
  opacity: 0.68;
}
@keyframes rankSubmitBar {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(260%);
  }
}

.tier-preview {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  padding: 4px 0;
}
.tier-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px;
  background: var(--bg-soft);
  border: 2px solid rgba(58, 41, 32, 0.12);
  border-radius: var(--radius-sm);
}
.tier-cell canvas { width: 44px; height: 44px; }
.tier-name { font-size: 10px; color: var(--ink-soft); text-align: center; line-height: 1.2; }

/* ---------- 반응형 ---------- */
@media (max-width: 380px) {
  :root {
    --menu-pad-y: 24px;
    --menu-pad-x: 18px;
    --menu-gap: 22px;
    --title-emoji-size: 60px;
    --title-size: 34px;
    --tagline-size: 14px;
    --best-pad-y: 14px;
    --best-pad-x: 22px;
    --best-min-width: 200px;
    --best-value-size: 30px;
    --menu-btn-max-width: 260px;
    --btn-font-size: 16px;
    --btn-pad-y: 12px;
    --btn-pad-x: 18px;
    --modal-shell-pad: 16px;
    --modal-body-pad-y: 20px;
    --modal-body-pad-x: 16px;
    --modal-gap: 12px;
    --modal-title-size: 22px;
    --final-value-size: 42px;
    --rank-row-font-size: 13px;
  }
  #game {
    --game-pad-x: 8px;
    --stat-value-size: 20px;
    --strip-gap: 3px;
    --strip-padding: 5px;
    --tier-icon-size: 16px;
    --tier-num-size: 8px;
    --tier-name-size: 7px;
    --tier-cell-gap: 2px;
    --tier-cell-pad-y: 2px;
    --tier-cell-pad-x: 3px;
  }
  .tier-preview { grid-template-columns: repeat(3, 1fr); }
  .tier-cell canvas { width: 40px; height: 40px; }
}

@media (orientation: portrait) and (max-width: 720px) {
  #game {
    padding-bottom: calc(var(--mobile-browser-bottom-gap) + env(safe-area-inset-bottom));
  }
}

@media (orientation: portrait) and (max-height: 700px) {
  :root {
    --menu-pad-y: 22px;
    --menu-gap: 20px;
    --title-emoji-size: 58px;
    --title-size: 34px;
    --best-pad-y: 12px;
    --best-value-size: 28px;
    --btn-font-size: 15px;
    --btn-pad-y: 11px;
    --modal-shell-pad: 14px;
    --modal-body-pad-y: 18px;
    --modal-gap: 10px;
    --final-value-size: 40px;
  }
  #game {
    --game-pad-top: 6px;
    --game-gap: 3px;
    --hud-pad-y: 6px;
    --hud-pad-x: 12px;
    --hud-border: 2px;
    --hud-gap: 8px;
    --icon-size: 36px;
    --next-cat-size: 36px;
    --stat-label-size: 9px;
    --stat-value-size: 21px;
    --chip-font-size: 9px;
    --chip-pad-y: 1px;
    --chip-pad-x: 6px;
    --next-name-font-size: 8px;
    --strip-gap: 2px;
    --strip-padding: 4px;
    --tier-icon-size: 14px;
    --tier-num-size: 7px;
    --tier-name-size: 6.5px;
    --tier-cell-gap: 2px;
    --tier-cell-pad-y: 1px;
    --tier-cell-pad-x: 3px;
    --game-hint-font-size: 11px;
  }
  .cat-name-chip {
    min-height: 15px;
    margin-top: 1px;
  }
  .next-stat canvas { margin-top: 1px; }
  .next-cat-name {
    min-height: 11px;
    margin-top: 1px;
  }
  .icon-btn { box-shadow: 0 2px 0 0 var(--line); }
  .game-tier-text { gap: 0; }
}

@media (orientation: portrait) and (max-height: 600px) {
  :root {
    --menu-pad-y: 18px;
    --menu-gap: 16px;
    --title-emoji-size: 52px;
    --title-size: 30px;
    --tagline-size: 13px;
    --best-min-width: 190px;
    --best-value-size: 26px;
    --btn-font-size: 14px;
    --btn-pad-y: 10px;
    --modal-body-pad-y: 16px;
    --modal-title-size: 20px;
    --final-value-size: 36px;
  }
  #game {
    --game-pad-top: 4px;
    --game-pad-x: 8px;
    --game-gap: 2px;
    --hud-pad-y: 4px;
    --hud-pad-x: 10px;
    --hud-gap: 7px;
    --icon-size: 32px;
    --next-cat-size: 32px;
    --stat-label-size: 8px;
    --stat-value-size: 20px;
    --chip-font-size: 8px;
    --next-name-font-size: 7.5px;
    --strip-padding: 3px;
    --tier-icon-size: 13px;
    --tier-num-size: 6.5px;
    --tier-name-size: 6px;
    --game-hint-font-size: 10px;
  }
  .cat-name-chip { max-width: 126px; }
}

@media (orientation: portrait) and (min-width: 390px) and (min-height: 820px) {
  :root {
    --screen-max-width: 430px;
    --screen-max-height: 940px;
    --menu-pad-y: 40px;
    --menu-gap: 32px;
    --title-emoji-size: 84px;
    --title-size: 44px;
    --tagline-size: 16px;
    --best-pad-y: 18px;
    --best-pad-x: 30px;
    --best-value-size: 34px;
    --menu-btn-max-width: 300px;
    --btn-font-size: 18px;
    --modal-body-max-width: 380px;
  }
  #game {
    --game-pad-top: 12px;
    --game-pad-x: 15px;
    --hud-pad-y: 11px;
    --hud-pad-x: 15px;
    --icon-size: 44px;
    --next-cat-size: 50px;
    --stat-value-size: 26px;
    --chip-font-size: 11px;
    --next-name-font-size: 10px;
    --strip-gap: 6px;
    --strip-padding: 7px;
    --tier-icon-size: 20px;
    --tier-num-size: 10px;
    --tier-name-size: 9px;
    --tier-cell-pad-y: 4px;
  }
}

@media (min-width: 720px) {
  /* 태블릿/PC — 세로 게임 영역 유지, 좌우 여백 */
  :root {
    --screen-max-width: 460px;
    --screen-max-height: 920px;
    --menu-pad-y: 48px;
    --menu-pad-x: 32px;
    --menu-gap: 32px;
    --title-emoji-size: 96px;
    --title-size: 48px;
    --tagline-size: 16px;
    --best-pad-y: 18px;
    --best-pad-x: 32px;
    --best-value-size: 36px;
    --menu-btn-max-width: 300px;
    --btn-font-size: 18px;
    --modal-body-max-width: 400px;
    --modal-title-size: 26px;
    --final-value-size: 52px;
  }
}

/* 가로모드에서 경고 (세로 전용 게임) */
@media (orientation: landscape) and (max-height: 500px) {
  #app::before {
    content: '📱 세로 모드에서 플레이해 주세요';
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    color: var(--ink);
    font-weight: 700;
    font-size: 16px;
    z-index: 1000;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  #app {
    display: none;
  }

  .rotate-lock {
    display: grid;
    grid-template-rows: auto auto auto auto;
    justify-items: center;
    align-content: center;
    gap: clamp(6px, 2.2vh, 12px);
  }
}

/* ---------- Raster UI Skin ---------- */
:root {
  --ink: #2A1A10;
  --ink-soft: #6A4328;
  --line: #4A2B16;
  --shadow: 0 3px 0 0 #2D1A0E;
  --shadow-deep: 0 6px 0 0 #2D1A0E;
  --ui-wood: url("assets/ui/wood-texture.webp");
  --ui-paper: url("../cat-tower/assets/ui/paper-texture.webp");
  --ui-cushion: url("assets/ui/cushion-field.webp");
}

body {
  background-color: #F4DFBE;
  background-image:
    radial-gradient(rgba(58, 41, 32, 0.07) 1px, transparent 1.2px),
    radial-gradient(rgba(58, 41, 32, 0.05) 1px, transparent 1.2px),
    linear-gradient(180deg, rgba(255, 247, 230, 0.86), rgba(238, 201, 154, 0.38)),
    var(--ui-paper);
  background-size: 22px 22px, 22px 22px, 100% 100%, 420px 420px;
  background-position: 0 0, 11px 11px, 0 0, center;
  background-blend-mode: normal, normal, normal, multiply;
}

.topbar-btn,
.lang-switch,
.best-card,
.btn-secondary,
.modal-body,
.rank-submit-row input,
.tier-cell,
.cat-name-chip,
.next-stat canvas,
.icon-btn,
.game-tier-cell {
  background-color: var(--card);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.22), rgba(196, 117, 42, 0.07)), var(--ui-paper);
  background-size: auto, 280px 280px;
}

.hud,
.game-tier-strip {
  background-color: #BF741F;
  background-image: linear-gradient(180deg, rgba(255, 233, 165, 0.30), rgba(78, 38, 13, 0.14)), var(--ui-wood);
  background-size: auto, cover;
  border-color: var(--line);
  box-shadow: 0 6px 0 0 #2D1A0E, inset 0 2px 0 rgba(255, 236, 173, 0.52), inset 0 -3px 0 rgba(83, 39, 15, 0.20);
}

.hud {
  border-width: calc(var(--hud-border) + 1px);
  border-radius: 22px;
}

.score-stat {
  min-width: 0;
  padding: 3px 10px;
  border-radius: 14px;
  background: rgba(255, 248, 223, 0.27);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.35), inset 0 -2px 0 rgba(75, 36, 15, 0.12);
}

.stat-label {
  color: #FFF1C9;
  text-shadow: 0 2px 0 rgba(70, 34, 13, 0.48);
}

.stat-value {
  color: #FFF8DE;
  text-shadow: 0 3px 0 rgba(63, 31, 13, 0.56);
}

.next-cat-name {
  color: #FFF0C6;
  text-shadow: 0 2px 0 rgba(70, 34, 13, 0.45);
}

.best-card,
.btn,
.modal-body,
.icon-btn,
.game-tier-strip,
#canvas {
  border-color: var(--line);
}

.best-card,
.modal-body {
  border-width: 4px;
  border-radius: 18px;
  box-shadow: 0 6px 0 0 #2D1A0E, inset 0 1px 0 rgba(255,255,255,0.38);
}

.rank-body {
  background-color: #FFF7E9;
  background-image:
    linear-gradient(180deg, rgba(255, 251, 241, 0.36), rgba(255, 247, 233, 0.72)),
    url("assets/ui/rank-popup-frame.webp");
  background-size: cover;
  background-position: center;
  box-shadow:
    0 6px 0 0 #2D1A0E,
    0 16px 28px rgba(58, 41, 32, 0.24),
    inset 0 1px 0 rgba(255,255,255,0.65);
}

.btn {
  border-width: 4px;
  border-radius: 16px;
}

.btn-primary {
  background-color: var(--accent);
  background-image: linear-gradient(180deg, rgba(255,255,255,0.24), rgba(133,38,20,0.20)), var(--ui-wood);
  background-size: auto, 360px 360px;
  color: #FFF5EC;
  text-shadow: 0 2px 0 rgba(68, 35, 18, 0.42);
}

.icon-btn,
.next-stat canvas {
  border-width: calc(var(--hud-border) + 1px);
  border-radius: 16px;
}

.game-tier-strip {
  border-width: 3px;
  border-radius: 16px;
}

.game-tier-cell {
  border-color: rgba(74, 43, 22, 0.24);
  border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.42);
}

#canvas {
  background-color: #DCECE7;
  background-image:
    linear-gradient(180deg, rgba(238, 250, 246, 0.78), rgba(180, 211, 205, 0.70)),
    var(--ui-cushion);
  background-size: auto, cover;
  background-blend-mode: normal, luminosity;
  border-width: 5px;
  border-radius: 24px;
  box-shadow: 0 8px 0 0 #2D1A0E, 0 0 0 4px rgba(255, 226, 171, 0.42), inset 0 2px 0 rgba(255,255,255,0.35);
}

.combo-flash {
  background-color: var(--yellow);
  background-image: linear-gradient(180deg, rgba(255,255,255,0.28), rgba(139,82,13,0.12)), var(--ui-paper);
  background-size: auto, 220px 220px;
}

#game.danger #canvas {
  animation: dangerCanvasPulse 0.95s ease-in-out infinite;
}

#game.danger .game-hint {
  color: var(--accent-dark);
  opacity: 0.95;
}

@keyframes dangerCanvasPulse {
  0%, 100% {
    box-shadow: 0 8px 0 0 #2D1A0E, 0 0 0 4px rgba(255, 226, 171, 0.42), 0 0 0 0 rgba(232, 90, 79, 0), inset 0 2px 0 rgba(255,255,255,0.35);
  }
  50% {
    box-shadow: 0 8px 0 0 #2D1A0E, 0 0 0 4px rgba(255, 226, 171, 0.42), 0 0 0 7px rgba(232, 90, 79, 0.22), inset 0 2px 0 rgba(255,255,255,0.35);
  }
}

@media (orientation: portrait) and (max-width: 720px) {
  #game {
    --strip-gap: 0;
    --strip-padding: 0;
    --tier-icon-size: clamp(25px, 7.1vw, 31px);
  }

  .game-tier-strip {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--strip-gap);
    min-height: 50px;
    padding: 5px 10px;
    overflow: visible;
    border-width: 3px;
    border-radius: 999px 18px 18px 999px;
    background-color: #FFF4D8;
    background-image: linear-gradient(180deg, rgba(255,255,255,0.38), rgba(224, 149, 62, 0.12)), var(--ui-paper);
    background-size: auto, 280px 280px;
    box-shadow: 0 4px 0 0 #2D1A0E, inset 0 2px 0 rgba(255,255,255,0.46);
  }

  .game-tier-strip::before {
    content: "";
    position: absolute;
    left: 14px;
    right: 49px;
    bottom: 8px;
    height: 5px;
    border-radius: 999px;
    background: rgba(232, 90, 79, 0.58);
    box-shadow: 0 1px 0 rgba(255,255,255,0.55);
  }

  .game-tier-cell {
    position: relative;
    z-index: 1;
    flex: 0 0 clamp(28px, 7.7vw, 33px);
    min-width: 0;
    width: clamp(28px, 7.7vw, 33px);
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    background-image: none;
    box-shadow: none;
  }

  .game-tier-cell canvas {
    width: var(--tier-icon-size);
    height: var(--tier-icon-size);
    filter: drop-shadow(0 2px 0 rgba(74, 43, 22, 0.18));
  }

  .game-tier-cell:last-child {
    flex-basis: clamp(38px, 10.2vw, 44px);
    width: clamp(38px, 10.2vw, 44px);
    height: clamp(38px, 10.2vw, 44px);
    margin-left: 2px;
    border: 3px solid var(--line);
    background: rgba(255, 248, 223, 0.78);
    box-shadow: 0 3px 0 0 #2D1A0E, inset 0 1px 0 rgba(255,255,255,0.6);
  }

  .game-tier-cell:last-child canvas {
    width: clamp(34px, 9vw, 40px);
    height: clamp(34px, 9vw, 40px);
  }

  .game-tier-text {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    overflow: hidden;
    white-space: nowrap;
  }
}

@media (orientation: portrait) and (max-width: 720px) and (max-height: 620px) {
  .game-tier-strip {
    min-height: 42px;
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .game-tier-cell {
    flex-basis: 27px;
    width: 27px;
    height: 30px;
  }

  .game-tier-cell canvas {
    width: 24px;
    height: 24px;
  }

  .game-tier-cell:last-child {
    flex-basis: 36px;
    width: 36px;
    height: 36px;
  }

  .game-tier-cell:last-child canvas {
    width: 32px;
    height: 32px;
  }
}

/* ---------- Concept menu: cozy cat room ---------- */
#menu {
  position: relative;
  isolation: isolate;
  width: 100%;
  max-width: 1180px;
  height: 100%;
  max-height: none;
  padding:
    max(54px, calc(env(safe-area-inset-top) + 46px))
    max(12px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(118px, 0.72fr) auto auto;
  grid-template-areas:
    "visual"
    "panel"
    "credit";
  align-content: center;
  align-items: center;
  justify-items: center;
  gap: clamp(7px, 1.4dvh, 14px);
  text-align: center;
}

#menu::before,
#menu::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
}

#menu::before {
  z-index: 0;
  background-color: #F1C982;
  background-image: url("assets/ui/menu-room-bg-v2.png");
  background-image: image-set(
    url("assets/ui/menu-room-bg-v2.webp") type("image/webp"),
    url("assets/ui/menu-room-bg-v2.png") type("image/png")
  );
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}

#menu::after {
  z-index: 1;
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 250, 226, 0.14), transparent 38%),
    linear-gradient(180deg, rgba(76, 39, 16, 0.05), rgba(76, 39, 16, 0.14));
}

#menu > * {
  position: relative;
  z-index: 2;
}

.menu-visual {
  grid-area: visual;
  width: min(100%, 330px);
  height: min(25dvh, 196px);
  min-height: 118px;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: clamp(5px, 2vw, 18px);
  filter: drop-shadow(0 14px 18px rgba(69, 37, 18, 0.22));
}

#menu .title-emoji {
  flex: 0 0 auto;
  width: clamp(112px, 34vw, 164px);
  height: clamp(112px, 34vw, 164px);
  filter: drop-shadow(0 8px 0 rgba(74, 39, 18, 0.15));
  transform-origin: 50% 92%;
  animation: menuMascotFloat 3.4s ease-in-out infinite;
}

#menu .title-mascot {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.evolution-tower {
  position: relative;
  flex: 0 0 clamp(88px, 25vw, 118px);
  height: clamp(112px, 31vw, 154px);
  padding-top: 18px;
}

.evolution-tower__label {
  position: absolute;
  top: 0;
  left: 50%;
  translate: -50% 0;
  width: max-content;
  max-width: 116px;
  padding: 4px 8px;
  border: 2px solid rgba(74, 43, 22, 0.72);
  border-radius: 999px;
  background: rgba(255, 249, 231, 0.9);
  color: var(--ink);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.04em;
  box-shadow: 0 3px 0 rgba(45, 26, 14, 0.65);
}

.evolution-tower__stack {
  position: absolute;
  inset: 20px 0 0;
}

.evolution-cat {
  position: absolute;
  left: 50%;
  display: block;
  transform: translateX(-50%);
  filter: drop-shadow(0 4px 3px rgba(65, 34, 17, 0.22));
}

.evolution-cat img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.evolution-cat--kitten { bottom: 72%; width: 30%; height: 30%; }
.evolution-cat--cheese { bottom: 49%; width: 39%; height: 39%; }
.evolution-cat--mackerel { bottom: 24%; width: 50%; height: 50%; }
.evolution-cat--savannah { bottom: -2%; width: 65%; height: 65%; }

.menu-panel {
  grid-area: panel;
  width: min(100%, 366px);
  display: grid;
  gap: clamp(8px, 1.35dvh, 13px);
  padding: clamp(13px, 2.2dvh, 20px);
  border: 3px solid var(--line);
  border-radius: 24px;
  background-color: rgba(255, 249, 233, 0.9);
  background-image:
    linear-gradient(180deg, rgba(255,255,255,0.34), rgba(205,134,54,0.06)),
    var(--ui-paper);
  background-size: auto, 320px 320px;
  box-shadow:
    0 8px 0 #2D1A0E,
    0 22px 44px rgba(68, 35, 16, 0.2),
    inset 0 1px 0 rgba(255,255,255,0.64);
  backdrop-filter: blur(10px) saturate(1.04);
  -webkit-backdrop-filter: blur(10px) saturate(1.04);
}

#menu .title-wrap {
  display: grid;
  justify-items: center;
  gap: 3px;
}

.menu-kicker {
  margin: 0;
  color: var(--accent-dark);
  font-size: clamp(9px, 2.5vw, 11px);
  line-height: 1;
  font-weight: 900;
  letter-spacing: 0.14em;
}

#menu h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(31px, 9vw, 44px);
  line-height: 1;
  letter-spacing: -0.045em;
  text-wrap: balance;
  text-shadow: 0 2px 0 rgba(255,255,255,0.76);
}

#menu .tagline {
  color: var(--ink-soft);
  font-size: clamp(11px, 3.4vw, 14px);
  line-height: 1.3;
  font-weight: 750;
}

#menu .best-card {
  width: 100%;
  min-width: 0;
  min-height: 50px;
  padding: 7px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-width: 3px;
  border-radius: 15px;
  box-shadow: 0 4px 0 #2D1A0E, inset 0 1px 0 rgba(255,255,255,0.54);
}

#menu .best-label {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.04em;
}

#menu .best-value {
  min-width: 0;
  overflow: hidden;
  font-size: clamp(24px, 7vw, 32px);
  line-height: 1;
  text-overflow: ellipsis;
}

#menu .menu-btns {
  width: 100%;
  max-width: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
}

#menu #resume-btn-menu,
#menu #play-btn {
  grid-column: 1 / -1;
}

#menu .btn {
  min-width: 0;
  min-height: 45px;
  padding: 9px 10px;
  border-width: 3px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.12;
  text-wrap: balance;
}

#menu #play-btn,
#menu #resume-btn-menu {
  font-size: 16px;
}

#menu .credit {
  grid-area: credit;
  align-self: end;
  color: rgba(63, 39, 24, 0.72);
  font-size: 10px;
  font-weight: 750;
  text-shadow: 0 1px 0 rgba(255,255,255,0.82);
}

#menu .btn:focus-visible,
#topbar a:focus-visible,
#topbar button:focus-visible {
  outline: 4px solid rgba(255, 245, 204, 0.96);
  outline-offset: 3px;
  box-shadow: 0 0 0 3px var(--accent-dark), var(--shadow-deep);
}

@keyframes menuMascotFloat {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-7px) rotate(1.5deg); }
}

@media (orientation: portrait) {
  #menu::before {
    background-image: url("assets/ui/menu-room-bg-mobile-v2.png");
    background-image: image-set(
      url("assets/ui/menu-room-bg-mobile-v2.webp") type("image/webp"),
      url("assets/ui/menu-room-bg-mobile-v2.png") type("image/png")
    );
  }
}

@media (min-width: 760px) {
  #menu {
    grid-template-columns: minmax(330px, 1.1fr) minmax(350px, 0.8fr);
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas:
      "visual panel"
      "credit credit";
    align-content: center;
    gap: clamp(20px, 4vw, 62px);
    padding:
      max(66px, calc(env(safe-area-inset-top) + 54px))
      max(28px, calc(env(safe-area-inset-right) + 24px))
      max(18px, calc(env(safe-area-inset-bottom) + 12px))
      max(28px, calc(env(safe-area-inset-left) + 24px));
  }

  #menu::after {
    background:
      radial-gradient(circle at 51% 43%, rgba(255, 250, 226, 0.04), transparent 38%),
      linear-gradient(90deg, rgba(50, 25, 10, 0.12), rgba(255,255,255,0.02) 34%, rgba(255,255,255,0.02) 66%, rgba(50,25,10,0.12));
  }

  .menu-visual {
    justify-self: end;
    width: min(100%, 540px);
    height: min(66dvh, 560px);
    max-height: 560px;
    gap: clamp(14px, 2vw, 28px);
  }

  #menu .title-emoji {
    width: clamp(220px, 25vw, 330px);
    height: clamp(220px, 25vw, 330px);
  }

  .evolution-tower {
    flex-basis: clamp(150px, 17vw, 220px);
    height: clamp(240px, 30vw, 380px);
    padding-top: 28px;
  }

  .evolution-tower__label {
    max-width: none;
    padding: 6px 12px;
    font-size: 11px;
  }

  .evolution-tower__stack { inset: 30px 0 0; }

  .menu-panel {
    justify-self: start;
    width: min(100%, 404px);
    gap: 14px;
    padding: 24px;
    border-width: 4px;
    border-radius: 28px;
  }

  #menu h1 { font-size: clamp(44px, 4.4vw, 58px); }
  #menu .tagline { font-size: 15px; }
  #menu .best-card { min-height: 64px; padding: 10px 18px; }
  #menu .best-value { font-size: 34px; }
  #menu .btn { min-height: 50px; font-size: 15px; }
  #menu #play-btn,
  #menu #resume-btn-menu { font-size: 18px; }
}

@media (max-width: 759px) and (max-height: 650px) {
  #menu {
    padding-top: max(46px, calc(env(safe-area-inset-top) + 42px));
    padding-bottom: max(6px, env(safe-area-inset-bottom));
    grid-template-rows: minmax(88px, 0.52fr) auto auto;
    gap: 5px;
  }

  .menu-visual {
    width: min(100%, 260px);
    height: min(21dvh, 118px);
    min-height: 88px;
  }

  #menu .title-emoji {
    width: clamp(86px, 29vw, 108px);
    height: clamp(86px, 29vw, 108px);
  }

  .evolution-tower {
    flex-basis: clamp(72px, 23vw, 88px);
    height: clamp(82px, 26vw, 104px);
  }

  .evolution-tower__label {
    padding: 2px 6px;
    border-width: 1.5px;
    font-size: 7px;
    box-shadow: 0 2px 0 rgba(45, 26, 14, 0.6);
  }

  .menu-panel {
    gap: 6px;
    padding: 9px 10px 10px;
    border-radius: 19px;
    box-shadow: 0 5px 0 #2D1A0E, 0 14px 26px rgba(68,35,16,0.16);
  }

  .menu-kicker { font-size: 8px; }
  #menu h1 { font-size: clamp(27px, 8.8vw, 33px); }
  #menu .tagline { font-size: 11px; }
  #menu .best-card { min-height: 42px; padding: 5px 12px; }
  #menu .best-value { font-size: 23px; }
  #menu .menu-btns { gap: 6px; }
  #menu .btn { min-height: 39px; padding: 7px 8px; font-size: 12px; border-radius: 12px; }
  #menu #play-btn,
  #menu #resume-btn-menu { font-size: 14px; }
  #menu .credit { font-size: 9px; }
}

@media (pointer: coarse) {
  #menu .btn {
    min-height: 44px;
    touch-action: manipulation;
  }

  #menu .btn:not(:disabled):active {
    transform: translateY(3px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .title-emoji,
  .rotate-lock__phone::before,
  .modal,
  .modal-body,
  #game.danger #canvas {
    animation: none !important;
  }

  .title-emoji {
    transform: none !important;
  }

  #menu .title-emoji,
  #menu .btn,
  #topbar a,
  #topbar button {
    animation: none !important;
    transition: none !important;
  }

  .rotate-lock__phone::before {
    transform: rotate(0deg);
  }

  .combo-flash.pop,
  .combo-flash.legend.pop {
    animation: reducedComboPop 0.42s ease-out forwards !important;
  }

  #game.danger #canvas {
    box-shadow:
      0 8px 0 0 #2D1A0E,
      0 0 0 4px rgba(255, 226, 171, 0.42),
      0 0 0 5px rgba(232, 90, 79, 0.18),
      inset 0 2px 0 rgba(255,255,255,0.35);
  }

  @keyframes reducedComboPop {
    0% {
      opacity: 0;
      transform: translate(-50%, -50%) scale(0.98);
    }
    18%, 72% {
      opacity: 1;
      transform: translate(-50%, -50%) scale(1);
    }
    100% {
      opacity: 0;
      transform: translate(-50%, -50%) scale(1);
    }
  }
}
