/* Mahjong Tiles. Mobile-first. */
:root {
  --bg: #0f1726; --panel: #18233b; --line: rgba(255,255,255,.1);
  --text: #e8eef9; --muted: #93a3c0; --gold: #f4c150; --accent: #10b981;
  --felt1: #1c6b4c; --felt2: #0f3f2e;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; color: var(--text);
  font-family: "Poppins", system-ui, -apple-system, "Segoe UI", sans-serif; font-weight: 400;
  background: radial-gradient(1200px 600px at 50% -10%, #16213a 0%, var(--bg) 60%);
  overflow-x: hidden; touch-action: manipulation;
}
.app-header { text-align: center; padding: 10px 12px 4px; }
.logo { margin: 0; font-family: "Grenze", serif; font-weight: 700; font-size: clamp(22px, 6.2vw, 40px); line-height: 1.15; color: var(--gold); text-shadow: 0 2px 0 #0b1220, 0 0 24px rgba(244,193,80,.2); }
.logo .dot { opacity: .6; }
.logo-en { color: #fff4cf; }
.hdr-row { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; margin-top: 4px; }
.back { color: #f5d98a; font-size: 13px; text-decoration: none; padding: 8px 4px; }
.back:hover { text-decoration: underline; }

.btn { font: inherit; font-size: 14px; font-weight: 500; color: var(--text); background: #223357; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; min-height: 44px; cursor: pointer; }
.btn:hover:not(:disabled) { background: #2b4170; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: default; }
.btn:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.btn-sm { font-size: 13px; padding: 6px 10px; min-height: 40px; }
.btn.primary { background: var(--accent); color: #052e22; border-color: transparent; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #34d3a0; }

.game {
  display: grid; gap: 8px; padding: 6px 12px 18px; max-width: 1500px; margin: 0 auto;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas: "hud" "board" "ctl";
}
.hud { grid-area: hud; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 5px 4px; text-align: center; min-width: 0; }
.stat .k { display: block; font-size: 9.5px; color: var(--muted); letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .v { display: block; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.board-col { grid-area: board; min-width: 0; }
.board-wrap {
  position: relative; width: 100%; border-radius: 14px; overflow: hidden; display: flex; justify-content: center; align-items: center;
  background: radial-gradient(120% 120% at 50% 40%, var(--felt1) 0%, var(--felt2) 80%);
  border: 1px solid rgba(255,255,255,.12); box-shadow: inset 0 0 40px rgba(0,0,0,.45);
  padding: 8px;
}
.board-wrap.zoomed { overflow: auto; justify-content: flex-start; align-items: flex-start; -webkit-overflow-scrolling: touch; }
#board { display: block; flex: none; max-width: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.status { margin: 6px 2px 0; min-height: 20px; font-size: 13px; color: var(--muted); text-align: center; }

.ctl { grid-area: ctl; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; gap: 8px; align-content: start; }
.ctl-row { display: grid; gap: 8px; }
.sel-row { grid-template-columns: 1fr 1fr; }
.btn-row { grid-template-columns: repeat(4, 1fr); }
.fld { display: grid; gap: 3px; font-size: 11px; color: var(--muted); min-width: 0; }
select { font: inherit; font-size: 14px; color: var(--text); background: #0f1726; border: 1px solid var(--line); border-radius: 8px; padding: 8px; min-height: 42px; width: 100%; min-width: 0; }
.act { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; padding: 6px 2px; line-height: 1.15; min-width: 0; }
.act .vi { font-size: 13px; white-space: nowrap; }
.act .en { font-size: 10.5px; color: var(--muted); font-weight: 400; }
.opt-row { grid-template-columns: 1fr auto; align-items: center; }
.chk { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); line-height: 1.3; }
.chk input { width: 20px; height: 20px; flex: none; accent-color: var(--accent); }
.fine { margin: 0; font-size: 11px; color: var(--muted); }

/* wide / landscape: board left, panel right */
@media (min-width: 820px), (orientation: landscape) and (min-width: 600px) {
  .game {
    grid-template-columns: minmax(0, 1fr) clamp(190px, 24vw, 300px);
    grid-template-areas: "board hud" "board ctl";
    grid-template-rows: auto 1fr; align-items: start;
  }
  .hud { grid-template-columns: 1fr 1fr; }
  .sel-row { grid-template-columns: 1fr; }
  .btn-row { grid-template-columns: 1fr 1fr; }
  .opt-row { grid-template-columns: 1fr; }
  .stat .k { font-size: 10.5px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .app-header { padding: 4px 8px 0; display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap; }
  .logo { font-size: 20px; }
  .hdr-row { margin-top: 0; }
  .btn { min-height: 38px; padding: 4px 8px; }
  .game { padding-top: 2px; gap: 6px; }
  .fine, .fld span { display: none; }
  .ctl { padding: 6px; gap: 6px; }
  .status { margin-top: 2px; }
}

/* ---------- tiles ---------- */
.tile { cursor: pointer; transition: opacity .18s ease; }
.tile .sh { fill: rgba(0,0,0,.34); }
.tile .bk { fill: #1f8a5f; }
.tile .ed { fill: #d6cba9; }
.tile .face { fill: url(#ivory); stroke: #aaa085; stroke-width: .8; }
.tile.fl .face { fill: url(#ivoryPink); }
.tile.se .face { fill: url(#ivoryTeal); }
.tile .dim { fill: rgba(12,22,40,0); pointer-events: none; }
.tile .hl { fill: none; stroke: #ffd54a; stroke-width: 3; opacity: 0; pointer-events: none; }
.assist .tile.blocked .dim { fill: rgba(12,22,40,.46); }
.assist .tile.free .face { stroke: #1fbf86; stroke-width: 1.7; }
.tile.sel .hl { opacity: 1; }
.tile.hint .hl { opacity: 1; animation: pulse .7s ease-in-out infinite alternate; }
.tile.gone { opacity: 0; pointer-events: none; }
.tile.nope .face { animation: nope .35s; }
.tile.shuf .art { animation: flash .5s; }
@keyframes pulse { from { stroke: #ffd54a; stroke-width: 2.6; } to { stroke: #ff9f1a; stroke-width: 4; } }
@keyframes nope { 0%,100% { stroke: #aaa085; } 30% { stroke: #ef4444; stroke-width: 3; } }
@keyframes flash { from { opacity: .1; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .tile, .tile * { animation: none !important; transition: none !important; } }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 14px; background: rgba(5,10,20,.72); }
.modal[hidden] { display: none; }
.card { width: min(720px, 100%); max-height: calc(100vh - 28px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.card.small { width: min(420px, 100%); text-align: center; }
.card h2 { margin: 0 0 8px; font-family: "Grenze", serif; font-size: 24px; color: var(--gold); }
.card h3 { margin: 6px 0; font-size: 14px; color: #fff4cf; }
.card p { margin: 6px 0; font-size: 14px; }
.card ul { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.5; }
.card li { margin-bottom: 5px; }
.cols { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .cols { grid-template-columns: 1fr 1fr; gap: 20px; } }
.modal-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
