:root {
  --bg: #221534;
  --off: #33204a;
  --card: #3a2555;
  --on: #c4a2ff;
  --dim: #9b86bd;
  --yes: #6fe3c0;
  --no: #ff7a8a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background-color: var(--bg);
  color: #fff;
  font: 500 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}

/* 배경 이미지는 배경색과 따로 선언한다. 이 규칙이 통째로 실패해도 위의 배경색과
   화면 내용은 그대로 남는다. 배경 하나 때문에 게임이 안 보이는 일은 없어야 한다. */
body {
  background-image: linear-gradient(rgba(34, 21, 52, .82), rgba(34, 21, 52, .92)),
                    url("../assets/bg.webp");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

header {
  display: flex;
  justify-content: space-between;
  padding: 1.2rem 1.4rem;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
#level { color: #fff; font-weight: 700; }
#stage-best, #total-stars { font-size: .78rem; }
#stage-best { color: var(--on); }
#total-stars { color: #ffc24d; font-weight: 700; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: .7rem;
  padding: 0 1.1rem;
  width: 100%;
  max-width: 24rem;
  margin: 0 auto;
}

.example { display: flex; align-items: center; gap: .7rem; }
.tag {
  flex: 0 0 3.6rem;
  font-size: .8rem;
  font-weight: 700;
  text-align: right;
}
.tag.yes { color: var(--yes); }
.tag.no { color: var(--no); }

/* 카드 크기를 폭으로만 정하면 창이 넓어질수록 세로로 넘쳐 아래가 잘린다.
   화면 높이(vh)도 같이 상한으로 걸어야 어떤 창에서도 한 화면에 들어온다. */
.cards { display: flex; gap: .5rem; flex: 1; min-width: 0; }
.cards > * { flex: 0 0 auto; width: min(29%, 12vh); }
.cards svg { display: block; height: auto; }
.cardbg { fill: var(--card); }

/* #options 는 세로 flex(main)의 자식이라 flex:1 이면 높이로 늘어난다. 내용만큼만 차지하게. */
#options {
  flex: 0 0 auto;
  margin-top: .2rem;
  gap: .45rem;
}
#options > * { width: min(23%, 11vh); }
#options svg { width: 100%; }
#options button {
  padding: 0;
  border: 2px solid transparent;
  border-radius: .8rem;
  background: none;
  cursor: pointer;
  transition: transform .15s, opacity .2s, border-color .15s;
}
#options button:active:not(:disabled) { transform: scale(.95); }
#options button.wrong { opacity: .3; }
#options button.gone { opacity: .15; }
#options button.right {
  border-color: var(--on);
  transform: scale(1.06);
}
#options button.shake { animation: shake .3s; }
@keyframes shake {
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

#ask {
  color: var(--dim);
  font-size: .85rem;
  text-align: center;
  margin-top: .5rem;
}
#tip {
  color: var(--dim);
  font-size: .8rem;
  text-align: center;
  min-height: 1.2em;
  opacity: .8;
}
#tip[hidden] { display: none; }

footer {
  display: flex;
  gap: .6rem;
  padding: 1rem 1.2rem 1.6rem;
}
footer button {
  flex: 1;
  padding: .95rem 0;
  border: 0;
  border-radius: .9rem;
  background: var(--off);
  color: #fff;
  font: inherit;
  font-size: .92rem;
  cursor: pointer;
}
footer button:disabled { opacity: .35; cursor: default; }
footer button:active:not(:disabled) { transform: scale(.97); }

/* ---- 설명 오버레이 (세 게임 공통 구조) ---- */
#help-open {
  background: none;
  border: 0;
  color: var(--dim);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 0 .2rem;
}
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.4rem;
  background: rgba(0, 0, 0, .72);
}
.overlay[hidden] { display: none; }
.sheet {
  width: 100%;
  max-width: 22rem;
  background: var(--off);
  border-radius: 1.2rem;
  padding: 1.5rem 1.3rem;
}
/* 작은 화면에서 설명이 화면보다 길어져도 버튼에 닿을 수 있어야 한다 */
.sheet { max-height: 100%; overflow-y: auto; }

.sheet h1 { font-size: 1.15rem; margin-bottom: 1rem; }
.sheet > div {
  background: var(--bg);
  border-radius: .7rem;
  padding: .6rem;
}
.sheet ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  font-size: .9rem;
  line-height: 1.5;
  color: var(--dim);
  margin: 1.1rem 0 1.3rem;
}
.sheet li b { color: #fff; font-weight: 600; }
.sheet button {
  width: 100%;
  padding: .95rem;
  border: 0;
  border-radius: .9rem;
  background: var(--on);
  color: var(--bg);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.clear-sheet { text-align: center; }
.clear-kicker {
  color: var(--yes);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .18em;
}
.clear-sheet h1 { margin: .35rem 0 .15rem; }
.clear-stars {
  color: #ffc24d;
  font-size: 2.7rem;
  letter-spacing: .08em;
  line-height: 1.3;
  text-shadow: 0 0 18px rgba(255, 194, 77, .35);
  animation: star-pop .45s ease-out both;
}
.new-best {
  margin: .25rem 0 1.1rem;
  color: var(--yes);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .12em;
}
.new-best[hidden] { display: none; }
@keyframes star-pop {
  from { opacity: 0; transform: scale(.65); }
  to { opacity: 1; transform: scale(1); }
}

/* 설명 화면의 예제 판 */
.demo-row { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.demo-row .tag { flex: 0 0 3.2rem; font-size: .72rem; }
.demo-answer {
  margin-top: .6rem;
  text-align: center;
  font-size: .85rem;
  color: var(--dim);
}
.demo-answer b { color: var(--on); }

/* 세로 전용. 폰을 눕히면 게임 대신 안내만 띄운다.
   실제 앱은 AndroidManifest 의 screenOrientation="portrait" 로 못 눕히게 막는다. */
#rotate { display: none; }
@media (orientation: landscape) and (max-height: 520px) {
  header, main, footer, .overlay { display: none !important; }
  #rotate {
    display: flex;
    position: fixed;
    inset: 0;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
    color: var(--dim);
    font-size: 1.05rem;
    line-height: 1.6;
  }
}

/* 폰 크기를 넘어가면 가운데로 모은다 (데스크톱에서 늘어지지 않게) */
header, footer { width: 100%; max-width: 26rem; margin-inline: auto; }

/* 힌트 문구 (규칙 자체가 아니라 "어디를 볼지") */
#tip.lit { color: var(--on); opacity: 1; font-weight: 600; }
