/* Mahjong Matching: game styles. Colors and fonts come from ../shared/eg-theme.css */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 20px;
  line-height: 1.45;
}
[hidden] { display: none !important; }

.noscript { margin: 16px; padding: 16px; border: 2px solid var(--ink); border-radius: 12px; background: #FBF6EA; color: #1F3246; }

:focus-visible { outline: 4px solid var(--mid); outline-offset: 2px; }
/* Headings and the board frame take focus only so screen readers land in the right place; they are not controls. */
[tabindex="-1"]:focus, [tabindex="-1"]:focus-visible { outline: none; }

/* ---------- extra colors used only by this game ---------- */
:root {
  --blockbg: #DDD3BA;
  --edge-dim: #9A8D70;
}
:root[data-contrast="high"] {
  --blockbg: #D6D6D6;
  --edge-dim: #4D4D4D;
}

/* ---------- header and settings ---------- */
.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px 4px;
}
.name-block { min-width: 0; display: flex; align-items: baseline; flex-wrap: wrap; column-gap: 12px; }
.name { margin: 0; font-family: var(--font-head); font-weight: 800; font-size: 30px; line-height: 1.15; }
.kind { margin: 0; white-space: nowrap; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.kind::before { content: ""; width: 14px; height: 14px; border-radius: 50%; background: var(--dot); border: 2px solid var(--ink); flex: none; }

.textlink {
  color: var(--ink); font: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 4px;
  min-height: 44px; display: inline-flex; align-items: center; padding: 0 4px; white-space: nowrap;
}
.linkbtn { background: none; border: 0; cursor: pointer; }

.settings {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 4px 16px 10px; border-bottom: 2px solid var(--rule);
}
.settings-label { font-size: 18px; margin-right: 2px; }

/* ---------- buttons ---------- */
.btn {
  min-height: 52px; padding: 8px 16px;
  font: inherit; font-weight: 700; font-size: 20px; line-height: 1.2;
  color: var(--ink); background: var(--card);
  border: 2px solid var(--ink); border-radius: 12px; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.btn.small { min-height: 46px; font-size: 18px; padding: 6px 14px; }
.btn.primary { background: var(--ink); color: var(--card); }
.btn[aria-disabled="true"] { opacity: 0.5; border-style: dashed; cursor: default; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--card); }
/* A thick outline asks for attention (for example Shuffle, when no matches are left). */
.btn.attn { outline: 5px solid var(--dot); outline-offset: 2px; }

/* ---------- layout ---------- */
main { padding: 12px 12px 40px; max-width: 1180px; margin: 0 auto; }
.h2 { margin: 8px 0 12px; font-family: var(--font-head); font-weight: 800; font-size: 30px; line-height: 1.15; }
.panel { background: var(--card); border: 2px solid var(--rule); border-radius: 20px; padding: 4px 18px; margin: 0 0 16px; max-width: 760px; }
.howto { margin: 14px 0; font-size: 20px; }
.note { margin: 12px 0 0; font-size: 18px; }
.legend { margin-top: 6px; }

.msg {
  margin: 0 0 8px; padding: 8px 12px;
  font-size: 19px; line-height: 1.35;
  background: var(--card); border: 2px solid var(--rule); border-radius: 12px;
}
.msg:empty { display: none; }

/* ---------- choose a board ---------- */
.stylebar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 4px 0 0; }
.stylenote { margin: 8px 0 14px; max-width: 760px; }
.plist { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.ptile {
  width: 100%; height: 100%; min-height: 92px; padding: 12px 14px; text-align: left;
  font: inherit; color: var(--ink); background: var(--card);
  border: 3px solid var(--ink); border-radius: 20px; cursor: pointer;
  display: flex; flex-direction: column; justify-content: flex-start; gap: 2px;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.ptile .thumb { display: block; width: 100%; height: 76px; margin-bottom: 6px; }
.ptile .thumb rect { fill: var(--card); stroke: var(--ink); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.ptile .thumb rect.up { fill: var(--iconbg); }
.ptile .pn { font-family: var(--font-head); font-weight: 800; font-size: 26px; line-height: 1.1; }
.ptile .ps { font-size: 18px; }
.ptile .pt { font-size: 18px; min-height: 1.3em; }
.ptile.done .pt, .ptile.going .pt { font-weight: 700; color: var(--accent-text); }
.ptile[aria-disabled="true"] { opacity: 0.6; border-style: dashed; cursor: default; }
.ptile[aria-disabled="true"] .pt { font-weight: 700; color: var(--ink); }

/* ---------- playing ---------- */
.titlerow { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.titlerow .h2 { font-size: 26px; margin: 4px 0; }
.count { margin: 0 0 8px; font-size: 18px; }

.board-wrap {
  background: var(--iconbg); border: 3px solid var(--ink); border-radius: 16px;
  padding: 6px; overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch; touch-action: pan-x pan-y pinch-zoom;
}
.board { position: relative; margin: 0 auto; }

/* A tile. Size and position come from the numbers set on .board by app.js. */
.tile {
  position: absolute; margin: 0; padding: calc(var(--tw) * 0.1);
  width: calc(var(--tw) - 4px); height: calc(var(--th) - 4px);
  left: calc(var(--x) * var(--ux) + (var(--zm) - var(--z)) * var(--dx));
  top: calc(var(--y) * var(--uy) + (var(--zm) - var(--z)) * var(--dy));
  z-index: var(--zi);
  background: var(--card); color: var(--ink);
  border: 3px solid var(--ink); border-radius: calc(var(--tw) * 0.16);
  box-shadow: 3px 4px 0 var(--ink);
  cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.tile .face { pointer-events: none; }

/* Blocked tiles look flatter and dimmer. Free tiles look bright and raised. */
.tile.blocked { background: var(--blockbg); border-color: var(--edge-dim); box-shadow: 3px 4px 0 var(--edge-dim); cursor: default; }
.tile.blocked .face { opacity: 0.5; }

/* Holding a tile: lifted, with a thick dark outline. */
.tile.held {
  transform: translate(-3px, -5px); box-shadow: 6px 9px 0 var(--ink);
  outline: 5px solid var(--ink); outline-offset: 2px; z-index: calc(var(--zi) + 500);
}
/* A solid orange outline means "try this one". A dashed outline means "this one is in the way". */
.tile.hint { outline: 6px solid var(--dot); outline-offset: 2px; background: var(--iconbg); z-index: calc(var(--zi) + 500); }
.tile.blocker { outline: 5px dashed var(--accent-text); outline-offset: 2px; z-index: calc(var(--zi) + 500); }

.tile.gone { display: none; }
.tile.leaving { pointer-events: none; animation: vanish 0.26s ease-in forwards; }
.tile.nudge { animation: nudge 0.35s ease-in-out; }
.tile.back { animation: pop 0.3s ease-out; }
@keyframes vanish { to { opacity: 0; transform: scale(0.7); } }
@keyframes nudge { 0%, 100% { translate: 0 0; } 25% { translate: -5px 0; } 75% { translate: 5px 0; } }
@keyframes pop { from { opacity: 0; transform: scale(0.8); } to { opacity: 1; transform: none; } }

.dock {
  position: sticky; bottom: 0; z-index: 5000;
  margin-top: 10px; padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  background: var(--bg); border-top: 2px solid var(--rule);
}
.dock.static { position: static; }
.dock .msg { margin-bottom: 8px; }
.controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 8px; margin-top: 12px; }
.controls.two { grid-template-columns: 1fr 1fr; }
.controls.four { grid-template-columns: repeat(4, 1fr); margin-top: 0; }
.dock.narrow .controls.four { grid-template-columns: 1fr 1fr; }
.controls .btn { min-height: 56px; font-size: 19px; }
.dock .controls .btn { padding: 6px 4px; }
.confirm { margin-top: 0; }
.confirm-text { margin: 0 0 4px; font-size: 19px; }
.confirm .controls { margin-top: 8px; }
.zoombar { margin-top: 4px; }
/* Board size and tile style: four smaller buttons side by side when there is room, otherwise two by two. */
.zoombar .controls { grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 4px; }
.zoombar.row4 .controls { grid-template-columns: repeat(4, 1fr); }
.zoombar .controls .btn { min-height: 46px; font-size: 16px; line-height: 1.15; padding: 4px 6px; }
.tile { scroll-margin: 12px 12px 230px 12px; }
@media (max-height: 480px) { .dock { position: static; } .tile { scroll-margin-bottom: 12px; } }

/* ---------- all matched ---------- */
.clear { margin-top: 16px; padding: 18px; }
.clear-title { margin: 0 0 6px; font-family: var(--font-head); font-weight: 800; font-size: 36px; line-height: 1.1; }
.clear p { margin: 0 0 14px; }
.clear-buttons { display: grid; gap: 8px; }
.clear-buttons .btn { min-height: 56px; }

/* After the last match: leave just the title and the "All matched" panel. */
.won #board-wrap, .won .legend, .won #dock, .won #zoombar, .won #count { display: none; }
.won .clear { margin-top: 8px; }

@media (prefers-reduced-motion: reduce) {
  .tile.leaving { animation: none; opacity: 0; }
  .tile.nudge, .tile.back { animation: none; }
}

/* ---------- tile faces: colors and line styles ---------- */
:root {
  --sw: 4;
  --fc-red: #CF3A2B; --fc-orange: #E8741E; --fc-yellow: #F4B820; --fc-green: #3B8B43; --fc-lime: #A7C23A;
  --fc-teal: #1C8C8C; --fc-blue: #2F6DB8; --fc-sky: #9CC7EE; --fc-purple: #7B4CA6; --fc-pink: #E0568F;
  --fc-brown: #7E4F24; --fc-tan: #E0A84E; --fc-white: #FFFFFF; --fc-cream: #F6E9C8;
}
:root[data-contrast="high"] {
  --sw: 5;
  --fc-red: #B00020; --fc-orange: #C25400; --fc-yellow: #F2B600; --fc-green: #1B6B24; --fc-lime: #7A9400;
  --fc-teal: #006A6A; --fc-blue: #0B5394; --fc-sky: #7DB3E6; --fc-purple: #5B2A86; --fc-pink: #B3135E;
  --fc-brown: #5A3410; --fc-tan: #D69A22; --fc-white: #FFFFFF; --fc-cream: #FFF4D6;
}
.face { display: block; width: 100%; height: 100%; overflow: visible; }
.face .o  { stroke: var(--ink); stroke-width: var(--sw); stroke-linejoin: round; stroke-linecap: round; }
.face .n  { stroke: none; }
.face .ub { fill: var(--ink); stroke: var(--ink); stroke-width: calc(var(--sw) * 2); stroke-linejoin: round; }
.face .ln { fill: none; stroke: var(--ink); stroke-width: var(--sw); stroke-linecap: round; stroke-linejoin: round; }
.face .hl { fill: none; stroke: #fff; stroke-width: 5; stroke-linecap: round; }
.face .sk  { fill: none; stroke: var(--ink); stroke-width: calc(var(--sw) * 2.3); stroke-linecap: round; stroke-linejoin: round; }
.face .skc { fill: none; stroke-width: calc(var(--sw) * 0.9); stroke-linecap: round; stroke-linejoin: round; }
.k-red { fill: var(--fc-red); } .k-orange { fill: var(--fc-orange); } .k-yellow { fill: var(--fc-yellow); }
.k-green { fill: var(--fc-green); } .k-lime { fill: var(--fc-lime); } .k-teal { fill: var(--fc-teal); }
.k-blue { fill: var(--fc-blue); } .k-sky { fill: var(--fc-sky); } .k-purple { fill: var(--fc-purple); }
.k-pink { fill: var(--fc-pink); } .k-brown { fill: var(--fc-brown); } .k-tan { fill: var(--fc-tan); }
.k-white { fill: var(--fc-white); } .k-cream { fill: var(--fc-cream); } .k-ink { fill: var(--ink); }
.k-s-brown { stroke: var(--fc-brown); } .k-s-green { stroke: var(--fc-green); } .k-s-teal { stroke: var(--fc-teal); }

/* ---------- traditional tiles: in high contrast the tile itself is dark, to match the dark tile art ---------- */
:root[data-contrast="high"] .set-classic .tile { background: #1E1E1E; border-color: #000; }
:root[data-contrast="high"] .set-classic .tile.blocked { background: #6B6B6B; border-color: #3D3D3D; box-shadow: 3px 4px 0 #3D3D3D; }
:root[data-contrast="high"] .set-classic .tile.hint { background: #1E1E1E; }

/* Traditional tiles: let the tile art fill more of the tile so it is easier to read. */
.set-classic .tile { padding: calc(var(--tw) * 0.05); }
