/* Mahjong — habillage. Les couleurs dépendent du jeu de tuiles choisi (body[data-theme]). */
:root {
  --bg1: #0e5a3f; --bg2: #06281c;
  --accent: #f2c14e; --accent-ink: #2b1d00;
  --ink: #fdf8ea; --ink-soft: rgba(253, 248, 234, .72);
  --panel: rgba(8, 28, 20, .62); --panel-line: rgba(255, 255, 255, .14);
  --danger: #ff5263;
  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
body[data-theme="neon"] {
  --bg1: #241452; --bg2: #05040f; --accent: #27d7ff; --accent-ink: #00131a;
  --ink: #f2f3ff; --ink-soft: rgba(210, 215, 255, .72); --panel: rgba(12, 8, 34, .68); --panel-line: rgba(140, 110, 255, .35);
}
body[data-theme="zen"] {
  --bg1: #6a4630; --bg2: #1f120b; --accent: #e9b65a; --accent-ink: #2a1703;
  --ink: #fff4e2; --ink-soft: rgba(255, 240, 215, .72); --panel: rgba(30, 16, 8, .62); --panel-line: rgba(255, 220, 170, .18);
}
body[data-theme="bonbon"] {
  --bg1: #ff9ec7; --bg2: #7b4fd6; --accent: #fff06a; --accent-ink: #4a2a00;
  --ink: #ffffff; --ink-soft: rgba(255, 255, 255, .82); --panel: rgba(84, 36, 130, .5); --panel-line: rgba(255, 255, 255, .3);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  color: var(--ink);
  background: radial-gradient(120% 90% at 50% 20%, var(--bg1), var(--bg2) 75%) fixed var(--bg2);
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
body::before {   /* trame discrète façon tapis de jeu */
  content: ""; position: fixed; inset: 0; pointer-events: none; opacity: .5;
  background-image: radial-gradient(rgba(255, 255, 255, .05) 1px, transparent 1.4px);
  background-size: 7px 7px;
}
body[data-theme="neon"]::before {
  opacity: .35;
  background-image: linear-gradient(rgba(120, 90, 255, .25) 1px, transparent 1px), linear-gradient(90deg, rgba(120, 90, 255, .25) 1px, transparent 1px);
  background-size: 44px 44px;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
h1, h2, h3, p { margin: 0; }

#app { position: fixed; inset: 0; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; animation: screen-in .28s ease both; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 4px calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l)); }

/* ------------------------------------------------------------ barre de titre */
.bar { display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-t)) calc(14px + var(--safe-r)) 10px calc(14px + var(--safe-l)); }
.bar h2 { font-size: 1.25rem; font-weight: 800; letter-spacing: .01em; }
.back { width: 44px; height: 44px; border-radius: 14px; background: var(--panel); border: 1px solid var(--panel-line);
  display: grid; place-items: center; backdrop-filter: blur(8px); }
.back::before { content: ""; width: 11px; height: 11px; border-left: 3px solid var(--ink); border-bottom: 3px solid var(--ink);
  transform: translateX(2px) rotate(45deg); border-radius: 2px; }

/* ------------------------------------------------------------ boutons */
.btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 54px; padding: 10px 18px; border-radius: var(--radius); font-weight: 800; font-size: 1.05rem;
  background: var(--panel); border: 1px solid var(--panel-line); backdrop-filter: blur(8px);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .28); transition: transform .08s, box-shadow .08s, filter .15s; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .28); }
.btn-primary { background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 88%, #fff), var(--accent));
  color: var(--accent-ink); border-color: rgba(255, 255, 255, .5); min-height: 72px; }
.btn-primary .btn-title { font-size: 1.5rem; letter-spacing: .02em; }
.btn-daily { background: linear-gradient(135deg, rgba(255, 255, 255, .2), rgba(255, 255, 255, .05)), var(--panel); }
.btn-ghost { background: transparent; box-shadow: none; border-color: var(--panel-line); font-weight: 700; font-size: .98rem; min-height: 46px; }
.btn-sub { font-size: .78rem; font-weight: 600; opacity: .78; }
.btn-danger { color: #fff; background: color-mix(in srgb, var(--danger) 70%, #000); }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ------------------------------------------------------------ accueil */
#screen-home { overflow-y: auto; }
.home-hero { flex: 0 0 auto; height: min(44vh, 84vw); background-size: cover; background-position: center 60%;
  -webkit-mask-image: linear-gradient(#000 62%, transparent); mask-image: linear-gradient(#000 62%, transparent); }
.home-body { position: relative; flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: 0 calc(20px + var(--safe-r)) calc(20px + var(--safe-b)) calc(20px + var(--safe-l)); margin-top: -34px; }
.logo { font-size: clamp(2.4rem, 11vw, 3.6rem); font-weight: 900; letter-spacing: -.02em; line-height: 1;
  display: flex; align-items: baseline; gap: .28em; text-shadow: 0 3px 0 rgba(0, 0, 0, .35), 0 10px 30px rgba(0, 0, 0, .45); }
.logo span { font-size: .55em; color: var(--accent); font-weight: 700; }
.tagline { margin: 8px 0 18px; color: var(--ink-soft); font-weight: 600; font-size: .95rem; text-align: center; }
.menu { width: min(100%, 420px); display: flex; flex-direction: column; gap: 12px; }
.menu-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.profile-chip { position: fixed; top: calc(12px + var(--safe-t)); right: calc(12px + var(--safe-r)); z-index: 3;
  padding: 8px 14px; border-radius: 999px; background: var(--panel); border: 1px solid var(--panel-line);
  backdrop-filter: blur(10px); font-weight: 800; font-size: .9rem; max-width: 70vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-chip small { opacity: .65; font-weight: 700; margin-left: 4px; font-variant-numeric: tabular-nums; }
@media (orientation: landscape) and (max-height: 560px) {
  #screen-home { flex-direction: row; }
  .home-hero { flex: 1 1 46%; height: auto; -webkit-mask-image: linear-gradient(90deg, #000 62%, transparent); mask-image: linear-gradient(90deg, #000 62%, transparent); }
  .home-body { flex: 1 1 54%; margin: 0; justify-content: center; padding-top: calc(10px + var(--safe-t)); overflow-y: auto; }
  .logo { font-size: 2.2rem; } .tagline { margin: 4px 0 10px; }
  .menu { gap: 8px; } .btn { min-height: 44px; } .btn-primary { min-height: 54px; } .btn-primary .btn-title { font-size: 1.2rem; }
}

/* ------------------------------------------------------------ cartes (tableaux, thèmes) */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 12px; max-width: 980px; margin: 0 auto; }
.card { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 10px 12px; text-align: center;
  border-radius: var(--radius); background: var(--panel); border: 1px solid var(--panel-line); backdrop-filter: blur(8px);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .25); transition: transform .08s; }
.card:active { transform: translateY(3px); }
.card h3 { font-size: 1.08rem; font-weight: 800; }
.card p { font-size: .78rem; color: var(--ink-soft); font-weight: 600; }
.card .meta { display: flex; gap: 8px; font-size: .76rem; font-weight: 800; margin-top: 2px; }
.card .meta span { padding: 2px 8px; border-radius: 999px; background: rgba(255, 255, 255, .12); font-variant-numeric: tabular-nums; }
.card .meta .best { background: var(--accent); color: var(--accent-ink); }
.cards.themes { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.card.theme { position: relative; padding: 16px 12px; }
.card.theme.current { outline: 3px solid var(--accent); outline-offset: -1px; }
.card.theme.current::after { content: "Actif"; position: absolute; top: 10px; right: 10px; font-size: .7rem; font-weight: 900;
  padding: 3px 9px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); }
.tile-row { display: flex; justify-content: center; gap: 2px; margin-bottom: 6px; }
.sprite { display: block; flex: none; background-repeat: no-repeat; }

/* ------------------------------------------------------------ partie */
#screen-game { display: none; }
#screen-game.active { display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: 1fr; }
.hud { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(8px + var(--safe-t)) calc(12px + var(--safe-r)) 6px calc(12px + var(--safe-l)); }
.icon-btn { width: 46px; height: 46px; border-radius: 14px; background: var(--panel); border: 1px solid var(--panel-line);
  display: grid; place-items: center; backdrop-filter: blur(8px); flex: none; }
.icon-btn svg { width: 22px; height: 22px; fill: var(--ink); }
.timer-box { position: relative; text-align: center; }
.timer { font-size: 2rem; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: .01em;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .35); line-height: 1.1; }
.timer.hit { animation: timer-hit .5s ease; }
@keyframes timer-hit { 20% { color: var(--danger); transform: scale(1.14); } }
.penalty-pop { position: absolute; left: 50%; top: 100%; transform: translateX(-50%); pointer-events: none;
  font-weight: 900; color: var(--danger); font-size: 1.15rem; opacity: 0; white-space: nowrap; text-shadow: 0 1px 0 rgba(0, 0, 0, .5); }
.penalty-pop.show { animation: pop 1.1s ease forwards; }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, -8px) scale(.7); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.1); }
  70% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, 14px); } }
.counters { display: flex; gap: 8px; flex: none; }
.counters div { min-width: 50px; padding: 4px 8px; border-radius: 12px; background: var(--panel); border: 1px solid var(--panel-line);
  display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.counters b { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.counters span { font-size: .62rem; font-weight: 700; opacity: .7; text-transform: uppercase; letter-spacing: .04em; }
.board-wrap { position: relative; min-height: 0; min-width: 0; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.board-wrap.hidden #board { visibility: hidden; }
.toolbar { display: flex; justify-content: center; gap: 8px;
  padding: 6px calc(10px + var(--safe-r)) calc(8px + var(--safe-b)) calc(10px + var(--safe-l)); }
.tool { flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 4px 5px;
  border-radius: 14px; background: var(--panel); border: 1px solid var(--panel-line); backdrop-filter: blur(8px);
  font-size: .76rem; font-weight: 800; transition: transform .08s; }
.tool:active { transform: scale(.94); }
.tool svg { width: 22px; height: 22px; fill: none; stroke: var(--ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tool em { font-style: normal; font-size: .64rem; font-weight: 800; color: var(--accent); opacity: .95; }
.tool[disabled] { opacity: .4; pointer-events: none; }
@media (orientation: landscape) and (max-height: 560px) {
  #screen-game.active { grid-template-rows: 1fr; grid-template-columns: auto 1fr auto; }
  .hud { flex-direction: column; justify-content: flex-start; gap: 12px; width: 104px;
    padding: calc(10px + var(--safe-t)) 6px 10px calc(8px + var(--safe-l)); }
  .timer { font-size: 1.45rem; }
  .counters { flex-direction: column; gap: 6px; }
  .toolbar { flex-direction: column; width: 84px; padding: calc(8px + var(--safe-t)) calc(8px + var(--safe-r)) calc(8px + var(--safe-b)) 4px; }
  .tool { max-width: none; flex: 1; justify-content: center; }
}

/* ------------------------------------------------------------ classement */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px calc(16px + var(--safe-r)) 12px calc(16px + var(--safe-l)); scrollbar-width: none; flex: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 999px; background: var(--panel); border: 1px solid var(--panel-line);
  font-weight: 800; font-size: .86rem; white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.lb { max-width: 640px; margin: 0 auto; display: flex; flex-direction: column; gap: 6px; }
.lb-note { text-align: center; color: var(--ink-soft); font-weight: 600; font-size: .9rem; padding: 22px 10px; line-height: 1.5; }
.lb-row { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 8px; padding: 10px 14px 10px 8px;
  border-radius: 14px; background: var(--panel); border: 1px solid var(--panel-line); }
.lb-row .rank { text-align: center; font-weight: 900; font-variant-numeric: tabular-nums; opacity: .85; }
.lb-row:nth-child(1) .rank, .lb-row.top1 .rank { color: #ffd54a; font-size: 1.2rem; }
.lb-row.top2 .rank { color: #dfe6ee; font-size: 1.1rem; } .lb-row.top3 .rank { color: #f0a36b; font-size: 1.05rem; }
.lb-row .who { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .who small { opacity: .55; font-weight: 700; margin-left: 6px; font-variant-numeric: tabular-nums; }
.lb-row .time { font-weight: 900; font-variant-numeric: tabular-nums; }
.lb-row.me { outline: 2px solid var(--accent); background: color-mix(in srgb, var(--accent) 22%, var(--panel)); }
.lb-sep { text-align: center; opacity: .5; letter-spacing: .3em; }
.lb-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 6px 6px; font-size: .82rem; color: var(--ink-soft); font-weight: 700; }

/* ------------------------------------------------------------ texte (règles, réglages) */
.prose { max-width: 640px; margin: 0 auto; line-height: 1.55; font-weight: 500; }
.prose h3 { font-size: 1.05rem; font-weight: 800; margin: 20px 0 8px; }
.prose p { margin: 0 0 10px; color: var(--ink-soft); }
.prose strong { color: var(--ink); }
.panel { padding: 14px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--panel-line); margin-bottom: 12px; }
.fam { display: flex; flex-wrap: wrap; gap: 2px; margin: 4px 0 4px; }
.pen-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.pen-list li { display: flex; justify-content: space-between; font-weight: 700; }
.pen-list b { color: var(--accent); font-variant-numeric: tabular-nums; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-weight: 700; font-size: .9rem; }
.field input { font: inherit; font-weight: 700; font-size: 1.05rem; color: var(--ink); padding: 12px 14px; border-radius: 14px;
  background: rgba(0, 0, 0, .28); border: 1px solid var(--panel-line); outline: none; width: 100%; user-select: text; -webkit-user-select: text; }
.field input:focus { border-color: var(--accent); }
.switch { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; font-weight: 700; }
.switch input { appearance: none; -webkit-appearance: none; width: 52px; height: 30px; border-radius: 999px; background: rgba(0, 0, 0, .35);
  border: 1px solid var(--panel-line); position: relative; transition: background .15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(22px); }
.hint { font-size: .8rem; color: var(--ink-soft); font-weight: 600; }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.row-btns .btn { flex: 1; min-width: 120px; }

/* ------------------------------------------------------------ fenêtres modales */
.modal-root { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(0, 0, 0, .55); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); animation: fade .2s ease; }
.modal-root[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(100%, 400px); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 22px 20px 20px; border-radius: 24px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg1) 80%, #000), color-mix(in srgb, var(--bg2) 88%, #000));
  border: 1px solid var(--panel-line); box-shadow: 0 24px 60px rgba(0, 0, 0, .55); animation: modal-in .25s cubic-bezier(.2, 1.3, .4, 1); text-align: center; }
@keyframes modal-in { from { opacity: 0; transform: scale(.9) translateY(10px); } }
.modal h2 { font-size: 1.5rem; font-weight: 900; margin-bottom: 6px; }
.modal p { color: var(--ink-soft); font-weight: 600; margin-bottom: 14px; line-height: 1.45; }
.modal .stack { display: flex; flex-direction: column; gap: 10px; }
.modal .field { text-align: left; }
.big-time { font-size: 3rem; font-weight: 900; font-variant-numeric: tabular-nums; line-height: 1; margin: 6px 0 4px;
  color: var(--accent); text-shadow: 0 3px 0 rgba(0, 0, 0, .35); }
.breakdown { margin: 12px 0 14px; padding: 10px 14px; border-radius: 14px; background: rgba(0, 0, 0, .25); display: grid; gap: 4px;
  font-weight: 700; font-size: .92rem; text-align: left; }
.breakdown div { display: flex; justify-content: space-between; }
.breakdown .pen { color: var(--danger); }
.rank-line { min-height: 1.5em; font-weight: 800; margin-bottom: 14px; }
.rank-line b { color: var(--accent); }
.err { color: var(--danger); font-weight: 700; font-size: .85rem; min-height: 1.2em; margin: -4px 0 8px; }

.toast { position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%); z-index: 30;
  padding: 10px 16px; border-radius: 999px; background: rgba(0, 0, 0, .8); color: #fff; font-weight: 700; font-size: .9rem;
  max-width: 90vw; text-align: center; animation: fade .2s ease; }
.toast[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; } }
