/* Sokoban 3D — mise en page adaptative portrait/paysage, zones sûres iOS,
   cibles tactiles confortables. Aucune police externe, aucune image. */

:root {
  --bg: #eef1f7;
  --panel: #ffffff;
  --panel-2: #f4f6fb;
  --text: #1d2432;
  --muted: #5d6779;
  --line: #d7dce8;
  --accent: #2d7bda;
  --accent-t: #ffffff;
  --ok: #2f9e63;
  --warn: #c8871b;
  --bad: #cc4238;
  --r: 14px;
  --pad: max(10px, env(safe-area-inset-left));
  --padb: max(10px, env(safe-area-inset-bottom));
  --padt: max(10px, env(safe-area-inset-top));
}
html.dark {
  --bg: #161b26;
  --panel: #212836;
  --panel-2: #1a2130;
  --text: #e8ecf5;
  --muted: #a3adc2;
  --line: #333c50;
  --accent: #4b93ef;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-top: 1.2em; }
p { margin: .4em 0; }
ul { margin: .4em 0; padding-left: 1.2em; }

/* ---------- plateau ---------- */
#stage { position: fixed; inset: 0; display: none; }
#stage.active { display: block; }
.canvas-wrap { position: absolute; inset: 0; }
#board { display: block; width: 100%; height: 100%; touch-action: none; }

/* ---------- écrans de menu ---------- */
#screens {
  position: fixed; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: var(--padt) var(--pad) var(--padb);
}
.screen { max-width: 760px; margin: 0 auto; padding: 8px 4px 40px; }
.screen-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.screen-head h2 { margin: 0; }
.home { text-align: center; padding-top: 6vh; }
.home h1 { margin-bottom: .1em; }
.sub { color: var(--muted); margin-bottom: 22px; }
.foot { color: var(--muted); font-size: .85rem; margin-top: 22px; }
.empty { color: var(--muted); padding: 24px 0; }

.menu { display: flex; flex-direction: column; gap: 10px; max-width: 380px; margin: 0 auto; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel);
  border-radius: var(--r); padding: 12px 18px; min-height: 46px; cursor: pointer;
  font-weight: 600; transition: transform .08s, background .15s;
}
.btn:active { transform: scale(.98); }
.btn:focus-visible, .icon:focus-visible, .tile:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); color: var(--accent-t); border-color: transparent; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.big { min-height: 56px; font-size: 1.05rem; }
.btn.wide { width: 100%; }
.btn.small { padding: 10px 12px; }
.btn[disabled] { opacity: .45; cursor: default; }

.icon {
  appearance: none; border: 1px solid var(--line); background: var(--panel);
  width: 46px; height: 46px; border-radius: 50%; cursor: pointer;
  font-size: 1.15rem; display: grid; place-items: center; padding: 0;
}
.icon[disabled] { opacity: .4; }

/* ---------- sélecteur de niveaux ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.tile {
  position: relative; appearance: none; border: 1px solid var(--line); background: var(--panel);
  border-radius: var(--r); padding: 12px 8px; min-height: 84px; cursor: pointer; text-align: center;
  display: grid; gap: 2px; align-content: center;
}
.tile .num { font-size: 1.4rem; font-weight: 700; }
.tile .name { font-size: .78rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .best { font-size: .75rem; color: var(--muted); }
.tile.done { border-color: var(--ok); }
.tile .check { position: absolute; top: 6px; right: 8px; color: var(--ok); font-weight: 700; }
.tile.locked { opacity: .5; cursor: default; }

/* ---------- listes ---------- */
.items { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center;
  border: 1px solid var(--line); background: var(--panel); border-radius: var(--r); padding: 12px 14px;
}
.item-name { font-weight: 600; }
.item-meta { color: var(--muted); font-size: .82rem; }
.item-actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.badge { font-size: .74rem; padding: 3px 9px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.warn { color: var(--warn); border-color: var(--warn); }
.badge.draft { color: var(--muted); }

/* ---------- réglages ---------- */
.settings { display: flex; flex-direction: column; gap: 4px; }
.setting {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 4px; border-bottom: 1px solid var(--line);
}
.setting-label { display: flex; flex-direction: column; }
.setting-label small { color: var(--muted); font-size: .8rem; }
.switch { position: relative; width: 52px; height: 31px; flex: none; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.slider { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background .2s; pointer-events: none; }
.slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 25px; height: 25px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::after { transform: translateX(21px); }
.switch input:focus-visible + .slider { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- interface de partie ---------- */
.hud { position: absolute; inset: 0; pointer-events: none; }
.hud > * { pointer-events: auto; }
.hud-top {
  position: absolute; top: var(--padt); left: var(--pad); right: var(--pad);
  display: flex; align-items: center; gap: 10px;
}
.hud-title { font-weight: 600; max-width: 34%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.counters {
  margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; font-size: .82rem; color: var(--muted);
}
.counters b { color: var(--text); }
.hud-tools {
  position: absolute; right: var(--pad); top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 8px;
}
.dpad {
  position: absolute; left: var(--pad); bottom: var(--padb);
  display: grid; grid-template-columns: repeat(3, 62px); grid-template-rows: repeat(2, 62px); gap: 6px;
}
.pad {
  appearance: none; border: 1px solid var(--line); background: var(--panel);
  border-radius: 16px; font-size: 1.3rem; cursor: pointer; display: grid; place-items: center;
  user-select: none; -webkit-user-select: none;
}
.pad.held { background: var(--accent); color: var(--accent-t); }
.pad.u { grid-column: 2; grid-row: 1; }
.pad.l { grid-column: 1; grid-row: 2; }
.pad.d { grid-column: 2; grid-row: 2; }
.pad.r { grid-column: 3; grid-row: 2; }

/* ---------- barre de l'éditeur ---------- */
.editor { position: absolute; inset: 0; pointer-events: none; }
.editor > * { pointer-events: auto; }
.ed-top {
  position: absolute; top: var(--padt); left: var(--pad); right: var(--pad);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.ed-name { appearance: none; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 8px 14px; cursor: pointer; font-weight: 600; }
.ed-info { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: .8rem; color: var(--muted); }
.ed-info.mismatch { color: var(--warn); border-color: var(--warn); }
.ed-bottom {
  position: absolute; left: var(--pad); right: var(--pad); bottom: var(--padb);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.palette { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.tool {
  appearance: none; border: 1px solid var(--line); background: var(--panel); border-radius: 14px;
  padding: 8px 10px; min-height: 54px; min-width: 54px; cursor: pointer;
  display: grid; justify-items: center; gap: 4px;
}
.tool.on { border-color: var(--accent); box-shadow: inset 0 0 0 2px var(--accent); }
.tool .chip { width: 22px; height: 22px; border-radius: 5px; border: 1px solid rgba(0,0,0,.25); }
.tool .lbl { font-size: .7rem; color: var(--muted); }
.tool.wall .chip { background: #5a6378; }
.tool.floor .chip { background: #dadde6; }
.tool.target .chip { background: #f9c442; border-radius: 50%; }
.tool.box .chip { background: #cd8345; }
.tool.player .chip { background: #2d7bda; border-radius: 50%; }
.ed-tools { position: absolute; right: var(--pad); top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; }
.ed-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.ed-actions .btn { padding: 11px 14px; min-height: 44px; }

/* ---------- fenêtres ---------- */
.backdrop {
  position: fixed; inset: 0; background: rgba(12, 16, 26, .45); z-index: 40;
  display: grid; place-items: center; padding: 16px; opacity: 0; transition: opacity .18s;
}
.backdrop.in { opacity: 1; }
.card {
  background: var(--panel); border-radius: 18px; max-width: 460px; width: 100%;
  max-height: 86vh; overflow: auto; box-shadow: 0 18px 50px rgba(10, 16, 30, .3);
  transform: translateY(8px); transition: transform .18s;
}
.card.wide { max-width: 640px; }
.backdrop.in .card { transform: none; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 4px; }
.card-head h2 { margin: 0; flex: 1; }
.card-body { padding: 6px 18px 12px; }
.card-actions { display: flex; gap: 8px; padding: 8px 18px 18px; flex-wrap: wrap; justify-content: flex-end; }
.result .big { font-size: 1.2rem; font-weight: 700; }
.hint { color: var(--muted); font-size: .86rem; }
.warn { color: var(--warn); }
.preview { font-family: ui-monospace, Menlo, Consolas, monospace; white-space: pre; background: var(--panel-2); border-radius: 10px; padding: 10px; overflow: auto; font-size: .85rem; }
.form { display: flex; flex-direction: column; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 6px; }
.field { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 10px; padding: 11px 12px; font: inherit; width: 100%; }
.field.num { max-width: 120px; }

/* ---------- messages ---------- */
.toasts { position: fixed; top: calc(var(--padt) + 56px); left: 0; right: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  pointer-events: auto; background: var(--text); color: var(--bg); border-radius: 999px;
  padding: 10px 18px; font-size: .9rem; max-width: min(92vw, 520px);
  opacity: 0; transform: translateY(-6px); transition: opacity .2s, transform .2s;
  display: flex; align-items: center; gap: 10px;
}
.toast.in { opacity: 1; transform: none; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.warn { background: var(--warn); color: #23180a; }
.toast-act { appearance: none; border: 0; background: rgba(255,255,255,.22); border-radius: 999px; padding: 4px 10px; cursor: pointer; }

#loading, #fatal { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; padding: 20px; background: var(--bg); z-index: 70; }
#fatal[hidden] { display: none; }
.noscript { text-align: center; padding: 40px 20px; }

/* ---------- paysage : commandes de part et d'autre ---------- */
@media (orientation: landscape) and (max-height: 560px) {
  .dpad { grid-template-columns: repeat(3, 54px); grid-template-rows: repeat(2, 54px); }
  .counters { font-size: .76rem; padding: 5px 10px; }
  .home { padding-top: 2vh; }
}
@media (max-width: 380px) {
  .dpad { grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(2, 56px); }
  .hud-title { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
html.no-anim * { transition: none !important; }

/* Accès au niveau suivant même après fermeture du résultat. */
.next-level { position: absolute; right: calc(12px + env(safe-area-inset-right)); bottom: calc(12px + env(safe-area-inset-bottom)); pointer-events: auto; max-width: calc(100% - 220px); padding: 10px 12px; }

/* Accueil : une invitation à jouer, distincte des écrans utilitaires. */
.home {
  --home-ink: #272139;
  --home-muted: #695f79;
  --home-paper: #fffdf8;
  --home-violet: #7654c8;
  --home-orange: #f1ad70;
  max-width: 1160px;
  min-height: 100%;
  padding: clamp(14px, 3vw, 34px) clamp(16px, 4vw, 46px) 26px;
  text-align: left;
  color: var(--home-ink);
  background: radial-gradient(circle at 82% 22%, #f2e5ff 0, transparent 32%),
    radial-gradient(circle at 18% 80%, #ffe8d2 0, transparent 32%), var(--home-paper);
  border-radius: 26px;
  box-shadow: 0 24px 80px #43305c13;
}
#screens:has(.home) { background: #f5f0f7; padding: max(12px, var(--padt)) max(12px, var(--pad)) max(12px, var(--padb)); }
.home-top, .home-bottom { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.home-top { padding-bottom: 22px; border-bottom: 1px solid #e8dfeb; }
.home-brand { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; letter-spacing: .16em; font-weight: 850; white-space: nowrap; }
.home-brand-mark { color: var(--home-violet); font-size: 1.7rem; line-height: 1; margin-right: 3px; }
.home-brand-small { color: var(--home-violet); }
.home-top-note, .home-eyebrow, .home-art-caption { font-size: .7rem; letter-spacing: .18em; font-weight: 800; }
.home-top-note { color: #82748e; }
.home-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, .95fr); align-items: center; gap: clamp(20px, 4vw, 55px); padding: clamp(26px, 4vw, 54px) 0 26px; }
.home-intro { position: relative; z-index: 1; }
.home-eyebrow { color: var(--home-violet); margin: 0 0 20px; }
.home h1 { max-width: 650px; margin: 0; font-size: clamp(2.8rem, 5.7vw, 5.3rem); line-height: 1.02; letter-spacing: -.065em; font-weight: 850; }
.home h1 em { font-style: normal; color: var(--home-violet); }
.home-lead { max-width: 470px; margin: 23px 0 28px; color: var(--home-muted); font-size: clamp(1rem, 1.5vw, 1.17rem); line-height: 1.65; }
.home-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.home .btn { font-size: .95rem; border-radius: 14px; }
.home .home-cta { min-width: 200px; min-height: 56px; background: var(--home-violet); box-shadow: 0 12px 22px #7654c83d; }
.home .home-cta:hover { background: #6040b4; transform: translateY(-2px); }
.home .home-secondary { min-height: 56px; background: #fff; border-color: #d7cbe3; }
.home .home-secondary:hover { background: #f8f3ff; }
.home-progress { display: flex; align-items: center; gap: 9px; margin: 22px 0 0; color: var(--home-muted); font-size: .87rem; }
.home-progress-dot { width: 8px; height: 8px; border-radius: 50%; background: #55a985; box-shadow: 0 0 0 4px #55a98523; }
.home-art { position: relative; min-height: 390px; display: grid; place-items: center; isolation: isolate; }
.home-art-orbit { position: absolute; width: min(100%, 435px); aspect-ratio: 1; border-radius: 50%; background: radial-gradient(circle, #f8e7d7 0 34%, #ebddfb 68%, transparent 70%); opacity: .85; z-index: -1; }
.home-board { width: min(73%, 310px); aspect-ratio: 1; display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 7px; background: #ad90d5; border: 6px solid #7358a8; border-radius: 16px; box-shadow: 15px 20px 0 #4c397b, 26px 32px 36px #59417e55; transform: rotateX(42deg) rotateZ(-34deg); }
.home-cell { position: relative; min-width: 0; border-radius: 5px; background: #f6e9cf; box-shadow: inset 0 1px 0 #fff9; }
.home-cell.wall { background: #8063b0; box-shadow: inset 0 5px 0 #a58acb, inset -5px -5px 0 #5a438c; }
.home-cell.target::after { content: ''; position: absolute; inset: 21%; border: 5px solid #e79d69; border-radius: 50%; box-shadow: 0 0 0 3px #fff3; }
.home-cell.crate::after { content: '✕'; position: absolute; inset: 11%; display: grid; place-items: center; border-radius: 5px; background: #e7a46d; color: #9b5b3d; font-size: clamp(1.3rem, 4vw, 2.1rem); font-weight: 900; border: 4px solid #f3c08b; box-shadow: 5px 6px 0 #a5674d; }
.home-cell.player::after { content: ''; position: absolute; inset: 14%; border-radius: 50%; background: radial-gradient(circle at 38% 32%, #fff5d7 0 16%, #64b09b 17% 67%, #327867 68%); box-shadow: 4px 5px 0 #285e5c; }
.home-art-caption { position: absolute; bottom: 3px; color: #8f7ba4; white-space: nowrap; }
.home-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 6px; }
.home-card { display: flex; align-items: center; gap: 15px; min-height: 108px; padding: 18px 20px; border: 1px solid #e3daea; border-radius: 19px; background: #fff; text-align: left; cursor: pointer; box-shadow: 0 7px 20px #5139660d; }
.home-card:hover { border-color: #ad8fe1; transform: translateY(-2px); box-shadow: 0 12px 26px #5139661c; }
.home-card-symbol { display: grid; place-items: center; flex: 0 0 48px; width: 48px; height: 48px; border-radius: 14px; background: #f0e8fc; color: var(--home-violet); font-size: 1.6rem; }
.home-card:nth-child(2) .home-card-symbol { background: #fff0e2; color: #c47b43; }
.home-card-copy { display: grid; gap: 3px; min-width: 0; }
.home-card-copy strong { font-size: 1rem; }
.home-card-copy small { color: var(--home-muted); font-size: .84rem; }
.home-card-arrow { margin-left: auto; color: var(--home-violet); font-size: 1.3rem; }
.home-bottom { margin-top: 26px; padding-top: 19px; border-top: 1px solid #e8dfeb; color: var(--home-muted); font-size: .83rem; }
.home-bottom-links { display: flex; gap: 9px; }
.home-bottom-links .btn { min-height: 40px; padding: 8px 13px; font-size: .82rem; background: transparent; border-color: #d9cde4; }
.home-bottom-links .btn:hover { background: #fff; }
.home button:focus-visible { outline: 3px solid var(--home-violet); outline-offset: 3px; }
html.dark #screens:has(.home) { background: #181522; }
html.dark .home { --home-ink: #f7f2ff; --home-muted: #c7bcd4; --home-paper: #282238; background: radial-gradient(circle at 82% 22%, #49375d 0, transparent 33%), #282238; box-shadow: none; }
html.dark .home-top, html.dark .home-bottom { border-color: #4c415b; }
html.dark .home-card, html.dark .home .home-secondary { background: #342c46; border-color: #5c4c70; color: var(--home-ink); }
html.dark .home-card-copy small { color: var(--home-muted); }
html.dark .home h1 em, html.dark .home-eyebrow, html.dark .home-brand-small { color: #c1a2ff; }
@media (max-width: 700px) {
  .home { border-radius: 18px; }
  .home-top-note { display: none; }
  .home-grid { grid-template-columns: 1fr; padding-top: 34px; gap: 0; }
  .home h1 { max-width: 560px; }
  .home-art { min-height: 300px; margin-top: 8px; }
  .home-board { width: min(65%, 250px); }
}
@media (max-width: 480px) {
  .home { padding: 17px 17px 22px; }
  .home h1 { font-size: clamp(2.65rem, 12vw, 3.7rem); }
  .home-lead { margin: 17px 0 22px; }
  .home-actions .btn { flex: 1 1 100%; }
  .home-art { min-height: 260px; }
  .home-cards { grid-template-columns: 1fr; }
  .home-card { min-height: 84px; }
  .home-bottom { align-items: flex-start; flex-direction: column; }
}
