/* =========================================================================
 * style.css — Mahjong Solitaire
 *
 * 시니어 사용성 우선: 큰 터치 타겟, 명확한 대비, 절제된 애니메이션.
 * 배경은 차분한 초록 펠트톤. 프레임워크/외부 폰트 없음(시스템 폰트만).
 * ========================================================================= */

/* ---- 리셋 & 기본 ------------------------------------------------------- */
* {
  box-sizing: border-box;
}

:root {
  --felt-dark: #0b4a35;
  --felt: #146b4c;
  --felt-light: #1c8a63;
  --ink: #0f2419;
  --paper: #fdfcf8;
  --paper-dim: #eef1ec;
  --accent: #f2b705;
  --accent-ink: #3a2a00;
  --danger: #b3261e;
  --focus-ring: #ffd166;
  --tile-face: #fbf7ec;
  --tile-edge: #cfc6ab;
  --tile-locked-face: #cfcabd;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.3);

  /* 타일 크기 3단계 — 설정에서 토글, 기본값은 large */
  --unit-normal: 18px;
  --unit-large: 22px;
  --unit-xlarge: 28px;
  --unit: var(--unit-large);
}

html {
  height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  /* 보드 확대 시 내부 가로 스크롤(#board-viewport)은 의도된 것이지만,
   * 페이지 전체가 옆으로 밀리는 일은 절대 없어야 한다는 안전장치. */
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 18px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
}

body[data-tile-size="normal"] { --unit: var(--unit-normal); }
body[data-tile-size="large"]  { --unit: var(--unit-large); }
body[data-tile-size="xlarge"] { --unit: var(--unit-xlarge); }

h1, h2, h3 {
  line-height: 1.25;
}

a { color: #0a5c8a; }
a:visited { color: #5c3d99; }

/* 포커스 링: 항상 뚜렷하게 */
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 12px 18px;
  z-index: 1000;
  font-weight: 700;
  border-radius: 0 0 8px 0;
}
.skip-link:focus {
  left: 0;
}

/* ---- 헤더 -------------------------------------------------------------- */
.site-header {
  background: linear-gradient(180deg, var(--felt-dark), var(--felt));
  color: var(--paper);
  padding: 14px clamp(12px, 3vw, 28px);
  text-align: center;
}

.site-header h1 {
  margin: 0;
  font-size: clamp(20px, 3.2vw, 28px);
}

.site-header .tagline {
  margin: 4px 0 0;
  font-size: 15px;
  opacity: 0.9;
}

/* ---- 게임 영역 레이아웃 -------------------------------------------------
 * 데스크톱: 보드 + 우측 광고 슬롯을 나란히. 모바일: 세로로 쌓임.
 * ------------------------------------------------------------------------- */
.game-shell {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  padding: 16px clamp(12px, 3vw, 28px) 8px;
  max-width: 1280px;
  margin: 0 auto;
}

@media (min-width: 980px) {
  .game-shell {
    grid-template-columns: 1fr minmax(300px, 320px);
    align-items: start;
  }
}

.game-column {
  min-width: 0;
}

/* ---- 상단 툴바(상시 버튼 4개 + 상태 표시) -------------------------------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.toolbar-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  min-width: 48px;
  padding: 10px 16px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  color: var(--paper);
  background: var(--felt);
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background-color 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: var(--felt-light); }
.btn:active { transform: translateY(1px); }
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn .btn-icon {
  font-size: 20px;
  line-height: 1;
}
.btn-accent {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: rgba(0, 0, 0, 0.15);
}
.btn-accent:hover { background: #ffc72c; }
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: #b9c2ba;
}
.btn-ghost:hover { background: var(--paper-dim); }

.status-strip {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 15px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid #d8ddd6;
  border-radius: var(--radius-md);
  padding: 8px 14px;
}
.status-strip .stat-value {
  font-weight: 700;
}
.status-strip .timer-value {
  font-variant-numeric: tabular-nums;
}
body[data-show-timer="false"] .timer-stat { display: none; }

/* ---- 보드 뷰포트 --------------------------------------------------------
 * 초록 펠트 배경. 타일 크기/화면 폭에 맞춰 JS가 --fit-scale을 계산해
 * 적용하고, 필요시 스크롤을 허용한다.
 * ------------------------------------------------------------------------- */
.board-viewport {
  position: relative;
  display: flex;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(255, 255, 255, 0.08), transparent 60%),
    linear-gradient(180deg, var(--felt), var(--felt-dark));
  border-radius: var(--radius-lg);
  padding: 20px;
  min-height: 320px;
  overflow: auto;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.35);
}

/* 크기: JS가 (자연 크기 × fit-scale)로 계산해 인라인으로 설정 —
 * 실제로 축소 렌더링되는 #board가 차지할 시각적 공간을 문서 흐름에
 * 정확히 반영해 가운데 정렬/스크롤이 어긋나지 않게 한다. */
.board-scale-wrap {
  position: relative;
  flex: 0 0 auto;
}

.board {
  position: relative;
  transform: scale(var(--fit-scale, 1));
  transform-origin: top left;
}

.tile-btn {
  position: absolute;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.tile-btn:disabled,
.tile-btn[aria-disabled="true"] {
  cursor: default;
}

.tile-face {
  /* <span>은 기본 display:inline이라 width/height %가 적용되지 않으므로
   * 반드시 block으로 바꿔줘야 한다(안 그러면 타일이 실같이 찌그러짐). */
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(180deg, var(--tile-face), #f1ecdd);
  border: 1px solid var(--tile-edge);
  box-shadow:
    0 2px 0 var(--tile-edge),
    0 3px 4px rgba(0, 0, 0, 0.35);
  transition: opacity 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease, transform 0.05s ease;
}

.tile-face svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* 열린(free) / 잠긴 타일 구분 — 토글로 켜고 끔 */
body[data-show-free="true"] .tile-btn[data-free="true"] .tile-face {
  filter: brightness(1.05);
}
body[data-show-free="true"] .tile-btn[data-free="false"] .tile-face {
  filter: brightness(0.72) saturate(0.85);
  background: linear-gradient(180deg, var(--tile-locked-face), #bfb9a4);
}

.tile-btn[data-free="true"]:hover .tile-face {
  box-shadow:
    0 2px 0 var(--tile-edge),
    0 3px 4px rgba(0, 0, 0, 0.35),
    0 0 0 3px rgba(255, 255, 255, 0.55);
}

.tile-btn[data-selected="true"] .tile-face {
  box-shadow:
    0 2px 0 var(--accent),
    0 0 0 3px var(--accent),
    0 4px 10px rgba(0, 0, 0, 0.4);
  transform: translateY(-2px);
}

.tile-btn[data-hint="true"] .tile-face {
  animation: hint-blink 0.5s ease-in-out 3;
}

.tile-btn.is-removing .tile-face {
  opacity: 0;
}

@keyframes hint-blink {
  0%, 100% { box-shadow: 0 2px 0 var(--tile-edge), 0 3px 4px rgba(0,0,0,0.35); }
  50% { box-shadow: 0 0 0 4px var(--accent), 0 0 16px 4px var(--accent); }
}

@media (prefers-reduced-motion: reduce) {
  .tile-face,
  .tile-btn.is-removing .tile-face,
  .tile-btn[data-hint="true"] .tile-face {
    transition: none;
    animation: none;
  }
}

/* ---- 사이드바(광고 + 통계 요약) ----------------------------------------- */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.ad-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper-dim);
  border: 1px dashed #b9c2ba;
  border-radius: var(--radius-md);
  color: #4b544e;
  font-size: 13px;
  text-align: center;
  margin: 24px auto;
}
.ad-slot--300x250 { width: 300px; height: 250px; }
.ad-slot--728x90 { width: 728px; height: 90px; max-width: 100%; }
.ad-slot--320x100 { width: 320px; height: 100px; max-width: 100%; }

/* 데스크톱 전용(300x250, 728x90) / 모바일 전용(320x100) 슬롯 전환.
 * 광고 자리 자체는 항상 고정 크기라 전환 시에도 레이아웃 이동(CLS) 없음. */
.ad-slot-mobile-only { display: flex; }
.ad-slot-desktop-only { display: none; }
@media (min-width: 768px) {
  .ad-slot-mobile-only { display: none; }
  .ad-slot-desktop-only { display: flex; }
}

/* ---- 설정 패널(톱니바퀴) ------------------------------------------------ */
.settings-panel {
  position: fixed;
  inset: 0;
  background: rgba(15, 36, 25, 0.55);
  display: none;
  align-items: flex-start;
  justify-content: flex-end;
  z-index: 100;
  padding: 16px;
}
.settings-panel[data-open="true"] { display: flex; }

.settings-sheet {
  background: var(--paper);
  border-radius: var(--radius-lg);
  max-width: 420px;
  width: 100%;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 20px;
  box-shadow: var(--shadow-md);
}

.settings-sheet h2 {
  margin-top: 0;
  font-size: 20px;
}

.settings-row {
  margin: 18px 0;
}
.settings-row legend,
.settings-row .settings-label {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 8px;
  display: block;
}

.segmented {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border: none;
  padding: 0;
  margin: 0;
}
.segmented label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  min-height: 48px;
  border: 2px solid #b9c2ba;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 16px;
}
.segmented input {
  width: 20px;
  height: 20px;
}
.segmented input:checked + span,
.segmented label:has(input:checked) {
  font-weight: 700;
}
.segmented label:has(input:checked) {
  border-color: var(--felt);
  background: #e4f2ea;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  font-size: 16px;
}
.toggle-row input[type="checkbox"] {
  width: 24px;
  height: 24px;
}

.settings-stats {
  background: var(--paper-dim);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-size: 15px;
}
.settings-stats dt { font-weight: 600; }
.settings-stats dd { margin: 0 0 8px; }

.settings-close {
  margin-top: 8px;
  width: 100%;
}

/* ---- 모달(승리 / 짝 없음 / 이어하기) ------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 36, 25, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-overlay[data-open="true"] { display: flex; }

.modal-box {
  background: var(--paper);
  border-radius: var(--radius-lg);
  max-width: 420px;
  width: 100%;
  padding: 24px;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.modal-box h2 {
  margin-top: 0;
  font-size: 22px;
}
.modal-box p {
  font-size: 17px;
}
.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}
/* author 규칙(.modal-actions{display:flex})이 hidden 속성의 UA 기본
 * display:none보다 우선순위가 높아 그냥 두면 hidden이 무시된다 —
 * 명시적으로 다시 꺼줘야 한다("더 이상 짝 없음" 모달의 대기 상태에서
 * 버튼을 완전히 숨기는 데 씀). */
.modal-actions[hidden] {
  display: none;
}
@media (min-width: 420px) {
  .modal-actions { flex-direction: row; justify-content: center; }
}
.modal-actions .btn { flex: 1; justify-content: center; }

/* ---- 본문 SEO 섹션 ------------------------------------------------------- */
.content {
  max-width: 820px;
  margin: 0 auto;
  padding: 8px clamp(12px, 3vw, 28px) 40px;
}
.content h2 {
  font-size: 24px;
  margin-top: 40px;
}
.content p {
  font-size: 17px;
}
.faq-item {
  margin: 18px 0;
  padding: 14px 16px;
  background: var(--paper-dim);
  border-radius: var(--radius-md);
}
.faq-item h3 {
  margin: 0 0 6px;
  font-size: 18px;
}
.faq-item p {
  margin: 0;
}

.site-footer {
  text-align: center;
  padding: 24px 16px 40px;
  font-size: 14px;
  color: #5c665e;
}

/* ---- 반응형 세부 조정 ---------------------------------------------------- */
@media (max-width: 640px) {
  body { font-size: 17px; }
  .status-strip { margin-left: 0; width: 100%; justify-content: space-between; }
  .toolbar { flex-direction: column; align-items: stretch; }
  /* 좁은 화면에서 버튼을 2열로 욱여넣으면 "Full Screen" 같은 라벨이 잘릴
   * 수 있어(flex item은 기본적으로 내용보다 좁아지지 않음) 세로로 한 줄씩
   * 넉넉하게 쌓는다 — 큰 터치 타겟에도 유리하다. */
  .toolbar-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .toolbar-buttons .btn { width: 100%; justify-content: center; }
}
