/* 다리 놓기 — linkflow/css/style.css 를 파일째 복사해 팔레트와 말(piece)만 갈았다.
   헤더·판·푸터·오버레이·회전안내 구조는 그대로다.
   섬은 격자 칸에 놓고 다리는 그 위에 겹치는 SVG 로 그린다 — 다리가 칸 경계를
   넘어 이어져야 해서 칸 안에는 못 그린다. */
:root {
  --bg-top: #1b3350;
  --bg-bottom: #0d1826;

  --water: #16283c;
  --water-edge: #101d2c;

  --island: #f4e3c1;
  --island-lo: #d9c091;
  --island-ink: #3a2c14;
  --island-done: #6ee7b7;
  --island-over: #ff8b7a;

  --link: #ffd88a;

  --pill: #cfe0f2;
  --pill-ink: #1e3550;
  --ink: #e6f0fb;
  --dim: #90a8c4;
  --accent: #7fc4ff;
}

* { 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(13, 24, 38, .32), rgba(13, 24, 38, .60) 45%, rgba(13, 24, 38, .32)),
    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(207, 224, 242, .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;
}

#board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--w, 5), 1fr);
  grid-template-rows: repeat(var(--h, 5), 1fr);
  width: min(92vw, 420px, calc(64vh * var(--w, 5) / var(--h, 5)));
  aspect-ratio: var(--w, 5) / var(--h, 5);
  padding: 0;
  border-radius: 1rem;
  background: var(--water);
  box-shadow: inset 0 0 0 2px var(--water-edge);
  transition: transform .25s;
  touch-action: none; /* 드래그를 브라우저 스크롤에 뺏기지 않게 */
  filter: drop-shadow(0 1.2rem 1.6rem rgba(0, 0, 0, .45));
}

/* 다리 레이어 — 섬 아래에 깔린다 */
#links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
#links .link {
  stroke: var(--link);
  stroke-width: .1;
  stroke-linecap: round;
}

/* ---- 섬 ----
   그림은 assets/island.webp (가운데를 비워 뽑았다). 숫자는 그 위에 얹는다.
   상태 표시는 **색 + 테두리 두 가지**로 한다 (색약 대응). 테두리는 box-shadow 로
   주면 투명 배경 밖으로 네모가 생기니 drop-shadow 로 알파 모양을 따라가게 한다. */
.island {
  position: relative;
  z-index: 1;
  place-self: center;
  width: 88%;
  height: 88%;
  border: 0;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  background: none;
  color: var(--island-ink);
  font: inherit;
  font-size: min(4.4vw, 1.1rem);
  font-weight: 800;
  cursor: pointer;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .5));
  transition: transform .1s;
}
.island .face {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.island .num {
  position: relative;
  z-index: 1;
}

.island.done {
  filter: drop-shadow(0 0 5px rgba(110, 231, 183, .95)) drop-shadow(0 2px 3px rgba(0, 0, 0, .5));
}
.island.done::after {
  content: "";
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  border: 2px solid rgba(110, 231, 183, .9);
}
.island.over {
  filter: hue-rotate(-55deg) saturate(1.7) drop-shadow(0 0 5px rgba(255, 139, 122, .95));
}
.island.picked { transform: scale(1.12); }

#board.cleared { transform: scale(1.04); }

#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; }
}
