/* ══════════════════════════════════════
   계보 2048 — 양피지 / 따뜻한 톤
   ══════════════════════════════════════ */

:root {
  --bg:         #F4EDD8;        /* 따뜻한 양피지 */
  --bg-deep:    #E6DBBC;
  --board:      #BCAA85;        /* 보드 배경 (어두운 양피지) */
  --cell:       #A89776;        /* 빈 셀 */
  --cell-soft:  rgba(168, 151, 118, 0.5);
  --panel:      #FFFAF0;
  --border:     rgba(58, 44, 26, 0.18);
  --border-strong: rgba(58, 44, 26, 0.35);

  --text:       #3A2C1A;        /* 진한 갈색 */
  --text-dim:   #6E5F44;
  --text-soft:  #97876A;
  --text-light: #FFFAF0;

  --accent:     #8B6F2D;        /* 황금 갈색 */
  --accent-hot: #C8821F;        /* 따뜻한 골드 */
  --accent-soft:rgba(139, 111, 45, 0.14);

  --era-yellow: #C8821F;
  --era-purple: #5C2C7A;
  --era-blue:   #2D4F7A;

  --jesus-glow: #FFD56B;

  --radius-sm:  6px;
  --radius:     10px;
  --radius-lg:  16px;

  --shadow-sm:  0 2px 6px rgba(58, 44, 26, 0.12);
  --shadow-md:  0 6px 20px rgba(58, 44, 26, 0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Sunflower', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  font-weight: 500;
  background:
    radial-gradient(ellipse at top, #F8F0D8 0%, transparent 60%),
    radial-gradient(ellipse at bottom, #E6D9B0 0%, transparent 65%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

button { font-family: inherit; cursor: pointer; border: none; background: transparent; color: inherit; }
button:disabled { cursor: not-allowed; opacity: 0.4; }

/* ══════ 화면 ══════ */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  overflow-y: auto;
}
.screen.active { display: flex; }
[hidden] { display: none !important; }


/* ══════ 홈 화면 ══════ */
#homeScreen {
  align-items: safe center;
  justify-content: safe center;
  padding: 24px 24px 40px;
}
.home-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 30px 26px;
  width: 100%;
  max-width: 540px;
  box-shadow: var(--shadow-md);
  text-align: center;
}
.home-card h1 {
  font-family: 'Sunflower', sans-serif;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
  color: var(--accent);
}
.home-card .sub {
  color: var(--text-dim);
  font-size: 1.1rem;
  line-height: 1.6;
  margin-bottom: 22px;
}

/* 모드 카드 */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 18px 14px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-align: center;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
  cursor: pointer;
  position: relative;
}
.mode-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-hot);
  box-shadow: var(--shadow-sm);
}
.mode-tag {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  padding: 3px 10px;
  border-radius: 99px;
  letter-spacing: 0.04em;
}
.mode-card--full .mode-tag { background: var(--era-purple); }
.mode-size {
  font-family: 'Sunflower', 'Sunflower', sans-serif;
  font-size: 1.85rem;
  font-weight: 700;
  color: var(--accent-hot);
  margin-top: 8px;
  line-height: 1.05;
}
.mode-name {
  font-size: 1.25rem;
  font-weight: 700;
}
.mode-desc {
  font-size: 0.98rem;
  color: var(--text-dim);
  line-height: 1.5;
  margin-top: 4px;
}
.mode-best {
  margin-top: 10px;
  font-size: 0.92rem;
  color: var(--text-soft);
  padding-top: 8px;
  border-top: 1px solid var(--border);
  width: 100%;
}
.mode-best b { color: var(--accent-hot); font-weight: 700; }

/* 규칙 안내 */
.rules-summary {
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 16px;
}
.rules-summary h3 {
  font-size: 1.05rem;
  color: var(--accent);
  margin-bottom: 8px;
  font-weight: 700;
}
.rules-summary ul {
  list-style: none;
  font-size: 1rem;
  color: var(--text-dim);
  line-height: 1.75;
}
.rules-summary li::before {
  content: '·';
  margin-right: 6px;
  color: var(--accent-hot);
  font-weight: 700;
}
.rules-summary b { color: var(--text); font-weight: 700; }

/* 시대 범례 */
.period-legend {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}
.period-pill {
  font-size: 0.88rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 99px;
  color: #fff;
  letter-spacing: -0.01em;
}
.period-pill.patriarch { background: var(--era-yellow); }
.period-pill.kingdom   { background: var(--era-purple); }
.period-pill.exile     { background: var(--era-blue); }

/* ── 계보 목록 ── */
.lineage-list {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: left;
}
.lineage-block {
  margin-bottom: 14px;
}
.lineage-block:last-child { margin-bottom: 0; }
.lineage-block h4 {
  font-size: 0.95rem;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}
.lineage-era {
  margin-bottom: 6px;
  font-family: 'Sunflower', 'Sunflower', sans-serif;
  font-size: 0.92rem;
  line-height: 1.75;
  word-break: keep-all;
}
.lineage-era:last-child { margin-bottom: 0; }
.lineage-era-label {
  display: inline-block;
  font-family: 'Sunflower', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 99px;
  margin-right: 8px;
  color: #fff;
  vertical-align: 1px;
  letter-spacing: 0;
}
.lineage-era.patriarch .lineage-era-label { background: var(--era-yellow); }
.lineage-era.kingdom   .lineage-era-label { background: var(--era-purple); }
.lineage-era.exile     .lineage-era-label { background: var(--era-blue); }

.lineage-names { color: var(--text); }
.lineage-era.patriarch .lineage-names { color: #8B6F2D; }
.lineage-era.kingdom   .lineage-names { color: #6B388A; }
.lineage-era.exile     .lineage-names { color: #2D4F7A; }
.lineage-name { font-weight: 700; font-family: 'Sunflower', 'Sunflower', sans-serif; }
.lineage-sep {
  margin: 0 4px;
  color: var(--text-soft);
  font-weight: 400;
}


/* ══════ 게임 헤더 ══════ */
#gameScreen {
  flex-direction: column;
  align-items: center;
  padding: 12px 14px 14px;
  gap: 8px;
  height: 100%;
  overflow: hidden;
  touch-action: none;     /* 게임 화면 전체에서 스와이프 가능, 페이지 스크롤/제스처 차단 */
}
/* 버튼/링크 등 인터랙티브 요소는 일반 탭이 그대로 동작하도록 복원 */
#gameScreen button,
#gameScreen a,
#gameScreen input { touch-action: manipulation; }
.game-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 580px;
  flex-wrap: wrap;
  flex: none;
}
.header-stats {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: center;
}
.stat-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 60px;
}
.stat-label {
  font-size: 0.66rem;
  color: var(--text-soft);
  letter-spacing: 0.04em;
  font-weight: 700;
}
.stat-value {
  font-family: 'Sunflower', sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-hot);
  line-height: 1.1;
}

.ghost-btn {
  padding: 8px 14px;
  background: var(--panel);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 700;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.ghost-btn:hover {
  color: var(--text);
  background: var(--bg-deep);
  border-color: var(--border-strong);
}

.primary-btn {
  padding: 10px 22px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.92rem;
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 2px 6px rgba(139, 111, 45, 0.4);
}
.primary-btn:hover {
  background: var(--accent-hot);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(200, 130, 31, 0.4);
}


/* ══════ 보드 ══════ */
.board-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}
.board {
  background: var(--board);
  border-radius: var(--radius);
  padding: 8px;
  display: grid;
  gap: 6px;
  aspect-ratio: 1;
  /* 가용 영역에 맞춰 정사각형 유지 — flex 부모가 높이를 제한해줌 */
  width: 100%;
  max-width: 440px;
  max-height: 100%;
  height: auto;
  box-shadow: var(--shadow-md);
  touch-action: none;
}
.board[data-size='4'] { grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); }
.board[data-size='6'] { grid-template-columns: repeat(6, 1fr); grid-template-rows: repeat(6, 1fr); gap: 4px; padding: 6px; }

.cell {
  background: var(--cell);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
}

.tile {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Sunflower', 'Sunflower', sans-serif;
  font-weight: 700;       /* Sunflower 자체 Bold (가짜 볼드 아님) */
  letter-spacing: -0.02em;
  border-radius: var(--radius-sm);
  background: #FFFAF0;
  color: var(--text);
  padding: 2px 4px;
  text-align: center;
  line-height: 1.1;
  word-break: keep-all;
  box-shadow: 0 1px 2px rgba(58, 44, 26, 0.15) inset, 0 2px 4px rgba(58, 44, 26, 0.10);
  /* 매 렌더마다 모든 타일에 적용되면 깜빡임 → 새로 생긴 타일에만 .new 로 */
}
.tile.new {
  animation: tilePop 0.18s ease;
}
@keyframes tilePop {
  0%   { transform: scale(0.4); opacity: 0; }
  100% { transform: scale(1);   opacity: 1; }
}
.tile.merged {
  animation: tileBump 0.22s ease;
  z-index: 2;
}
@keyframes tileBump {
  0%, 100% { transform: scale(1); }
  40%      { transform: scale(1.18); }
}

/* 4×4 타일 폰트 사이즈 */
.board[data-size='4'] .tile { font-size: clamp(0.85rem, 4.6vw, 1.45rem); }
/* 6×6 타일은 더 작게 */
.board[data-size='6'] .tile { font-size: clamp(0.62rem, 2.9vw, 0.95rem); padding: 1px 2px; }

/* 예수님 타일 — 황금 빛남 */
.tile.is-final {
  background: linear-gradient(135deg, #FFE89B 0%, #F4C84A 50%, #C8821F 100%) !important;
  color: #3A2C1A !important;
  font-weight: 800;
  box-shadow:
    0 0 0 2px rgba(255, 213, 107, 0.6),
    0 0 18px rgba(255, 213, 107, 0.7),
    0 0 36px rgba(255, 213, 107, 0.45);
  animation: jesusGlow 1.6s ease-in-out infinite alternate;
}
@keyframes jesusGlow {
  from {
    box-shadow:
      0 0 0 2px rgba(255, 213, 107, 0.55),
      0 0 14px rgba(255, 213, 107, 0.55),
      0 0 30px rgba(255, 213, 107, 0.35);
  }
  to {
    box-shadow:
      0 0 0 3px rgba(255, 213, 107, 0.85),
      0 0 26px rgba(255, 213, 107, 0.95),
      0 0 50px rgba(255, 213, 107, 0.6);
  }
}


/* ══════ 현재 정보 / 힌트 ══════ */
.now-info {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 1.05rem;
  color: var(--text-dim);
}
.now-era {
  padding: 5px 14px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.95rem;
}
.now-era[data-era='kingdom'] { background: rgba(92, 44, 122, 0.12); color: var(--era-purple); }
.now-era[data-era='exile']   { background: rgba(45, 79, 122, 0.12); color: var(--era-blue); }
.now-name b { color: var(--text); font-weight: 700; font-family: 'Sunflower', sans-serif; }

.hint {
  font-size: 0.78rem;
  color: var(--text-soft);
  text-align: center;
  flex: none;
}
.hint b { color: var(--text-dim); font-weight: 700; }

/* ── 게임 화면 하단 계보 (현재 모드만 컴팩트하게) ── */
.game-lineage {
  width: 100%;
  max-width: 720px;
  text-align: left;
  font-family: 'Sunflower', 'Sunflower', sans-serif;
  font-size: 0.85rem;
  line-height: 1.6;
  flex: none;
  word-break: keep-all;
  padding: 0 4px;
}
.gl-era {
  margin-bottom: 1px;
}
.gl-era:last-child { margin-bottom: 0; }
.gl-label {
  display: inline-block;
  font-family: 'Gaegu', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 99px;
  margin-right: 5px;
  color: #fff;
  vertical-align: 1px;
  letter-spacing: -0.02em;
}
.gl-era.patriarch .gl-label { background: var(--era-yellow); }
.gl-era.kingdom   .gl-label { background: var(--era-purple); }
.gl-era.exile     .gl-label { background: var(--era-blue); }
.gl-names {
  font-family: 'Sunflower', 'Sunflower', sans-serif;
  font-weight: 700;
}
.gl-era.patriarch .gl-names { color: #8B6F2D; }
.gl-era.kingdom   .gl-names { color: #6B388A; }
.gl-era.exile     .gl-names { color: #2D4F7A; }
.gl-sep {
  margin: 0 3px;
  color: var(--text-soft);
  font-weight: 400;
}
.gl-name.current {
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 0 3px;
  color: var(--accent-hot);
}

/* 6×6 모드는 글자가 많으니 살짝 작게 */
.game-lineage.is-6x6 {
  font-size: 0.76rem;
  line-height: 1.55;
}
.game-lineage.is-6x6 .gl-label {
  font-size: 0.66rem;
  padding: 0 6px;
}


/* ══════ 모달 ══════ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal[hidden] { display: none !important; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(58, 44, 26, 0.55);
  backdrop-filter: blur(6px);
}
.modal-content {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 28px 26px;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow-md);
  text-align: center;
}
.modal-content h2 {
  font-family: 'Sunflower', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--accent);
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 16px;
}

/* 승리 모달 */
.win-content {
  background: linear-gradient(180deg, #FFFAF0 0%, #FFF1D5 100%);
  border-color: rgba(200, 130, 31, 0.4);
  box-shadow: var(--shadow-md), 0 0 60px rgba(255, 213, 107, 0.45);
}
.win-cross {
  font-size: 2.2rem;
  color: var(--accent-hot);
  margin-bottom: 4px;
  text-shadow: 0 2px 8px rgba(255, 213, 107, 0.6);
}
.win-content h2 {
  font-size: 1.55rem;
  background: linear-gradient(135deg, #C8821F, #8B6F2D);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.win-meta {
  font-size: 0.95rem;
  color: var(--text-dim);
  margin-bottom: 14px;
}
.win-meta span {
  font-family: 'Sunflower', sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--accent-hot);
  margin: 0 2px;
}
.bible-quote {
  background: var(--bg);
  border-left: 4px solid var(--accent-hot);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 14px 16px;
  margin: 0 0 16px;
  text-align: left;
}
.bible-quote p {
  font-family: 'Sunflower', sans-serif;
  font-size: 1rem;
  line-height: 1.55;
  color: var(--text);
  margin-bottom: 6px;
}
.bible-quote cite {
  font-style: normal;
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 700;
}
.win-stats, .over-stats {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ws-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}
.ws-row span { color: var(--text-dim); }
.ws-row b { color: var(--accent-hot); font-weight: 700; font-family: 'Sunflower', sans-serif; }


/* ══════ 모바일 ══════ */
@media (max-width: 600px) {
  .home-card { padding: 22px 18px; }
  .home-card h1 { font-size: 1.6rem; }
  .home-card .sub { font-size: 0.84rem; }
  .mode-card { padding: 14px 10px; }
  .mode-size { font-size: 1.25rem; }
  .mode-name { font-size: 0.92rem; }
  .mode-desc { font-size: 0.72rem; }

  #gameScreen { padding: 8px 10px 12px; gap: 6px; }
  .game-header { gap: 6px; }
  .stat-box { padding: 4px 8px; min-width: 50px; }
  .stat-value { font-size: 0.95rem; }
  .ghost-btn { padding: 6px 10px; font-size: 0.76rem; }
  .now-info { font-size: 0.78rem; }
  .hint { font-size: 0.72rem; }
  .game-lineage { font-size: 0.72rem; line-height: 1.45; }
  .game-lineage.is-6x6 { font-size: 0.66rem; line-height: 1.35; }

  .modal-content { padding: 22px 18px; }
  .win-content h2 { font-size: 1.35rem; }
  .bible-quote p { font-size: 0.92rem; }
}
