/* Mahjong Solitaire — turtle layout */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: clamp(28px, 4.4vw, 40px);
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.05;
}
.page-head .sub {
  color: var(--ink-soft);
  margin: 6px 0 0;
  font-size: 14px;
  min-height: 1.4em;
}
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.meta-row {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 88px;
}
.stat-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-value {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
}

.play {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
}

.board-wrap {
  width: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.board {
  position: relative;
  margin: 0 auto;
  /* Sized in JS via inline style. Width/height represent the bounding box of all tiles. */
}

/* ── Tile ─────────────────────────────────────────────────────────────── */
/*
 * Each tile is positioned absolutely with left/top/z computed in JS.
 * Tile face dimensions are driven by CSS variables --tw / --th.
 * Stacked layers are offset by (--ox, --oy) per layer to give the 3D look.
 */

.tile {
  position: absolute;
  width: var(--tw);
  height: var(--th);
  background: linear-gradient(180deg, #faf3df 0%, #f0e3bb 100%);
  border: 1px solid #8a7a4a;
  border-radius: 6px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.6),
    inset 0 -2px 0 rgba(0,0,0,0.05),
    2px 3px 0 #b9a677,
    3px 5px 0 #8c7a48;
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: transform 120ms ease, box-shadow 120ms ease;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
}

.tile-face {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  line-height: 1;
  color: #1f3a5f;
  pointer-events: none;
}

.tile.is-blocked {
  filter: brightness(0.78) saturate(0.7);
  cursor: not-allowed;
}
.tile.is-blocked .tile-face { opacity: 0.45; }

.tile.is-free { cursor: pointer; }
.tile.is-free:hover {
  transform: translate(-1px, -1px);
}

.tile.is-selected {
  border-color: #c0392b;
  box-shadow:
    inset 0 0 0 2px #c0392b,
    inset 0 1px 0 rgba(255,255,255,0.6),
    2px 3px 0 #b9a677,
    3px 5px 0 #8c7a48;
}
.tile.is-hint {
  animation: hintPulse 1.4s ease-in-out 2;
}
@keyframes hintPulse {
  0%, 100% { box-shadow: inset 0 1px 0 rgba(255,255,255,0.6), 2px 3px 0 #b9a677, 3px 5px 0 #8c7a48; }
  50% {
    box-shadow:
      inset 0 0 0 2px #2d8a4f,
      inset 0 1px 0 rgba(255,255,255,0.6),
      2px 3px 0 #b9a677,
      3px 5px 0 #8c7a48;
  }
}

.tile.is-removing {
  transition: transform 200ms ease, opacity 200ms ease;
  transform: scale(0.6) rotate(6deg);
  opacity: 0;
  pointer-events: none;
}

/* Match flash — both tiles glow gold before removal */
@keyframes mj-match-flash {
  0%   { box-shadow: inset 0 0 0 2px #d5c07d, inset 0 1px 0 rgba(255,255,255,0.6), 2px 3px 0 #b9a677, 3px 5px 0 #8c7a48; }
  50%  { box-shadow: inset 0 0 0 3px #d5c07d, 0 0 0 6px rgba(213, 192, 125, 0.5); }
  100% { box-shadow: inset 0 0 0 2px #d5c07d; }
}
.tile.is-match {
  animation: mj-match-flash 320ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .tile.is-hint, .tile.is-removing, .tile.is-match { animation: none; transition: none; }
}

/* Face colours by category */
.tile[data-cat="bam"] .tile-face { color: #2d8a4f; }
.tile[data-cat="dot"] .tile-face { color: #1f3a5f; }
.tile[data-cat="char"] .tile-face,
.tile[data-cat="dragon-red"] .tile-face,
.tile[data-cat="dragon-green"] .tile-face,
.tile[data-cat="dragon-white"] .tile-face,
.tile[data-cat="wind"] .tile-face,
.tile[data-cat="flower"] .tile-face,
.tile[data-cat="season"] .tile-face { color: #1f3a5f; }
.tile[data-cat="dragon-red"] .tile-face { color: #c0392b; }
.tile[data-cat="dragon-green"] .tile-face { color: #2d8a4f; }
.tile[data-cat="flower"] .tile-face { color: #c0392b; }
.tile[data-cat="season"] .tile-face { color: #d4a017; }

.tile-glyph {
  font-size: calc(var(--th) * 0.42);
  line-height: 1;
}
.tile-sub {
  font-family: 'Inter', sans-serif;
  font-size: calc(var(--th) * 0.18);
  letter-spacing: 0.04em;
  margin-top: calc(var(--th) * 0.06);
  font-weight: 600;
  opacity: 0.7;
}

/* ── Overlay (win / stuck) ─────────────────────────────────────────────── */

.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 42, 58, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}
.win-overlay[hidden] { display: none; }
.win-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 28px;
  text-align: center;
  box-shadow: var(--shadow-lift);
  max-width: 360px;
  width: 100%;
}
.win-card h2 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 24px;
  margin: 0 0 8px;
}
.overlay-sub {
  color: var(--ink-soft);
  margin: 0 0 18px;
  font-size: 14px;
}
.overlay-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── How-to-play panel ─────────────────────────────────────────────────── */

.aside-info { margin-top: 22px; }
.aside-info details {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
}
.aside-info summary {
  cursor: pointer;
  font: 700 14px 'Inter', sans-serif;
  color: var(--ink);
}
.aside-info .help-body {
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
}
.aside-info .help-body p { margin: 0 0 8px; }
.aside-info .help-body ul { margin: 0; padding-left: 18px; }
.aside-info .help-body li { margin: 4px 0; }

/* ── Mobile ────────────────────────────────────────────────────────────── */

@media (max-width: 760px) {
  .page-head { gap: 10px; }
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1 1 auto; padding: 8px 10px; font-size: 13px; }
  .meta-row { gap: 8px; }
  .stat { padding: 6px 10px; min-width: 0; flex: 1 1 0; }
  .stat-value { font-size: 15px; }
  .stat-label { font-size: 10px; }
  .play { padding: 8px; }
}

/* ── Fullscreen polish ─────────────────────────────────────────────────── */
body[data-fullscreen="true"] .meta-row {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 30;
  background: rgba(251, 246, 234, 0.92);
  padding: 6px;
  border-radius: 10px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
body[data-fullscreen="true"] .play {
  margin: 0;
  border-radius: 0;
  border: none;
  box-shadow: none;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
