html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  /* Le ciel est un simple dégradé derrière le canvas transparent */
  background: linear-gradient(to bottom, #7cc8f5 0%, #bfe8ff 55%, #fff1d6 100%);
  font-family: "Trebuchet MS", system-ui, sans-serif;
}

canvas {
  display: block;
}

#hud {
  position: fixed;
  top: 16px;
  left: 16px;
  padding: 10px 16px;
  color: #4a3326;
  background: rgba(255, 248, 232, 0.85);
  border: 3px solid #4a3326;
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(74, 51, 38, 0.35);
  user-select: none;
}

#hud {
  padding: 6px 12px;
  max-width: min(400px, calc(100vw - 260px));
}

#hud .hud-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

#hud h1 {
  margin: 0;
  font-size: 18px;
}

/* Boutons de l'aide : le panneau laisse passer les clics, sauf sur ses boutons */
#hud button {
  pointer-events: auto;
  padding: 2px 9px;
  font: bold 12px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 8px;
  cursor: pointer;
}

#hud button:hover {
  background: #ffe7c2;
}

#hud .help[hidden],
#hud ul[hidden] {
  display: none;
}

#hud .tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 8px 0 6px;
}

#hud .tabs button {
  font-weight: normal;
  border-width: 1.5px;
  background: rgba(242, 215, 176, 0.5);
}

#hud .tabs button.active {
  font-weight: bold;
  background: #f2c14e;
}

#hud ul {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.5;
}

/* Jauge d'endurance : apparaît quand on court, disparaît une fois pleine */
#stamina {
  position: fixed;
  left: 50%;
  bottom: 28px;
  width: 220px;
  height: 16px;
  transform: translateX(-50%);
  background: rgba(255, 248, 232, 0.85);
  border: 3px solid #4a3326;
  border-radius: 10px;
  box-shadow: 0 3px 0 rgba(74, 51, 38, 0.35);
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
}

#stamina.visible {
  opacity: 1;
}

#stamina .fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(to bottom, #9be36a, #5fae3e);
  transform-origin: left;
}

/* Épuisé : la jauge vire au rouge et clignote jusqu'à ce qu'on ait récupéré */
#stamina.tired .fill {
  background: linear-gradient(to bottom, #f08a6a, #d94848);
  animation: tired 0.8s ease-in-out infinite alternate;
}

@keyframes tired {
  to { opacity: 0.55; }
}
/* Date, heure, météo et âge du personnage */
#clock {
  position: fixed;
  top: 16px;
  right: 16px;
  padding: 8px 14px;
  min-width: 190px;
  max-width: 330px; /* il retient les clics, maintenant qu'on l'attrape : autant qu'il cache peu le monde */
  color: #4a3326;
  background: rgba(255, 248, 232, 0.85);
  border: 3px solid #4a3326;
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(74, 51, 38, 0.35);
  font-size: 13px;
  line-height: 1.5;
  text-align: right;
  user-select: none;
}

#clock .date {
  font-weight: bold;
  font-size: 15px;
}

#clock .who {
  font-style: italic;
}

#clock .speed {
  color: #d94848;
  font-weight: bold;
}

/* Annonces : décès, arrivées, héritier */
#toasts {
  position: fixed;
  top: 16px;
  left: 50%;
  width: min(460px, calc(100vw - 32px));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  z-index: 25; /* les annonces restent lisibles, quel que soit le cadre posé dessous */
}

.toast {
  padding: 8px 14px;
  color: #4a3326;
  background: rgba(255, 248, 232, 0.92);
  border: 3px solid #4a3326;
  border-radius: 12px;
  box-shadow: 0 3px 0 rgba(74, 51, 38, 0.35);
  font-size: 14px;
  text-align: center;
  transition: opacity 0.8s, transform 0.8s;
}

.toast.out {
  opacity: 0;
  transform: translateY(-8px);
}
/* Boutons pour accélérer / ralentir le temps */
#clock .time-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  pointer-events: auto;
}

#clock button {
  width: 26px;
  height: 26px;
  padding: 0;
  font: bold 16px/1 "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 8px;
  cursor: pointer;
}

#clock button:hover {
  background: #ffe7c2;
}

#speed {
  min-width: 90px;
  text-align: center;
}

#speed.fast {
  color: #d94848;
  font-weight: bold;
}

/* Étiquettes au-dessus des habitants et des tombes */
#labels {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.label {
  position: absolute;
  left: 0;
  top: 0;
  padding: 4px 10px;
  color: #4a3326;
  background: rgba(255, 248, 232, 0.9);
  border: 2px solid #4a3326;
  border-radius: 10px;
  box-shadow: 0 2px 0 rgba(74, 51, 38, 0.35);
  font-size: 13px;
  line-height: 1.35;
  text-align: center;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.25s;
}

.label.visible {
  opacity: 1;
}

.label span {
  display: block;
  font-size: 12px;
}
#clock button.wide {
  width: auto;
  margin-top: 6px;
  padding: 0 10px;
  font-size: 13px;
  pointer-events: auto;
}

/* Panneau des compétences, inventaire */
#skills,
#inventory,
#quests,
#village {
  position: fixed;
  left: 16px;
  bottom: 16px;
  width: min(300px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 10px 14px;
  color: #4a3326;
  background: rgba(255, 248, 232, 0.94);
  border: 3px solid #4a3326;
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(74, 51, 38, 0.35);
  font-size: 13px;
}

#skills[hidden],
#inventory[hidden],
#quests[hidden],
#village[hidden] {
  display: none;
}

#skills h2,
#inventory h2,
#quests h2,
#village h2,
#training h2 {
  margin: 0 0 8px;
  font-size: 16px;
}

#inventory h3 {
  margin: 10px 0 4px;
  font-size: 13.5px;
  border-bottom: 2px solid rgba(74, 51, 38, 0.25);
}

#inventory {
  width: min(340px, calc(100vw - 32px));
}

#inventory h3 i {
  font-weight: normal;
  font-style: normal;
  font-size: 11.5px;
  opacity: 0.7;
}

.icon {
  display: block;
  width: 34px;
  height: 34px;
}

#inventory .inv-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 5px;
}

#inventory .inv-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 5px 3px 4px;
  text-align: center;
  background: rgba(74, 51, 38, 0.08);
  border: 2px solid rgba(74, 51, 38, 0.28);
  border-radius: 9px;
}

#inventory .inv-tile span {
  max-width: 100%;
  font-size: 10.5px;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

#inventory .inv-tile .count {
  position: absolute;
  top: 1px;
  right: 2px;
  padding: 0 4px;
  font-size: 11px;
  color: #fff8e8;
  background: #4a3326;
  border-radius: 7px;
}

#inventory .wear {
  display: block;
  width: 90%;
  height: 5px;
  overflow: hidden;
  background: rgba(74, 51, 38, 0.2);
  border-radius: 3px;
}

#inventory .wear i {
  display: block;
  height: 100%;
  background: #5a9a40;
}

#inventory .wear.low i {
  background: #c8503a;
}

#inventory .inv-tile button {
  padding: 0 3px;
  font: bold 10px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 6px;
  cursor: pointer;
}

#inventory .inv-empty,
#quests .inv-empty {
  font-size: 12px;
  opacity: 0.6;
}

/* Les commandes à livrer (touche J) */
#quests .quest {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 0;
  border-bottom: 2px solid rgba(74, 51, 38, 0.15);
}

#quests .quest span {
  font-size: 12px;
}

#quests .quest button {
  margin-left: 6px;
  padding: 0 6px;
  font: bold 11.5px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 7px;
  cursor: pointer;
}

#skills p,
#inventory p,
#quests p,
#training p {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.4;
  opacity: 0.8;
}

.skill {
  margin-bottom: 8px;
}

.skill.soon {
  opacity: 0.55;
}

.skill-head {
  display: flex;
  justify-content: space-between;
}

.skill .bar {
  position: relative;
  height: 10px;
  margin: 2px 0;
  background: #ead8b8;
  border: 2px solid #4a3326;
  border-radius: 6px;
}

.skill .bar .fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(to bottom, #8fd0ff, #3e7bd6);
}

/* Repères du plancher (niveau de départ) et du plafond de la vie */
.skill .bar i {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 3px;
  margin-left: -1.5px;
  border-radius: 2px;
}

.skill .bar i.floor {
  background: #8a5a2a;
}

.skill .bar i.cap {
  background: #d94848;
}

.skill-foot {
  font-size: 11px;
  opacity: 0.75;
}
#clock .place {
  font-weight: bold;
  font-size: 15px;
  color: #2e6a3a;
}

/* Mode illimité (?illimite) : bien visible, pour ne pas l'oublier */
#clock .unlimited {
  margin-bottom: 4px;
  padding: 1px 6px;
  font-weight: bold;
  font-size: 12px;
  color: #fff8e8;
  background: #c0443c;
  border-radius: 6px;
}
/* Carte du monde (touche M) */
#map {
  position: fixed;
  inset: 4vh 4vw;
  display: flex;
  flex-direction: column;
  color: #4a3326;
  background: #f4e8cc;
  border: 4px solid #4a3326;
  border-radius: 16px;
  box-shadow: 0 6px 0 rgba(74, 51, 38, 0.4), 0 0 0 100vmax rgba(20, 14, 10, 0.35);
  overflow: hidden;
  z-index: 30;
}

#map[hidden] {
  display: none;
}

#map .map-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  padding: 8px 14px;
  border-bottom: 2px solid #4a3326;
  font-size: 14px;
}

#map .map-head b {
  font-size: 17px;
}

#map .map-place {
  font-style: italic;
}

#map .map-help {
  margin-left: auto;
  font-size: 12px;
  opacity: 0.75;
}

#map canvas {
  flex: 1;
  width: 100%;
  min-height: 0;
  cursor: grab;
  touch-action: none;
}

#map canvas:active {
  cursor: grabbing;
}

#map .map-legend {
  padding: 6px 14px;
  border-top: 2px solid #4a3326;
  font-size: 13px;
}
#clock .tools {
  font-size: 12px;
  opacity: 0.85;
}

/* Étal du marchand d'outils */
.panel {
  position: fixed;
  left: 50%;
  bottom: 60px;
  transform: translateX(-50%);
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding: 10px 14px;
  color: #4a3326;
  background: rgba(255, 248, 232, 0.96);
  border: 3px solid #4a3326;
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(74, 51, 38, 0.35);
  font-size: 13px;
  z-index: 5;
}

.panel[hidden] {
  display: none;
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 16px;
}

.panel h3 {
  margin: 10px 0 4px;
  font-size: 14px;
  border-bottom: 2px solid rgba(74, 51, 38, 0.25);
}

.panel .purse b {
  color: #b07a10;
}

.panel .shop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
}

.panel .shop-row span {
  display: block;
  font-size: 11.5px;
  opacity: 0.75;
}

.panel button {
  flex: none;
  padding: 4px 10px;
  font: bold 12.5px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 8px;
  cursor: pointer;
}

.panel button:hover:not(:disabled) {
  background: #ffe7c2;
}

.panel button:disabled {
  opacity: 0.45;
  cursor: default;
}

.panel p {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.4;
  opacity: 0.8;
}

/* Les tâches planifiées (Maj+E) : en bas à droite */
#plan {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: min(340px, calc(100vw - 32px));
  max-height: 55vh;
  overflow-y: auto;
  padding: 10px 14px;
  color: #4a3326;
  background: rgba(255, 248, 232, 0.94);
  border: 3px solid #4a3326;
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(74, 51, 38, 0.35);
  font-size: 12.5px;
}

#plan[hidden] {
  display: none;
}

#plan h2 {
  margin: 0;
  font-size: 15px;
}

#plan .plan-state,
#plan .plan-more {
  margin-bottom: 4px;
  font-size: 11.5px;
  opacity: 0.7;
}

#plan .plan-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px;
  border-radius: 6px;
}

#plan .plan-row.now {
  background: #ffe7c2;
  font-weight: bold;
}

#plan button {
  padding: 2px 8px;
  font: bold 12px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 8px;
  cursor: pointer;
}

#plan .plan-row span {
  flex: 1;
}

#plan .plan-row i {
  font-weight: normal;
  opacity: 0.7;
}

#plan .plan-row.later {
  opacity: 0.55;
}

#plan .plan-row button {
  flex: none;
  padding: 0 6px;
}

/* ↻ : la tâche revient chaque jour */
#plan .plan-row button.daily {
  opacity: 0.35;
  background: transparent;
}

#plan .plan-row button.daily.on {
  opacity: 1;
  background: #cfe6b8;
}

#plan .plan-buttons {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

/* Le menu des actions (E quand plusieurs sont possibles) */
#choices {
  width: min(320px, calc(100vw - 32px));
}

#choices button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: 6px;
  padding: 6px 10px;
  text-align: left;
}

#choices button.on {
  background: #ffe7c2;
  box-shadow: inset 0 0 0 2px #b07a10;
}

#choices button b {
  flex: none;
  width: 22px;
  height: 22px;
  line-height: 22px;
  text-align: center;
  color: #fff8e8;
  background: #4a3326;
  border-radius: 6px;
}

#choices button span {
  display: flex;
  flex-direction: column;
}

#choices button i {
  font-weight: normal;
  font-style: normal;
  font-size: 11px;
  opacity: 0.7;
}

#clock button.wide + button.wide {
  margin-left: 6px;
}
/* Deux boutons côte à côte (acheter 1 ou 5) */
.panel .shop-row span.btns {
  display: flex;
  flex: none;
  gap: 6px;
  opacity: 1;
}

/* La forme (fatigue) : sous l'horloge, verte quand on est reposé, orange fatigué, rouge épuisé */
#energy {
  margin-top: 6px;
}

#energy .bar {
  height: 10px;
  margin-left: auto;
  width: 100%;
  background: #ead8b8;
  border: 2px solid #4a3326;
  border-radius: 6px;
  overflow: hidden;
}

#energy .fill {
  height: 100%;
  background: linear-gradient(to bottom, #9be36a, #5fae3e);
  transform-origin: left;
  transition: transform 0.3s;
}

#energy.tired .fill {
  background: linear-gradient(to bottom, #f5c56a, #e08a2a);
}

#energy.exhausted .fill {
  background: linear-gradient(to bottom, #f08a6a, #d94848);
  animation: tired 0.8s ease-in-out infinite alternate;
}

#energy .text {
  font-size: 12px;
}

/* Le sommeil : l'écran s'assombrit, l'heure défile */
#sleep {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #f4ead8;
  background: rgba(12, 14, 34, 0.78);
  opacity: 0;
  transition: opacity 0.6s;
  pointer-events: none;
  z-index: 28;
  font-size: 15px;
}

#sleep[hidden] {
  display: none;
}

#sleep.on {
  opacity: 1;
}

#sleep .zzz {
  font-size: 34px;
  font-style: italic;
  animation: tired 1.4s ease-in-out infinite alternate;
}

#sleep .time {
  font-size: 28px;
  font-weight: bold;
}

#sleep .hint {
  margin-top: 10px;
  font-size: 12px;
  opacity: 0.7;
}

/* Avancement d'un travail, dans son étiquette */
.label i.progress {
  display: block;
  width: 140px;
  height: 7px;
  margin: 3px auto;
  background: #ead8b8;
  border: 1.5px solid #4a3326;
  border-radius: 4px;
  overflow: hidden;
}

.label i.progress i {
  display: block;
  height: 100%;
  background: linear-gradient(to bottom, #f2c14e, #c98a1a);
}

/* Matériaux à l'enclume : ce qu'on a (vert) ou ce qui manque (rouge) */
.panel i {
  font-style: normal;
}

.panel i.ok {
  color: #2e7a3a;
}

.panel i.missing {
  color: #c0392b;
}

/* La santé, sous la forme */
#health {
  margin-top: 4px;
}

#health .bar {
  height: 10px;
  width: 100%;
  background: #ead8b8;
  border: 2px solid #4a3326;
  border-radius: 6px;
  overflow: hidden;
}

#health .fill {
  height: 100%;
  background: linear-gradient(to bottom, #f08a8a, #c8403c);
  transform-origin: left;
  transition: transform 0.3s;
}

#health.low .fill {
  animation: tired 0.6s ease-in-out infinite alternate;
}

#health .text {
  font-size: 12px;
}

/* L'écran de combat : un bandeau bleu en bas de l'écran, à la façon de FF7 */
#battle {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  width: min(860px, calc(100vw - 24px));
  display: grid;
  grid-template-columns: 1.2fr 1fr 1.2fr;
  gap: 10px;
  padding: 10px;
  color: #f4f6ff;
  background: linear-gradient(to bottom, #2a4aa8, #101c5a);
  border: 3px solid #d8dcf0;
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
  font-size: 13px;
  z-index: 20;
}

#battle[hidden] {
  display: none;
}

#battle .foes,
#battle .cmds {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#battle button {
  font: inherit;
  color: inherit;
  text-align: left;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 6px;
  padding: 3px 8px;
  cursor: pointer;
}

#battle button:hover:not(:disabled),
#battle .foe.on {
  background: rgba(255, 255, 255, 0.24);
}

#battle button:disabled {
  opacity: 0.4;
  cursor: default;
}

#battle .cmds b {
  display: inline-block;
  width: 16px;
  color: #ffe08a;
}

#battle .foe span {
  display: block;
}

#battle .gauge {
  display: block;
  height: 7px;
  margin-top: 2px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  overflow: hidden;
}

#battle .gauge i {
  display: block;
  height: 100%;
  width: 0;
}

#battle .gauge.hp i {
  background: linear-gradient(to right, #6ae08a, #38b868);
}

#battle .gauge.atb i {
  background: linear-gradient(to right, #ffe08a, #f0b030);
}

#battle .gauge.limit i {
  background: linear-gradient(to right, #ff9a6a, #f04060);
}

#battle .hero label {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  opacity: 0.8;
}

/* Les chiffres qui s'envolent */
#battle-fx {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 19;
}

#battle-fx .float {
  position: absolute;
  transform: translate(-50%, -50%);
  font: bold 24px "Trebuchet MS", sans-serif;
  color: #fff;
  text-shadow: 0 2px 0 #000, 0 0 6px #000;
  animation: float-up 1s ease-out forwards;
}

#battle-fx .hurt {
  color: #ff8a7a;
}

#battle-fx .guarded {
  color: #a8c8ff;
}

#battle-fx .heal {
  color: #8affa8;
}

#battle-fx .limit {
  font-size: 36px;
  color: #ffd04a;
}

#battle-fx .info {
  font-size: 16px;
}

@keyframes float-up {
  from {
    margin-top: 0;
    opacity: 1;
  }
  to {
    margin-top: -60px;
    opacity: 0;
  }
}

@media (max-width: 640px) {
  #battle {
    grid-template-columns: 1fr;
    font-size: 12px;
  }
}

/* L'équipement (touche U) */
#gear {
  position: fixed;
  left: 398px; /* à côté de l'inventaire, s'ils sont ouverts ensemble */
  bottom: 16px;
  width: min(650px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 10px 14px;
  color: #4a3326;
  background: rgba(255, 248, 232, 0.96);
  border: 3px solid #4a3326;
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(74, 51, 38, 0.35);
  font-size: 13px;
}

#gear[hidden] {
  display: none;
}

#gear h2 {
  margin: 0 0 6px;
  font-size: 16px;
}

#gear h3 {
  margin: 0 0 4px;
  font-size: 13.5px;
  border-bottom: 2px solid rgba(74, 51, 38, 0.25);
}

#gear .gear-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  margin-bottom: 10px;
  padding: 5px 8px;
  background: rgba(74, 51, 38, 0.08);
  border-radius: 8px;
}

#gear .gear-cols {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: start;
}

/* Le héros, entouré de ce qu'il porte */
#gear .doll {
  display: grid;
  grid-template-columns: 66px 150px 66px;
  grid-template-rows: repeat(4, 66px);
  grid-template-areas:
    "head view amulet"
    "body view hands"
    "left view right"
    "feet view ring";
  gap: 6px;
}

#gear .hero-view {
  grid-area: view;
  overflow: hidden;
  background: radial-gradient(circle at 50% 40%, #fff3d8, #d8c4a0);
  border: 2px solid rgba(74, 51, 38, 0.4);
  border-radius: 12px;
}

#gear .hero-view canvas {
  display: block;
  /* (le canvas fait la taille exacte du cadre, bordure comprise) */
  margin: -2px;
}

/* Une case : un emplacement sur le héros, ou une place dans le sac */
#gear .gear-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  aspect-ratio: 1;
  background: rgba(74, 51, 38, 0.1);
  border: 2px solid rgba(74, 51, 38, 0.28);
  border-radius: 9px;
  touch-action: none;
  user-select: none;
}

#gear .gear-cell[data-item] {
  cursor: grab;
}

#gear .gear-cell small {
  position: absolute;
  top: 1px;
  left: 0;
  right: 0;
  font-size: 9.5px;
  line-height: 1.1;
  text-align: center;
  opacity: 0.75;
  pointer-events: none;
}

#gear .doll .gear-cell .icon {
  margin-top: 8px;
}

#gear .gear-cell.empty .icon {
  opacity: 0.25;
  filter: grayscale(1);
}

#gear .gear-cell.ghost .icon {
  opacity: 0.35;
}

#gear .gear-cell .two {
  position: absolute;
  bottom: 0;
  right: 2px;
  font: bold 8.5px "Trebuchet MS", system-ui, sans-serif;
  pointer-events: none;
}

#gear .gear-cell.selected {
  box-shadow: 0 0 0 2px #4a3326;
}

#gear.dragging .gear-cell[data-slot]:not(.can-drop) {
  opacity: 0.45;
}

#gear .gear-cell.can-drop {
  background: rgba(90, 170, 70, 0.3);
  border-color: #3f8a35;
}

#gear .bag {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 4px;
  margin-top: 5px;
}

#gear .bag .icon {
  width: 30px;
  height: 30px;
}

/* Le bord des cases dit la rareté */
.rb-normal {
  border-color: #8a7a6a !important;
  background: rgba(138, 122, 106, 0.16) !important;
}

.rb-magic {
  border-color: #2f6ad8 !important;
  background: rgba(79, 143, 255, 0.2) !important;
}

.rb-rare {
  border-color: #c89a10 !important;
  background: rgba(255, 208, 64, 0.26) !important;
}

.rb-legendary {
  border-color: #e0640e !important;
  background: rgba(255, 138, 32, 0.3) !important;
}

/* L'objet que l'on fait glisser suit la souris */
.gear-ghost {
  position: fixed;
  left: 0;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: 2px solid;
  border-radius: 9px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
  pointer-events: none;
  z-index: 40;
}

#gear .gear-info {
  min-height: 92px;
  margin-top: 8px;
  padding: 6px 8px;
  background: rgba(74, 51, 38, 0.08);
  border-radius: 8px;
}

#gear .gear-info p {
  margin: 0;
}

#gear .gear-info b,
#gear .gear-info small {
  display: block;
}

#gear .gear-info small {
  font-size: 11.5px;
  line-height: 1.35;
}

#gear .gear-info .btns {
  flex-wrap: wrap;
  margin-top: 5px;
}

#gear h3 button {
  float: right;
  margin-bottom: 2px;
}

#gear .gear-empty {
  font-size: 12px;
  opacity: 0.55;
}

#gear .up {
  color: #2f7a35;
}

#gear .down {
  color: #b23a2e;
}

#gear .btns {
  display: flex;
  flex-shrink: 0;
  gap: 3px;
}

#gear button {
  padding: 1px 6px;
  font: bold 11.5px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 7px;
  cursor: pointer;
}

#gear button:hover {
  background: #f8e4c6;
}

#gear p {
  font-size: 11.5px;
  line-height: 1.4;
}

/* Les cadres s'attrapent à la souris (voir frames.js) */
#hud,
#clock,
#skills,
#inventory,
#gear,
#quests,
.panel,
#plan,
#battle {
  cursor: grab;
}

.moving {
  cursor: grabbing !important;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.4) !important;
  user-select: none;
}

/* La couleur de la rareté, sur fond clair (panneaux)… */
.r-normal {
  color: #5a4a3e;
}

.r-magic {
  color: #2458c0;
}

.r-rare {
  color: #9a7000;
}

.r-legendary {
  color: #c8500a;
}

/* … et sur le fond sombre du donjon */
#battle-fx .r-normal {
  color: #e8e4d8;
}

#battle-fx .r-magic {
  color: #8ab4ff;
}

#battle-fx .r-rare {
  color: #ffd84a;
}

#battle-fx .r-legendary {
  color: #ff9a30;
}

@media (max-width: 1040px) {
  #gear {
    left: 16px;
  }
}

@media (max-width: 640px) {
  #gear .gear-cols {
    grid-template-columns: 1fr;
  }
}

/* Le village et la famille (V), la conversation, le bilan de la journée */
#village {
  left: auto;
  right: 16px;
  bottom: auto;
  top: 16px;
  width: min(400px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
}

#village h3 {
  margin: 12px 0 4px;
  font-size: 13.5px;
  border-bottom: 2px solid rgba(74, 51, 38, 0.25);
}

#village p {
  margin: 4px 0;
  line-height: 1.4;
}

#village .shop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px dashed rgba(74, 51, 38, 0.2);
}

#village .shop-row > div {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#village .shop-row span {
  font-size: 12px;
  opacity: 0.8;
}

#village .shop-row .gauge {
  flex: 0 0 90px;
}

#village button {
  font: inherit;
  font-size: 12px;
  padding: 3px 8px;
  border: 2px solid #4a3326;
  border-radius: 8px;
  background: #f6dfa8;
  color: #4a3326;
  cursor: pointer;
}

#village button:hover {
  background: #ffe9b8;
}

#village .btns {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: flex-end;
  opacity: 1;
}

.gauge.friend {
  display: block;
  height: 8px;
  margin: 3px 0 6px;
  border: 2px solid #4a3326;
  border-radius: 6px;
  background: rgba(74, 51, 38, 0.15);
  overflow: hidden;
}

.gauge.friend > i {
  display: block;
  height: 100%;
  background: #e0805a;
}

#talk .remark {
  font-style: italic;
  font-size: 14px;
  margin: 8px 0;
}

#report {
  z-index: 40;
}

#report p {
  margin: 4px 0;
}

.panel .wanted {
  margin: 4px 0 8px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(240, 180, 60, 0.25);
}

#inventory .fed {
  margin: 6px 0;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(120, 190, 90, 0.25);
}

/* ⏱ La durée d'une tâche à un poste (cliquer pour la changer) */
#plan .plan-row button.hours {
  white-space: nowrap;
  font-weight: normal;
  background: #fff3dc;
}

/* Panneau des tâches et menus pour planifier : filtre par catégorie, intertitres */
#plan .plan-filters,
#choices .choice-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 6px 0 4px;
}

#plan .plan-filters button,
#choices .choice-filters button {
  width: auto;
  margin: 0;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: normal;
  background: transparent;
  border: 1px solid #4a3326;
  border-radius: 999px;
  box-shadow: none;
}

#plan .plan-filters button.on,
#choices .choice-filters button.on {
  color: #fff8e8;
  background: #4a3326;
}

#plan .plan-cat,
#choices .choice-cat {
  margin: 6px 0 0;
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.6;
}

#plan .plan-row b.ord {
  flex: none;
  min-width: 16px;
  font-size: 11px;
  text-align: right;
  opacity: 0.5;
}

#choices .choice-list {
  max-height: min(60vh, 520px);
  overflow-y: auto;
}

/* Les gemmes : un petit losange de leur couleur (plus grand et plus brillant selon leur taille) */
.gem {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin: 0 2px;
  vertical-align: middle;
  background: var(--gem, #888);
  border: 1px solid rgba(0, 0, 0, 0.55);
  transform: rotate(45deg);
}
.gem.g1 { width: 11px; height: 11px; }
.gem.g2 { width: 12px; height: 12px; box-shadow: 0 0 5px var(--gem); }
.gem.empty { background: transparent; border-style: dashed; }
#gear .gear-cell i.sockets {
  position: absolute;
  left: 3px;
  bottom: 2px;
  display: flex;
  gap: 1px;
  font-style: normal;
}
#gear .gear-cell i.sockets .gem { width: 6px; height: 6px; margin: 0 1px; }
.gem-purse {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0;
  font-size: 12px;
}
.gear-info .sockets {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.gear-info .socket em {
  font-style: normal;
  opacity: 0.7;
}
.gear-info .socket select {
  max-width: 100%;
  font: inherit;
}

/* Poser et prendre (G, E sur une caisse) : deux colonnes, un compteur par marchandise */
#transfer {
  width: min(620px, calc(100vw - 32px));
}
#transfer .tr-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
@media (max-width: 560px) {
  #transfer .tr-cols { grid-template-columns: 1fr; }
}
#transfer .tr-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 3px 0;
  border-bottom: 1px dashed rgba(74, 51, 38, 0.2);
}
#transfer .tr-what {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
#transfer .tr-what svg {
  flex: none;
  width: 22px;
  height: 22px;
}
#transfer .tr-what small {
  display: block;
  font-size: 11px;
  opacity: 0.7;
}
#transfer .stepper {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: none;
}
#transfer button {
  padding: 1px 7px;
  font: bold 12px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 7px;
  cursor: pointer;
}
#transfer button:disabled {
  opacity: 0.4;
  cursor: default;
}
#transfer button.all,
#transfer button.small {
  font-weight: normal;
  font-size: 11px;
}
#transfer .stepper input {
  width: 42px;
  padding: 1px 2px;
  font: bold 12px "Trebuchet MS", system-ui, sans-serif;
  text-align: center;
  border: 2px solid #4a3326;
  border-radius: 6px;
}
#transfer .purse b.over {
  color: #b03020;
}
#transfer p {
  font-size: 12px;
  opacity: 0.8;
}

/* La faim, entre la forme et la santé : dorée repu, orange affamé, rouge à jeun */
#hunger {
  margin-top: 4px;
}
#hunger .bar {
  height: 10px;
  width: 100%;
  background: #ead8b8;
  border: 2px solid #4a3326;
  border-radius: 6px;
  overflow: hidden;
}
#hunger .fill {
  height: 100%;
  background: linear-gradient(to bottom, #f2d27a, #c89a3a);
  transform-origin: left;
  transition: transform 0.3s;
}
#hunger.hungry .fill {
  background: linear-gradient(to bottom, #f5b06a, #d9782a);
}
#hunger.starving .fill {
  background: linear-gradient(to bottom, #f08a6a, #d94848);
  animation: tired 0.8s ease-in-out infinite alternate;
}
#hunger .text {
  font-size: 12px;
}
.inv-tile .eat-btns {
  display: flex;
  gap: 2px;
  justify-content: center;
}

/* L'onglet Formation : la liste des maîtres */
table.masters {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
table.masters th {
  text-align: left;
  border-bottom: 2px solid rgba(74, 51, 38, 0.25);
}
table.masters td {
  padding: 1px 4px 1px 0;
  border-bottom: 1px dashed rgba(74, 51, 38, 0.15);
}
table.masters tr.done {
  opacity: 0.45;
}

/* L'arrivée d'un joueur : pseudo, garçon ou fille, allure, métier */
#intro {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(30, 22, 16, 0.55);
}
#intro[hidden] {
  display: none;
}
#intro .intro-card {
  width: min(720px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 14px 18px;
  color: #4a3326;
  background: #fff8e8;
  border: 3px solid #4a3326;
  border-radius: 16px;
  box-shadow: 0 6px 0 rgba(74, 51, 38, 0.35);
  font-size: 13px;
}
#intro h2 {
  margin: 0;
  font-size: 22px;
}
#intro h3 {
  margin: 10px 0 4px;
  font-size: 14px;
}
#intro h3 small {
  font-weight: normal;
  opacity: 0.7;
}
#intro .intro-cols {
  display: flex;
  gap: 14px;
}
#intro .intro-view {
  flex: none;
  width: 170px;
  height: 300px;
  background: radial-gradient(circle at 50% 40%, #f6e7c8, #e6cfa4);
  border: 2px solid #4a3326;
  border-radius: 12px;
}
#intro .intro-form {
  flex: 1;
  min-width: 0;
}
#intro label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-weight: bold;
}
#intro input {
  padding: 6px 8px;
  font: bold 15px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #fff;
  border: 2px solid #4a3326;
  border-radius: 8px;
}
#intro .intro-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
}
#intro .intro-row > span {
  width: 64px;
  font-weight: bold;
}
#intro button {
  padding: 4px 9px;
  font: 12px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 8px;
  cursor: pointer;
}
#intro button.on {
  color: #fff8e8;
  background: #4a3326;
}
#intro button.swatch {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
}
#intro button.swatch.on {
  box-shadow: 0 0 0 3px #fff8e8, 0 0 0 5px #4a3326;
}
#intro .intro-jobs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: 5px;
}
#intro .intro-jobs button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
}
#intro .intro-jobs small {
  opacity: 0.75;
}
#intro .intro-go {
  margin-top: 12px;
  text-align: center;
}
#intro .intro-go button {
  padding: 8px 22px;
  font-size: 15px;
  font-weight: bold;
}
#intro .intro-go button:disabled {
  opacity: 0.5;
  cursor: default;
}
#intro .intro-note {
  margin: 8px 0 0;
  font-size: 12px;
  text-align: center;
  opacity: 0.75;
}
@media (max-width: 560px) {
  #intro .intro-cols { flex-direction: column; align-items: center; }
}

/* Par étapes (téléphone) : une étape par écran, l'en-tête et les boutons restent visibles, seul le milieu défile */
#intro.stepped {
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}
#intro.stepped .intro-card {
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  max-height: calc(100vh - 16px);
  max-height: calc(100dvh - 16px);
  overflow: hidden;
  padding: 12px 14px;
  font-size: 14px;
}
#intro.stepped .intro-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
#intro.stepped h2 {
  font-size: 19px;
}
#intro .intro-step {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: bold;
  opacity: 0.8;
}
#intro .intro-step i {
  width: 8px;
  height: 8px;
  border: 2px solid #4a3326;
  border-radius: 50%;
}
#intro .intro-step i.done {
  background: #c9a47a;
}
#intro .intro-step i.on {
  background: #4a3326;
}
#intro.stepped .intro-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin: 8px -4px 0;
  padding: 0 4px 4px;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}
#intro.stepped .intro-body > p {
  margin: 0 0 10px;
}
#intro.stepped .intro-names {
  grid-template-columns: 1fr;
}
#intro.stepped .intro-names input {
  font-size: 16px; /* (en dessous de 16 px, l'iPhone zoome sur le champ) */
  padding: 9px 10px;
}
#intro.stepped button {
  min-height: 38px;
  padding: 6px 12px;
  font-size: 14px;
}
#intro.stepped button.swatch {
  width: 34px;
  height: 34px;
  min-height: 0;
}
#intro.stepped .intro-row > span {
  width: 100%;
}
#intro.stepped .intro-cols {
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
}
#intro.stepped .intro-view {
  width: 110px;
  height: 194px;
  overflow: hidden;
}
#intro.stepped .intro-view canvas {
  width: 100% !important;
  height: 100% !important;
}
#intro.stepped .intro-hint {
  font-size: 13px;
  opacity: 0.75;
}
#intro.stepped .intro-jobs {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px;
}
#intro.stepped .intro-jobs button {
  min-height: 46px;
}
#intro.stepped .intro-nav {
  flex: none;
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
#intro.stepped .intro-nav button {
  flex: 1;
  min-height: 46px;
  font-size: 15px;
  font-weight: bold;
}
#intro.stepped .intro-nav [data-back] {
  flex: 0 0 auto;
}
#intro.stepped .intro-nav button:disabled {
  opacity: 0.5;
  cursor: default;
}
/* Très étroit : le portrait passe au-dessus, en plus petit */
@media (max-width: 380px) {
  #intro.stepped .intro-cols { flex-direction: column; align-items: center; }
  #intro.stepped .intro-view { width: 90px; height: 160px; }
}
/* Téléphone à l'horizontale : peu de hauteur, le portrait rapetisse */
@media (max-height: 420px) {
  #intro.stepped .intro-view { width: 80px; height: 141px; }
  #intro.stepped .intro-body > p { margin-bottom: 6px; }
  #intro.stepped .intro-names { grid-template-columns: 1fr 1fr; }
  #intro.stepped .intro-jobs { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
}

/* --- La barre des boutons (au-dessus de l'horloge) : icône + infobulle, repliable -------------------------- */
#toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin: 0 -6px 6px;
  padding-bottom: 6px;
  border-bottom: 2px solid rgba(74, 51, 38, 0.2);
}

#toolbar .tools-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

#toolbar.folded {
  margin-bottom: 2px;
  padding-bottom: 0;
  border-bottom: 0;
}

#toolbar.folded .tools-row {
  display: none;
}

#clock #toolbar button {
  position: relative;
  width: 30px;
  height: 30px;
  font-size: 16px;
  line-height: 1;
}

#clock #toolbar button.fold {
  width: 22px;
  font-size: 13px;
  background: transparent;
  border-color: rgba(74, 51, 38, 0.45);
}

#clock #toolbar button.active {
  background: #f2c14e;
  box-shadow: inset 0 2px 0 rgba(74, 51, 38, 0.3);
}

/* Infobulles : tout de suite au survol (celles du navigateur se font attendre) */
#clock [data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  padding: 3px 8px;
  white-space: nowrap;
  font: 12px/1.4 "Trebuchet MS", system-ui, sans-serif;
  color: #fff8e8;
  background: #4a3326;
  border-radius: 6px;
  pointer-events: none;
}

/* --- Les jauges (forme, faim, santé), réductibles ------------------------------------------------------- */
#bars {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 6px;
  align-items: center;
}

#bars > div {
  grid-column: 2;
}

#clock #bars .bars-size {
  position: relative;
  grid-column: 1;
  grid-row: 1 / span 3;
  width: 18px;
  height: 18px;
  font-size: 12px;
  background: transparent;
  border-color: rgba(74, 51, 38, 0.45);
}

#bars.compact #energy,
#bars.compact #hunger,
#bars.compact #health {
  margin-top: 3px;
}

#bars.compact .bar {
  height: 6px !important;
  border-width: 1px !important;
  border-radius: 3px !important;
}

#bars.compact .text {
  display: none;
}

/* --- Pour tester seulement (?test ou ?illimite) : vitesse du temps, saison suivante ---------------------- */
.test-only {
  display: none;
}

body.test-mode .test-only {
  display: block;
}

/* --- La fiche du personnage : un cadre à onglets --------------------------------------------------------- */
#sheet {
  position: fixed;
  left: 16px;
  bottom: 16px;
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 0 14px 10px;
  color: #4a3326;
  background: rgba(255, 248, 232, 0.96);
  border: 3px solid #4a3326;
  border-radius: 14px;
  box-shadow: 0 4px 0 rgba(74, 51, 38, 0.35);
  font-size: 13px;
  cursor: grab;
}

#sheet[hidden] {
  display: none;
}

#sheet .sheet-tabs {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0 -14px 10px;
  padding: 8px 14px 6px;
  background: rgba(255, 248, 232, 0.98);
  border-bottom: 2px solid rgba(74, 51, 38, 0.25);
}

#sheet .sheet-tabs button {
  padding: 4px 10px;
  font: bold 12.5px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 8px;
  cursor: pointer;
}

#sheet .sheet-tabs button:hover {
  background: #ffe7c2;
}

#sheet .sheet-tabs button.active {
  background: #f2c14e;
}

#sheet .sheet-tabs .sheet-close {
  margin-left: auto;
  padding: 4px 8px;
}

/* Les anciens panneaux deviennent des onglets : plus de cadre à eux */
#sheet > div:not(.sheet-tabs) {
  position: static;
  width: auto;
  max-height: none;
  overflow: visible;
  padding: 0;
  background: none;
  border: 0;
  box-shadow: none;
}

#skills .who-card {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 4px 12px;
  margin-bottom: 6px;
}

#skills .who-card div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 0;
  border-bottom: 1px dashed rgba(74, 51, 38, 0.2);
}

#skills .who-card span {
  opacity: 0.75;
}

#skills h3 {
  margin: 12px 0 6px;
  font-size: 13.5px;
  border-bottom: 2px solid rgba(74, 51, 38, 0.25);
}

#skills .trades {
  margin: 2px 0 0;
  font-size: 12px;
  font-style: italic;
}

/* Niveau, expérience, caractéristiques de combat, blessure (voir heroHtml dans main.js) */
#skills .points {
  color: #b0402a;
  font-weight: normal;
}

#skills .xp-bar {
  position: relative;
  height: 16px;
  border-radius: 8px;
  background: rgba(74, 51, 38, 0.15);
  overflow: hidden;
}

#skills .xp-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, #d8a838, #f2c858);
}

#skills .xp-bar span {
  position: absolute;
  inset: 0;
  text-align: center;
  font-size: 11px;
  line-height: 16px;
}

#skills .hero-stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 4px 12px;
  margin: 6px 0 2px;
}

#skills .hero-stat {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 0 6px;
  padding: 2px 0;
  border-bottom: 1px dashed rgba(74, 51, 38, 0.2);
}

#skills .hero-stat span {
  opacity: 0.75;
}

#skills .hero-stat small {
  grid-column: 1 / -1;
  font-size: 11px;
  opacity: 0.7;
}

#skills .hero-stat button {
  grid-row: 1;
  grid-column: 3;
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  font-weight: bold;
  cursor: pointer;
}

#skills .wound {
  margin: 6px 0 0;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(176, 64, 42, 0.12);
  font-size: 12.5px;
}

#skills .skill-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0 18px;
}

/* --- Sur téléphone et tablette (body.touch, voir touch.js) ---------------------------------------------- */
.touch-only {
  display: none !important;
}

body.touch .touch-only {
  display: inline-block !important;
}

body.touch .desk-only {
  display: none !important;
}

#map .map-close {
  margin-left: auto;
  width: 32px;
  height: 32px;
  font: bold 16px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 8px;
  cursor: pointer;
}

body.touch {
  touch-action: none; /* le navigateur ne zoome ni ne fait défiler la page : les doigts sont au jeu */
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* … mais les panneaux longs défilent au doigt */
body.touch #sheet,
body.touch .panel,
body.touch #plan,
body.touch #intro .intro-card,
body.touch #hud .help {
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

body.touch #map canvas {
  touch-action: none;
}

/* Pas d'infobulles au survol (elles resteraient affichées après un toucher) */
body.touch #clock [data-tip]:hover::after {
  display: none;
}

/* L'aide n'apparaît que lorsqu'on l'ouvre (❓ dans la barre) */
body.touch #hud:not(.open) {
  display: none;
}

body.touch #hud.open {
  top: 8px;
  left: 8px;
  right: 8px;
  max-width: none;
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  z-index: 26;
}

/* L'horloge, plus petite, dans le coin */
body.touch #clock {
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  min-width: 0;
  max-width: min(300px, 60vw);
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.35;
}

body.touch #clock .place,
body.touch #clock .date {
  font-size: 13px;
}

body.touch #clock #toolbar button {
  width: 34px;
  height: 34px;
  font-size: 17px;
}

body.touch #clock #toolbar button.fold {
  width: 26px;
}

/* La fiche : tout l'écran */
body.touch #sheet {
  inset: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  width: auto;
  max-height: none;
  z-index: 24;
}

body.touch #sheet .sheet-tabs button {
  padding: 7px 10px;
}

/* Les panneaux (boutique, conversation, forge, choix…) : en portrait en haut, au-dessus des commandes ;
   en paysage entre le joystick et les boutons */
body.touch .panel {
  left: 8px;
  right: 8px;
  top: max(8px, env(safe-area-inset-top));
  bottom: auto;
  width: auto;
  transform: none;
  max-height: calc(100vh - 230px);
  z-index: 22;
}

@media (orientation: landscape) {
  body.touch .panel {
    left: 170px;
    right: 200px;
    top: auto;
    bottom: 8px;
    max-height: calc(100vh - 16px);
  }
}

body.touch .panel button,
body.touch #sheet button,
body.touch #plan button {
  min-height: 32px;
}

body.touch #plan {
  left: 8px;
  right: auto;
  top: max(8px, env(safe-area-inset-top));
  bottom: auto;
  width: min(300px, 55vw);
  max-height: 40vh;
}

body.touch #map {
  inset: 6px;
}

body.touch #battle {
  width: calc(100vw - 12px);
  bottom: 6px;
  grid-template-columns: 1fr 1fr;
  font-size: 12px;
}

/* Le joystick */
#stick {
  position: fixed;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: rgba(255, 248, 232, 0.28);
  border: 3px solid rgba(74, 51, 38, 0.55);
  box-shadow: inset 0 0 18px rgba(74, 51, 38, 0.25);
  touch-action: none;
  z-index: 15;
}

#stick .knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: rgba(255, 248, 232, 0.92);
  border: 3px solid #4a3326;
  box-shadow: 0 3px 0 rgba(74, 51, 38, 0.35);
  pointer-events: none;
}

#stick.run .knob {
  background: #f2c14e;
}

/* Les boutons d'action */
#actions {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-auto-rows: 56px;
  gap: 8px;
  direction: rtl; /* (le gros bouton Agir dans le coin, sous le pouce) */
  touch-action: none;
  z-index: 15;
}

#actions button {
  direction: ltr;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: #4a3326;
  background: rgba(255, 248, 232, 0.9);
  border: 3px solid #4a3326;
  border-radius: 50%;
  box-shadow: 0 3px 0 rgba(74, 51, 38, 0.35);
  font: bold 9px "Trebuchet MS", system-ui, sans-serif;
}

#actions button span {
  font-size: 20px;
  line-height: 1;
}

#actions button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(74, 51, 38, 0.35);
  background: #f2c14e;
}

#actions button.big {
  grid-row: span 2;
  grid-column: span 1;
  height: 120px;
  border-radius: 40px;
  background: rgba(242, 193, 78, 0.95);
}

#actions button.big span {
  font-size: 32px;
}

#actions button.more {
  display: none;
}

#actions.open button.more {
  display: flex;
}

/* Un écran prend toute la place (combat, carte, fiche, début de partie) : les commandes s'effacent */
body.touch-busy #stick,
body.touch-busy #actions {
  display: none;
}

/* Les annonces ne cachent ni l'horloge ni les commandes */
body.touch #toasts {
  top: auto;
  bottom: 170px;
  left: 8px;
  right: 8px;
  width: auto;
  transform: none;
}

body.touch .toast {
  font-size: 12.5px;
  padding: 6px 10px;
}

@media (orientation: landscape) {
  body.touch #toasts {
    top: max(8px, env(safe-area-inset-top));
    bottom: auto;
    right: min(316px, calc(60vw + 16px));
  }
}

/* --- Changer de nom (fiche, ✏️) et nom à l'arrivée --------------------------------------------------- */
#skills h2.who-name {
  display: flex;
  align-items: center;
  gap: 8px;
}

#skills h2.who-name button {
  padding: 1px 6px;
  font-size: 13px;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 8px;
  cursor: pointer;
}

#skills .rename label,
#intro .intro-names label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 8px;
  font-weight: bold;
}

#skills .rename input,
#intro .intro-names input {
  padding: 6px 8px;
  font: 15px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #fffaf0;
  border: 2px solid #4a3326;
  border-radius: 8px;
}

#intro .intro-names {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 10px;
}

#skills .rename-err {
  min-height: 1.3em;
  margin: 0 0 6px;
  color: #c0392b;
  font-weight: bold;
}

#skills .rename-note {
  font-size: 12px;
  opacity: 0.8;
}

#skills .rename .btns {
  display: flex;
  gap: 8px;
}

#skills .rename .btns button {
  padding: 6px 14px;
  font: bold 13px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 8px;
  cursor: pointer;
}

#skills .rename .btns button[data-ok] {
  background: #f2c14e;
}

/* (sur téléphone, on peut tout de même écrire et sélectionner dans les champs) */
body.touch input {
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
  font-size: 16px; /* (en dessous, l'iPhone zoome sur le champ) */
}

/* --- Le suivi du tutoriel (en haut à gauche, sous l'aide) ---------------------------------------------- */
#tuto {
  position: fixed;
  top: 64px;
  left: 16px;
  width: min(320px, calc(100vw - 32px));
  padding: 8px 12px;
  color: #4a3326;
  background: rgba(255, 248, 232, 0.94);
  border: 3px solid #4a3326;
  border-left-width: 8px;
  border-left-color: #f2c14e;
  border-radius: 12px;
  box-shadow: 0 4px 0 rgba(74, 51, 38, 0.35);
  font-size: 13px;
  cursor: grab;
  z-index: 6;
}

#tuto[hidden] {
  display: none;
}

#tuto .tuto-head {
  display: flex;
  align-items: center;
  gap: 6px;
}

#tuto .tuto-head span {
  margin-left: auto;
  font-size: 11px;
  opacity: 0.7;
}

#tuto .tuto-head button {
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 12px;
  color: #4a3326;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 6px;
  cursor: pointer;
}

#tuto .tuto-step {
  margin-top: 4px;
  font-weight: bold;
  font-size: 14px;
}

#tuto .tuto-step i {
  font-weight: normal;
  opacity: 0.75;
}

#tuto .tuto-hint {
  margin-top: 2px;
  font-size: 12px;
  opacity: 0.85;
}

body.touch #tuto {
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  width: min(280px, 40vw);
  font-size: 12px;
}

@media (orientation: portrait) {
  body.touch #tuto {
    top: auto;
    bottom: 170px;
    width: calc(100vw - 16px);
  }
  body.touch #tuto .tuto-hint {
    display: none; /* (la place manque : le détail est dans l'onglet Métiers) */
  }
}

/* --- L'onglet « Métiers » de la fiche -------------------------------------------------------------------- */
#guide .guide-note {
  font-size: 12px;
  opacity: 0.85;
}

#guide .guide-card {
  margin: 6px 0;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.45);
  border: 2px solid rgba(74, 51, 38, 0.3);
  border-radius: 10px;
}

#guide .guide-card.active {
  border-color: #f2c14e;
  background: rgba(242, 193, 78, 0.15);
}

#guide .guide-card.done summary b {
  color: #2e7a3a;
}

#guide summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  list-style: none;
}

#guide summary::-webkit-details-marker {
  display: none;
}

#guide .g-icon {
  font-size: 18px;
}

#guide summary small {
  opacity: 0.7;
}

#guide .g-mine {
  padding: 0 6px;
  font-size: 11px;
  font-style: normal;
  color: #fff8e8;
  background: #4a3326;
  border-radius: 6px;
}

#guide .g-status {
  margin-left: auto;
  font-size: 12px;
  opacity: 0.8;
}

#guide .guide-card p {
  margin: 6px 0;
  font-size: 12.5px;
}

#guide ol {
  margin: 6px 0;
  padding-left: 22px;
}

#guide li.ok {
  color: #2e7a3a;
  text-decoration: line-through;
}

#guide li.now {
  font-weight: bold;
}

#guide .btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 6px 0 2px;
}

#guide button {
  padding: 4px 12px;
  font: bold 12.5px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2c14e;
  border: 2px solid #4a3326;
  border-radius: 8px;
  cursor: pointer;
}

#guide button.test {
  background: #f4b4a8;
  border-style: dashed;
}

/* --- L'onglet « Classement » de la fiche ----------------------------------------------------------------- */
#ranks h2 {
  margin: 0 0 4px;
  font-size: 16px;
}

#ranks p {
  margin: 6px 0;
  font-size: 12px;
  opacity: 0.85;
}

#ranks .rank-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

#ranks .rank-tabs button {
  padding: 3px 8px;
  font: bold 12px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 8px;
  cursor: pointer;
}

#ranks .rank-tabs button.active {
  background: #f2c14e;
}

#ranks tr.me td {
  background: rgba(242, 193, 78, 0.35);
}

#ranks h3 {
  margin: 12px 0 6px;
  font-size: 13.5px;
  border-bottom: 2px solid rgba(74, 51, 38, 0.25);
}

#ranks .rank-name {
  padding: 0;
  font: inherit;
  color: inherit;
  text-decoration: underline;
  background: none;
  border: 0;
  cursor: pointer;
}

#ranks [data-rank-back] {
  margin-bottom: 8px;
  padding: 3px 10px;
  font: bold 12px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2d7b0;
  border: 2px solid #4a3326;
  border-radius: 8px;
  cursor: pointer;
}

#ranks .deeds {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 6px;
}

#ranks .deed {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  background: rgba(255, 255, 255, 0.45);
  border: 2px solid rgba(74, 51, 38, 0.3);
  border-radius: 10px;
}

#ranks .deed.none {
  opacity: 0.5;
}

#ranks .deed b {
  margin-left: auto;
  font-size: 15px;
}

/* --- L'onglet « Admin » de la fiche, et l'annonce d'un nouveau monde --------------------------------------- */
#admin h2 {
  margin: 0 0 6px;
  font-size: 16px;
}

#admin h3 {
  margin: 12px 0 6px;
  font-size: 13.5px;
  border-bottom: 2px solid rgba(74, 51, 38, 0.25);
}

#admin form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 8px;
}

#admin label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
}

#admin input {
  padding: 4px 8px;
  font: inherit;
  color: #4a3326;
  background: #fff;
  border: 2px solid #4a3326;
  border-radius: 8px;
}

#admin button {
  padding: 4px 12px;
  font: bold 12.5px "Trebuchet MS", system-ui, sans-serif;
  color: #4a3326;
  background: #f2c14e;
  border: 2px solid #4a3326;
  border-radius: 8px;
  cursor: pointer;
}

#admin button.danger {
  background: #f4b4a8;
}

#admin .admin-err {
  min-height: 1.2em;
  color: #b0402a;
}

.new-world {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  font: bold 22px "Trebuchet MS", system-ui, sans-serif;
  text-align: center;
  color: #fff8e8;
  background: rgba(30, 22, 16, 0.85);
}
