/* 선 잇기 — iceslide/css/style.css 를 파일째 복사해 팔레트와 말(piece)만 갈았다.
   헤더·판·푸터·오버레이·회전안내 구조는 그대로다.
   선과 점은 전부 CSS다 — 색 8종을 이미지로 뽑으면 8배가 되고, 여기선 순수 색면이라
   그라데이션만으로 충분하다. */
:root {
  --bg-top: #232a4a;
  --bg-bottom: #10142a;

  --cell: #1e2542;
  --cell-edge: #151b33;

  --pill: #d5dcf5;
  --pill-ink: #2a3050;
  --ink: #e6eaff;
  --dim: #9aa3cc;
  --accent: #8fa0ff;

  /* 색약 대응: 색상환에서 최대한 벌리고, 명도도 서로 다르게 잡았다.
     그래도 색만으로 구분되지 않도록 완성된 선은 안쪽에 밝은 심을 하나 더 넣는다. */
  --c0: #ff6b6b;
  --c1: #4dd2ff;
  --c2: #ffd93d;
  --c3: #7bed9f;
  --c4: #c77dff;
  --c5: #ff9f43;
  --c6: #5f7bff;
  --c7: #ff7ac6;
}

* { 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(16, 20, 42, .30), rgba(16, 20, 42, .62) 45%, rgba(16, 20, 42, .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, #filled, #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;
}

/* 칸 사이 간격이 없다 — 선이 칸을 넘어 이어져야 하기 때문이다.
   경계는 각 칸의 안쪽 그림자로 그린다. */
#board {
  display: grid;
  grid-template-columns: repeat(var(--w, 5), 1fr);
  grid-template-rows: repeat(var(--h, 5), 1fr);
  gap: 0;
  width: min(92vw, 420px, calc(62vh * var(--w, 5) / var(--h, 5)));
  aspect-ratio: var(--w, 5) / var(--h, 5);
  padding: 6px;
  border-radius: 1rem;
  background: var(--cell-edge);
  transition: transform .25s;
  touch-action: none; /* 드래그를 브라우저 스크롤에 뺏기지 않게 */
  filter: drop-shadow(0 1.2rem 1.6rem rgba(0, 0, 0, .45));
}

.cell {
  position: relative;
  background: var(--cell);
  box-shadow: inset 0 0 0 1px var(--cell-edge);
}

/* ---- 선: 칸 가운데에서 이웃 방향으로 뻗는 굵은 막대 ---- */
.cell::before,
.cell::after { content: none; }

.cell.to-up, .cell.to-down, .cell.to-left, .cell.to-right { --link: currentColor; }

.cell[class*="c"] { color: var(--c0); }
.cell.c0 { color: var(--c0); }
.cell.c1 { color: var(--c1); }
.cell.c2 { color: var(--c2); }
.cell.c3 { color: var(--c3); }
.cell.c4 { color: var(--c4); }
.cell.c5 { color: var(--c5); }
.cell.c6 { color: var(--c6); }
.cell.c7 { color: var(--c7); }

/* 방향별 막대를 겹쳐 그린다. 가운데에서 각 변까지 절반씩 뻗어 이웃과 만난다. */
.cell.to-up,
.cell.to-down,
.cell.to-left,
.cell.to-right {
  background-image:
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor),
    linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-position: 50% 0, 50% 100%, 0 50%, 100% 50%;
  background-size: 0 0, 0 0, 0 0, 0 0;
}
.cell.to-up { background-size: 34% 52%, 0 0, 0 0, 0 0; }
.cell.to-up.to-down { background-size: 34% 52%, 34% 52%, 0 0, 0 0; }
.cell.to-up.to-left { background-size: 34% 52%, 0 0, 52% 34%, 0 0; }
.cell.to-up.to-right { background-size: 34% 52%, 0 0, 0 0, 52% 34%; }
.cell.to-down { background-size: 0 0, 34% 52%, 0 0, 0 0; }
.cell.to-down.to-left { background-size: 0 0, 34% 52%, 52% 34%, 0 0; }
.cell.to-down.to-right { background-size: 0 0, 34% 52%, 0 0, 52% 34%; }
.cell.to-left { background-size: 0 0, 0 0, 52% 34%, 0 0; }
.cell.to-left.to-right { background-size: 0 0, 0 0, 52% 34%, 52% 34%; }
.cell.to-right { background-size: 0 0, 0 0, 0 0, 52% 34%; }

/* 선이 꺾이거나 지나가는 칸의 가운데를 둥글게 이어 준다 */
.cell.line .dot {
  position: absolute;
  inset: 33%;
  border-radius: 50%;
  background: currentColor;
}

/* ---- 끝점: 큰 원. 색만으로 구분되지 않게 테두리와 안쪽 심을 함께 쓴다 ---- */
.cell.endpoint .dot {
  position: absolute;
  inset: 15%;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, .18), 0 2px 6px rgba(0, 0, 0, .45);
}
.cell.endpoint.done .dot::after {
  content: "";
  position: absolute;
  inset: 30%;
  border-radius: 50%;
  background: rgba(255, 255, 255, .9);
}

#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; }
}
