/* KITA — HUD / terminal. Fond noir, un seul accent #F8C89F. Police : Space Mono. */

@font-face {
  font-family: "Space Mono";
  src: url("/fonts/SpaceMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Space Mono";
  src: url("/fonts/SpaceMono-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #000;
  --fg: #f8c89f;
  --fg-dim: #7a6350;
  --fg-mid: #b8987e;
  --line: #2a2320;
  --line-bright: #4a3d33;
  --line-soft: #171310;
  --danger: #e5786d;
  --ok: #9fd8a8;
  --font: "Space Mono", ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --bp: 769px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html,
body {
  height: 100%;
}
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.55;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
a {
  color: var(--fg);
}
button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--line-bright);
  border-radius: 0;
  padding: 8px 10px;
  outline: none;
}
button {
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 11px;
  font-weight: 700;
}
button:hover {
  background: var(--fg);
  color: var(--bg);
}
button:disabled {
  opacity: 0.4;
  cursor: default;
}
button:disabled:hover {
  background: transparent;
  color: inherit;
}
input:focus,
textarea:focus {
  border-color: var(--fg);
}
::placeholder {
  color: var(--fg-dim);
}
select {
  background: #000;
  color: var(--fg);
  -webkit-appearance: none;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-mid) 50%),
    linear-gradient(135deg, var(--fg-mid) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}
select option {
  background: #000;
  color: var(--fg);
}
::selection {
  background: var(--fg);
  color: var(--bg);
}

/* --- boot --- */
#app[data-view="boot"] {
  display: grid;
  place-items: center;
  height: 100%;
}
.boot {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0.28em;
}
.cursor {
  animation: blink 1s steps(1) infinite;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* ================================================================
   Telegram Mini App — contexte Web App (pas de barre d'adresse,
   hauteur fournie par le SDK via --tg-vh, header natif Telegram).
   On garde le style HUD ; on ajuste juste la hauteur et les marges.
   ================================================================ */
html.tg,
html.tg body {
  height: var(--tg-vh, 100%);
}
html.tg #app {
  height: var(--tg-vh, 100%);
  border-left: none;
  border-right: none;
}
/* le header Telegram remplace la status bar : plus besoin du padding safe-area */
html.tg header.topbar {
  padding-top: 12px;
}
/* le Main Button natif recouvre le bas : on dégage les onglets */
html.tg nav.tabs {
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

/* ================================================================
   LAYOUT — mobile (base, < 769px)
   ================================================================ */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 720px;
  margin: 0 auto;
  border-left: 1px solid var(--line);
  border-right: 1px solid var(--line);
}
header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  padding-top: max(12px, env(safe-area-inset-top));
}
header .brand {
  font-weight: 700;
  letter-spacing: 0.22em;
  font-size: 15px;
}
header .mode {
  font-size: 10px;
  font-weight: 700;
  border: 1px solid var(--line-bright);
  padding: 3px 7px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
header .mode.sanspitie {
  color: var(--bg);
  background: var(--fg);
  border-color: var(--fg);
}
header .mode.normal {
  color: var(--fg-mid);
}
header .mode.test {
  color: var(--bg);
  background: var(--fg-mid);
  border-color: var(--fg-mid);
  cursor: pointer;
}

main {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  -webkit-overflow-scrolling: touch;
}

nav.tabs {
  display: flex;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button {
  flex: 1;
  min-width: 0;
  border: none;
  border-right: 1px solid var(--line);
  padding: 13px 1px;
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--fg-dim);
  background: transparent;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
nav.tabs button:last-child {
  border-right: none;
}
nav.tabs button.active {
  color: var(--fg);
}
nav.tabs button:hover {
  background: transparent;
  color: var(--fg);
}

/* --- primitives --- */
.panel {
  border: 1px solid var(--line);
  padding: 12px;
  margin-bottom: 12px;
}
.panel > h2 {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-dim);
  margin-bottom: 10px;
}
.row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 3px 0;
}
.row .k {
  color: var(--fg-mid);
}
.big {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.muted {
  color: var(--fg-dim);
}
.danger {
  color: var(--danger);
}
.ok {
  color: var(--ok);
}
.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 10px 0;
}

/* barre de progression HUD */
.bar {
  height: 8px;
  border: 1px solid var(--line-bright);
  margin: 6px 0;
  position: relative;
}
.bar > i {
  position: absolute;
  inset: 0;
  background: var(--fg);
  transform-origin: left;
}
.bar.warn > i {
  background: var(--danger);
}

.tag {
  display: inline-block;
  border: 1px solid var(--line-bright);
  padding: 1px 6px;
  font-size: 10px;
  color: var(--fg-mid);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* --- login --- */
.login {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 20px;
}
.login form {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login .title {
  font-weight: 700;
  letter-spacing: 0.28em;
  font-size: 22px;
  text-align: center;
  margin-bottom: 8px;
}

/* --- orbe d'état de Kita --- */
.orb-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--line);
}
.orb-bar canvas {
  flex-shrink: 0;
  display: block;
}
.orb-bar .lbl {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--fg-dim);
}
.orb-meta {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.orb-bar .clock {
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
}
.orb-bar .clock-date {
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--fg-dim);
  text-transform: lowercase;
}
.orb-bar .clock-time {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
}

/* --- chat --- */
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg {
  white-space: pre-wrap;
  word-break: break-word;
}
.msg .who {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-dim);
  margin-bottom: 2px;
}
.msg .who .chan {
  display: inline-block;
  margin-left: 6px;
  padding: 0 5px;
  border: 1px solid var(--line-bright);
  border-radius: 2px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
  vertical-align: 1px;
}
.msg .who .chan-telegram {
  color: var(--bg);
  background: var(--fg-mid);
  border-color: var(--fg-mid);
}
.msg .who .chan-auto {
  color: var(--fg-mid);
  border-style: dashed;
}
.msg.user .who {
  text-align: right;
}
.msg.user .body {
  border-left: 2px solid var(--line-bright);
  padding-left: 10px;
  color: var(--fg-mid);
}
.msg.kita .body {
  border-left: 2px solid var(--fg);
  padding-left: 10px;
}
.chat-input {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.chat-input textarea {
  flex: 1;
  resize: none;
  height: 42px;
  max-height: 140px;
}
.chat-input button {
  white-space: nowrap;
}
.chat-input .imgbtn,
.chat-input .mic {
  padding: 8px 9px;
}

/* images dans les bulles */
.msg-img {
  display: block;
  max-width: 220px;
  max-height: 220px;
  border: 1px solid var(--line-bright);
  margin-bottom: 6px;
  cursor: pointer;
}

/* bandeau des images en attente d'envoi */
.img-strip {
  display: flex;
  gap: 8px;
  padding: 8px 14px 0;
  overflow-x: auto;
}
.img-strip .thumb {
  position: relative;
  flex-shrink: 0;
}
.img-strip .thumb img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border: 1px solid var(--line-bright);
  display: block;
}
.img-strip .thumb .rm {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 18px;
  height: 18px;
  padding: 0;
  line-height: 1;
  font-size: 13px;
  border-radius: 50%;
  background: #000;
  border: 1px solid var(--fg);
  color: var(--fg);
}
.img-strip .thumb .rm:hover {
  background: var(--fg);
  color: #000;
}

.dropping {
  outline: 2px dashed var(--fg);
  outline-offset: -6px;
}
.mic.rec {
  background: var(--danger);
  color: var(--bg);
  border-color: var(--danger);
}
.toolcalls {
  font-size: 10px;
  color: var(--fg-dim);
  margin-top: 4px;
}

/* --- listes --- */
.list .item {
  border-top: 1px solid var(--line);
  padding: 8px 0;
  font-size: 12px;
}
.list .item:first-child {
  border-top: none;
}
.list .item .meta {
  font-size: 10px;
  color: var(--fg-dim);
}

form.inline {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}
form.inline .fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
form.inline .fields > * {
  min-width: 0; /* empêche les inputs de déborder du panneau */
  width: 100%;
}
form.inline > .fields,
form.inline > button {
  width: 100%;
}
.notice {
  border: 1px solid var(--line-bright);
  padding: 10px;
  margin-bottom: 12px;
  font-size: 11px;
  color: var(--fg-mid);
}

/* --- leaderboard --- */
.chips {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.chips button {
  padding: 5px 9px;
  font-size: 10px;
  border-color: var(--line-bright);
}
.chips button.on {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}
.lb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 4px;
  border-top: 1px solid var(--line);
}
.lb-row:first-child {
  border-top: none;
}
.lb-row.me {
  background: var(--fg);
  color: var(--bg);
  margin: 4px -4px;
  padding: 10px 8px;
}
.lb-row.me .sub,
.lb-row.me .rank {
  color: var(--bg);
  opacity: 0.75;
}
.lb-row .rank {
  width: 40px;
  text-align: right;
  font-size: 10px;
  color: var(--fg-dim);
  flex-shrink: 0;
}
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  color: #000;
  flex-shrink: 0;
}
.avatar.celebrite {
  background: #f8c89f;
}
.avatar.moyenne {
  background: #b8987e;
}
.avatar.pauvrete {
  background: #7a6350;
  color: #000;
}
.avatar.moi {
  background: #000;
  color: #f8c89f;
  border: 2px solid #f8c89f;
}
.lb-row .who2 {
  flex: 1;
  min-width: 0;
}
.lb-row .who2 .nm {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lb-row .sub {
  font-size: 9px;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lb-row .val {
  font-size: 12px;
  font-weight: 700;
  text-align: right;
  flex-shrink: 0;
  white-space: nowrap;
}

/* --- chrono --- */
.chrono {
  text-align: center;
}
.chrono .time {
  font-size: 38px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 8px 0;
}
.chrono .time.paused {
  color: var(--fg-dim);
}
.chrono .controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 6px;
}
.chrono select {
  width: 100%;
  margin-bottom: 8px;
}
.chrono .cat {
  font-size: 10px;
  font-weight: 700;
  color: var(--fg-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.err {
  color: var(--danger);
  font-size: 11px;
  min-height: 16px;
}

/* ================================================================
   LAYOUT — desktop (>= 769px)
   #app occupe 100% de la largeur : sidebar fixe à gauche + zone de contenu
   fluide qui prend tout l'espace restant. Le contenu est ensuite borné et
   CENTRÉ à l'intérieur pour la lisibilité (pas collé à gauche).
   ================================================================ */
@media (min-width: 769px) {
  body {
    font-size: 13px;
  }
  #app {
    width: 100%;
    max-width: none; /* annule le plafond mobile — plus aucune largeur fixe */
    margin: 0;
    display: grid;
    grid-template-columns: clamp(200px, 15vw, 240px) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "side head"
      "side main";
    border: none;
  }
  #app[data-view="login"],
  #app[data-view="boot"] {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    place-items: center;
  }

  header.topbar {
    grid-area: head;
    padding: 16px clamp(20px, 3vw, 44px);
    border-bottom: 1px solid var(--line);
  }
  header .brand {
    font-size: 16px;
    letter-spacing: 0.24em;
  }

  nav.tabs {
    grid-area: side;
    flex-direction: column;
    border-top: none;
    border-right: 1px solid var(--line);
    padding: 0;
    background: var(--line-soft);
  }
  nav.tabs button {
    flex: none;
    text-align: left;
    border: none;
    border-bottom: 1px solid var(--line);
    padding: 16px 20px;
    font-size: 11px;
    letter-spacing: 0.1em;
  }
  nav.tabs button.active {
    color: var(--fg);
    background: #000;
    box-shadow: inset 3px 0 0 var(--fg);
  }

  /* zone de contenu : pleine largeur, scroll interne */
  #app > main {
    grid-area: main;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    padding: 24px clamp(20px, 4vw, 72px);
  }
  #app > .chatwrap {
    grid-area: main;
    min-width: 0;
    min-height: 0;
  }

  /* Tableau / Finance / Journal : panneaux en colonnes fluides,
     bloc centré, largeur bornée pour rester lisible sur très grand écran */
  .view-dash,
  .view-fin,
  .view-hist,
  .view-inv {
    max-width: 1180px;
    margin: 0 auto;
    columns: 320px 2; /* 2 colonnes si la place le permet, sinon 1 */
    column-gap: 24px;
  }
  .view-dash > *,
  .view-fin > *,
  .view-hist > *,
  .view-inv > * {
    break-inside: avoid;
  }
  .view-dash > .panel,
  .view-fin > .panel,
  .view-hist > .panel,
  .view-inv > .panel {
    margin-bottom: 22px;
  }

  /* Leaderboard : bloc centré ~1080px, « ma position » épinglée en haut */
  .view-lb {
    max-width: 1080px;
    margin: 0 auto;
  }
  .view-lb > .panel:not(.list-panel) {
    position: sticky;
    top: -24px; /* compense le padding vertical de main */
    z-index: 3;
    background: #000;
  }

  /* Chat : conversation centrée, largeur de lecture bornée, orbe agrandi */
  .orb-bar {
    justify-content: center;
    gap: 18px;
    padding: 16px;
  }
  .chatwrap .chat-log,
  .chatwrap .chat-input,
  .chatwrap .img-strip {
    max-width: 920px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
  }
  .msg-img {
    max-width: 320px;
    max-height: 320px;
  }

  .big {
    font-size: 28px;
  }
  .chrono .time {
    font-size: 44px;
  }
}

