/* ============================================================
   Mahjong solitario — tablero y fichas (templates/play_mahjong.html,
   mahjong_hub.html).

   Profundidad sutil: cada capa se corre --d hacia arriba a la izquierda;
   el canto se dibuja abajo a la derecha (dos tonos: la cara y el dorso de
   color de cada juego) y una sombra muy suave cae sobre la capa inferior.
   Cada juego de fichas define:
     --mj-face  cara       --mj-line  filete     --mj-ink-bg  color de la cara (huecos del SVG)
     --mj-edge1 canto      --mj-edge2 dorso      --mj-edge3   dorso, sombra
     --mj-cast  sombra proyectada
   ============================================================ */
[data-theme-tiles="clasico"] {
  --mj-face: linear-gradient(160deg, #FFFDF8 0%, #F7F0E2 58%, #EDE3CF 100%);
  --mj-line: rgba(120, 95, 55, .2); --mj-ink-bg: #FAF5EA;
  --mj-edge1: #E1D5BD; --mj-edge2: #2F7461; --mj-edge3: #235A4B;
  --mj-cast: rgba(45, 35, 20, .3);
}
[data-theme-tiles="astronomia"] {
  --mj-face: linear-gradient(160deg, #FCFBF8 0%, #F2EFE7 60%, #E8E4D9 100%);
  --mj-line: rgba(46, 63, 114, .16); --mj-ink-bg: #F6F4EE;
  --mj-edge1: #DFDACD; --mj-edge2: #2E3F72; --mj-edge3: #222F57;
  --mj-cast: rgba(25, 30, 55, .3);
}
[data-theme-tiles="naturaleza"] {
  --mj-face: linear-gradient(160deg, #FEFCF5 0%, #F4EFDF 60%, #EAE3CC 100%);
  --mj-line: rgba(80, 100, 50, .18); --mj-ink-bg: #F8F4E8;
  --mj-edge1: #E0D8BF; --mj-edge2: #4A6533; --mj-edge3: #3A5027;
  --mj-cast: rgba(40, 45, 20, .3);
}
[data-theme-tiles="oceano"] {
  --mj-face: linear-gradient(160deg, #FCFDFD 0%, #EFF4F4 60%, #E2EBEC 100%);
  --mj-line: rgba(28, 92, 108, .16); --mj-ink-bg: #F4F8F8;
  --mj-edge1: #D7E1E2; --mj-edge2: #1C5C6C; --mj-edge3: #144552;
  --mj-cast: rgba(15, 45, 55, .3);
}
[data-theme-tiles="geometrico"] {
  --mj-face: linear-gradient(160deg, #FFFFFF 0%, #F6F4F0 60%, #ECE9E3 100%);
  --mj-line: rgba(28, 26, 24, .14); --mj-ink-bg: #FAF9F6;
  --mj-edge1: #E0DCD4; --mj-edge2: #24221F; --mj-edge3: #111;
  --mj-cast: rgba(20, 18, 15, .3);
}
[data-theme-tiles="nocturno"] {
  --mj-face: linear-gradient(160deg, #30343D 0%, #262A31 58%, #1F2228 100%);
  --mj-line: rgba(205, 215, 240, .13); --mj-ink-bg: #292D34;
  --mj-edge1: #1A1C22; --mj-edge2: #121419; --mj-edge3: #0A0B0E;
  --mj-cast: rgba(0, 0, 0, .5);
}

/* ---------- tablero ---------- */
.mj-shell { --tw: 44px; --th: 57px; --d: 4px; }
.mj-stage {
  position: relative; isolation: isolate; overflow: hidden;
  height: clamp(440px, calc(100dvh - 212px), 980px);
  border-radius: var(--r-lg); border: 1px solid var(--line);
  background:
    radial-gradient(110% 80% at 50% 44%, color-mix(in srgb, var(--surface) 64%, var(--surface-2)) 0%, var(--surface-2) 64%, color-mix(in srgb, var(--surface-3) 55%, var(--surface-2)) 100%);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--surface) 70%, transparent), inset 0 -24px 50px -36px rgba(60, 40, 20, .28);
  --tt-table: var(--surface-2);
}
:root[data-theme="dark"] .mj-stage { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .03), inset 0 -24px 50px -36px rgba(0, 0, 0, .6); }
.mj-board { position: absolute; inset: 0; z-index: 0; isolation: isolate; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }

/* ---------- una ficha ---------- */
.mj-tile {
  position: absolute; width: var(--tw); height: var(--th); padding: 0; margin: 0; border: 0; font: inherit;
  border-radius: calc(var(--tw) * .13);
  background: var(--mj-face);
  box-shadow:
    inset 0 0 0 1px var(--mj-line),
    inset 1px 1px 0 rgba(255, 255, 255, .55),
    calc(var(--d) * .5) calc(var(--d) * .5) 0 var(--mj-edge1),
    var(--d) var(--d) 0 var(--mj-edge2),
    calc(var(--d) + .8px) calc(var(--d) + .8px) 0 var(--mj-edge3),
    calc(var(--d) * 1.3) calc(var(--d) * 2) calc(var(--d) * 2.6) var(--mj-cast);
  cursor: default; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: transform .16s var(--ease), box-shadow .16s var(--ease), filter .22s ease, opacity .22s ease;
}
[data-theme-tiles="nocturno"] .mj-tile { box-shadow:
    inset 0 0 0 1px var(--mj-line), inset 1px 1px 0 rgba(255, 255, 255, .06),
    calc(var(--d) * .5) calc(var(--d) * .5) 0 var(--mj-edge1), var(--d) var(--d) 0 var(--mj-edge2),
    calc(var(--d) + .8px) calc(var(--d) + .8px) 0 var(--mj-edge3), calc(var(--d) * 1.3) calc(var(--d) * 2) calc(var(--d) * 2.6) var(--mj-cast); }
.mj-face { position: absolute; inset: 5% 6%; display: block; pointer-events: none; }
.mj-face svg { display: block; width: 100%; height: 100%; }
.mj-tile.is-free { cursor: pointer; }
@media (hover: hover) {
  .mj-tile.is-free:hover { transform: translate(-1px, -2px); }
}
.mj-tile:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.mj-tile.is-sel {
  transform: translate(-1px, -4px);
  box-shadow:
    inset 0 0 0 1px var(--mj-line), inset 1px 1px 0 rgba(255, 255, 255, .55),
    calc(var(--d) * .5) calc(var(--d) * .5) 0 var(--mj-edge1), var(--d) var(--d) 0 var(--mj-edge2),
    calc(var(--d) + .8px) calc(var(--d) + .8px) 0 var(--mj-edge3),
    calc(var(--d) * 2) calc(var(--d) * 3.4) calc(var(--d) * 4) var(--mj-cast),
    0 0 0 2px color-mix(in srgb, var(--sel) 85%, transparent),
    0 0 16px 1px color-mix(in srgb, var(--sel) 30%, transparent);
}
.mj-tile.is-hint { animation: mj-hint .85s ease-in-out 2; }
@keyframes mj-hint {
  50% { box-shadow:
    inset 0 0 0 1px var(--mj-line), calc(var(--d) * .5) calc(var(--d) * .5) 0 var(--mj-edge1), var(--d) var(--d) 0 var(--mj-edge2),
    calc(var(--d) + .8px) calc(var(--d) + .8px) 0 var(--mj-edge3),
    0 0 0 2px color-mix(in srgb, var(--present) 85%, transparent), 0 0 18px 2px color-mix(in srgb, var(--present) 40%, transparent); }
}
.mj-tile.is-blocked { filter: brightness(.88) saturate(.7); }
[data-theme-tiles="nocturno"] .mj-tile.is-blocked { filter: brightness(.68) saturate(.7); }
.mj-tile.is-leaving { animation: mj-out .22s ease forwards; pointer-events: none; }
.mj-tile.is-gone { visibility: hidden; pointer-events: none; }
@keyframes mj-out { to { opacity: 0; transform: translateY(-7px) scale(.94); } }

/* final: una sola luz suave que se abre y se va */
.mj-stage.is-complete::after {
  content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(40% 40% at 50% 50%, color-mix(in srgb, var(--present) 22%, transparent), transparent 70%);
  animation: mj-bloom 1.8s ease-out forwards;
}
@keyframes mj-bloom { from { opacity: 0; transform: scale(.6); } 35% { opacity: 1; } to { opacity: 0; transform: scale(1.5); } }

.mj-msg {
  position: absolute; left: 50%; bottom: 12px; z-index: 20; max-width: calc(100% - 24px); margin: 0;
  padding: 8px 14px; border-radius: var(--r-pill); background: var(--ink); color: var(--on-ink);
  font-size: var(--t-xs); text-align: center; box-shadow: var(--shadow-md);
  transform: translate(-50%, 6px); opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s var(--ease);
}
.mj-msg.is-on { opacity: 1; transform: translate(-50%, 0); }
.play-mahjong .tool-btn.is-hint { color: var(--ink); background: color-mix(in srgb, var(--present) 20%, transparent); animation: mj-attn 1.4s ease 2; }
@keyframes mj-attn { 50% { background: color-mix(in srgb, var(--present) 36%, transparent); } }

/* ---------- selector de fichas y de distribución ---------- */
.mj-theme-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mj-theme-grid .mj-mini { width: 32px; height: 42px; }
.mj-prev { display: flex; gap: 3px; }
.mj-mini {
  position: relative; width: 26px; height: 34px; border-radius: 4px; background: var(--mj-face);
  box-shadow: inset 0 0 0 1px var(--mj-line), 1px 1px 0 var(--mj-edge1), 2px 2px 0 var(--mj-edge2);
}
.mj-mini .mj-face { inset: 4% 5%; }
.mj-layout-list { display: grid; gap: 8px; margin-top: 14px; text-align: left; }
.mj-layout-opt {
  display: flex; align-items: center; gap: 14px; padding: 10px 12px; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); cursor: pointer; text-align: left;
  transition: background var(--dur), border-color var(--dur);
}
.mj-layout-opt:hover { background: var(--surface-2); border-color: var(--line-2); }
.mj-layout-opt b { display: block; font-weight: 600; font-size: var(--t-sm); }
.mj-layout-opt small { display: block; color: var(--muted); font-size: var(--t-xs); }
.mj-layout-mini { flex: none; display: grid; place-items: center; width: 74px; height: 46px; }
.mj-layout-mini svg { width: 100%; height: 100%; }
.mj-layout-mini rect { fill: var(--ink); }

/* ---------- portada ---------- */
.mj-hub-art { position: relative; height: 150px; border-radius: var(--r-lg); border: 1px solid var(--line); overflow: hidden;
  background: radial-gradient(110% 90% at 50% 40%, color-mix(in srgb, var(--surface) 60%, var(--surface-2)), var(--surface-2)); }
.mj-hub-art .mj-tile { --tw: 40px; --th: 52px; --d: 4px; }
.mj-hub-layouts { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.mj-hub-layouts label { position: relative; }
.mj-hub-layouts input { position: absolute; opacity: 0; pointer-events: none; }
.mj-hub-layouts span {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 6px; border-radius: var(--r-md);
  border: 1px solid var(--line-2); background: var(--surface); font-size: var(--t-xs); color: var(--ink-2); cursor: pointer;
  transition: background var(--dur), border-color var(--dur);
}
.mj-hub-layouts .mj-layout-mini { width: 60px; height: 34px; }
.mj-hub-layouts input:checked + span { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); color: var(--ink); font-weight: 600; }
.mj-hub-layouts input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.mj-hub-themes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.mj-hub-themes .tt-skin-opt { padding: 8px 4px 6px; gap: 6px; font-size: .7rem; }
.mj-hub-themes .mj-mini { width: 20px; height: 26px; }

@media (max-width: 640px) {
  .mj-stage { height: clamp(420px, calc(100dvh - 196px), 900px); margin: 0 -4px; }
  .play-mahjong .tt-hud { gap: 10px; }
  .play-mahjong .tt-hud-i small { font-size: .58rem; }
}
@media (prefers-reduced-motion: reduce) {
  .mj-tile { transition: none; }
  .mj-tile.is-hint, .mj-tile.is-leaving, .mj-stage.is-complete::after, .play-mahjong .tool-btn.is-hint { animation: none; }
}
