/* Mahjong Bay */
:root {
  --sand: #f3eee2;
  --paper: #fffdf7;
  --ink: #22303a;
  --muted: #5e6b74;
  --line: #ddd3bd;
  --teal: #0f6e7d;
  --teal-dark: #0b4f5b;
  --deep: #0c3f4a;
  --amber: #e9a23b;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--sand); color: var(--ink); font: 17px/1.62 var(--sans); }
a { color: var(--teal-dark); }
a:hover { color: var(--teal); }
img, svg { max-width: 100%; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.head { background: var(--paper); border-bottom: 1px solid var(--line); }
.head .wrap { display: flex; align-items: center; gap: 18px; min-height: 54px; flex-wrap: wrap; }
.logo { display: inline-flex; align-items: center; gap: 9px; font: 700 21px/1 var(--serif); color: var(--ink); text-decoration: none; letter-spacing: .01em; }
.logo svg { width: 25px; height: 33px; flex: none; }
.logo span { color: var(--teal); }
.nav { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { padding: 6px 11px; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: 15.5px; }
.nav a:hover { background: var(--sand); }
.nav a[aria-current] { color: var(--teal-dark); font-weight: 600; box-shadow: inset 0 -2px 0 var(--teal); border-radius: 0; }

/* ---------- game ---------- */
.game { background: var(--deep); padding: 10px 0 12px; }
.game:fullscreen { padding: 8px 10px; display: flex; flex-direction: column; justify-content: flex-start; }
.game:-webkit-full-screen { padding: 8px 10px; }
.game .grid { display: grid; grid-template-columns: 1fr auto; grid-template-areas: "bar acts" "water water" "status status" "tip tip" "best best"; }
.bar { grid-area: bar; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-bottom: 10px; }
.acts { grid-area: acts; display: flex; align-items: center; gap: 8px; padding-bottom: 10px; }
.water { grid-area: water; }
.status { grid-area: status; }
.tip { grid-area: tip; margin: 8px 0 0; color: #ffd996; font-size: 14.5px; }
.tip[hidden] { display: none; }
.best { grid-area: best; }
.game button, .game select {
  font: 600 15px/1 var(--sans); color: #f2f7f7; background: #185866; border: 1px solid #2b7482;
  border-radius: 7px; padding: 10px 14px; cursor: pointer; min-height: 40px;
}
.game select { padding-right: 8px; max-width: 100%; }
.game label.pick { color: #b9d3d6; font-size: 14px; display: inline-flex; align-items: center; gap: 7px; }
.game button:hover:not(:disabled), .game select:hover { background: #1f6a79; }
.game button:disabled { opacity: .45; cursor: default; }
.game button.main { background: var(--amber); border-color: #f3bb63; color: #2a1c05; }
.game button.main:hover { background: #f1b152; }
.game button:focus-visible, .game select:focus-visible, .tile:focus-visible { outline: 3px solid #ffd27a; outline-offset: 2px; }

.water {
  position: relative; border-radius: 12px; min-height: 300px; padding: 10px;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  background: radial-gradient(120% 90% at 50% 35%, #1e7c88 0%, #12606d 55%, #0d4a56 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .07), inset 0 0 60px rgba(0, 0, 0, .25);
}
.board { position: relative; flex: none; visibility: hidden; }
.game.ready .board { visibility: visible; }

.game .tile {
  position: absolute; width: var(--tw); height: var(--th); padding: 0; margin: 0; min-height: 0 !important;
  background: var(--bg, #fbf6e6) !important; border: 1px solid #94855d !important; border-radius: var(--tr) !important;
  box-shadow:
    calc(var(--td) * .45) calc(var(--td) * .45) 0 #d9cda6,
    var(--td) var(--td) 0 #23775d,
    calc(var(--td) + 3px) calc(var(--td) + 4px) 7px rgba(0, 0, 0, .5);
  cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: opacity .18s ease, transform .18s ease;
}
.tile.z0 { --bg: #ebe2c6; } .tile.z1 { --bg: #f2ead3; } .tile.z2 { --bg: #f8f2df; } .tile.z3 { --bg: #fcf8ea; } .tile.z4 { --bg: #fffdf4; }
.tile svg { display: block; width: 100%; height: 100%; pointer-events: none; }
.tile::after { content: ''; position: absolute; inset: -1px; border-radius: inherit; pointer-events: none; background: rgba(9, 38, 46, 0); transition: background .15s; }
.board.dim .tile:not(.free)::after { background: rgba(9, 38, 46, .42); }
.tile.free:hover { background: #fffbe9 !important; }
.tile.sel { background: #ffe9ae !important; border-color: #c7851b !important; transform: translate(-2px, -2px); }
.tile.sel::after { box-shadow: 0 0 0 3px var(--amber); }
.tile.hint::after { animation: hint 0.8s ease-in-out 3; }
.tile.nope { animation: nope .28s; }
.tile.gone { opacity: 0; transform: scale(.86); pointer-events: none; }
.board.dealt .tile { animation: dealt .35s ease; }
@keyframes hint { 0%, 100% { box-shadow: 0 0 0 0 rgba(233, 162, 59, 0); } 50% { box-shadow: 0 0 0 5px #ffb938; background: rgba(255, 190, 70, .35); } }
@keyframes nope { 0%, 100% { transform: translateX(0); } 30% { transform: translateX(-3px); } 70% { transform: translateX(3px); } }
@keyframes dealt { from { opacity: .2; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .tile, .tile::after { transition: none; } .tile.nope, .board.dealt .tile { animation: none; } }

.status { display: flex; align-items: center; gap: 6px 18px; flex-wrap: wrap; padding-top: 10px; color: #d5e6e8; font-size: 15px; }
.status .num { font-variant-numeric: tabular-nums; }
.status #g-time { font-weight: 600; color: #fff; }
.status .gap { flex: 1 1 auto; }
.status label { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; color: #b9d3d6; }
.status input { width: 18px; height: 18px; accent-color: var(--amber); }
.best { margin: 6px 0 0; color: #9fc1c5; font-size: 14px; min-height: 1.3em; }

.panel { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(6, 32, 39, .62); z-index: 9000; padding: 14px; }
.panel[hidden] { display: none; }
.panel-in { background: var(--paper); color: var(--ink); border-radius: 12px; padding: 20px 22px; max-width: 470px; box-shadow: 0 18px 50px rgba(0, 0, 0, .45); }
.panel-in h2 { margin: 0 0 6px; font: 700 23px/1.25 var(--serif); }
.panel-in p { margin: 0 0 14px; font-size: 16px; }
.panel-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.panel-btns button { background: var(--teal); border-color: var(--teal); }
.panel-btns button:first-child { background: var(--amber); border-color: #f3bb63; color: #2a1c05; }
.panel-btns button.quiet { background: transparent; color: var(--teal-dark); border-color: var(--line); }
.panel-btns button.quiet:hover { background: var(--sand) !important; }
.noscript { color: #fff; padding: 30px 10px; text-align: center; }

/* ---------- text ---------- */
.text { max-width: 760px; margin: 0 auto; padding: 34px 16px 50px; }
.text h1 { font: 700 34px/1.18 var(--serif); margin: 0 0 14px; letter-spacing: -.005em; }
.text h2 { font: 700 24px/1.25 var(--serif); margin: 38px 0 10px; }
.text h3 { font: 700 18.5px/1.3 var(--sans); margin: 26px 0 6px; }
.text p { margin: 0 0 15px; }
.text .lead { font-size: 19px; color: #33444f; }
.text ul, .text ol { padding-left: 22px; margin: 0 0 16px; }
.text li { margin-bottom: 8px; }
.text dl { margin: 0 0 16px; }
.text dt { font-weight: 700; margin-top: 12px; }
.text dd { margin: 2px 0 0; }
.text kbd { font: 600 13px/1 var(--sans); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 2px 6px; background: var(--paper); }
.text .note { background: var(--paper); border: 1px solid var(--line); border-left: 4px solid var(--teal); border-radius: 6px; padding: 12px 16px; font-size: 16px; }
.text small, .text .small { color: var(--muted); font-size: 14.5px; }
.cta { display: inline-block; background: var(--teal); color: #fff !important; text-decoration: none; font-weight: 600; padding: 11px 18px; border-radius: 8px; }
.cta:hover { background: var(--teal-dark); }

/* static tiles inside articles */
.tiles { display: flex; flex-wrap: wrap; gap: 9px 8px; margin: 12px 0 8px; padding: 14px 14px 18px; background: #12606d; border-radius: 10px; }
.t { display: inline-block; width: 45px; height: 60px; flex: none; background: #fbf6e6; border: 1px solid #a99a72; border-radius: 6px; box-shadow: 2px 2px 0 #e2d7b4, 4px 4px 0 #2c8a6d; }
.t svg { display: block; width: 100%; height: 100%; }
.t.off { filter: brightness(.62); }
.tiles.row3 { gap: 0; align-items: flex-end; }
.tiles.row3 .t { margin-right: -1px; }
figure { margin: 0 0 18px; }
figcaption { color: var(--muted); font-size: 14.5px; }

.foot { border-top: 1px solid var(--line); background: var(--paper); color: var(--muted); font-size: 14.5px; }
.foot .wrap { display: flex; gap: 8px 20px; flex-wrap: wrap; padding-top: 16px; padding-bottom: 20px; }
.foot a { color: var(--muted); }
.foot .gap { flex: 1 1 auto; }

@media (max-width: 640px) {
  body { font-size: 16.5px; }
  .head .wrap { min-height: 46px; gap: 6px; padding-top: 4px; padding-bottom: 4px; }
  .nav { margin-left: 0; width: 100%; }
  .nav a { padding: 5px 9px; }
  .game .wrap { padding: 0 8px; }
  .game button, .game select { padding: 9px 10px; font-size: 14.5px; }
  .head .wrap { flex-wrap: nowrap; }
  .nav { margin-left: auto; width: auto; flex-wrap: nowrap; }
  .nav a:first-child { display: none; }
  .logo { font-size: 19px; }
  .game { padding: 8px 0 10px; }
  .game .grid { grid-template-columns: 1fr; grid-template-areas: "bar" "water" "acts" "status" "tip" "best"; }
  .bar { gap: 6px; padding-bottom: 8px; flex-wrap: nowrap; }
  .game label.pick { flex: 1 1 auto; min-width: 0; }
  .game label.pick span { display: none; }
  .game label.pick select { width: 100%; }
  .acts { gap: 6px; padding: 8px 0 0; }
  .acts button { flex: 1 1 auto; min-height: 44px; }
  .status { padding-top: 8px; gap: 4px 14px; font-size: 14.5px; }
  .status .gap { display: none; }
  .water { padding: 6px 2px; border-radius: 8px; }
  .text h1 { font-size: 28px; }
  .text h2 { font-size: 22px; }
  .t { width: 36px; height: 48px; }
}

/* phone held sideways: controls move to a side column, the board takes the full height */
@media (max-height: 480px) and (orientation: landscape) {
  .head .wrap { min-height: 40px; }
  .game { padding: 6px 0; }
  .game .wrap { padding: 0 8px; }
  .game .grid { grid-template-columns: 150px 1fr; grid-template-rows: auto auto auto auto 1fr; column-gap: 8px;
    grid-template-areas: "bar water" "acts water" "status water" "best water" "tip water"; }
  .bar, .acts { flex-wrap: wrap; gap: 6px; padding: 0 0 6px; }
  .bar button, .game label.pick, .game label.pick select { width: 100%; flex: 1 1 100%; min-width: 0; }
  .game label.pick span { display: none; }
  .acts button { flex: 1 1 44%; padding: 8px 4px; font-size: 13.5px; min-height: 38px; }
  .game button, .game select { min-height: 38px; padding: 8px 8px; font-size: 14px; }
  .status { flex-direction: column; align-items: flex-start; gap: 3px; padding-top: 2px; font-size: 13.5px; }
  .status .gap { display: none; }
  .best { font-size: 12.5px; margin-top: 4px; }
  .water { padding: 4px; min-height: 0; border-radius: 8px; }
}
