/* Mahjong Encore. Tile geometry comes from --tw/--th/--dz/--gap on .ltm-board and each
   tile's left/top, all written by mahjong-encore.js from the stage's measured box: the
   stage carries the size, the board never does. Nothing here may use `inset`, flex `gap` or an
   svh length outside @supports — the game has to run on Safari 14. */

.game-root[data-game="mahjong-encore"] { padding: 14px 16px 16px; text-align: left; }
.ltm { position: relative; width: 100%; align-self: stretch; display: flex; flex-direction: column; text-align: center; }

.ltm-bar {
  display: flex; justify-content: space-between; align-items: center;
  min-height: 34px; margin: 0 4px 8px; font-size: 1.05rem; font-weight: 700; color: var(--c-text);
}
.ltm-left { margin-left: auto; color: var(--c-text-soft); font-weight: 600; }
/* 66:34 is the notes' viewBox; keep the two in step. --beat comes from the song's tempo: each
   note bobs once every four beats, the next one a beat behind. */
.ltm-notes { display: block; flex: none; width: 62px; height: 32px; overflow: visible; transition: opacity .3s ease; }
.ltm-note { animation: ltm-bob calc(var(--beat, .7s) * 4) ease-in-out calc(var(--beat, .7s) * var(--k)) infinite; }
.ltm-notes.still .ltm-note { animation: none; }
.ltm-notes.off { opacity: .35; filter: grayscale(1); }
@keyframes ltm-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

/* The stage's height is the board's budget: the window less the header band and every row of
   chrome round the stage, measured (300px in the page card, 280px on a phone). */
.ltm-stage {
  position: relative; flex: none; padding: 10px; border-radius: 14px;
  height: clamp(320px, calc(100vh - 300px), 760px);
  background: radial-gradient(120% 100% at 50% 0%, #f2f4f0 0%, #e6eae2 55%, #dde3d8 100%);
  box-shadow: inset 0 1px 3px rgba(60, 70, 50, .12);
}
@supports (height: 100svh) {
  .ltm-stage { height: clamp(320px, calc(100svh - 300px), 760px); }
}
@media (max-height: 520px) and (min-width: 641px) {
  .ltm-stage { height: max(200px, calc(100vh - 214px)); }
}
@media (max-width: 640px) {
  .game-root[data-game="mahjong-encore"] {
    padding: 6px 0 8px; margin-top: 6px; border: 0; border-radius: 0; background: none; box-shadow: none;
  }
  .ltm-stage { height: max(300px, calc(100vh - 280px)); padding: 6px; border-radius: 12px; }
  @supports (height: 100svh) {
    .ltm-stage { height: max(300px, calc(100svh - 280px)); }
  }
  .ltm-bar { font-size: 1rem; margin-bottom: 6px; }
}

/* The page-filling panel (game-layout.css sizes it): the column takes the panel's height and the
   stage whatever the rows leave. */
html.fills-window .game-root[data-game="mahjong-encore"] .ltm:not(.ltm-full) { height: 100%; }
html.fills-window .game-root[data-game="mahjong-encore"] .ltm:not(.ltm-full) .ltm-stage { flex: 1 1 0; min-height: 0; height: auto; }

/* Full screen: the game over the page, on the Fullscreen API or as the fixed fallback. */
.ltm.ltm-full {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 200; margin: 0;
  padding: 10px 12px 12px; overflow: hidden;
  background: radial-gradient(120% 100% at 50% 0%, #fbfbf8 0%, #eef1ea 60%, #e3e8dd 100%);
}
.ltm.ltm-full .ltm-stage { flex: 1 1 0; min-height: 0; height: auto; }
body.ltm-locked { overflow: hidden; }

/* ---------- the board ---------- */
/* isolation: the tiles' z-indexes climb past 4000 and must not compete with the end card. */
.ltm-board { position: absolute; isolation: isolate; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
.ltm-tile {
  position: absolute; width: var(--tw); height: var(--th);
  padding: 0; border: 0; background: none; font: inherit; cursor: default;
  transition: transform .09s ease; -webkit-tap-highlight-color: transparent;
}
.ltm-tile[hidden] { display: none; }
/* The body is the tile's thickness, sticking out past the face to the right and below: within a
   layer the next tile along is painted over it, so only the outer edge and stacked tiles show it. */
.ltm-body {
  position: absolute; left: 0; top: 0;
  right: calc(-1 * var(--dz)); bottom: calc(-1 * var(--dz));
  border-radius: calc(var(--tw) * .12);
  background: linear-gradient(152deg, #d6c29a 0%, #b49b6d 42%, #8a7245 100%);
  box-shadow: 0 0 0 1px rgba(78, 64, 36, .5),
              calc(var(--dz) * (.4 + var(--lz) * .3)) calc(var(--dz) * (.7 + var(--lz) * .45))
              calc(var(--dz) * (1.2 + var(--lz) * .7)) rgba(28, 32, 50, calc(.36 + var(--lz) * .06));
}
.ltm-face {
  position: absolute; left: 0; top: 0; right: var(--gap); bottom: var(--gap);
  display: flex; align-items: center; justify-content: center;
  border: 1px solid #bfae87; border-radius: calc(var(--tw) * .1);
  background: linear-gradient(155deg, #fffefa 0%, #fdf8ec 55%, #f5eeda 100%);
  overflow: hidden;
}
.ltm-face img { width: 90%; height: 90%; object-fit: contain; pointer-events: none; }
.ltm-tile.free { cursor: pointer; }
.ltm-tile.free:hover .ltm-face { background: linear-gradient(155deg, #ffffff 0%, #fffdf4 55%, #fbf6e6 100%); }
.ltm-tile.free:focus-visible { outline: 3px solid #2e9d57; outline-offset: 2px; border-radius: 8px; }
/* The shade is on every tile and switched with opacity, so a tile a match frees is seen coming
   out of it. */
.ltm-tile .ltm-face::after {
  content: ''; position: absolute; top: 0; right: 0; bottom: 0; left: 0; pointer-events: none;
  background: rgba(90, 78, 50, .3); opacity: 0; transition: opacity .3s ease;
}
.ltm-tile.blocked .ltm-face::after { opacity: 1; }
.ltm-tile.sel { transform: translateY(calc(var(--tw) * -.07)); }
.ltm-tile.sel .ltm-face { background: #effaf2; box-shadow: inset 0 0 0 calc(var(--tw) * .065) #2e9d57; }
.ltm-tile.hint .ltm-face { animation: ltm-flash .6s ease-in-out 4; }
/* Straight up only: a sideways lift slides under the next tile along, whose z-index is higher. */
.ltm-tile.ltm-guide { animation: ltm-guide 1.6s ease-in-out infinite; }
.ltm-tile.ltm-guide .ltm-body { animation: ltm-guide-body 1.6s ease-in-out infinite; }
.ltm-tile.nope { animation: ltm-nope .4s ease; }
@keyframes ltm-flash { 50% { background: #fff4d6; box-shadow: inset 0 0 0 calc(var(--tw) * .075) #f0a020; } }
@keyframes ltm-guide { 50% { transform: translateY(calc(var(--tw) * -.12)); } }
@keyframes ltm-guide-body {
  50% { box-shadow: 0 0 0 1px rgba(78, 64, 36, .5),
                    0 0 0 calc(4px * var(--ltm-u, 1)) rgba(46, 157, 87, .95),
                    0 0 calc(18px * var(--ltm-u, 1)) calc(6px * var(--ltm-u, 1)) rgba(46, 157, 87, .5); }
}
@keyframes ltm-nope { 25% { transform: translateX(calc(var(--tw) * -.06)); } 75% { transform: translateX(calc(var(--tw) * .06)); } }

/* ---------- the match ----------
   POP_MS in the script is this animation's length. Every fixed size is multiplied by --ltm-u
   (tile width over 62px), so a bigger tile gets a bigger copy of the same burst. */
.ltm-tile.ltm-go { pointer-events: none; animation: ltm-go .18s linear forwards; }
.ltm-tile.ltm-go .ltm-face { animation: ltm-go-face .18s linear forwards; }
@keyframes ltm-go-face {
  25%  { background: #fff6d8; box-shadow: inset 0 0 0 3px #ff9d2e, 0 0 14px #ffb02e; }
  100% { background: #ffb85e; box-shadow: inset 0 0 0 3px #f4710b; }
}
@keyframes ltm-go {
  0%   { transform: scale(1); opacity: 1; }
  25%  { transform: scale(1.22); opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}
.ltm-fx { position: absolute; pointer-events: none; }
.ltm-spark {
  z-index: 5000;
  width: calc(5px * var(--ltm-u, 1)); height: calc(13px * var(--ltm-u, 1));
  margin: calc(-6.5px * var(--ltm-u, 1)) calc(-2.5px * var(--ltm-u, 1));
  border-radius: 3px;
  background: linear-gradient(#fff4d2 0%, #ffab24 55%, #f4710b 100%);
  box-shadow: 0 0 calc(9px * var(--ltm-u, 1)) rgba(244, 113, 11, .85);
  animation: ltm-spark .44s cubic-bezier(.16, .58, .5, 1) var(--delay, 0ms) both;
}
@keyframes ltm-spark {
  0%   { opacity: 0; transform: translate(0, 0) rotate(var(--rot, 0deg)) scale(.3); }
  10%  { opacity: 1; transform: translate(calc(var(--sx) * .14), calc(var(--sy) * .14)) rotate(var(--rot, 0deg)) scale(1.15); }
  70%  { opacity: .9; transform: translate(calc(var(--sx) * .82), calc(var(--sy) * .82)) rotate(var(--rot, 0deg)) scale(.85); }
  100% { opacity: 0; transform: translate(var(--sx), var(--sy)) rotate(var(--rot, 0deg)) scale(.45); }
}
.ltm-ring {
  z-index: 4990;
  width: calc(14px * var(--ltm-u, 1)); height: calc(14px * var(--ltm-u, 1));
  margin: calc(-7px * var(--ltm-u, 1));
  border: calc(4px * var(--ltm-u, 1)) solid #ff9d2e; border-radius: 50%;
  box-shadow: 0 0 calc(12px * var(--ltm-u, 1)) rgba(244, 113, 11, .8), inset 0 0 calc(6px * var(--ltm-u, 1)) rgba(255, 244, 210, .9);
  animation: ltm-ring .26s cubic-bezier(.12, .68, .45, 1) both;
}
@keyframes ltm-ring {
  0%   { opacity: .95; transform: scale(.3); }
  70%  { opacity: .5; }
  100% { opacity: 0; transform: scale(3.4); }
}

/* ---------- the rows under the board ---------- */
/* Two lines, always: a line that grew and shrank would move the buttons under a finger. */
.ltm-msg {
  display: flex; align-items: center; justify-content: center;
  height: 2.7em; margin: 6px 6px 6px; overflow: hidden;
  font-size: 1.02rem; line-height: 1.35; font-weight: 600; color: var(--c-text);
}
.ltm-controls { display: flex; justify-content: center; margin: 0 -4px; }
.ltm-ctl {
  flex: 1 1 0; max-width: 150px; min-width: 0; margin: 0 4px; min-height: 58px; padding: 6px 2px;
  white-space: nowrap;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border: 1px solid var(--c-border); border-radius: 12px; background: #fff; color: var(--c-text);
  font: inherit; font-size: .95rem; font-weight: 700; line-height: 1.15; cursor: pointer;
  box-shadow: 0 1px 2px rgba(28, 32, 50, .06); -webkit-tap-highlight-color: transparent;
}
.ltm-ctl:hover { border-color: #2e9d57; }
.ltm-ctl .ltm-icon { width: 24px; height: 24px; margin-bottom: 4px; }
.ltm-ctl.armed { background: #fff4e0; border-color: #e0a040; color: #7a4f00; }
.ltm-icon { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ltm-icon [fill="currentColor"] { fill: currentColor; }
.ltm-opts { display: flex; justify-content: center; flex-wrap: wrap; margin: 8px -4px 0; }
.ltm-opt {
  margin: 0 4px; min-height: 40px; padding: 0 12px;
  border: 1px solid var(--c-border); border-radius: 999px; background: var(--c-bg); color: var(--c-text);
  font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.ltm-opt[aria-pressed="false"] { color: var(--c-text-soft); }
.ltm-fs { display: inline-flex; align-items: center; }
/* Two nested corners drawn in borders, so it cannot tofu. */
.ltm-fsicon {
  position: relative; display: inline-block; width: .85em; height: .72em; margin-right: 7px;
  border: 2px solid currentColor; border-radius: 2px;
}
.ltm-fsicon::before {
  content: ''; position: absolute; top: 2px; right: 2px; bottom: 2px; left: 2px;
  border-top: 2px solid currentColor; border-bottom: 2px solid currentColor; opacity: .45;
}
/* Each row stays one line on a 320px-wide stage: a second line is height the board loses. */
@media (max-width: 420px) {
  .ltm-ctl { font-size: .86rem; }
  .ltm-opts { margin-left: -3px; margin-right: -3px; }
  .ltm-opt { margin: 0 3px; min-height: 36px; padding: 0 9px; font-size: .8rem; }
  .ltm-fsicon { margin-right: 5px; }
  .ltm-msg { font-size: .95rem; }
  .ltm-notes { width: 56px; height: 29px; }
}
@media (max-width: 340px) {
  .ltm-notes { width: 50px; height: 26px; }
  .ltm-left { font-size: .9rem; }
}

/* A short, wide window (a phone on its side): every row of chrome under the board would cost the
   tiles their height, so the rows go into a column beside the stage. */
@media (max-height: 520px) and (min-aspect-ratio: 3/2) {
  .game-root[data-game="mahjong-encore"] { padding: 6px; border: 0; border-radius: 0; background: none; box-shadow: none; }
  .ltm {
    display: grid; grid-template-columns: minmax(0, 1fr) 184px; grid-template-rows: auto auto auto auto;
    column-gap: 10px; align-content: center;
  }
  .ltm-stage { grid-column: 1; grid-row: 1 / span 4; height: max(200px, calc(100vh - 24px)); }
  .ltm-bar { grid-column: 2; grid-row: 1; flex-direction: column; align-items: flex-start; margin: 0 0 4px; font-size: .92rem; }
  .ltm-left { margin-left: 0; }
  .ltm-notes { width: 52px; height: 27px; margin-bottom: 4px; }
  .ltm-msg { grid-column: 2; grid-row: 2; height: 5.4em; margin: 2px 0 6px; font-size: .85rem; justify-content: flex-start; text-align: left; }
  .ltm-controls { grid-column: 2; grid-row: 3; flex-wrap: wrap; margin: 0 -3px; }
  .ltm-ctl { flex: 0 0 auto; width: calc(50% - 6px); max-width: none; min-height: 50px; margin: 3px; font-size: .82rem; }
  .ltm-ctl .ltm-icon { width: 20px; height: 20px; margin-bottom: 2px; }
  .ltm-opts { grid-column: 2; grid-row: 4; flex-direction: column; align-items: stretch; margin: 6px 0 0; }
  .ltm-opt { margin: 3px 0; min-height: 34px; font-size: .8rem; }
  .ltm-fs { justify-content: center; }
  .ltm.ltm-full .ltm-stage { height: auto; }
}
@supports (height: 100svh) {
  @media (max-height: 520px) and (min-aspect-ratio: 3/2) {
    .ltm-stage { height: max(200px, calc(100svh - 24px)); }
  }
}

/* ---------- the end card ----------
   Over the whole game, not just the stage: on a short screen the stage alone is too small. */
.ltm-pop {
  position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 20;
  display: none; align-items: center; justify-content: center; padding: 10px;
  border-radius: 14px; background: rgba(40, 48, 36, .16);
}
.ltm-pop.on { display: flex; }
.ltm-card {
  width: 94%; max-width: 360px; max-height: 100%; overflow: auto;
  padding: 20px 22px 16px; border: 1px solid var(--c-border); border-radius: 16px;
  background: rgba(255, 255, 255, .97); box-shadow: 0 12px 34px rgba(28, 32, 50, .22);
  text-align: center; animation: ltm-in .35s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes ltm-in { from { opacity: 0; transform: translateY(10px) scale(.94); } }
.ltm .ltm-h { margin: 0 0 6px; font-size: 1.8rem; line-height: 1.2; font-weight: 800; color: var(--c-text); }
.ltm-card-line { margin: 0 0 4px; font-size: 1.1rem; font-weight: 600; color: var(--c-text); }
.ltm-card-time { margin: 0 0 14px; font-size: .85rem; color: var(--c-text-soft); }
.ltm-next { width: 100%; min-height: 50px; font-size: 1.1rem; }
.ltm-ask { margin: 14px 0 0; font-weight: 600; color: var(--c-text); }
.ltm-chips { display: flex; justify-content: center; flex-wrap: wrap; margin: 8px -4px 0; }
.ltm-chip {
  display: inline-flex; align-items: center; margin: 4px; min-height: 42px; padding: 0 14px;
  border: 1px solid var(--c-border); border-radius: 999px; background: #fff; color: var(--c-text);
  font: inherit; font-size: .95rem; font-weight: 600; cursor: pointer;
}
.ltm-chip .ltm-icon { width: 20px; height: 20px; margin-right: 6px; }
.ltm-chip.on { border-color: #2e9d57; background: #eefaf1; color: #1f7a42; }
.ltm-note { min-height: 1.2em; margin: 8px 0 0; font-size: .88rem; color: var(--c-text-soft); }
.ltm-kbd { padding: 1px 6px; border: 1px solid var(--c-border); border-bottom-width: 2px; border-radius: 5px; background: #fff; font: inherit; font-size: .82rem; }
/* After the card's own rules, or they win on source order. Three moods on one row at 320px. */
@media (max-width: 420px) {
  .ltm-pop { padding: 6px; }
  .ltm-card { width: 97%; padding: 18px 10px 14px; }
  .ltm-chips { margin-left: -3px; margin-right: -3px; }
  .ltm-chip { margin: 3px; padding: 0 9px; font-size: .88rem; }
  .ltm-chip .ltm-icon { width: 18px; height: 18px; margin-right: 5px; }
}

/* ---------- review build ---------- */
.ltm-tools {
  display: flex; flex-wrap: wrap; align-items: center; margin: -14px 0 22px; padding: 8px 10px;
  border: 1px dashed #c9b26a; border-radius: 10px; background: #fffbea; font-size: .85rem;
}
.ltm-tools > * { margin: 3px 4px; }
.ltm-tools-tag { font-weight: 700; color: #8a6a10; }
.ltm-tool { padding: 4px 10px; border: 1px solid #d8c27a; border-radius: 8px; background: #fff; color: #4a3d10; font: inherit; cursor: pointer; }
.ltm-tools-note { flex-basis: 100%; color: #6b5a20; word-break: break-all; }
.ltm-tools-note:empty { display: none; }
