:root {
  --encre: #2a2438;
  --sable: #f3e6c4;
  --sable-2: #e6d3a3;
  --rouge: #c8423a;
  --vert: #5a9a4f;
  --mer: #3f7f9a;
  --blanc: #fffaf0;
  --font: 'Pixelify Sans', ui-rounded, system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--encre); color: var(--encre); font-family: var(--font); overflow: hidden; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
[hidden] { display: none !important; }
button { font-family: var(--font); cursor: pointer; }
#game { position: fixed; inset: 0; touch-action: none; overscroll-behavior: none; }
#game canvas { image-rendering: pixelated; }

/* Joystick tactile flottant */
#joy { position: fixed; z-index: 15; width: 92px; height: 92px; margin: -46px 0 0 -46px; border-radius: 50%; border: 3px solid rgba(255, 250, 240, .8); background: rgba(42, 36, 56, .25); pointer-events: none; }
#joy .knob { position: fixed; width: 40px; height: 40px; margin: -20px 0 0 -20px; border-radius: 50%; background: rgba(255, 250, 240, .9); border: 3px solid var(--encre); }

/* Écrans */
.screen { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: linear-gradient(#9fcfdb 0 45%, #f3e6c4 45% 100%); overflow-y: auto; }
.title-box { width: min(420px, 100%); background: var(--blanc); border: 3px solid var(--encre); box-shadow: 6px 6px 0 var(--encre); padding: 20px; text-align: center; }
h1 { font-size: 34px; line-height: 1; margin: 8px 0 12px; color: var(--rouge); }
h2 { margin: 0 0 6px; font-size: 22px; }
.kicker { margin: 0; font-size: 13px; opacity: .7; text-transform: uppercase; letter-spacing: .06em; }
#title-sprites { display: flex; justify-content: center; align-items: flex-end; gap: 10px; margin: 10px 0; }
#title-sprites img, .perso img, .cell img, .fiche-img img { image-rendering: pixelated; }
.big { display: block; width: 100%; margin-top: 14px; padding: 12px; font-size: 20px; font-weight: 600; background: var(--rouge); color: var(--blanc); border: 3px solid var(--encre); box-shadow: 3px 3px 0 var(--encre); }
.big:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--encre); }
.link { margin-top: 14px; background: none; border: 0; color: var(--encre); opacity: .6; text-decoration: underline; font-size: 13px; }
.persos { display: grid; gap: 10px; margin-top: 12px; text-align: left; }
.perso { display: flex; gap: 12px; align-items: center; padding: 10px; background: var(--sable); border: 3px solid var(--encre); box-shadow: 3px 3px 0 var(--encre); font-size: 14px; }
.perso b { display: block; font-size: 17px; margin-bottom: 2px; }
.perso img { flex: none; width: 48px; }

/* HUD */
#hud { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
#hud > * { pointer-events: auto; }
#hud .top { position: absolute; top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px; display: flex; gap: 8px; justify-content: space-between; align-items: stretch; }
.tide, .clean, .bag { background: var(--blanc); border: 2px solid var(--encre); box-shadow: 2px 2px 0 var(--encre); padding: 5px 8px; font-size: 13px; }
.tide { display: flex; gap: 6px; align-items: center; flex: 1; min-width: 0; }
.tide > div { flex: 1; min-width: 0; }
#tide-text { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#tide-arrow { font-size: 16px; }
#tide-arrow.up { color: var(--rouge); }
#tide-arrow.down { color: var(--mer); }
.tide .bar { height: 4px; background: var(--sable-2); margin-top: 3px; }
#tide-fill { height: 100%; background: var(--mer); }
.clean { white-space: nowrap; display: flex; align-items: center; gap: 4px; }
.clean b { color: var(--vert); }
#toasts { position: absolute; top: calc(max(8px, env(safe-area-inset-top)) + 46px); left: 8px; right: 8px; display: grid; gap: 6px; pointer-events: none; }
.toast { pointer-events: auto; background: var(--encre); color: var(--blanc); padding: 8px 10px; font-size: 14px; line-height: 1.3; border: 2px solid var(--blanc); display: flex; gap: 8px; align-items: center; animation: pop .2s ease-out; transition: opacity .4s; }
.toast span { flex: 1; }
.toast b { color: #f2c230; }
.toast button { flex: none; background: var(--rouge); color: var(--blanc); border: 2px solid var(--blanc); padding: 4px 8px; font-size: 13px; }
.toast.out { opacity: 0; }
@keyframes pop { from { transform: translateY(-6px); opacity: 0; } }
#signal, #watch { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(max(10px, env(safe-area-inset-bottom)) + 66px); background: var(--blanc); border: 2px solid var(--encre); padding: 4px 8px; font-size: 13px; display: flex; align-items: flex-end; gap: 3px; }
#signal span { margin-right: 4px; }
#signal i { display: block; width: 6px; background: var(--sable-2); border: 1px solid var(--encre); }
#signal i:nth-of-type(1) { height: 6px; } #signal i:nth-of-type(2) { height: 9px; } #signal i:nth-of-type(3) { height: 12px; } #signal i:nth-of-type(4) { height: 15px; } #signal i:nth-of-type(5) { height: 18px; }
#signal i.on { background: var(--rouge); }
#watch { flex-direction: column; align-items: stretch; width: 160px; }
#watch > div { height: 6px; background: var(--sable-2); }
#watch b { display: block; height: 100%; background: var(--vert); }
#hud .bottom { position: absolute; bottom: max(10px, env(safe-area-inset-bottom)); left: 8px; right: 8px; display: flex; gap: 6px; align-items: center; }
#hud .bottom button { background: var(--blanc); border: 2px solid var(--encre); box-shadow: 2px 2px 0 var(--encre); padding: 7px 8px; font-size: 14px; color: var(--encre); }
.perso div { text-align: left; }
#hud .bottom button:active { transform: translate(2px, 2px); box-shadow: none; }
#btn-besace .count { background: var(--rouge); color: var(--blanc); padding: 0 4px; margin-left: 2px; }
.bag { white-space: nowrap; }
#btn-a { margin-left: auto; flex: none; display: flex; flex-direction: column; align-items: center; width: 64px; height: 64px; border-radius: 50%; background: var(--rouge) !important; color: var(--blanc); justify-content: center; padding: 4px 2px !important; }
#btn-a b { font-size: 20px; line-height: 1; }
#btn-a .label { font-size: 10px; max-width: 100%; overflow: hidden; text-overflow: clip; white-space: nowrap; letter-spacing: -.02em; }

/* Fenêtres */
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(42, 36, 56, .55); display: grid; place-items: end center; padding: 12px; }
.modal.small { place-items: center; }
.sheet { position: relative; width: min(520px, 100%); max-height: 88vh; overflow-y: auto; background: var(--blanc); border: 3px solid var(--encre); box-shadow: 5px 5px 0 var(--encre); padding: 18px 16px; user-select: text; -webkit-user-select: text; }
.close { position: sticky; top: 0; float: right; background: var(--encre); color: var(--blanc); border: 0; width: 32px; height: 32px; font-size: 16px; z-index: 2; }
.besace-head p { margin: 0 0 10px; font-size: 14px; opacity: .75; }
.sheet h3 { margin: 16px 0 6px; font-size: 16px; color: var(--rouge); }
.sheet h3 small { color: var(--encre); opacity: .6; font-weight: 400; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.cell { background: var(--sable); border: 2px solid var(--encre); padding: 8px 4px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; min-height: 92px; justify-content: center; color: var(--encre); }
.cell img { max-width: 64px; max-height: 40px; }
.cell.unknown { background: #e8e1cf; cursor: default; }
.cell.unknown img { filter: brightness(0); opacity: .3; }
.cell.unknown span { opacity: .5; }
.fiche-top { display: flex; gap: 14px; align-items: center; margin-bottom: 4px; }
.fiche-img { flex: none; width: 96px; height: 96px; display: grid; place-items: center; background: var(--sable); border: 2px solid var(--encre); }
.fiche-img img { max-width: 84px; max-height: 84px; }
.sci { margin: 0; font-style: italic; opacity: .75; }
.tags { margin: 6px 0 0; display: flex; gap: 6px; flex-wrap: wrap; }
.tags span { background: var(--encre); color: var(--blanc); font-size: 12px; padding: 2px 6px; }
.sheet p { line-height: 1.45; font-size: 15px; margin: 0 0 6px; }
.geste { background: #e5f0de; border-left: 4px solid var(--vert); padding: 6px 8px; }
.valider { margin-top: 14px !important; font-size: 12px !important; opacity: .6; }
.gauge { position: relative; height: 28px; background: var(--mer); border: 2px solid var(--encre); margin: 14px 0 4px; }
.gauge .zone { position: absolute; top: 0; bottom: 0; background: var(--vert); }
.gauge .cursor { position: absolute; top: -6px; bottom: -6px; width: 4px; margin-left: -2px; background: var(--encre); }
.danger .sheet { border-color: var(--rouge); }
.danger h2 { color: var(--rouge); }
