/* 꼬들 v2 — 디자인 시스템: 라이트 테마 전용, 마이크로 인터랙션 */
:root {
  --bg: #fbfbfb;
  --bg-elev: #f0f0f1;
  --bg-key-hover: #e2e4e8;
  --text: #1a1a1b;
  --text-dim: #6e7275;
  --border: #d3d6da;
  --border-active: #8f9296;
  --key-bg: #d6d9dd;
  --key-text: #1a1a1b;
  --correct: #43a047;
  --present: #d4a72c;
  --absent: #9aa0a6;
  --accent: #43a047;
  --modal-bg: #ffffff;
  --shadow: rgba(0, 0, 0, 0.22);
  --tile-size: min(13vw, 58px);
  --radius: 8px;
}
:root[data-contrast='high'] {
  --correct: #f5793a;
  --present: #85c0f9;
  --accent: #f5793a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  transition: background 0.25s ease, color 0.25s ease;
}
button { font-family: inherit; }
#app {
  max-width: 500px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── 헤더 ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding: 6px 10px;
}
.title {
  font-size: 1.55rem;
  font-weight: 900;
  letter-spacing: 0.28em;
  margin-left: 0.28em;
  background: linear-gradient(135deg, var(--text) 55%, var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.header-side { display: flex; gap: 2px; min-width: 76px; }
.header-side.left { justify-content: flex-start; }
.header-side.right { justify-content: flex-end; }
.icon-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.icon-btn:hover { background: var(--bg-elev); color: var(--text); }
.icon-btn:active { transform: scale(0.9); }
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }

/* ── 메인 ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  width: 100%;
  min-height: 0;
}

/* ── 퍼즐 캡션 ── */
.puzzle-caption {
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin-top: 10px;
}

/* ── 보드 ── */
.board {
  display: grid;
  grid-template-rows: repeat(6, var(--tile-size));
  gap: 6px;
  margin: auto 0;
}
.row { display: grid; grid-template-columns: repeat(6, var(--tile-size)); gap: 6px; }
.tile {
  width: var(--tile-size);
  height: var(--tile-size);
  border: 2px solid var(--border);
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-size: calc(var(--tile-size) * 0.5);
  font-weight: 800;
  user-select: none;
  color: var(--text);
  will-change: transform;
}
/* 보드 등장 스태거 */
.board.enter .row { animation: row-in 0.4s ease backwards; }
.board.enter .row:nth-child(1) { animation-delay: 0.02s; }
.board.enter .row:nth-child(2) { animation-delay: 0.06s; }
.board.enter .row:nth-child(3) { animation-delay: 0.1s; }
.board.enter .row:nth-child(4) { animation-delay: 0.14s; }
.board.enter .row:nth-child(5) { animation-delay: 0.18s; }
.board.enter .row:nth-child(6) { animation-delay: 0.22s; }
@keyframes row-in {
  from { opacity: 0; transform: translateY(10px); }
}

.tile.filled { border-color: var(--border-active); animation: pop 0.12s ease; }
.tile.correct { background: var(--correct); border-color: var(--correct); color: #fff; }
.tile.present { background: var(--present); border-color: var(--present); color: #fff; }
.tile.absent { background: var(--absent); border-color: var(--absent); color: #fff; }
.row.shake { animation: shake 0.5s; }
.tile.dance { animation: dance 0.5s ease both; }

@keyframes pop { 50% { transform: scale(1.14); } }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}
@keyframes dance {
  20% { transform: translateY(-46%); }
  45% { transform: translateY(10%); }
  70% { transform: translateY(-16%); }
  100% { transform: translateY(0); }
}

/* ── 미리보기 ── */
.preview {
  height: 1.8em;
  color: var(--text-dim);
  font-size: 1rem;
  margin: 4px 0 8px;
  letter-spacing: 0.12em;
  transition: color 0.15s;
}
.preview strong { color: var(--text); font-size: 1.1em; }
.preview .answer-reveal {
  color: var(--text);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 12px;
  font-weight: 800;
}

/* ── 키보드 ── */
.keyboard { width: 100%; max-width: 500px; }
.kb-row { display: flex; justify-content: center; gap: 5px; margin-bottom: 6px; }
.key {
  flex: 1;
  max-width: 44px;
  height: 56px;
  border: none;
  border-radius: 6px;
  background: var(--key-bg);
  color: var(--key-text);
  font-size: 1.08rem;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.15s, transform 0.06s, opacity 0.2s;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
}
.key.wide { max-width: 66px; flex: 1.5; font-size: 0.85rem; }
.key:active { transform: translateY(2px) scale(0.97); box-shadow: none; }
.key.correct { background: var(--correct); color: #fff; }
.key.present { background: var(--present); color: #fff; }
.key.absent { background: var(--absent); color: #e6e6e6; box-shadow: none; }
.key.shift-on { background: var(--text); color: var(--bg); }

/* ── 토스트 ── */
.toast-wrap {
  position: fixed;
  top: 11%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 100;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: var(--bg);
  font-weight: 800;
  font-size: 0.95rem;
  padding: 11px 18px;
  border-radius: 8px;
  box-shadow: 0 4px 14px var(--shadow);
  animation: toast-in 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}
.toast.out { opacity: 0; transform: translateY(-4px); transition: opacity 0.3s, transform 0.3s; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px) scale(0.95); }
}

/* ── 모달 ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--shadow);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 16px;
  animation: fade-in 0.15s ease;
}
.modal-backdrop.hidden { display: none; }
@keyframes fade-in { from { opacity: 0; } }
.modal {
  position: relative;
  background: var(--modal-bg);
  border-radius: 14px;
  padding: 26px 24px 22px;
  width: 100%;
  max-width: 430px;
  max-height: 85dvh;
  overflow-y: auto;
  box-shadow: 0 12px 40px var(--shadow);
  animation: modal-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
}
.modal h2 { font-size: 1.15rem; margin-bottom: 12px; letter-spacing: 0.04em; }
.modal h3 { font-size: 0.95rem; margin: 18px 0 8px; }
.modal p { font-size: 0.92rem; line-height: 1.6; margin-bottom: 10px; }
.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  transition: background 0.15s;
}
.modal-close:hover { background: var(--bg-elev); }
.jamo-ex { color: var(--accent); font-weight: 800; }
.example {
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
  margin: 14px 0;
}
.ex-row { display: flex; gap: 4px; margin-bottom: 6px; }
.ex-tile {
  width: 38px;
  height: 38px;
  border: 2px solid var(--border);
  border-radius: 5px;
  display: grid;
  place-items: center;
  font-weight: 800;
}
.ex-tile.correct { background: var(--correct); border-color: var(--correct); color: #fff; }
.ex-tile.present { background: var(--present); border-color: var(--present); color: #fff; }
.ex-tile.absent { background: var(--absent); border-color: var(--absent); color: #fff; }
.ex-caption { font-size: 0.85rem; color: var(--text-dim); margin-bottom: 12px; }
.modal-foot { color: var(--text-dim); font-size: 0.85rem; }

/* ── 통계 ── */
.stats-grid { display: flex; gap: 8px; text-align: center; margin-bottom: 4px; }
.stat { flex: 1; background: var(--bg-elev); border-radius: 10px; padding: 10px 4px; }
.stat-num { font-size: 1.7rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.72rem; color: var(--text-dim); margin-top: 2px; }
.dist { display: flex; flex-direction: column; gap: 5px; }
.dist-row { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; font-weight: 700; }
.dist-row > span { width: 12px; color: var(--text-dim); }
.dist-track { flex: 1; }
.dist-bar {
  background: var(--absent);
  color: #fff;
  font-weight: 800;
  padding: 3px 8px;
  min-width: 26px;
  text-align: right;
  border-radius: 4px;
  transition: width 0.5s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.dist-bar.best { background: var(--correct); }
.setting-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
}
.setting-row small { color: var(--text-dim); font-weight: 400; }
.setting-row input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }

/* ── 컨페티 ── */
.confetti {
  position: fixed;
  top: -12px;
  z-index: 90;
  pointer-events: none;
  border-radius: 2px;
  animation: confetti-fall linear forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(105vh) rotateZ(720deg); opacity: 0.6; }
}

.stats-footer {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 20px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}
.countdown-box { flex: 1; text-align: center; }
.countdown { font-size: 1.55rem; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: 0.04em; }
.share-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--correct);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1.02rem;
  font-weight: 900;
  padding: 13px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.08s;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}
.share-btn:hover { filter: brightness(1.08); }
.share-btn:active { transform: translateY(2px); box-shadow: none; }
.share-btn svg { width: 18px; height: 18px; fill: currentColor; }

/* ── 아카이브 ── */
.archive-list { list-style: none; display: flex; flex-direction: column; gap: 8px; padding: 16px; max-width: 500px; margin: 0 auto; width: 100%; }
.archive-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 700;
}
.archive-item .num { color: var(--text-dim); font-size: 0.9rem; }
.archive-item .word { font-size: 1.15rem; letter-spacing: 0.1em; }
.archive-item .word.today { color: var(--text-dim); font-size: 0.9rem; letter-spacing: 0; }
.archive-note { text-align: center; color: var(--text-dim); font-size: 0.85rem; padding: 8px 16px 24px; }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-weight: 800;
  text-decoration: none;
  padding: 12px 16px;
}

/* ── SEO 콘텐츠 (게임 하단 스크롤 영역) ── */
.seo-content {
  max-width: 500px;
  margin: 0 auto;
  padding: 28px 20px 48px;
  border-top: 1px solid var(--border);
  color: var(--text);
}
.seo-content h2 { font-size: 1.05rem; margin: 22px 0 10px; }
.seo-content p, .seo-content li, .seo-content dd { font-size: 0.9rem; line-height: 1.65; color: var(--text-dim); }
.seo-content strong { color: var(--text); }
.seo-content ol { padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.seo-content dt { font-weight: 800; font-size: 0.92rem; margin-top: 12px; }
.seo-content dd { margin: 4px 0 0; }
.seo-content a { color: var(--accent); font-weight: 700; }

@media (max-width: 360px) {
  :root { --tile-size: 12.5vw; }
  .key { height: 50px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ── 쿠팡 파트너스 슬롯 ── */
.promo { margin: 16px 0; text-align: center; }
.promo-label { font-size: 0.68rem; color: var(--text-dim); font-weight: 800; letter-spacing: 0.05em; }
.promo a { font-weight: 800; display: inline-block; margin: 4px 0; }
.promo-disclosure { font-size: 0.72rem; color: var(--text-dim); margin-top: 6px; line-height: 1.5; text-align: center; }
.coupang-wrap { display: flex; justify-content: center; margin: 8px 0; min-height: 140px; max-width: 100%; overflow-x: hidden; }

/* ── 쿠팡 사이드 레일 (넓은 화면 전용) ── */
.side-rail { position: fixed; top: 90px; width: 160px; display: none; z-index: 5; }
@media (min-width: 900px) { .side-rail { display: block; } }
.side-l { left: calc(50% - 434px); }
.side-r { left: calc(50% + 274px); }
.fs-active .side-rail { display: none !important; }
