/* =========================================================================================
 * Mode kiosque — un écran, sans défilement, lisible de loin. Mêmes tokens que le dashboard
 * (style.css). La taille de base suit la diagonale de l'écran: du 13" au mur de salon.
 * ========================================================================================= */

body.kiosk-on {
  overflow: hidden;
}

body.kiosk-on > .app {
  display: none;
}

body.kiosk-idle,
body.kiosk-idle * {
  cursor: none !important;
}

.kiosk {
  --k-gap: clamp(8px, 1.1vh, 18px);
  --k-radius: 12px;
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  /* La carte prend toute la hauteur à gauche (le monde est plus haut que large) ; à droite,
     les personnages puis monde | état du bot | fil d'événements. */
  grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.5fr);
  grid-template-rows: auto minmax(0, 1fr) minmax(0, 30vh);
  grid-template-areas:
    "head head head head"
    "map roster roster roster"
    "map world system journal";
  gap: var(--k-gap);
  padding: calc(var(--k-gap) * 1.2) calc(var(--k-gap) * 1.4);
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: clamp(12px, calc(0.45vw + 0.55vh), 30px);
  line-height: 1.35;
  transition: transform 1.2s ease;
}

.kiosk[hidden] {
  display: none;
}

.kiosk h2 {
  margin: 0 0 0.7em;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.05em;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}

.kiosk h3 {
  margin: 1em 0 0.5em;
  font-weight: 600;
  font-size: 0.9em;
  color: var(--text-dim);
}

/* --------------------------------- En-tête --------------------------------- */

.k-head {
  grid-area: head;
  display: flex;
  align-items: center;
  gap: 2.2em;
  padding-bottom: var(--k-gap);
  border-bottom: 1px solid var(--border);
}

.k-brand {
  display: flex;
  align-items: center;
  gap: 0.6em;
  flex-shrink: 0;
}

.k-dot {
  width: 0.7em;
  height: 0.7em;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0.9em 0.15em rgba(255, 180, 84, 0.7);
  animation: k-pulse 2.4s ease-in-out infinite;
}

@keyframes k-pulse {
  50% {
    opacity: 0.5;
  }
}

.k-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.6em;
  white-space: nowrap;
}

.k-title span {
  color: var(--accent);
}

.k-kpis {
  display: flex;
  flex: 1;
  justify-content: center;
  gap: 2.6em;
  margin: 0;
}

.k-kpi {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.k-kpi dt {
  font-size: 0.8em;
  color: var(--text-dim);
}

.k-kpi dd {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.75em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.k-kpi[data-kpi="gold"] dd {
  color: var(--accent);
}

.k-clock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
}

.k-time {
  font-family: var(--display);
  font-weight: 700;
  font-size: 2.3em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.k-date {
  margin-top: 0.2em;
  font-size: 0.8em;
  color: var(--text-dim);
}

.k-date::first-letter {
  text-transform: uppercase;
}

.k-live {
  display: flex;
  align-items: center;
  gap: 0.45em;
  flex-shrink: 0;
  font-size: 0.85em;
  color: var(--text-dim);
}

.k-live-dot {
  width: 0.6em;
  height: 0.6em;
  border-radius: 50%;
  background: var(--bad);
}

.k-live.online .k-live-dot {
  background: var(--good);
  box-shadow: 0 0 0.6em var(--good);
}

.k-live.online {
  color: var(--good);
}

/* --------------------------------- Carte + personnages --------------------------------- */

/* Enveloppe sans boîte: la carte et les personnages sont placés dans la grille du kiosque. */
.k-main {
  display: contents;
}

/* Toute la hauteur disponible, largeur au ratio du monde (calculée en JS, plafonnée). */
.k-map {
  grid-area: map;
  min-height: 0;
  display: flex;
}

.kiosk .map-wrap {
  flex: 1;
  height: auto;
  border-radius: var(--k-radius);
  cursor: default;
}

.kiosk .map-controls,
.kiosk .map-legend {
  display: none;
}

/* Événement en cours sur la carte: seul élément animé du kiosque, il signale du temporaire. */
.k-event-marker {
  position: absolute;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border: 4px solid var(--accent);
  border-radius: 50%;
  pointer-events: none;
  /* Même niveau que les avatars: au-dessus des marqueurs de lieux des tuiles (z 3-4). */
  z-index: 5;
  /* Liseré sombre: lisible sur l'herbe comme sur l'eau. */
  box-shadow: 0 0 0 2px rgba(6, 9, 15, 0.75), inset 0 0 0 2px rgba(6, 9, 15, 0.75), 0 0 22px rgba(255, 180, 84, 0.8);
}

/* Onde qui s'échappe de l'anneau fixe. */
.k-event-marker::after {
  content: "";
  position: absolute;
  inset: -4px;
  border: 3px solid var(--accent);
  border-radius: 50%;
  animation: k-marker 2s ease-out infinite;
}

@keyframes k-marker {
  0% {
    transform: scale(1);
    opacity: 0.9;
  }
  100% {
    transform: scale(1.9);
    opacity: 0;
  }
}

.k-roster {
  grid-area: roster;
  display: grid;
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: var(--k-gap);
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.k-char {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(8em, 0.7fr) minmax(0, 2fr) auto;
  grid-template-rows: 1fr auto 1fr;
  grid-template-areas:
    "portrait ident activity level"
    "portrait xp xp level"
    "portrait meta meta level";
  align-items: center;
  column-gap: 0.9em;
  row-gap: 0.2em;
  min-height: 0;
  padding: 0.4em 1em 0.4em 1.2em;
  border: 1px solid var(--border);
  border-radius: var(--k-radius);
  background: linear-gradient(90deg, color-mix(in srgb, var(--char-color) 12%, var(--bg-card)), var(--bg-card) 40%);
  overflow: hidden;
}

/* Liseré à la couleur du personnage: même couleur que son avatar sur la carte et dans le fil. */
.k-char::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0.3em;
  background: var(--char-color);
}

.k-char.paused {
  opacity: 0.55;
}

.k-char.flash {
  animation: k-flash 2.4s ease-out;
}

@keyframes k-flash {
  0%,
  20% {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent), 0 0 2.4em rgba(255, 180, 84, 0.35);
  }
  100% {
    border-color: var(--border);
    box-shadow: none;
  }
}

.k-portrait {
  grid-area: portrait;
  width: 3.2em;
  height: 3.2em;
  border-radius: 50%;
  border: 2px solid var(--char-color);
  background: rgba(6, 9, 15, 0.6);
  overflow: hidden;
}

.k-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
}

.k-char.fighting .k-portrait {
  border-color: var(--bad);
  box-shadow: 0 0 0.8em rgba(255, 93, 93, 0.45);
}

.k-ident {
  grid-area: ident;
  min-width: 0;
}

.k-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.2em;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.k-role {
  display: flex;
  align-items: center;
  gap: 0.5em;
  font-size: 0.82em;
  color: var(--text-dim);
}

.k-badge {
  padding: 0.05em 0.6em;
  border-radius: 999px;
  font-size: 0.9em;
  font-weight: 600;
}

.k-badge[hidden] {
  display: none;
}

.k-badge[data-kind="paused"] {
  background: rgba(255, 180, 84, 0.15);
  color: var(--accent);
}

.k-badge[data-kind="training"] {
  background: rgba(255, 93, 93, 0.12);
  color: #ff9a9a;
}

.k-activity {
  grid-area: activity;
  display: flex;
  align-items: center;
  gap: 0.5em;
  min-width: 0;
  font-size: 1em;
  font-weight: 500;
}

.k-activity-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.k-level {
  grid-area: level;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 2.6em;
  line-height: 1;
}

.k-level-num {
  font-family: var(--display);
  font-weight: 700;
  font-size: 2.1em;
  color: var(--char-color);
  font-variant-numeric: tabular-nums;
}

.k-level-label {
  margin-top: 0.2em;
  font-size: 0.72em;
  color: var(--text-dim);
}

.k-xp-line {
  grid-area: xp;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.9em;
}

.k-bar {
  display: block;
  height: 0.5em;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.k-bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  transition: width 0.8s ease;
}

.k-xp {
  height: 0.6em;
}

.k-xp > span {
  background: var(--char-color);
}

.k-xp-text {
  font-size: 0.8em;
  color: var(--text-dim);
  white-space: pre;
  font-variant-numeric: tabular-nums;
}

.k-meta {
  grid-area: meta;
  display: flex;
  align-items: center;
  gap: 1.6em;
  min-width: 0;
  font-size: 0.82em;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
}

.k-stat {
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
}

.k-hp {
  width: 4.5em;
  height: 0.4em;
}

.k-hp-text,
.k-bag-text {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.k-task {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
}

.k-task-bar {
  width: 4.5em;
  height: 0.4em;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.k-task-bar > span {
  display: block;
  height: 100%;
  background: var(--accent2);
}

.k-task-count {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.k-skills {
  display: inline-flex;
  gap: 0.4em;
  margin-left: auto;
}

.k-skill {
  padding: 0.1em 0.55em;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
}

/* --------------------------------- Bandeau du bas --------------------------------- */

.k-panel {
  min-height: 0;
  padding: 0.9em 1.1em;
  border: 1px solid var(--border);
  border-radius: var(--k-radius);
  background: var(--bg-panel);
  overflow: hidden;
}

.k-world {
  grid-area: world;
}

.k-system {
  grid-area: system;
}

.k-journal {
  grid-area: journal;
}

.k-events {
  display: grid;
  gap: 0.5em;
  margin: 0;
  padding: 0;
  list-style: none;
}

.k-event {
  display: grid;
  grid-template-columns: 2.4em minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.7em;
}

.k-event img {
  width: 2.4em;
  height: 2.4em;
  object-fit: contain;
  image-rendering: pixelated;
}

.k-event-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.k-event-where {
  font-size: 0.78em;
  color: var(--text-dim);
}

.k-event-left {
  font-family: var(--display);
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.k-empty {
  color: var(--text-dim);
  font-size: 0.85em;
}

.k-offerings {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45em;
}

.k-chip {
  padding: 0.2em 0.7em;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  font-size: 0.85em;
}

.k-offerings-until {
  font-size: 0.78em;
  color: var(--text-dim);
}

.k-system-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.9em 1.2em;
}

.k-sys-label {
  font-size: 0.78em;
  color: var(--text-dim);
}

.k-sys-value {
  font-family: var(--display);
  font-weight: 600;
  font-size: 1.2em;
  font-variant-numeric: tabular-nums;
}

.k-sys[data-tone="good"] .k-sys-value {
  color: var(--good);
}

.k-sys[data-tone="warn"] .k-sys-value {
  color: var(--warn);
}

.k-sys[data-tone="bad"] .k-sys-value {
  color: var(--bad);
}

.k-sys-bar {
  margin-top: 0.3em;
  height: 0.35em;
}

.k-sys-bar[hidden] {
  display: none;
}

.k-sys-bar > span {
  background: var(--accent2);
}

.k-sys[data-tone="warn"] .k-sys-bar > span {
  background: var(--warn);
}

.k-sys[data-tone="bad"] .k-sys-bar > span {
  background: var(--bad);
}

.k-system-grid {
  gap: 0.75em 1.2em;
}

.k-feed {
  display: flex;
  flex-direction: column;
  gap: 0.45em;
  height: calc(100% - 2em);
  overflow: hidden;
  /* Le plus ancien s'efface au lieu d'être coupé net. */
  mask-image: linear-gradient(180deg, #000 78%, transparent);
  margin: 0;
  padding: 0;
  list-style: none;
}

.k-msg {
  display: grid;
  grid-template-columns: 3.2em minmax(0, 1fr);
  grid-template-areas:
    "time head"
    "time body";
  column-gap: 0.6em;
  padding-left: 0.6em;
  border-left: 2px solid var(--border);
  animation: k-in 0.5s ease-out;
}

@keyframes k-in {
  from {
    opacity: 0;
    transform: translateY(-0.3em);
  }
}

.k-msg.sev-warn {
  border-left-color: var(--warn);
}

.k-msg.sev-error {
  border-left-color: var(--bad);
}

.k-msg.sev-success {
  border-left-color: var(--good);
}

.k-msg time {
  grid-area: time;
  font-size: 0.8em;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.k-msg-head {
  grid-area: head;
  display: flex;
  gap: 0.5em;
  font-size: 0.85em;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
}

.k-msg-head span {
  color: var(--text-dim);
}

.k-msg-body {
  grid-area: body;
  font-size: 0.85em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --------------------------------- Commandes (au mouvement de la souris) --------------------------------- */

.k-tools {
  position: fixed;
  right: calc(var(--k-gap) * 1.4);
  bottom: calc(var(--k-gap) * 1.2);
  z-index: 60;
  display: flex;
  gap: 0.5em;
  transition: opacity 0.3s ease;
}

body.kiosk-idle .k-tools {
  opacity: 0;
  pointer-events: none;
}

.k-tool {
  padding: 0.5em 1em;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
  font: inherit;
  font-size: 0.85em;
  cursor: pointer;
}

.k-tool:hover {
  border-color: var(--accent2);
}

.k-tool:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.k-tool[hidden] {
  display: none;
}

/* Écrans en portrait ou étroits: une colonne, défilement autorisé. */
@media (max-aspect-ratio: 4/3) {
  body.kiosk-on {
    overflow: auto;
  }
  .kiosk {
    position: absolute;
    min-height: 100%;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto auto auto;
    grid-template-areas: "head" "map" "roster" "world" "system" "journal";
  }
  .k-map {
    height: 45vh;
    width: auto !important;
  }
  .k-roster {
    grid-template-rows: none;
  }
  .k-head {
    flex-wrap: wrap;
  }
  .k-kpis {
    flex-wrap: wrap;
    justify-content: flex-start;
  }
}

@media (prefers-reduced-motion: reduce) {
  .kiosk,
  .k-dot,
  .k-char.flash,
  .k-msg,
  .k-event-marker::after,
  .k-bar > span {
    animation: none !important;
    transition: none !important;
  }
}
