/* 지뢰찾기 — 형제 게임들의 헤더·푸터·오버레이 구조를 그대로 쓰고, 판만 갈았다.
   14×14 = 196칸이라 DOM 으로 충분하다(캔버스면 히트 판정·글자를 손으로 그려야 한다). */
:root {
  --bg-top: #232a44;
  --bg-bottom: #11162a;
  --pill: #d5dcf5;
  --pill-ink: #2a3050;
  --ink: #e6eaff;
  --dim: #9aa3cc;
  --accent: #8fa0ff;

  --closed: #38406a;
  --closed-top: #4a5386;
  --opened: rgba(10, 14, 30, .55);

  /* 숫자 색 — 고전 지뢰찾기 관례를 따르되 어두운 배경에 맞게 밝혔다.
     색만으로 구분되지 않도록 숫자 자체가 이미 구분자다. */
  --n1: #7ec8f5;
  --n2: #7fe0b0;
  --n3: #ff8f8f;
  --n4: #c79bff;
  --n5: #ffc46b;
  --n6: #6fd8d0;
  --n7: #e6eaff;
  --n8: #9aa3cc;
}

* { 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(17, 22, 42, .34), rgba(17, 22, 42, .62) 45%, rgba(17, 22, 42, .34)),
    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;
}

/* ---- 판 ---- */
#board {
  display: grid;
  grid-template-columns: repeat(var(--w, 9), 1fr);
  gap: 2px;
  width: min(94vw, 30rem, calc(62vh));
  aspect-ratio: 1;
  padding: 6px;
  border-radius: .9rem;
  background: rgba(10, 14, 30, .5);
  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); }

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  padding: 0;
  border-radius: .18rem;
  background: linear-gradient(180deg, var(--closed-top), var(--closed));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), inset 0 -2px 0 rgba(0, 0, 0, .25);
  color: transparent;
  font: inherit;
  /* 칸 크기에 따라 글자도 줄어든다 — 14×14 에서 고정 크기면 넘친다 */
  font-size: min(4.2vw, 1.05rem);
  font-weight: 800;
  cursor: pointer;
}
.cell.open {
  background: var(--opened);
  box-shadow: inset 0 0 0 1px rgba(216, 224, 255, .07);
  cursor: default;
}
.cell.n1 { color: var(--n1); }
.cell.n2 { color: var(--n2); }
.cell.n3 { color: var(--n3); }
.cell.n4 { color: var(--n4); }
.cell.n5 { color: var(--n5); }
.cell.n6 { color: var(--n6); }
.cell.n7 { color: var(--n7); }
.cell.n8 { color: var(--n8); }
.cell.flag { color: #ffd76a; }
.cell.boom { background: #ff5c4d; color: #2a1010; }
.cell.mine { color: #ffb27a; }

#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 #adb6dd, 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 #adb6dd;
}

/* ---- 설명 오버레이 (형제 게임들과 공통 구조) ---- */
#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(6, 9, 22, .82);
}
.overlay[hidden] { display: none; }
.sheet {
  width: 100%;
  max-width: 22rem;
  max-height: 100%;
  overflow-y: auto;
  background: linear-gradient(180deg, #2a3157, #1b2140);
  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, #c3ccff, 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 #6474d8;
}
.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 #adb6dd;
}
.sheet button.ghost[hidden] { display: none; }

.result-sheet { text-align: center; }
.result-sheet h1 { margin-bottom: .35rem; }
#result-stars {
  color: #ffd76a;
  font-size: 2.4rem;
  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; }
}
