/* Mahjong Solitaire — a garden pavilion at dusk, lanterns lit. Self-contained. */

@import url("https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,600;0,700;1,600&family=Manrope:wght@500;700;800&display=swap");
/* the Chinese characters on the tiles, as a tiny subset: the numerals, wan, the winds and the dragons */
@import url("https://fonts.googleapis.com/css2?family=Noto+Serif+TC:wght@900&text=%E4%B8%80%E4%BA%8C%E4%B8%89%E5%9B%9B%E4%BA%94%E5%85%AD%E4%B8%83%E5%85%AB%E4%B9%9D%E8%90%AC%E6%9D%B1%E5%8D%97%E8%A5%BF%E5%8C%97%E4%B8%AD%E7%99%BC&display=block");

:root{
  --ink: #f6ecdc;
  --dim: rgba(246, 236, 220, 0.78);
  --faint: rgba(246, 236, 220, 0.5);
  --bg: #120708;
  --lamp: #e8a24a;
  --lamp-lite: #f6cd84;
  --jade: #4fae84;
  --cinnabar: #c2331e;
  --line: rgba(240, 190, 120, 0.2);
  --glass: rgba(24, 9, 8, 0.82);
  --font-display: "Cormorant Garamond", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --font-ui: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
}

*, *::before, *::after{ box-sizing: border-box; }
html, body{
  height: 100%; margin: 0; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
canvas#canvas{
  display: block; width: 100%; height: 100%; touch-action: none;
  -webkit-touch-callout: none; user-select: none; -webkit-user-select: none;
}

/* ---------- the status bar ---------- */
.hud{
  position: fixed; z-index: 6; pointer-events: none;
  top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  padding: 6px 16px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--glass);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  white-space: nowrap;
}
.hud[hidden]{ display: none; }
.hud__item{ display: flex; flex-direction: column; align-items: center; line-height: 1.1; min-width: 44px; }
.hud__num{ font-family: var(--font-display); font-weight: 700; font-size: 1.32rem; font-variant-numeric: tabular-nums lining-nums; color: var(--ink); }
.hud__lab{ font-size: 0.6rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); }
.hud__sep{ width: 1px; height: 26px; background: var(--line); }
#hudMatchBox.is-none .hud__num{ color: #ff9a7a; }
#hudMatchBox.is-none .hud__lab{ color: rgba(255, 154, 122, 0.8); }

/* ---------- the bar ---------- */
.bar{
  position: fixed; z-index: 6; left: 50%; transform: translateX(-50%);
  bottom: max(40px, calc(env(safe-area-inset-bottom) + 30px));
  display: flex; flex-wrap: nowrap; justify-content: center; align-items: center; gap: 6px;
  padding: 6px;
  border: 1px solid var(--line); border-radius: 15px;
  background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  width: max-content; max-width: calc(100vw - 16px);
}
.bar[hidden]{ display: none; }
.btn{
  appearance: none; cursor: pointer;
  font-family: var(--font-ui); font-size: 0.82rem; font-weight: 800; letter-spacing: 0.01em;
  min-height: 42px; padding: 8px 15px; border-radius: 10px;
  border: 1px solid transparent; background: rgba(246, 205, 132, 0.09); color: var(--ink);
  transition: background 140ms ease, transform 120ms ease, opacity 140ms ease, box-shadow 140ms ease;
}
.btn[hidden]{ display: none; }
.btn:hover:not(:disabled){ background: rgba(246, 205, 132, 0.17); transform: translateY(-1px); }
.btn:disabled{ opacity: 0.3; cursor: default; }
.btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(232, 162, 74, 0.65); }
.btn--go{ background: linear-gradient(180deg, var(--lamp-lite), var(--lamp)); color: #2c1606; }
.btn--go:hover:not(:disabled){ background: linear-gradient(180deg, #fbdc9e, #ecae5c); }
.btn--toggle[aria-pressed="true"]{ background: rgba(232, 162, 74, 0.2); color: var(--lamp-lite); box-shadow: inset 0 0 0 1px rgba(232, 162, 74, 0.5); }
.btn--big{ padding: 11px 16px; font-size: 0.86rem; }
.btn--sure{ background: rgba(194, 51, 30, 0.38); }
#btnShuffle.is-pulse{ animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse{
  0%, 100%{ box-shadow: 0 0 0 0 rgba(246, 205, 132, 0.0); }
  50%{ box-shadow: 0 0 0 6px rgba(246, 205, 132, 0.35), 0 0 26px rgba(232, 162, 74, 0.7); }
}

/* ---------- callout + notes ---------- */
.callout{
  position: fixed; z-index: 7; pointer-events: none;
  left: 50%; top: 32%; transform: translate(-50%, -50%);
  font-family: var(--font-display); font-weight: 700; letter-spacing: 0.01em;
  font-size: clamp(2rem, 7.5vw, 3.4rem); line-height: 1;
  color: var(--lamp-lite); text-align: center; white-space: nowrap;
  text-shadow: 0 2px 0 #4a250a, 0 0 3px rgba(10, 3, 2, 0.95), 0 0 14px rgba(10, 3, 2, 0.95), 0 0 30px rgba(10, 3, 2, 0.8), 0 0 46px rgba(240, 160, 80, 0.45);
}
.callout[hidden]{ display: none; }
.callout.is-cool{ color: #ffe1cf; text-shadow: 0 2px 0 #3d1a14, 0 0 3px rgba(10, 3, 2, 0.95), 0 0 14px rgba(10, 3, 2, 0.95), 0 0 30px rgba(10, 3, 2, 0.8), 0 0 46px rgba(255, 140, 110, 0.4); }
.callout.is-pop{ animation: pop 1.3s ease both; }
@keyframes pop{
  0%{ opacity: 0; transform: translate(-50%, -40%) scale(0.86); }
  14%{ opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  24%{ transform: translate(-50%, -50%) scale(1); }
  78%{ opacity: 1; }
  100%{ opacity: 0; transform: translate(-50%, -58%); }
}
.note, .size-note{
  position: fixed; z-index: 7; pointer-events: none; margin: 0;
  left: 50%; transform: translateX(-50%);
  top: calc(max(10px, env(safe-area-inset-top)) + 58px);
  padding: 7px 14px; border-radius: 14px;
  width: max-content; max-width: min(460px, calc(100vw - 24px)); text-align: center;
  font-size: 0.78rem; font-weight: 700; line-height: 1.4; color: var(--ink);
  background: rgba(24, 9, 8, 0.9); border: 1px solid var(--line);
  opacity: 0; transition: opacity 260ms ease;
}
.note.is-on{ opacity: 1; }
.size-note{ opacity: 1; top: auto; bottom: calc(max(40px, env(safe-area-inset-bottom) + 30px) + 62px); background: rgba(70, 22, 14, 0.92); }
.size-note[hidden]{ display: none; }

/* ---------- corner buttons ---------- */
.corner-btn{
  position: fixed; z-index: 7;
  top: max(10px, env(safe-area-inset-top));
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--glass); color: var(--ink);
  font-family: var(--font-ui); font-size: 15px; cursor: pointer; backdrop-filter: blur(8px);
  transition: transform 140ms ease, border-color 140ms ease, opacity 140ms ease;
}
.sound-btn{ right: max(12px, env(safe-area-inset-right)); }
.help-btn{ right: max(58px, calc(env(safe-area-inset-right) + 58px)); font-weight: 800; font-size: 16px; }
.corner-btn:hover{ transform: translateY(-1px); border-color: var(--lamp); }
.corner-btn[aria-pressed="false"]{ opacity: 0.45; }
.corner-btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(232, 162, 74, 0.55); }

/* ---------- overlays ---------- */
.overlay{
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: radial-gradient(90% 70% at 50% 40%, rgba(40, 14, 12, 0.55), rgba(8, 3, 3, 0.94));
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  transition: opacity 240ms ease; overflow-y: auto;
}
.overlay[hidden]{ display: none; }
.overlay.is-out{ opacity: 0; pointer-events: none; }
.overlay--lesson{ z-index: 12; }
.panel{
  max-width: 680px; width: 100%; text-align: center; margin: auto;
  padding: clamp(20px, 4vw, 30px);
  border: 1px solid var(--line); border-radius: 20px;
  background: linear-gradient(180deg, rgba(46, 16, 13, 0.96), rgba(16, 6, 6, 0.97));
  box-shadow: 0 30px 90px -20px rgba(0, 0, 0, 0.9), inset 0 1px 0 rgba(246, 205, 132, 0.1);
}
.panel--result{ max-width: 520px; }
.panel--lesson{ max-width: 400px; }
.panel__eyebrow{ margin: 0 0 4px; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.24em; text-transform: uppercase; color: var(--lamp); }
.panel__title{
  margin: 0 0 10px; font-family: var(--font-display); font-weight: 700;
  font-size: clamp(2.5rem, 9vw, 3.9rem); letter-spacing: 0.01em; line-height: 1.02;
  color: var(--ink); text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), 0 10px 30px rgba(0, 0, 0, 0.5);
}
.panel__text{ margin: 0 auto 16px; max-width: 52ch; font-size: 0.88rem; line-height: 1.6; color: var(--dim); }
.panel__text b{ color: var(--ink); font-weight: 800; }

/* ---------- the layout picker ---------- */
.layouts{ display: grid; gap: 8px; margin: 0 0 8px; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); }
.lay{
  appearance: none; cursor: pointer; position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 8px 10px;
  border: 1px solid var(--line); border-radius: 14px;
  background: rgba(246, 205, 132, 0.04); color: var(--ink);
  font-family: var(--font-ui);
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
}
.lay:hover{ transform: translateY(-3px); background: rgba(246, 205, 132, 0.09); border-color: rgba(232, 162, 74, 0.45); }
.lay:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(232, 162, 74, 0.6); }
.lay.is-pick{ border-color: rgba(232, 162, 74, 0.75); background: rgba(232, 162, 74, 0.12); box-shadow: inset 0 0 0 1px rgba(232, 162, 74, 0.4); }
.lay__map{ width: 120px; height: 78px; margin-bottom: 4px; }
.lay__name{ font-family: var(--font-display); font-weight: 700; font-size: 1.16rem; line-height: 1.1; }
.lay__meta{ font-size: 0.68rem; color: var(--faint); }
.lay__best{ font-size: 0.66rem; font-weight: 800; letter-spacing: 0.04em; color: var(--lamp-lite); }
.pick-note{ margin: 0 auto 14px; max-width: 46ch; font-size: 0.72rem; line-height: 1.5; color: var(--faint); }

.play-btn{
  appearance: none; cursor: pointer;
  font-family: var(--font-display); font-weight: 700; font-size: 1.32rem; letter-spacing: 0.01em;
  padding: 10px 30px 11px; border-radius: 999px; border: 0;
  background: linear-gradient(180deg, var(--lamp-lite), var(--lamp));
  color: #2c1606; box-shadow: 0 10px 30px -8px rgba(232, 162, 74, 0.6), inset 0 -2px 0 rgba(120, 60, 10, 0.35);
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.play-btn:hover{ transform: translateY(-2px); box-shadow: 0 16px 38px -10px rgba(232, 162, 74, 0.8), inset 0 -2px 0 rgba(120, 60, 10, 0.35); }
.play-btn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(246, 205, 132, 0.7); }
.panel__keys{ margin: 12px 0 0; font-size: 0.7rem; color: var(--faint); line-height: 1.7; }
.linkbtn{ appearance: none; border: 0; background: none; padding: 2px 0; cursor: pointer; font: inherit; font-weight: 800; color: var(--lamp-lite); text-decoration: underline; text-underline-offset: 3px; }
.linkbtn:focus-visible{ outline: none; box-shadow: 0 0 0 3px rgba(232, 162, 74, 0.55); border-radius: 4px; }

/* ---------- the lesson ---------- */
.lesson__stage{ display: flex; justify-content: center; margin: 6px 0 12px; }
#lessonCv{ width: 260px; height: 170px; border-radius: 14px; box-shadow: 0 18px 40px -16px rgba(0, 0, 0, 0.9), inset 0 0 0 1px rgba(205, 160, 80, 0.4); }
.lesson__title{ margin: 0 0 6px; font-family: var(--font-display); font-weight: 700; font-size: 1.6rem; }
.lesson__text{ margin: 0 auto 8px; max-width: 38ch; font-size: 0.86rem; line-height: 1.55; color: var(--dim); min-height: 4.6em; }
.lesson__aside{ margin: 0 auto 12px; max-width: 38ch; font-size: 0.76rem; line-height: 1.5; color: var(--faint); }
.lesson__aside:empty{ display: none; }
.lesson__aside b{ color: var(--lamp-lite); }
.lesson__nav{ display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.lesson__nav .btn{ min-width: 84px; }
.lesson__dots{ display: flex; gap: 6px; }
.lesson__dots i{ width: 7px; height: 7px; border-radius: 50%; background: rgba(246, 205, 132, 0.2); }
.lesson__dots i.on{ background: var(--lamp); }

/* ---------- result ---------- */
.result__line{ margin: 4px 0 2px; font-size: 0.74rem; font-weight: 800; letter-spacing: 0.18em; text-transform: uppercase; color: var(--dim); }
.result__time{ margin: -4px 0 2px; font-family: var(--font-display); font-weight: 700; font-size: clamp(2.6rem, 10vw, 3.6rem); line-height: 1; color: var(--lamp-lite); font-variant-numeric: lining-nums tabular-nums; text-shadow: 0 0 30px rgba(240, 160, 80, 0.45); }
.result__best{ margin: 4px 0 2px; font-size: 0.84rem; color: var(--ink); }
.result__shuf{ margin: 0 0 16px; font-size: 0.74rem; color: var(--faint); }
.result__btns{ display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; }
.result__record{ margin: 14px 0 8px; font-size: 0.72rem; color: var(--faint); }
.panel--result [data-more-games]{ margin-top: 14px; }

/* ---------- frame + hint ---------- */
.frame{ position: fixed; inset: 0; z-index: 4; pointer-events: none; }
.frame__corner{ position: fixed; font-size: 0.66rem; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--faint); }
.frame__corner--tl{ top: max(14px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); }
.frame__corner--tr{ top: max(14px, env(safe-area-inset-top)); right: max(108px, calc(env(safe-area-inset-right) + 108px)); }
.frame__corner--bl{ bottom: max(14px, env(safe-area-inset-bottom)); left: max(14px, env(safe-area-inset-left)); pointer-events: auto; }
.frame__corner--bl a{ color: var(--faint); text-decoration: none; }
.frame__corner--bl a:hover{ color: var(--lamp); }
body.is-playing .frame__corner--tl, body.is-playing .frame__corner--tr{ display: none; }
.hint{
  position: fixed; z-index: 4; pointer-events: none;
  bottom: max(14px, calc(env(safe-area-inset-bottom) + 4px)); left: 50%; transform: translateX(-50%);
  margin: 0; font-size: 0.7rem; letter-spacing: 0.06em; color: var(--faint); white-space: nowrap;
  transition: opacity 500ms ease;
}
.hint.is-gone{ opacity: 0; }

/* ---------- responsive ---------- */
@media (max-width: 720px){
  .panel__text{ font-size: 0.82rem; }
}
@media (max-width: 620px){
  .hint{ display: none; }
  .hud{ left: max(10px, env(safe-area-inset-left)); transform: none; padding: 5px 12px; gap: 9px; }
  .hud__num{ font-size: 1.12rem; }
  .hud__lab{ font-size: 0.54rem; letter-spacing: 0.08em; }
  .hud__item{ min-width: 36px; }
  .hud__sep{ height: 22px; }
  /* clear the tickets pill and the docked badges along the bottom edge */
  .bar{ bottom: max(56px, calc(env(safe-area-inset-bottom) + 46px)); gap: 5px; padding: 5px; }
  .size-note{ bottom: calc(max(56px, env(safe-area-inset-bottom) + 46px) + 58px); }
  .note{ top: calc(max(10px, env(safe-area-inset-top)) + 52px); }
  .btn{ padding: 7px 13px; font-size: 0.78rem; }
  .panel{ padding: 18px 14px; }
  .layouts{ grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .lay{ padding: 8px 4px; }
  .lay__map{ width: 92px; height: 60px; }
  .lay__name{ font-size: 1.02rem; }
}
@media (max-width: 380px){
  .hud{ gap: 7px; padding: 5px 10px; }
  .hud__num{ font-size: 1.04rem; }
  .btn{ padding: 7px 11px; }
  .lay__map{ width: 84px; height: 55px; }
}
@media (max-width: 620px) and (max-height: 740px){
  .bar{ bottom: max(48px, calc(env(safe-area-inset-bottom) + 38px)); padding: 4px; }
  .btn{ min-height: 38px; padding: 6px 12px; }
  .hud{ top: max(8px, env(safe-area-inset-top)); }
  .corner-btn{ top: max(8px, env(safe-area-inset-top)); width: 38px; height: 38px; }
  #lessonCv{ width: 240px; height: 156px; }
}
@media (max-height: 560px){
  .hud{ top: max(6px, env(safe-area-inset-top)); padding: 3px 12px; left: max(12px, env(safe-area-inset-left)); transform: none; }
  .hud__num{ font-size: 1.02rem; }
  .corner-btn{ top: max(6px, env(safe-area-inset-top)); width: 36px; height: 36px; }
  .help-btn{ right: max(52px, calc(env(safe-area-inset-right) + 52px)); }
  .bar{ bottom: max(6px, env(safe-area-inset-bottom)); padding: 4px; }
  .btn{ min-height: 36px; padding: 6px 11px; }
  .note{ top: calc(max(6px, env(safe-area-inset-top)) + 46px); }
  .hint{ display: none; }
  .callout{ top: 26%; }
  #lessonCv{ width: 220px; height: 144px; }
  .lay__map{ width: 90px; height: 58px; }
}
@media (prefers-reduced-motion: reduce){
  .play-btn, .corner-btn, .overlay, .btn, .lay, .note{ transition: none; }
  .callout.is-pop, #btnShuffle.is-pulse{ animation: none; }
  #btnShuffle.is-pulse{ box-shadow: 0 0 0 3px rgba(246, 205, 132, 0.6); }
}

/* The tiles fill the middle of the screen, so the shared tip-jar / full-screen badges at
   right-center would sit on them. Dock them along the bottom edge, side by side. Doubled
   classes out-specify the injected styles. */
.opt-tipjar.opt-tipjar{ top: auto; bottom: max(12px, env(safe-area-inset-bottom)); transform: none; }
.opt-fs.opt-fs{ top: auto; bottom: max(13px, calc(env(safe-area-inset-bottom) + 1px)); right: max(56px, calc(env(safe-area-inset-right) + 56px)); transform: none; }
.opt-tipjar.opt-tipjar.tj-nudge{ animation: none; }

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