/* ---------------------------------------------------------------
   Mahjong - game-specific styles.

   Loaded after /assets/base.css, which supplies the design tokens,
   the top bar, the buttons, the footer, the modals, the cookie
   banner and the legal-page layout shared by every Lynxy game.
   Only the board and the tokens it needs live here.
---------------------------------------------------------------- */

/* ------------------------------- tokens -------------------------------- */

/* The tiles: ivory faces on a jade body, as real mahjong tiles are. They
   stay light in the dark theme too -- they are objects on the table, and
   the pictures carry fixed colours -- only a little less bright. */
:root {
  --tile-face: #fffdf6;
  --tile-hi: #ffffff;
  --tile-line: #e3dcc6;
  --tile-side: #2f9c7a;
  --tile-select: #ffe8a3;
  --tile-select-ring: #f2a900;
  --tile-dim: .5;
  --felt: #e9f3ee;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tile-face: #ebe6d6;
    --tile-hi: #f6f2e6;
    --tile-line: #cfc6aa;
    --tile-side: #1f7a5e;
    --tile-select: #ffd873;
    --tile-select-ring: #ffc233;
    --tile-dim: .42;
    --felt: #13201c;
  }
}

:root[data-theme="dark"] {
  --tile-face: #ebe6d6;
  --tile-hi: #f6f2e6;
  --tile-line: #cfc6aa;
  --tile-side: #1f7a5e;
  --tile-select: #ffd873;
  --tile-select-ring: #ffc233;
  --tile-dim: .42;
  --felt: #13201c;
}

/* --------------------------- header extras ----------------------------- */

.topbar__inner { max-width: 640px; }

.brand__mark svg { width: 20px; height: 20px; display: block; }

.stats {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.stat {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px 10px;
  text-align: center;
  min-width: 58px;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.stat__value {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.stat__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-dim);
}

/* Three counters, the brand and the two buttons only fit a phone once the
   counters give up their padding and the brand keeps just its mark. */
@media (max-width: 520px) {
  .stats { gap: 6px; }
  .stat { min-width: 44px; padding: 4px 6px; }
  .stat__value { font-size: 15px; }
  .stat__label { font-size: 9px; letter-spacing: .04em; }
  .brand__name { display: none; }
}

.topbar__hint {
  max-width: 640px;
  margin: 6px auto 0;
  padding: 0 16px;
  font-size: 12px;
  color: var(--text-dim);
}

/* -------------------------------- page --------------------------------- */

.page {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  display: flex;
  gap: 10px;
  align-items: center;
}

.levels {
  flex: 1;
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
}

.level {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 7px 4px;
  border-radius: 9px;
  cursor: pointer;
  display: grid;
  gap: 1px;
  line-height: 1.15;
}

.level small {
  font-size: 10px;
  font-weight: 600;
  opacity: .75;
  font-variant-numeric: tabular-nums;
}

.level.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.meta {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 13px;
  color: var(--text-dim);
  flex-wrap: wrap;
}

.meta__item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.meta__item strong { color: var(--text); font-weight: 700; }

/* The name of the layout reads first: it is a different one every game. */
.meta__item--layout {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.meta__item--layout strong { color: var(--accent); }
.meta__item--time { margin-left: auto; }

@media (max-width: 380px) {
  .meta { font-size: 12px; gap: 5px; }
  .meta__item { padding: 3px 8px; }
}

/* -------------------------------- board -------------------------------- */

.board-wrap {
  position: relative;
  background: var(--felt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 8px;
  overflow: hidden;
}

/* The tiles are placed by app.js in pixels; the board is exactly as large
   as the layout it holds and sits in the middle of the felt. */
.board {
  --tw: 40px;
  --th: 53px;
  --edge: 3px 3px 0 var(--tile-side);
  position: relative;
  margin: 0 auto;
  touch-action: manipulation;
  /* The tiles' z-indexes stay inside the board, under the dialogs. */
  isolation: isolate;
}

.mj {
  position: absolute;
  width: var(--tw);
  height: var(--th);
  margin: 0;
  padding: calc(var(--tw) * .06);
  border: 0;
  border-radius: calc(var(--tw) * .14);
  background: linear-gradient(150deg, var(--tile-hi), var(--tile-face) 55%);
  box-shadow: inset 0 0 0 1px var(--tile-line), var(--edge);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform .12s ease, opacity .2s ease;
}

.mj[hidden] { display: none; }

.mj svg {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transition: opacity .15s ease;
}

@media (hover: hover) {
  .mj:not(.is-blocked):hover { background: linear-gradient(150deg, #fff, var(--tile-hi)); }
}

.mj:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Easy greys out the tiles that cannot be taken yet. */
.mj.is-blocked { cursor: default; background: var(--tile-face); filter: saturate(.7) brightness(.93); }
.mj.is-blocked svg { opacity: var(--tile-dim); }

/* The tile picked first stands up a little, in gold. */
.mj.is-selected {
  background: var(--tile-select);
  box-shadow: inset 0 0 0 2px var(--tile-select-ring), var(--edge);
  transform: translate(-1px, -2px);
}

.mj.is-gone {
  opacity: 0;
  transform: scale(.7) translateY(-6px);
  pointer-events: none;
  transition: transform .2s ease, opacity .2s ease;
}

.mj.is-nope { animation: nope .32s ease; }
.mj.is-shuffled svg { animation: shuffled .45s ease; }

@keyframes nope {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

@keyframes shuffled {
  0% { opacity: 0; transform: rotateY(90deg); }
  100% { opacity: 1; transform: rotateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .mj, .mj.is-gone { transition: none; }
  .mj.is-nope, .mj.is-shuffled svg { animation: none; }
}

.board-cover {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg); /* fallback for browsers without color-mix */
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: var(--radius);
  z-index: 2000;
}

.board-cover[hidden] { display: none; }

.board-cover__card {
  text-align: center;
  display: grid;
  gap: 12px;
  font-weight: 600;
}

.board-cover__card p { margin: 0; }

/* -------------------------------- tools -------------------------------- */

.tools {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-dim);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 8px 2px 6px;
  display: grid;
  justify-items: center;
  gap: 3px;
  cursor: pointer;
}

.tool:active { transform: scale(.97); }
.tool[disabled] { opacity: .45; cursor: default; }


/* ------------------------------ win dialog ----------------------------- */

.score-row {
  display: flex;
  gap: 8px;
  margin: 18px 0;
}

.score-row__item {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 4px;
  display: grid;
  gap: 2px;
}

.score-row__value {
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-row__item:first-child .score-row__value { color: var(--ok); }

.score-row__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-dim);
}

.modal__actions .modal__home {
  flex: none;
  width: 46px;
  padding: 0;
}

.modal__home img { width: 26px; height: 26px; display: block; }
.modal__home:active { transform: scale(.96); }

/* ------------------------ about / SEO copy ----------------------------- */

.about {
  border-top: 1px solid var(--border);
  padding-top: 18px;
  color: var(--text-dim);
  font-size: 14px;
}

.about h1 {
  font-size: 18px;
  letter-spacing: -.02em;
  color: var(--text);
  margin: 0 0 6px;
}

.about h2 {
  font-size: 15px;
  color: var(--text);
  margin: 18px 0 4px;
}

.about p { margin: 0 0 8px; }

kbd {
  font: inherit;
  font-size: .85em;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 0 5px;
}

/* --------------------------- tables in prose --------------------------- */

/* The level table on this page and in the guide; the shared sheet has no
   table styles because no other page needs one. */
.about table,
.doc table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 14px;
  font-size: 13px;
}

.about th, .about td,
.doc th, .doc td {
  border: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
}

.about th, .doc th { background: var(--surface-2); color: var(--text); font-weight: 600; }

.doc table { margin: 14px 0; font-size: 14px; }
.doc th, .doc td { padding: 7px 9px; }

/* The guide uses numbered lists; base.css only styles the bulleted ones. */
.doc ol { padding-left: 20px; }
