/* ==========================================================================
   스무칸 — 워들식 모바일 앱 (PC에서도 가운데 모바일 폭으로)
   흰 배경 · 다크 텍스트 · 세트는 초록/골드 교차 · 단독 칸은 회색
   ========================================================================== */

:root {
  --bg: #f4f5f6;        /* 데스크톱 배경 (앱 바깥) */
  --app: #ffffff;       /* 앱 셸 */
  --text: #1a1a1b;
  --muted: #787c7e;
  --line: #d3d6da;      /* 테두리 · 구분선 */
  --filled: #787c7e;    /* 단독 칸(0점) 회색 */
  --set-a: #6aaa64;     /* 세트 초록 */
  --set-b: #c9b458;     /* 세트 골드 */
  --accent: #6aaa64;
  --accent-press: #588a52;

  --font: "Pretendard", -apple-system, BlinkMacSystemFont, system-ui, "Apple SD Gothic Neo",
    "Malgun Gothic", sans-serif;

  --app-w: 480px;
  --header-h: 52px;

  font-variant-numeric: tabular-nums;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--app);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  word-break: keep-all; /* 한국어는 어절 단위로 줄바꿈 (음절 중간에 끊기지 않게) */
}

.hidden { display: none !important; }

/* 앱 셸 — 모바일 폭 컬럼만 가운데 정렬. 데스크톱/태블릿에서도 별도 프레임 없이 흰 배경 */
.app {
  width: 100%;
  max-width: var(--app-w);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--app);
  display: flex;
  flex-direction: column;
}

/* 헤더 ------------------------------------------------------------------- */
.app-header {
  height: var(--header-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 12px;
}
.title {
  grid-column: 2;
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-align: center;
}
.best-chip {
  justify-self: start;
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
  font-family: var(--font);
  font-size: 13px;
}
.best-chip .best-label { font-size: 11px; }
.best-chip #bestScore { font-size: 17px; font-weight: 800; color: var(--text); }
.header-right {
  justify-self: end;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.icon-btn {
  width: 34px;
  height: 34px;
  border: 1.5px solid var(--line);
  border-radius: 50%;
  background: var(--app);
  color: var(--text);
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: #f0f1f2; }
.lang-btn { font-size: 17px; padding: 0; line-height: 1; }

.lang-menu { position: relative; }
.lang-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--app);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
  min-width: 148px;
  z-index: 50;
}
.lang-list[hidden] { display: none; }
.lang-list li { margin: 0; }
.lang-list button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  border-radius: 6px;
  text-align: left;
}
.lang-list button:hover { background: #f0f1f2; }
.lang-list button.active { font-weight: 700; background: #f5f6f7; }
.lang-list .lang-flag { font-size: 18px; line-height: 1; }

/* 본문 ------------------------------------------------------------------- */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px clamp(12px, 4vw, 18px) 24px;
}

.subbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 14px;
}
.progress { font-size: 18px; font-weight: 800; color: var(--muted); }
.progress b { color: var(--text); }
.progress .slash { color: var(--line); margin: 0 1px; }

/* 이번에 놓을 수 --------------------------------------------------------- */
.draw {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin: auto 0 14px; /* 위 auto: 서브바 아래 빈 공간을 흡수해 보드 영역을 세로 중앙으로 */
}
.draw-cap {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.draw-tile {
  width: 76px;
  height: 76px;
  border-radius: 12px;
  background: var(--text);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 42px;
  font-weight: 800;
  line-height: 1;
}
.draw-tile.is-wild { color: var(--set-b); }
.draw-tile.done { background: var(--muted); font-size: 24px; }

/* 보드 ------------------------------------------------------------------- */
/* 5열 × 4줄 격자. 글처럼 왼→오, 줄 끝나면 아래 줄로 이어서 읽는다 */
.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 360px;
  margin: 2px auto 14px;
}
.cell {
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--line);
  border-radius: 7px;
  background: var(--app);
  color: var(--text);
  padding: 0;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 800;
  font-size: clamp(15px, 5vw, 26px);
  transition: transform 0.08s ease, background 0.12s ease, border-color 0.12s ease;
}
.cell.empty { color: transparent; }
.cell.empty:disabled { cursor: default; }
.cell.placeable:hover { border-color: var(--muted); background: #fafafa; }
.cell.placeable:active { transform: scale(0.94); }

/* 채워진 칸 */
.cell.filled { background: var(--filled); border-color: var(--filled); color: #fff; }
.cell.in-series { color: #fff; }
.cell.set-a { background: var(--set-a); border-color: var(--set-a); }
.cell.set-b { background: var(--set-b); border-color: var(--set-b); }

/* 튜토리얼: 놓을 칸 강조 */
.cell.tut-target {
  border-color: var(--accent);
  z-index: 1;
  animation: tutPulse 1.1s ease-in-out infinite;
}
@keyframes tutPulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(106, 170, 100, 0.45); }
  50% { box-shadow: 0 0 0 8px rgba(106, 170, 100, 0.12); }
}

.cell.just-placed { animation: pop 0.18s ease; }
@keyframes pop {
  0% { transform: scale(0.6); }
  70% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* 라이브 점수 ------------------------------------------------------------ */
.live {
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  margin-bottom: auto; /* 아래 auto: draw의 위 auto와 함께 블록을 세로 중앙 정렬 */
}
.live b { color: var(--text); font-size: 20px; font-weight: 800; }
.live .sep { margin: 0 8px; color: var(--line); }
html[lang="en"] .live b + span,
html[lang="es"] .live b + span { margin-left: 4px; }

/* 모드 토글 (워들식 칩) -------------------------------------------------- */
.modes {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 10px;
}
.mode-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 0;
  border-radius: 999px;
  background: #eef0f1;
  color: #4a4d4f;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.mode-btn:hover { background: #e3e6e8; }
.mode-btn.active { background: var(--accent); color: #fff; }
.mode-btn.active:hover { background: var(--accent-press); }
.mode-icon { flex-shrink: 0; }

/* 하단 크레딧 ------------------------------------------------------------ */
.credits {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
  justify-content: center;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  font-size: 12px;
}
.credits a { color: var(--muted); text-decoration: none; white-space: nowrap; }
.credits a:hover { color: var(--accent); text-decoration: underline; }
.credits .sep { color: var(--line); }

/* 짧은 뷰포트(iPhone SE 등): 스크롤 없이 한 화면에 들어오도록 압축 */
@media (max-height: 760px) {
  .app-main { padding: 10px clamp(10px, 4vw, 18px) 12px; }
  .subbar { margin-bottom: 8px; }
  .draw { margin: auto 0 12px; gap: 6px; }
  .draw-cap { font-size: 11px; }
  .draw-tile { width: 64px; height: 64px; font-size: 36px; border-radius: 12px; }
  .board { margin: 0 auto 12px; max-width: 320px; gap: 6px; }
  .live { font-size: 14px; margin-bottom: auto; }
  .live b { font-size: 18px; }
  .modes { gap: 6px; margin-bottom: 6px; }
  .mode-btn { padding: 6px 12px; font-size: 13px; }
  .credits { padding: 8px 16px calc(10px + env(safe-area-inset-bottom)); font-size: 11px; gap: 4px 10px; }
}

/* 버튼 (모달 공용) ------------------------------------------------------- */
.btn {
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 10px;
  padding: 13px 18px;
  border: 1.5px solid var(--line);
  background: var(--app);
  color: var(--text);
  transition: background 0.12s ease, transform 0.06s ease;
}
.btn:hover { background: #f3f4f5; }
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-press); }

/* ==========================================================================
   모달 (규칙 · 결과 · 튜토리얼)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow-y: auto;
}
.modal-sheet {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--app);
  border-radius: 14px;
  padding: 28px 22px 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  animation: sheetIn 0.22s ease;
}
@keyframes sheetIn {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  z-index: 3;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.06);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: #f0f1f2; color: var(--text); }
.modal-close:active { background: #e9eaeb; color: var(--text); }
.modal-sheet h2 {
  margin: 0 0 16px;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
}
.modal-sheet h3 { margin: 22px 0 10px; font-size: 15px; font-weight: 700; }
.modal-sheet .muted { color: var(--muted); font-weight: 400; font-size: 13px; }

/* 이미지 저장 미리보기 (인앱 브라우저용 — 길게 눌러 저장) ---------------- */
.save-preview-img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid var(--line);
  margin-top: 4px;
}
.save-preview-hint {
  text-align: center;
  font-size: 14px;
  color: var(--muted);
  margin: 14px 0 0;
  line-height: 1.5;
}

/* 결과 모달 -------------------------------------------------------------- */
.result-head { text-align: center; font-size: 14px; color: var(--muted); }
.result-head b { color: var(--accent); }
.result-score { text-align: center; font-weight: 800; line-height: 1; margin: 6px 0 8px; }
.result-score span:first-child { font-size: 76px; }
.result-score .pt { font-size: 24px; color: var(--muted); margin-left: 4px; }
.result-sub { text-align: center; font-size: 13px; color: var(--muted); }
.result-sub b { color: var(--text); }
.streak {
  display: block;
  width: fit-content;
  margin: 12px auto 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  padding: 5px 14px;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
}

.breakdown {
  list-style: none;
  padding: 0;
  margin: 18px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.breakdown li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  background: #f4f5f6;
}
.bd-swatch { width: 14px; height: 14px; border-radius: 3px; background: var(--set-a); }
.bd-swatch.alt { background: var(--set-b); }
.bd-len { flex: 1; font-size: 14px; }
.bd-pts { font-weight: 800; font-size: 16px; }
.bd-none { justify-content: center; color: var(--muted); font-size: 14px; background: none; }

.share-grid {
  font-size: 20px;
  line-height: 1.3;
  letter-spacing: 3px;
  text-align: center;
  margin: 6px 0 18px;
  white-space: pre;
}

.result-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.result-actions .full { grid-column: 1 / -1; }
.daily-note { text-align: center; color: var(--muted); font-size: 14px; margin: 14px 0 18px; }

/* 화면 상단 배너로 — 결과 모달 위에서도 확실히 보이게 */
.toast {
  position: fixed;
  left: 50%;
  top: calc(16px + env(safe-area-inset-top));
  transform: translate(-50%, -16px);
  background: var(--text);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  padding: 12px 20px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  white-space: nowrap;
  opacity: 0;
  z-index: 9999;
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 규칙: 리스트 · 카드표 · 점수표 · 예시 --------------------------------- */
.rules-list { padding-left: 20px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.rules-list li { font-size: 14.5px; line-height: 1.5; }
.rules-list b { color: var(--accent); }

.card-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.card-table td { border: 1px solid var(--line); padding: 9px 12px; }
.card-table td.x { text-align: right; white-space: nowrap; font-weight: 800; color: var(--accent); }
.card-table tr.hl td { background: #eef6ed; }
.card-caption { font-size: 13px; color: var(--muted); margin: 8px 0 0; line-height: 1.55; }
.card-caption b { color: var(--accent); }

.score-table { width: 100%; border-collapse: collapse; font-size: 12.5px; table-layout: fixed; }
.score-table th {
  background: var(--text); color: #fff; font-weight: 600; font-size: 11px;
  padding: 6px 4px; border: 1px solid var(--text);
}
.score-table td { border: 1px solid var(--line); padding: 5px 6px; white-space: nowrap; }
.score-table td:nth-child(odd) { color: var(--muted); }
.score-table td:nth-child(even) { text-align: right; font-weight: 800; color: var(--accent); }
.score-table td:empty { background: #f4f5f6; }

.ex-board-wrap { text-align: center; }
.exb { display: flex; flex-wrap: wrap; gap: 5px; padding: 4px 0 12px; justify-content: center; }
.exb-cell {
  width: 30px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--line); border-radius: 5px; background: var(--app);
  font-weight: 800; font-size: 14px; color: var(--text);
}
.exb-cell.s { color: #fff; border-color: var(--set-a); background: var(--set-a); }
.exb-cell.s.alt { border-color: var(--set-b); background: var(--set-b); }
.exb-cell.g { color: #fff; border-color: var(--filled); background: var(--filled); }
.exb-cell.w { color: var(--set-b); }
.exb-cell.s.w { color: #fff; }
.ex-total { margin-top: 4px; font-size: 16px; }
.ex-total b { font-weight: 800; font-size: 22px; color: var(--accent); }

/* 규칙 카드: 설명 + 미니 칸 그림 */
.rule-lead { font-size: 14.5px; line-height: 1.55; text-align: center; margin: 0 0 16px; }
.rule-lead b { color: var(--accent); }
.rule-cap { font-size: 13.5px; color: var(--muted); text-align: center; margin: 14px 0 0; line-height: 1.55; }
.rule-cap b { color: var(--accent); }
.exb.mini { gap: 4px; padding: 0; justify-content: center; }
.rule-demo { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.rule-demo .exb.mini { flex: 0 0 auto; }
.rule-demo p { margin: 0; font-size: 14px; line-height: 1.45; }
.rule-demo p b { color: var(--accent); }

/* 모드 카드: 두 모드 설명 (규칙 모달 마지막 페이지) */
.rule-mode-block { margin-bottom: 18px; }
.rule-mode-block:last-child { margin-bottom: 0; }
.rule-mode-h {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 0 6px;
  font-size: 15.5px;
  font-weight: 800;
  color: var(--accent);
}
.rule-mode-p { margin: 0; font-size: 14px; line-height: 1.55; color: #333; }

/* 예시 카드: 실제 게임처럼 5칸 × 4줄 보드 + 세트별 점수 분해 */
.ex-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; width: 100%; max-width: 230px; margin: 0 auto 8px; }
.ex-grid .exb-cell { width: 100%; height: auto; aspect-ratio: 1 / 1; font-size: 13px; }
.ex-breakdown { list-style: none; padding: 0; margin: 12px 0 8px; display: flex; flex-direction: column; gap: 8px; }
.ex-breakdown li { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.ex-breakdown .bd-len { flex: 1; text-align: left; }
.ex-breakdown .bd-pts { color: var(--accent); font-weight: 800; }
.bd-swatch.gray { background: var(--filled); }

.text-link {
  background: none; border: none; cursor: pointer;
  font-family: var(--font); font-size: 14px; color: var(--accent);
  font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
}

/* 규칙: 좌우로 넘기는 카드 덱 (세로 스크롤 없음) */
.rules-sheet { overflow: hidden; padding-left: 0; padding-right: 0; }
/* 모든 카드를 같은(가장 큰) 높이로 → 넘겨도 화살표 위치가 고정 */
.rules-deck { overflow: hidden; }
.rules-track { display: flex; align-items: stretch; transition: transform 0.25s ease; }
.rules-card { flex: 0 0 100%; box-sizing: border-box; padding: 0 44px; }
.rules-card h3 { margin: 4px 0 16px; font-size: 20px; font-weight: 800; text-align: center; }
/* 점은 하단 가운데 */
.rules-dots { display: flex; justify-content: center; gap: 6px; margin-top: 18px; }
.rules-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.rules-dots span.on { background: var(--accent); }
/* 좌우 화살표는 모달 세로 중앙의 양 측면에 고정 */
.rules-prev, .rules-next {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 2;
  width: 34px; height: 34px; border: 1.5px solid var(--line); border-radius: 50%;
  background: var(--app); color: var(--text); font-size: 18px; line-height: 1; cursor: pointer;
}
.rules-prev { left: 6px; }
.rules-next { right: 6px; }
.rules-prev:hover:not(:disabled), .rules-next:hover:not(:disabled) { background: #f3f4f5; }
.rules-prev:disabled, .rules-next:disabled { opacity: 0.3; cursor: default; }
.rules-footer { margin-top: 14px; text-align: center; padding: 0 44px; }

/* ==========================================================================
   튜토리얼 코치마크
   ========================================================================== */
/* 오버레이는 클릭을 통과(보드 직접 조작 가능), 카드만 클릭 받음 */
.coach-overlay { position: fixed; inset: 0; z-index: 150; pointer-events: none; }
.coach-spot {
  position: fixed;
  border-radius: 10px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
  transition: all 0.25s ease;
  pointer-events: none;
}
.coach-card {
  position: fixed;
  width: min(330px, calc(100vw - 32px));
  background: var(--app);
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
}
.coach-hint { font-size: 13px; font-weight: 700; color: var(--accent); }
.coach-card h3 { margin: 0 0 6px; font-size: 18px; font-weight: 800; }
.coach-card p { margin: 0 0 16px; font-size: 14.5px; line-height: 1.55; color: #333; }
.coach-card b { color: var(--accent); }
.coach-foot { margin-top: 16px; }
.coach-dots { display: flex; justify-content: center; gap: 5px; margin-bottom: 12px; }
.coach-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.coach-dots span.on { background: var(--accent); }
.coach-nav { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.coach-skip { background: none; border: none; color: var(--muted); font-family: var(--font); font-size: 13px; cursor: pointer; padding: 4px; white-space: nowrap; }
.coach-btns { display: flex; align-items: center; gap: 7px; }
.coach-back {
  font-family: var(--font); font-weight: 700; font-size: 14px; cursor: pointer; white-space: nowrap;
  border: 1.5px solid var(--line); border-radius: 8px; background: var(--app); color: var(--text); padding: 7px 14px;
}
.coach-back:hover { background: #f3f4f5; }
.coach-next {
  font-family: var(--font); font-weight: 700; font-size: 14px; cursor: pointer; white-space: nowrap;
  border: none; border-radius: 8px; background: var(--accent); color: #fff; padding: 8px 16px;
}
.coach-next:hover { background: var(--accent-press); }
.coach-hint { white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
