/* 한국사 숫자 퀴즈 — 수도 맞추기와 같은 어두운 네온 톤.
   한 화면에 문제·힌트·숫자판이 다 들어가야 해서 세로 스크롤이 안 생기게 잡는다. */
* { box-sizing: border-box; margin: 0; }

[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background:
    radial-gradient(ellipse 90% 55% at 50% -10%, #24356e 0%, transparent 60%),
    linear-gradient(#0e1638 0%, #0b1030 45%, #070b22 100%) #0b1030;
  color: #eaf2ff;
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  overflow-x: hidden;
}

.wrap {
  min-height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
}

/* ---------- 머리줄 ---------- */
.top { display: flex; align-items: center; gap: 10px; padding: 2px 2px 8px; }
.top h1 {
  flex: 1;
  text-align: center;
  font-size: clamp(1.05rem, 4.4vw, 1.4rem);
  font-weight: 900;
  letter-spacing: -.02em;
  text-shadow: 0 0 18px rgba(90, 150, 255, .55);
}
.home {
  color: #cfe0ff;
  background: rgba(20, 28, 66, .72);
  border: 1px solid #3a4a8f;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: .82rem;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}
.status {
  font-size: .88rem;
  font-weight: 700;
  color: #ffd86b;
  white-space: nowrap;
  text-shadow: 0 0 10px rgba(255, 200, 80, .5);
}

/* ---------- 공통 ---------- */
.panel { flex: 1; display: flex; flex-direction: column; gap: clamp(8px, 1.4vh, 14px); min-height: 0; }
.panel.center { align-items: center; justify-content: center; text-align: center; gap: 12px; }

.big-emoji { font-size: clamp(3rem, 13vw, 4.6rem); filter: drop-shadow(0 8px 18px rgba(60, 140, 255, .45)); }
.panel h2 { font-size: clamp(1.25rem, 5.2vw, 1.7rem); font-weight: 900; }

.hint { font-size: .9rem; font-weight: 600; color: #8fa0d6; line-height: 1.55; }
.hint.best { color: #ffd86b; }
.hint-dim { color: #7b8bc0; }

.btn-main {
  font: inherit; font-weight: 800; font-size: 1.05rem;
  color: #12183a;
  background: linear-gradient(#ffd86b, #ffab2e);
  border: none; border-radius: 999px;
  padding: 13px 34px;
  cursor: pointer;
  box-shadow: 0 5px 0 #b96b00, 0 10px 24px rgba(255, 170, 40, .35);
  transition: transform .1s ease, box-shadow .1s ease;
}
.btn-main:hover { transform: translateY(-2px); box-shadow: 0 7px 0 #b96b00, 0 14px 28px rgba(255, 170, 40, .45); }
.btn-main:active { transform: translateY(3px); box-shadow: 0 2px 0 #b96b00; }

.btn-sub {
  font: inherit; font-weight: 700; font-size: .95rem;
  color: #cfe0ff;
  background: rgba(20, 28, 66, .72);
  border: 1px solid #3a4a8f;
  border-radius: 999px;
  padding: 12px 22px;
  cursor: pointer; text-decoration: none;
}

/* ---------- 점수 규칙 (시작 화면) ---------- */
.rules { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; width: min(320px, 100%); }
.rules li {
  display: flex; align-items: center; gap: 10px;
  background: rgba(20, 28, 66, .55);
  border: 1px solid #2e3a75;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: .9rem; font-weight: 700;
}
.rules .pt { flex: none; width: 46px; text-align: right; font-weight: 900; }
.rules .txt { color: #b9c7ee; font-weight: 600; text-align: left; }
.rules .r3 .pt { color: #8ef0a8; }
.rules .r2 .pt { color: #ffd86b; }
.rules .rm .pt { color: #ff8f9e; }
.rules .rp .pt { color: #b9a8ff; }

/* ---------- 몇 문제 풀지 고르기 ---------- */
.size-pick { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 2px 0 4px; }
.size-label { font-size: .9rem; color: #a9bbe8; font-weight: 700; }
.size-btns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.size-btn {
  font: inherit;
  font-weight: 800;
  font-size: .95rem;
  color: #cfe0ff;
  background: rgba(90, 150, 255, .12);
  border: 2px solid rgba(120, 175, 255, .4);
  border-radius: 999px;
  padding: 9px 18px;
  cursor: pointer;
}
.size-btn:hover { background: rgba(90, 150, 255, .24); }
.size-btn[aria-pressed="true"] {
  color: #12183a;
  background: linear-gradient(#ffd86b, #ffab2e);
  border-color: #ffe9a8;
}

/* ---------- 진행 막대 ---------- */
.pbar {
  height: 10px; border-radius: 999px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(140, 165, 230, .25);
  overflow: hidden;
}
.pbar > i {
  display: block; height: 100%; width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd86b, #ffab2e);
  transition: width .4s ease;
}

/* ---------- 시대 딱지 ----------
   .era 와 .pad 에 자동 여백을 하나씩 줘서 남는 높이를 반씩 나눠 갖게 한다.
   그러면 문제 덩어리가 진행 막대와 숫자판 사이 한가운데에 뜬다. */
.era {
  margin-top: auto;
  align-self: center;
  background: rgba(90, 130, 255, .16);
  border: 1px solid #3f56a8;
  color: #b9c9ff;
  border-radius: 999px;
  padding: 5px 14px;
  font-size: .82rem;
  font-weight: 800;
  white-space: nowrap;
}

/* ---------- 문제 문장 ----------
   숫자 칸이 문장 안에 그대로 박힌다. 칸 묶음은 통째로 줄바꿈된다. */
.ask {
  flex: none;
  text-align: center;
  font-size: clamp(1.05rem, 4.6vw, 1.4rem);
  font-weight: 800;
  line-height: 2.1;
  letter-spacing: -.01em;
  padding: 4px 2px;
}

/* 숫자 칸 + 바로 뒤 낱말은 한 덩어리로 움직인다 */
.ask .nb { white-space: nowrap; }

.digits {
  display: inline-flex;
  gap: 5px;
  vertical-align: middle;
  margin: 0 4px;
}

.digit {
  width: clamp(34px, 10vw, 46px);
  height: clamp(46px, 13vw, 60px);
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  font-size: clamp(1.3rem, 5.6vw, 1.8rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  background: rgba(12, 18, 48, .8);
  border: 2px solid #34428c;
  color: #eaf2ff;
  transition: border-color .15s ease, background .15s ease, transform .1s ease;
}
/* 미리 채워 준 앞자리 — 못 지운다는 걸 색으로 알린다 */
.digit.given {
  background: rgba(90, 130, 255, .13);
  border-color: #3f56a8;
  border-style: dashed;
  color: #93a6e0;
}
.digit.filled { border-color: #ffab2e; color: #ffd86b; background: rgba(255, 190, 80, .1); }
/* 통과를 눌러 드러난 답 — 내가 맞힌 게 아니라는 걸 색으로 구분한다 */
.digit.shown { border-color: #8f7bff; color: #c3b6ff; background: rgba(140, 120, 255, .12); }
/* 지금 넣을 자리 — 깜빡이는 밑줄 */
.digit.on { border-color: #ffd86b; box-shadow: 0 0 0 3px rgba(255, 200, 80, .18); animation: blink 1.1s ease-in-out infinite; }
@keyframes blink { 0%, 100% { border-color: #ffd86b; } 50% { border-color: #5a6bb5; } }

/* 틀렸을 때 흔들기 */
.digits.shake { animation: shake .38s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}
.digits.shake .digit:not(.given) { border-color: #ff6d80; }

.oops {
  text-align: center;
  color: #ffb4bf;
  font-weight: 800;
  font-size: .95rem;
  min-height: 1.2em;
}

/* ---------- 힌트 ---------- */
.hint-slot { display: block; }
.hint-btn {
  width: 100%;
  display: flex; align-items: center; gap: 8px;
  font: inherit; font-weight: 800; font-size: .92rem;
  color: #ffd86b;
  background: rgba(255, 200, 80, .1);
  border: 1.5px dashed #7a6320;
  border-radius: 12px;
  padding: 11px 14px;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease;
}
.hint-btn:hover:not(:disabled) { background: rgba(255, 200, 80, .18); transform: translateY(-1px); }
.hint-btn:disabled { opacity: .35; cursor: default; }
.hint-btn .hint-num { color: #ffd86b; white-space: nowrap; }
.hint-btn .hint-label { flex: 1; white-space: nowrap; text-align: left; }
.hint-btn .hint-go {
  font-size: .74rem; font-weight: 700;
  color: #ffd86b;
  border: 1px solid #7a6320;
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
}
.hint-card {
  width: 100%;
  background: rgba(20, 28, 66, .72);
  border: 1px solid #3a4a8f;
  border-left: 3px solid #ffd86b;
  border-radius: 12px;
  padding: 11px 14px;
  text-align: left;
}
.hint-card .hint-num { display: block; font-size: .74rem; font-weight: 800; color: #ffd86b; margin-bottom: 4px; }
.hint-body { font-size: .95rem; font-weight: 600; color: #dbe6ff; line-height: 1.55; }

/* ---------- 숫자판 ----------
   아이 손가락으로 눌러야 하니 칸을 넉넉히. 남는 높이를 다 쓴다. */
.pad {
  margin-top: auto;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding-bottom: 4px;
}
.key {
  font: inherit;
  font-weight: 900;
  font-size: clamp(1.15rem, 5vw, 1.5rem);
  font-variant-numeric: tabular-nums;
  color: #eaf2ff;
  background: linear-gradient(#233066, #1a2450);
  border: 1px solid #3f56a8;
  border-radius: 12px;
  padding: clamp(12px, 2.4vh, 22px) 0;
  cursor: pointer;
  box-shadow: 0 3px 0 #131b42;
  transition: transform .07s ease, box-shadow .07s ease, background .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.key:hover { background: linear-gradient(#2a3a7a, #1f2b5e); }
.key:active, .key.down { transform: translateY(3px); box-shadow: 0 0 0 #131b42; }
.key.wide { grid-column: span 1; }
.key.back { color: #ffb4bf; font-size: clamp(1rem, 4.4vw, 1.25rem); }
/* 통과 — 숫자 옆에 있지만 숫자로 안 보이게. 잘못 눌러도 점수는 깎이지 않는다 */
.key.pass {
  font-size: clamp(.9rem, 3.6vw, 1.05rem);
  font-weight: 800;
  color: #a99ce0;
  background: transparent;
  border: 1.5px dashed #4a4180;
  box-shadow: none;
}
.key.pass:hover { background: rgba(140, 120, 255, .12); color: #c3b6ff; }
.key.pass:active { transform: translateY(2px); }

/* ---------- 맞혔을 때 올라오는 띠 ---------- */
.feedback {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  transform: translateY(105%);
  transition: transform .28s cubic-bezier(.2, .9, .3, 1.2);
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
}
.feedback.show { transform: translateY(0); }
.feedback.good { background: #103a24; border-top: 2px solid #46d178; }
.feedback.pass { background: #241f4d; border-top: 2px solid #8f7bff; }

.feedback-in { max-width: 720px; margin: 0 auto; display: flex; align-items: center; gap: 14px; }
.feedback-text { flex: 1; min-width: 0; }
.feedback .verdict-line { margin: 0; font-weight: 900; font-size: clamp(1rem, 4vw, 1.15rem); }
.feedback.good .verdict-line { color: #8ef0a8; }
.feedback.pass .verdict-line { color: #c3b6ff; }
.feedback .fact { margin: 3px 0 0; font-size: .88rem; color: #dbe6ff; line-height: 1.5; }
.feedback .btn-next { flex: none; margin: 0; padding: 12px 24px; }

/* 놀이 중에는 푸터를 치운다 — 피드백 띠 자리이기도 하다 */
body.in-game .foot { display: none; }
/* 띠가 올라오면 숫자판이 가려지지 않게 아래를 비워 준다 */
body.has-feedback #game { padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
/* 답을 맞히면 숫자판은 더 누를 일이 없다 — 흐리게 눕힌다 */
body.has-feedback .pad { opacity: .35; pointer-events: none; }

/* ---------- 결과 ---------- */
.score-line { font-size: clamp(2.2rem, 11vw, 3.4rem); font-weight: 900; color: #ffd86b; }
.score-line span { font-size: .45em; color: #8fa0d6; }
.end-btns { display: flex; flex-direction: column; gap: 10px; align-items: center; width: min(280px, 100%); }
.end-btns > * { width: 100%; text-align: center; }

.foot { text-align: center; font-size: .74rem; color: #55639b; padding: 10px 0 4px; }

/* ---------- 넓은 화면 ----------
   가운데 한 줄 기둥. 숫자판만 너무 커지지 않게 폭을 묶는다. */
@media (min-width: 900px) {
  .wrap { max-width: 640px; }
  .ask { font-size: 1.45rem; }
  /* 좌우 margin:auto 를 쓰면 세로 flex 항목의 stretch 가 꺼져서
     숫자판이 글자 폭(26px)까지 쪼그라든다. align-self 로 가운데에 둔다. */
  .pad { width: 100%; max-width: 420px; align-self: center; }
}

/* 낮은 화면에서는 줄 간격을 줄여 숫자판 자리를 지킨다 */
@media (max-height: 700px) {
  .ask { line-height: 1.9; font-size: clamp(1rem, 4.2vw, 1.2rem); }
  .rules li { padding: 6px 10px; font-size: .85rem; }
  /* 고르는 줄이 둘(어려움·문제 수)이라 시작 화면이 빡빡하다 */
  .panel.center { gap: 8px; }
  .size-pick { gap: 5px; margin: 0; }
  .size-btn { padding: 7px 14px; font-size: .88rem; }
  .big-emoji { font-size: clamp(2.2rem, 9vw, 3rem); }
}
