/*
 * 레이아웃과 모양. 색은 theme.css의 변수만 사용해요.
 */

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background-color: var(--sky);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
output {
  font: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}

/* ---------- 화면 전환 ---------- */
.screen {
  display: none;
}

.screen.active {
  display: block;
  animation: fadeIn 0.25s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 공통 카드·글자 ---------- */
.card {
  background: var(--paper);
  border: var(--border) solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow) var(--shadow) 0 var(--ink);
  padding: 18px;
}

.logo {
  margin: 0;
  font-family: var(--font-title);
  font-size: clamp(34px, 7vw, 52px);
  line-height: 1.1;
  text-shadow: 3px 3px 0 var(--paper);
}

.tagline {
  margin: 4px 0 0;
  font-size: 16px;
}

.card-title {
  margin: 0 0 12px;
  font-family: var(--font-title);
  font-size: 24px;
}

.section-title {
  margin: 20px 4px 12px;
  font-family: var(--font-title);
  font-size: 24px;
}

.section-title.small {
  font-size: 20px;
}

/* ---------- 버튼 ---------- */
.btn {
  min-height: var(--touch);
  padding: 10px 22px;
  border: var(--border) solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
  font-family: var(--font-title);
  font-size: 20px;
  cursor: pointer;
  box-shadow: 5px 5px 0 var(--ink);
}

.btn:active:not(:disabled) {
  transform: translate(4px, 4px);
  box-shadow: 1px 1px 0 var(--ink);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  background: var(--sun);
}

.btn-small {
  min-height: 46px;
  padding: 6px 16px;
  font-size: 17px;
  box-shadow: 3px 3px 0 var(--ink);
}

.btn-small:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.btn-quit {
  background: var(--pink);
}

.chip {
  min-height: 44px;
  padding: 6px 14px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  font-family: var(--font-title);
  font-size: 17px;
  box-shadow: 3px 3px 0 var(--ink);
  cursor: pointer;
}

.chip[aria-pressed="true"] {
  background: var(--mint);
}

.chip:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

/* ---------- 홈 상단 ---------- */
.top {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.top-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.lang-switch {
  display: flex;
  gap: 6px;
}

@media (min-width: 640px) {
  .top {
    flex-direction: row;
    justify-content: space-between;
    align-items: flex-end;
  }

  .top-tools {
    justify-content: flex-end;
  }
}

/* ---------- 설정 ---------- */
.field {
  margin-bottom: 16px;
}

.field:last-child {
  margin-bottom: 0;
}

.label {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 8px;
  font-family: var(--font-title);
  font-size: 18px;
}

label.label {
  cursor: pointer;
}

.note:empty {
  display: none;
}

.note {
  padding: 0 10px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--sun);
  font-family: var(--font-title);
  font-size: 14px;
}

.range-out {
  margin-left: auto;
  padding: 0 10px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--sun);
  font-family: var(--font-title);
  font-size: 16px;
}

.op-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.op-btn {
  min-height: var(--touch);
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
  border: var(--border) solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 4px 4px 0 var(--ink);
  font-family: var(--font-title);
  font-size: 17px;
  cursor: pointer;
}

.op-btn .sym {
  font-size: 30px;
}

.op-btn:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 var(--ink);
}

.op-btn[data-op="+"][aria-pressed="true"] { background: var(--mint); }
.op-btn[data-op="-"][aria-pressed="true"] { background: var(--pink); }
.op-btn[data-op="*"][aria-pressed="true"] { background: var(--sun); }
.op-btn[data-op="/"][aria-pressed="true"] { background: var(--lilac); }

.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.seg .chip {
  flex: 1 1 auto;
  min-height: 52px;
}

input[type="range"] {
  width: 100%;
  height: 40px;
  margin: 0;
  accent-color: var(--pink);
  cursor: pointer;
}

/* ---------- 모드 카드 ---------- */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

@media (min-width: 760px) {
  .mode-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.mode-card {
  min-width: 0;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: var(--border) solid var(--ink);
  border-radius: var(--radius-lg);
  background: var(--paper);
  box-shadow: 5px 5px 0 var(--ink);
  cursor: pointer;
}

.mode-card:active {
  transform: translate(3px, 3px);
  box-shadow: 2px 2px 0 var(--ink);
}

.mode-card:focus-visible {
  outline: 4px solid var(--sun);
  outline-offset: 3px;
}

.glyph {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--accent);
  box-shadow: 3px 3px 0 var(--ink);
  font-family: var(--font-title);
  font-size: 20px;
  line-height: 1;
}

.mode-info {
  min-width: 0;
}

.mode-info h3 {
  margin: 0 0 2px;
  font-family: var(--font-title);
  font-size: 20px;
  line-height: 1.2;
  word-break: keep-all;
}

.mode-info p {
  margin: 0 0 8px;
  font-size: 15px;
}

.tag {
  padding: 1px 8px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--paper);
  font-size: 13px;
}

.best {
  font-family: var(--font-title);
  font-size: 16px;
}

/* ---------- 약점 반복 카드 ---------- */
.weak {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.weak-title {
  font-family: var(--font-title);
  font-size: 20px;
}

.weak-hint {
  margin: 2px 0 0;
  font-size: 15px;
}

/* ---------- 게임 화면 ---------- */
.game-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.game-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-family: var(--font-title);
  font-size: 22px;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.score-cell {
  min-width: 0;
  padding: 6px 8px;
  text-align: center;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 3px 3px 0 var(--ink);
}

.score-label {
  display: block;
  font-size: 14px;
}

.score-value {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-family: var(--font-title);
  font-size: clamp(20px, 5.5vw, 28px);
  line-height: 1.2;
}

.game-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stage {
  position: relative;
  min-width: 0;
  border-radius: var(--radius-lg);
}

.stage.flash-ok {
  animation: flashOk 0.45s ease-out;
}

.stage.flash-bad {
  animation: flashBad 0.45s ease-out;
}

@keyframes flashOk {
  from { outline: 8px solid var(--ok); }
  to { outline: 8px solid transparent; }
}

@keyframes flashBad {
  from { outline: 8px solid var(--bad); }
  to { outline: 8px solid transparent; }
}

.shake {
  animation: shake 0.4s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(10px); }
  60% { transform: translateX(-6px); }
  80% { transform: translateX(6px); }
}

.prompt {
  margin: 6px 0 14px;
  text-align: center;
  font-family: var(--font-title);
  font-size: clamp(36px, 10vw, 64px);
  line-height: 1.2;
  word-break: keep-all;
}

.question-label {
  margin-bottom: 4px;
  font-family: var(--font-body);
  font-size: 18px;
}

.equation {
  font-family: var(--font-title);
  font-size: clamp(40px, 11vw, 72px);
}

.hint {
  margin: 10px 0 0;
  text-align: center;
  font-size: 15px;
  opacity: 0.85;
}

/* 떨어지는 문제 / 풍선 영역 */
.play-field,
.balloon-field {
  position: relative;
  overflow: hidden;
  flex: 1 1 auto;
  height: auto;
  min-height: 160px;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 28px 28px;
  border: var(--border) solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow) var(--shadow) 0 var(--ink);
  touch-action: manipulation;
}

.fall-card {
  position: absolute;
  top: 0;
  left: 0;
  padding: 6px 14px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--sun);
  box-shadow: 4px 4px 0 var(--ink);
  font-family: var(--font-title);
  font-size: clamp(22px, 6vw, 30px);
  line-height: 1.2;
  white-space: nowrap;
  will-change: transform;
}

.fall-card[data-op="+"] { background: var(--mint); }
.fall-card[data-op="-"] { background: var(--pink); }
.fall-card[data-op="*"] { background: var(--sun); }
.fall-card[data-op="/"] { background: var(--lilac); }

.fall-card.pop,
.balloon.popped {
  animation: pop 0.3s forwards;
}

@keyframes pop {
  to { scale: 1.6; opacity: 0; }
}

.balloon {
  position: absolute;
  top: 100%;
  left: 0;
  width: 84px;
  height: 100px;
  margin-left: -42px;
  display: grid;
  place-items: center;
  border: 3px solid var(--ink);
  border-radius: 50% 50% 46% 46% / 56% 56% 44% 44%;
  font-family: var(--font-title);
  font-size: clamp(24px, 6.5vw, 32px);
  cursor: pointer;
  user-select: none;
  will-change: transform;
}

.balloon::after {
  content: "";
  position: absolute;
  bottom: -18px;
  left: 50%;
  width: 2px;
  height: 18px;
  background: var(--ink);
}

.balloon.c0 { background: var(--mint); }
.balloon.c1 { background: var(--sun); }
.balloon.c2 { background: var(--pink); }
.balloon.c3 { background: var(--lilac); }

.balloon.wrong-pop {
  animation: wrongPop 0.3s forwards;
}

@keyframes wrongPop {
  0% { rotate: 0deg; }
  30% { rotate: -12deg; }
  60% { rotate: 12deg; }
  100% { scale: 0.2; opacity: 0; }
}

/* 보기 버튼 */
.choices {
  display: grid;
  gap: 10px;
}

.choices.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.choices.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 560px) {
  .choices.cols-3 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.choice {
  min-height: 68px;
  padding: 6px;
  border: var(--border) solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 4px 4px 0 var(--ink);
  font-family: var(--font-title);
  font-size: clamp(24px, 6vw, 32px);
  cursor: pointer;
}

.choices.cols-2 .choice {
  min-height: 96px;
}

.choice:active:not(:disabled) {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 var(--ink);
}

.choice:disabled {
  background: var(--pink);
  opacity: 0.75;
  text-decoration: line-through;
  cursor: default;
}

/* 참 거짓 O / X */
.ox {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.ox-btn {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: var(--border) solid var(--ink);
  border-radius: 26px;
  box-shadow: 6px 6px 0 var(--ink);
  font-family: var(--font-title);
  cursor: pointer;
}

.ox-o { background: var(--mint); }
.ox-x { background: var(--pink); }

.ox-btn:active {
  transform: translate(4px, 4px);
  box-shadow: 2px 2px 0 var(--ink);
}

.ox-mark {
  font-size: clamp(64px, 18vw, 110px);
  line-height: 1;
  text-shadow: 4px 4px 0 var(--paper);
}

.ox-text {
  font-size: 20px;
}

/* 시간 버티기 게이지 */
.clock {
  height: 18px;
  margin-bottom: 12px;
  overflow: hidden;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 999px;
}

.clock-fill {
  width: 100%;
  height: 100%;
  background: var(--mint);
  transition: width 0.1s linear;
}

/* 숫자패드 */
.pad-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.answer-box {
  min-height: 72px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
  border: var(--border) solid var(--ink);
  border-radius: 20px;
  box-shadow: 5px 5px 0 var(--ink);
  font-family: var(--font-title);
  font-size: 44px;
  line-height: 1;
}

.answer-val:empty::before {
  content: "?";
  opacity: 0.3;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.key {
  min-height: 66px;
  border: var(--border) solid var(--ink);
  border-radius: 18px;
  background: var(--paper);
  box-shadow: 4px 4px 0 var(--ink);
  font-family: var(--font-title);
  font-size: 30px;
  cursor: pointer;
}

.key:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 var(--ink);
}

.key-util {
  background: var(--sun);
  font-size: 19px;
}

.key-ok {
  background: var(--mint);
  font-size: 22px;
}

/* 아이패드 가로 화면: 숫자패드를 오른쪽에 세로로 */
@media (min-width: 760px) and (orientation: landscape) {
  .game-body {
    flex-direction: row;
    align-items: flex-start;
  }

  .stage {
    flex: 1 1 0;
  }

  .pad-wrap {
    flex: 0 0 340px;
  }
}

/* ---------- 결과 화면 ---------- */
.result-card {
  text-align: center;
}

.result-mode {
  font-family: var(--font-title);
  font-size: 22px;
}

.result-label {
  margin-top: 6px;
  font-size: 16px;
}

.result-big {
  font-family: var(--font-title);
  font-size: clamp(56px, 18vw, 110px);
  line-height: 1.1;
  text-shadow: 4px 4px 0 var(--sun);
}

.badge {
  display: inline-block;
  margin: 8px 0 14px;
  padding: 6px 16px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--sun);
  font-family: var(--font-title);
  font-size: 20px;
}

.badge-new {
  background: var(--pink);
  animation: bob 0.8s ease-in-out infinite alternate;
}

.badge-best {
  background: var(--paper);
}

@keyframes bob {
  from { transform: translateY(0); }
  to { transform: translateY(-4px); }
}

.result-note {
  margin: 0 0 12px;
  font-size: 15px;
}

.stats {
  margin: 12px 0 16px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.stat {
  padding: 8px 4px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 3px 3px 0 var(--ink);
}

.stat-value {
  display: block;
  font-family: var(--font-title);
  font-size: 26px;
  line-height: 1.2;
}

.stat-label {
  font-size: 14px;
}

.wrong-list {
  max-height: 40vh;
  margin: 0 0 18px;
  padding: 0;
  overflow: auto;
  list-style: none;
  text-align: left;
}

.miss {
  margin-bottom: 8px;
  padding: 8px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 14px;
}

.miss-q {
  font-family: var(--font-title);
  font-size: 19px;
}

.miss-tag {
  padding: 0 8px;
  border-radius: 999px;
  background: var(--pink);
  font-size: 14px;
}

.miss-mine,
.miss-a {
  font-size: 15px;
}

.miss-none {
  padding: 12px;
  text-align: center;
  font-family: var(--font-title);
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

/* 레벨 업 알림: 점수판의 레벨 칸에 잠깐 나타나요. */
.lv-flash {
  display: inline-block;
  padding: 0 8px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--sun);
  font-size: 0.8em;
  animation: lvPop 0.4s ease-out;
}

@keyframes lvPop {
  from { transform: scale(0.6); }
  to { transform: scale(1); }
}

/* ---------- 목숨(하트) ---------- */
.heart {
  color: var(--bad);
}

.heart.half {
  color: transparent;
  background: linear-gradient(90deg, var(--bad) 50%, var(--paper) 50%);
  -webkit-background-clip: text;
  background-clip: text;
}

/* ---------- 게임 시작 전 설정 팝업 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 55;
  display: grid;
  place-items: center;
  padding: 16px;
  background: var(--overlay);
}

.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 18px;
  background: var(--paper);
  border: var(--border) solid var(--ink);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow) var(--shadow) 0 var(--ink);
}

/* 제목과 닫기 버튼은 팝업을 스크롤해도 위에 붙어 있어요. */
.modal-head {
  position: sticky;
  top: -18px;
  z-index: 1;
  margin: -18px -18px 14px;
  padding: 18px 18px 10px;
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head .card-title {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-actions {
  margin-top: 18px;
  display: flex;
  justify-content: center;
}

.modal-actions .btn {
  min-width: 60%;
}

/* ---------- 공통 레이어 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: var(--overlay);
}

#countNum {
  font-family: var(--font-title);
  font-size: clamp(120px, 40vw, 220px);
  line-height: 1;
  color: var(--paper);
  text-shadow: 0 10px 0 var(--ink);
}

#countNum.pop {
  animation: countPop 0.8s ease-out;
}

@keyframes countPop {
  0% { scale: 0.4; opacity: 0; }
  40% { scale: 1.15; opacity: 1; }
  100% { scale: 1; }
}

/* 알림(레벨 업, 10문제 통과, 연속 정답)은 게임 제목 줄 오른쪽에 작게 띄워요.
   가운데에 띄우면 떨어지는 문제나 풍선을 가리기 때문이에요. */
.banner {
  position: fixed;
  top: 12px;
  right: 14px;
  z-index: 45;
  padding: 4px 14px;
  background: var(--sun);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 3px 3px 0 var(--ink);
  font-family: var(--font-title);
  font-size: clamp(16px, 4.5vw, 22px);
  white-space: nowrap;
  pointer-events: none;
}

.banner.show {
  animation: bannerIn 0.3s ease-out;
}

@keyframes bannerIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

.fx-layer {
  position: fixed;
  inset: 0;
  z-index: 40;
  overflow: hidden;
  pointer-events: none;
}

.float {
  position: absolute;
  top: 42%;
  transform: translateX(-50%);
  font-family: var(--font-title);
  font-size: 34px;
  white-space: nowrap;
  text-shadow: 3px 3px 0 var(--ink);
  animation: floatUp 0.9s ease-out forwards;
}

.float.good { color: var(--ok); }
.float.bad { color: var(--bad); }
.float.good,
.float.bad {
  color: var(--paper);
}

@keyframes floatUp {
  from { opacity: 1; margin-top: 0; }
  to { opacity: 0; margin-top: -70px; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  max-width: calc(100% - 32px);
  padding: 10px 18px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--paper);
  border-radius: 999px;
  font-family: var(--font-title);
  text-align: center;
}

/* ---------- 움직임 줄이기 설정 ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}


/* ---------- 게임 화면이 한 화면 안에 다 들어오게 ----------
 * 게임 중에는 스크롤 없이 숫자패드까지 전부 보이도록,
 * 게임 화면을 화면 높이에 맞추고 문제 칸이 남는 높이만 차지해요. */
#app:has(#game.active) {
  padding-bottom: 16px;
}

#game.screen.active {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 32px);
  min-height: 480px;
}

#game .game-body {
  flex: 1 1 auto;
  min-height: 0;
}

#game .stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  /* 테두리 그림자가 잘리지 않게 그림자만큼 여백 */
  padding: 0 var(--shadow) var(--shadow) 0;
}

#game .stage > .prompt {
  flex: 0 0 auto;
}

/* 키 높이는 화면 높이에 맞춰 줄어들어요 (작은 휴대폰 대비) */
#game .key {
  min-height: clamp(46px, 7.2dvh, 66px);
}

#game .answer-box {
  min-height: clamp(50px, 7.5dvh, 72px);
  font-size: clamp(32px, 5.5dvh, 44px);
}

#game .numpad {
  gap: clamp(6px, 1.2dvh, 10px);
}

@media (min-width: 760px) and (orientation: landscape) {
  #game .game-body {
    align-items: stretch;
  }

  #game .pad-wrap {
    justify-content: center;
  }
}

/* 화면에는 안 보이고 화면 읽기 프로그램만 읽는 글자 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- 순위표 (명예의 전당) ---------- */
.rank-board {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rank-head .section-title {
  margin: 0;
}

.rank-rule {
  margin: 4px 0 0;
  font-size: 14px;
  opacity: 0.8;
}

.rank-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.rank-tab {
  min-height: 40px;
  font-size: 15px;
}

.rank-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rank-row {
  display: grid;
  grid-template-columns: 4.5em minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  border-radius: 8px;
}

.rank-row:nth-child(odd) {
  background: rgba(127, 127, 127, 0.08);
}

.rank-no,
.rank-score {
  font-family: var(--font-pixel, var(--font-title));
  font-variant-numeric: tabular-nums;
}

.rank-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-family: var(--font-title);
  font-size: 19px;
}

.rank-empty {
  padding: 12px;
  text-align: center;
  opacity: 0.8;
}

/* 결과 화면: 이름 남기기 */
.rank-box {
  margin: 4px 0 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.rank-hi {
  font-family: var(--font-title);
  font-size: 22px;
}

.rank-form {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 360px;
}

.rank-form input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 46px;
  padding: 0 12px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  font-family: var(--font-title);
  font-size: 20px;
}

.rank-note,
.rank-err {
  margin: 0;
  font-size: 14px;
}

.rank-err {
  color: var(--bad);
}

.rank-box .rank-list {
  width: 100%;
  max-width: 420px;
  text-align: left;
}

.rank-form .btn {
  flex: none;
  white-space: nowrap;
}

/* ---------- 설정 팝업: 게임 방식 (연습 / 랭킹전) ---------- */
.play-note {
  margin: 8px 0 0;
  font-size: 14px;
  line-height: 1.45;
}

/* 랭킹전이면 아래 설정은 고정이라 흐리게 보여요 */
.setup-options.locked {
  opacity: 0.45;
  pointer-events: none;
}

/* 연산 버튼 글자: 좁은 화면에서도 버튼 밖으로 나가지 않게 */
.op-btn {
  min-width: 0;
  overflow: hidden;
}

.op-btn span:not(.sym) {
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: clamp(12px, 3.6vw, 17px);
}

/* 설정 팝업 제목이 길면("… · 랭킹전") 잘리지 않고 줄바꿈 */
.modal-head .card-title {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  word-break: keep-all;
}

/* ---------- 설정 팝업 간격 다듬기 ---------- */
.play-note {
  white-space: pre-line;
}

#setup .field {
  margin-bottom: 12px;
}

#setup .label {
  margin-bottom: 6px;
}

/* 슬라이더 칸이 너무 넓어서 줄였어요 (최대 숫자 → 최대 단 → 속도 사이) */
#setup input[type="range"] {
  height: 26px;
}

#setup .field:has(input[type="range"]) {
  margin-bottom: 4px;
}

#setup .field:has(input[type="range"]) .label {
  margin-bottom: 0;
}

/* 결과 공유 버튼 */
.btn-share {
  background: var(--mint);
}

/* 결과 화면 버튼: 휴대폰에서는 공유하기를 한 줄 전체로, 그 아래에 다시 하기·게임 고르기를 나란히 */
@media (max-width: 640px) {
  .result-actions {
    flex-wrap: wrap;
  }

  .result-actions .btn {
    flex: 1 1 0;
    min-width: 0;
    padding-left: 10px;
    padding-right: 10px;
  }

  .result-actions .btn-share {
    flex: 1 1 100%;
  }
}
