/* 보석 맞추기 — 형제 게임들의 헤더·푸터·오버레이 구조를 그대로 쓰고, 판만 갈았다.
   보석은 캔버스가 그린다. 색마다 모양이 달라서 색약이어도 판이 읽힌다. */
:root {
  --bg-top: #4a2454;
  --bg-bottom: #2a1430;
  --pill: #ecd9f2;
  --pill-ink: #452a50;
  --ink: #f6ebff;
  --dim: #c0a3cd;
  --accent: #c08cff;

}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background-color: var(--bg-bottom);
  color: var(--ink);
  font: 700 16px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  background-image: radial-gradient(120% 80% at 50% 0%, var(--bg-top), var(--bg-bottom) 70%);
}

/* 배경 그림은 배경색과 따로 선언한다 — 이 규칙이 통째로 실패해도 화면은 남는다. */
body {
  background-image:
    linear-gradient(rgba(30, 14, 38, .30), rgba(30, 14, 38, .58) 45%, rgba(30, 14, 38, .30)),
    url("../assets/bg.webp");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

header {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: .5rem;
  padding: 1rem 1.2rem .4rem;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}
#level, #left, #tokens {
  padding: .4rem .8rem;
  border-radius: 999px;
  background: rgba(213, 220, 245, .12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18);
  font-size: .85rem;
}
#level { color: var(--ink); }
#stars {
  flex-basis: 100%;
  margin-top: .3rem;
  color: #ffd76a;
  font-size: .78rem;
  font-weight: 600;
  text-align: center;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .8rem;
  min-height: 0;
}

/* ---- 판 ---- */
/* 크기는 JS 가 그릴 때마다 직접 넣는다(syncSize). CSS 로 aspect-ratio 를 잡으면
   판 비율이 티어마다 달라서(5×6 ~ 8×11) 규칙을 네 벌 써야 한다. */
#board {
  display: block;
  border-radius: .9rem;
  background: rgba(24, 10, 30, .38);
  box-shadow: inset 0 0 0 1px rgba(216, 224, 255, .14), 0 1rem 1.6rem rgba(0, 0, 0, .45);
  touch-action: none; /* 끌기를 브라우저 스크롤에 뺏기지 않게 */
  transition: transform .25s;
}
#board.cleared { transform: scale(1.03); }

#tip {
  color: var(--dim);
  font-size: .88rem;
  font-weight: 600;
  text-align: center;
  padding: 0 1.5rem;
  min-height: 2.6em;
}
#tip.warn { color: #ffb27a; }

footer {
  display: flex;
  gap: .6rem;
  padding: .8rem 1.2rem 1.4rem;
}
footer button {
  flex: 1;
  padding: .9rem 0;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #eef1ff, var(--pill));
  color: var(--pill-ink);
  font: inherit;
  font-size: .88rem;
  cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .9), inset 0 -3px 0 #bda6c6, 0 3px 6px rgba(0, 0, 0, .35);
}
footer button:disabled { opacity: .3; cursor: default; }
footer button:active:not(:disabled) {
  transform: translateY(2px);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .9), inset 0 -1px 0 #bda6c6;
}

/* ---- 설명 오버레이 (형제 게임들과 공통 구조) ---- */
#help-open {
  padding: .4rem .7rem;
  border: 0;
  border-radius: 999px;
  background: rgba(213, 220, 245, .12);
  color: var(--dim);
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.4rem;
  background: rgba(18, 7, 24, .84);
}
.overlay[hidden] { display: none; }
.sheet {
  width: 100%;
  max-width: 22rem;
  max-height: 100%;
  overflow-y: auto;
  background: linear-gradient(180deg, #52305c, #301a38);
  border-radius: 1.4rem;
  padding: 1.5rem 1.3rem;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .12), 0 1rem 2rem rgba(0, 0, 0, .5);
}
.sheet h1 { font-size: 1.15rem; margin-bottom: 1rem; color: var(--ink); }
.sheet > div {
  background: rgba(0, 0, 0, .28);
  border-radius: .9rem;
  padding: .6rem;
}
.sheet ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .6rem;
  font-size: .9rem;
  font-weight: 600;
  line-height: 1.5;
  color: var(--dim);
  margin: 1.1rem 0 1.3rem;
}
.sheet li b { color: var(--ink); }
.sheet button {
  width: 100%;
  padding: .95rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #e0c6ff, var(--accent));
  color: #171c38;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .8), inset 0 -3px 0 #9260cc;
}
.sheet button.ghost {
  margin-bottom: .6rem;
  background: linear-gradient(180deg, #eef1ff, var(--pill));
  color: var(--pill-ink);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .9), inset 0 -3px 0 #bda6c6;
}
.sheet button.ghost[hidden] { display: none; }

.result-sheet { text-align: center; }
.result-sheet h1 { margin-bottom: .35rem; }
#result-stars {
  color: #ffd76a;
  font-size: 2.2rem;
  letter-spacing: .18rem;
  text-shadow: 0 0 1.2rem rgba(255, 215, 106, .55);
}
#result-best {
  display: block;
  min-height: 1.4rem;
  margin: .2rem 0 .45rem;
  color: var(--accent);
  font-size: .86rem;
}
#result-summary {
  margin-bottom: 1.1rem;
  color: var(--dim);
  font-size: .9rem;
  font-weight: 600;
}

/* 세로 전용. 실제 앱은 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; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* 잠긴 도구는 회색이 아니라 **자물쇠와 레벨**로 알린다 — 회색만이면 고장으로 오해한다. */
button.locked { opacity: .55; letter-spacing: .02em; }

/* 마일스톤 진행 바 — 다음 상자까지 얼마나 왔나.
   두 시장 게임이 똑같이 레벨 10에 상자를 걸고 이 바를 보여 준다. */
.chest-bar {
  width: 100%;
  height: .5rem;
  border-radius: .25rem;
  background: rgba(255, 255, 255, .14);
  overflow: hidden;
  margin: .1rem 0 .3rem;
}
.chest-bar > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #7fe0b0, #ffd76a);
  transition: width .5s ease-out;
}
#result-chest { color: #ffd76a; font-weight: 800; }
#result-next-chest { opacity: .82; font-size: .92em; }

/* ---- 목표 칩 (업그레이드 A) ---- */
#goal {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .4rem .8rem;
  border-radius: 999px;
  background: rgba(213, 220, 245, .12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18);
  font-size: .85rem;
  color: var(--ink);
}
#goal-icon { font-size: 1rem; line-height: 1; }
#goal-left { font-variant-numeric: tabular-nums; }

/* ---- 부스터 툴바 ---- */
/* 판 바로 아래에 둔다 — 쓰는 자리와 고르는 자리가 멀면 안 쓴다.
   ⚠️ <footer> 안에 넣지 않는다: js/home.js 의 상점이 `footer button` 을 도구로 읽는다. */
#boostbar {
  display: flex;
  gap: .6rem;
  justify-content: center;
  width: 100%;
  max-width: 26rem;
  padding: 0 1.2rem;
}
.booster {
  position: relative;
  flex: 0 0 auto;
  width: 3.4rem;
  height: 3.4rem;
  border: 0;
  border-radius: 1rem;
  background: linear-gradient(180deg, rgba(255, 255, 255, .22), rgba(120, 80, 150, .3));
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .35), 0 3px 8px rgba(0, 0, 0, .4);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform .12s, box-shadow .12s;
}
.booster img { width: 2.1rem; height: 2.1rem; object-fit: contain; pointer-events: none; }
.booster .count {
  position: absolute;
  right: -.25rem;
  bottom: -.3rem;
  min-width: 1.25rem;
  padding: .05rem .3rem;
  border-radius: 999px;
  background: #2a1430;
  color: #ffd76a;
  font-size: .72rem;
  font-weight: 800;
  box-shadow: 0 0 0 2px rgba(255, 215, 106, .5);
}
.booster.empty { filter: grayscale(.55) brightness(.85); }
.booster.empty .count { color: #cbb7e0; box-shadow: 0 0 0 2px rgba(203, 183, 224, .35); }
.booster.armed {
  transform: translateY(-4px) scale(1.06);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .5), 0 0 0 3px #ffd76a, 0 6px 14px rgba(0, 0, 0, .5);
}
.booster:disabled { opacity: .45; cursor: default; }

/* 조준 중에는 판 말고 다른 걸 누르지 못하게 — 실수로 섞기를 누르면 부스터를 날린다 */
body.aiming footer { opacity: .35; pointer-events: none; }
body.aiming #tip { color: #ffd76a; }

/* ---- 실패 시트 (교훈 39) ---- */
.result-sheet.fail h1 {
  font-size: 1.9rem;
  color: #ff9a8a;
  text-shadow: 0 2px 14px rgba(255, 90, 70, .45);
}
.result-sheet.fail #result-stars { font-size: 2.6rem; text-shadow: none; }
.result-sheet.fail #next {
  background: linear-gradient(180deg, #ffd0a0, #ff8a4d);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .8), inset 0 -3px 0 #c05a20, 0 0 0 0 rgba(255, 138, 77, .6);
  animation: pulse 1.4s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: inset 0 2px 0 rgba(255, 255, 255, .8), inset 0 -3px 0 #c05a20, 0 0 0 0 rgba(255, 138, 77, .55); }
  70% { box-shadow: inset 0 2px 0 rgba(255, 255, 255, .8), inset 0 -3px 0 #c05a20, 0 0 0 .8rem rgba(255, 138, 77, 0); }
  100% { box-shadow: inset 0 2px 0 rgba(255, 255, 255, .8), inset 0 -3px 0 #c05a20, 0 0 0 0 rgba(255, 138, 77, 0); }
}

/* ---- 왕 구하기 ---- */
#king { z-index: 12; padding: .8rem; }
#king .king-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  width: 100%;
  max-width: 24rem;
  height: 100%;
}
#king h1 {
  font-size: 1.1rem;
  color: #ffd76a;
  text-align: center;
}
#king-board {
  flex: 1;
  width: 100%;
  min-height: 0;
  border-radius: 1rem;
  background: #1b0f22;
  box-shadow: inset 0 0 0 1px rgba(216, 224, 255, .14), 0 1rem 1.6rem rgba(0, 0, 0, .5);
  touch-action: none;
}
#king-tip {
  color: var(--dim);
  font-size: .85rem;
  font-weight: 600;
  text-align: center;
  min-height: 2.4em;
}
#king-next {
  width: 100%;
  padding: .9rem;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #e0c6ff, var(--accent));
  color: #171c38;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .8), inset 0 -3px 0 #9260cc;
}
#king-next[hidden] { display: none !important; }

/* 홈은 `_shared/home.js` 가 만든다(스타일은 게임 쪽에서 덮는다 — 공유 파일은 수정 금지).
   기본값이 남색이라 이 게임의 보라 판과 따로 놀았다 — 스토어 첫 그림이 그 화면이다. */
/* ⚠️ `!important` 가 필요하다 — home.js 는 <style> 을 **런타임에 head 끝에** 붙이므로
   같은 특이도(#home.overlay)면 그쪽이 이긴다. */
#home.overlay {
  background:
    linear-gradient(rgba(46, 22, 58, .5), rgba(26, 12, 34, .82)),
    url("../assets/bg.webp") center / cover no-repeat !important;
}
#home h1 { color: var(--ink); text-shadow: 0 .4rem 1.4rem rgba(0, 0, 0, .55); }
#home .home-band { color: var(--accent); }
#home-start {
  background: linear-gradient(180deg, #e0c6ff, var(--accent)) !important;
  color: #1d1030 !important;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .8), inset 0 -3px 0 #9260cc,
    0 .5rem 1.2rem rgba(120, 60, 190, .45) !important;
}
