 @font-face {
    font-family: "magdacleanmono";
    src: url("font.otf") format("opentype");
  }
  * { box-sizing: border-box; }
  html, body {
    height: 100%;
    margin: 0;
    padding: 0;
  }
  body {
    color: #000;
    background-color: #fff;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-family: "magdacleanmono", "Courier New", monospace;
    -webkit-user-select: none; user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
  p {
    font-family: "magdacleanmono";
    font-size: clamp(1.1em, 6vw, 2em);
    text-transform: uppercase;
    display: block !important;
    margin: 0;
  }
  #text {
    font-weight: bold;
    max-width: 100%;
    overflow-wrap: anywhere;
  }
  #text.word-in { animation: textIn 0.15s ease; }
  #text.word-out { animation: textOut 0.15s ease forwards; }
  @keyframes textIn { from { opacity: 0; } to { opacity: 1; } }
  @keyframes textOut { from { opacity: 1; } to { opacity: 0; } }
  #main {
    display: block;
    width: 100%;
    max-width: 1200px;
    padding: 0 16px;
  }
  #main hr {
    width: 30px;
    margin: 8px auto 0;
    border-top: 2px solid #000;
    border-bottom: none;
    transition: width 0.3s ease;
  }
  #main p, #main hr { margin-top: 0; margin-bottom: 0; }
  #main p.hidden { color: #fff; }
  #marker { margin-top: 5px; }
  #triangle {
    color: #F00;
    font-size: clamp(1.3em, 6vw, 2em);
    font-family: "magdacleanmono";
    display: inline-block;
  }
  body.listening #triangle { animation: pulse 1s ease-in-out infinite; }
  body.thinking #triangle  { animation: blink 1.4s ease-in-out infinite; }
  @keyframes pulse {
    0%   { transform: scale(1);    opacity: 0.6; }
    50%  { transform: scale(1.3); opacity: 1; }
    100% { transform: scale(1);    opacity: 0.6; }
  }
  @keyframes blink {
    0%, 100% { opacity: 0.25; }
    50%      { opacity: 1; }
  }
  #settings {
    width: 40px;
    height: 40px;
    font-size: 14px;
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px));
    right: calc(env(safe-area-inset-right, 0px));
    color: #888;
    line-height: 40px;
    text-align: center;
    cursor: pointer;
    z-index: 20;
  }
  #status {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent;
    z-index: 999;
    pointer-events: none;
    box-sizing: border-box;
  }
  #status.show { display: flex; }
  #status .label {
    background: #000;
    color: #fff;
    font-family: "magdacleanmono", "Courier New", monospace;
    font-size: clamp(1.2em, 6vw, 2.4em);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-align: center;
    padding: 20px 40px;
    max-width: 50%;
    border: 2px solid #000;
  }
  #status.show .label { animation: labelIn 0.5s ease; }
  #status.hide .label { animation: labelOut 0.5s ease forwards; }
  @keyframes labelIn {
    0%   { transform: scale(1.2);  opacity: 0; }
    45%  { transform: scale(0.55); opacity: 1; }
    100% { transform: scale(1);    opacity: 1; }
  }
  @keyframes labelOut {
    0%   { transform: scale(1);    opacity: 1; }
    45%  { transform: scale(0.55); opacity: 1; }
    100% { transform: scale(1.2);  opacity: 0; }
  }
  #panel {
    position: fixed;
    right: 10px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 44px);
    display: none;
    z-index: 10;
    max-width: min(300px, calc(100vw - 20px));
    padding: 12px 14px;
    background: #fff;
    border: 1px solid #ddd;
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.1);
    text-align: left;
  }
  #panel.open { display: block; animation: panelIn 0.3s ease; }
  #panel.closing { animation: panelOut 0.3s ease forwards; }
  #panel h1 {
    margin: 0 0 8px;
    color: #888;
    font-size: 0.65em;
    font-weight: normal;
    letter-spacing: 0.25em;
  }
  #panel p {
    margin: 0 0 8px;
    color: #000;
    font-size: 0.7em;
    word-break: break-all;
  }
  #panel button {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 6px 0;
    background: none;
    color: #000;
    border: 1px solid #888;
    font-family: inherit;
    font-size: 0.7em;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
  }
  #panel button:hover { background: #eee; }
  #logView {
    display: none;
    margin-top: 8px;
    max-height: 40vh;
    overflow: auto;
    background: #111;
    color: #0f0;
    font-family: "Courier New", monospace;
    font-size: 0.55em;
    line-height: 1.5;
    padding: 8px;
    white-space: pre-wrap;
    word-break: break-all;
  }
  #logView.show { display: block; }
  @keyframes panelIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
  }
  @keyframes panelOut {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(8px); }
  }
  .cursor-blink { animation: loaderBlink 1s steps(1) infinite; }
  @keyframes loaderBlink { 50% { opacity: 0; } }

  /* ---------- LOADER / BOOT (cosmétique uniquement, plus de chargement réel) ---------- */
  #loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    background: #fafafa;
    z-index: 1000;
    overflow: hidden;
  }
  .loader-pane {
    position: absolute;
    top: 0;
    height: 100%;
    width: 50%;
    background: #fff;
    z-index: 3;
    transition: width 1s cubic-bezier(0.77, 0, 0.18, 1);
  }
  #loader-left  { left: 0; border-right: 2px solid #000; }
  #loader-right { right: 0; border-left: 2px solid #000; }
  #loader.open  .loader-pane { width: 13%; }
  #loader.done  #loader-left  { transform: translateX(-100vw); }
  #loader.done  #loader-right { transform: translateX(100vw); }
  #loader.done  .loader-pane {
    border-color: transparent;
    transition: transform 1s cubic-bezier(0.77, 0, 0.18, 1), border-color 0.3s ease 0.5s;
  }
  #loader-left::after,
  #loader-right::after {
    content: "";
    position: absolute;
    width: 8px;
    height: 8px;
    background: #000;
    z-index: 4;
    box-shadow:
      0 24vh 0 0 #000,
      0 48vh 0 0 #000,
      0 72vh 0 0 #000;
  }
  #loader-left::after  { top: 12vh; right: -10px; }
  #loader-right::after { top: 12vh; left: -10px; }
  .loader-pane .cnr {
    position: absolute;
    width: 18px;
    height: 18px;
    z-index: 4;
  }
  #loader-left .cnr.t  { top: 14px;    right: 12px;  border-top: 2px solid #000;    border-right: 2px solid #000; }
  #loader-left .cnr.b  { bottom: 14px; right: 12px;  border-bottom: 2px solid #000; border-right: 2px solid #000; }
  #loader-right .cnr.t { top: 14px;    left: 12px;   border-top: 2px solid #000;    border-left: 2px solid #000; }
  #loader-right .cnr.b { bottom: 14px; left: 12px;   border-bottom: 2px solid #000; border-left: 2px solid #000; }
  #loader-center {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  #boot-log {
    position: absolute;
    top: max(12px, env(safe-area-inset-top, 0px));
    left: calc(13% + 12px);
    right: calc(50% + min(35vw, 230px) + 36px);
    width: auto;
    height: 72%;
    max-height: 72%;
    font-size: clamp(0.45em, 2.2vw, 0.6em);
    line-height: 1.7;
    color: #b0b0b0;
    text-align: left;
    overflow: hidden;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
  }
  @media (max-width: 820px) {
    #boot-log {
      left: calc(13% + 10px);
      right: calc(13% + 10px);
      top: 6px;
      height: 38%;
      max-height: 38%;
      font-size: clamp(0.32em, 1.8vw, 0.42em);
    }
  }
  #boot-log .boot-line { display: block; animation: logLineIn 0.2s ease; }
  #boot-log .boot-text { display: inline; }
  #boot-log .boot-cursor {
    display: inline-block;
    width: 0.55em;
    height: 1.05em;
    background: #000;
    vertical-align: text-bottom;
    margin-left: 2px;
    animation: cursorBlink 1s steps(1) infinite;
  }
  @keyframes logLineIn { from { opacity: 0; } to { opacity: 1; } }
  @keyframes cursorBlink { 50% { opacity: 0; } }
  #loader.open #boot-log { animation: logFadeIn 0.6s ease 0.2s forwards; }
  @keyframes logFadeIn { from { opacity: 0; } to { opacity: 1; } }
  #loading-pane-container { text-align: center; opacity: 0; }
  #loader.open #loading-pane-container { animation: pulseIn 0.7s ease 0.35s forwards; }
  @keyframes pulseIn {
    0%   { opacity: 0; }
    30%  { opacity: 0.85; }
    45%  { opacity: 0.05; }
    100% { opacity: 1; }
  }
  #loader.finishing #loading-pane-container,
  #loader.finishing #boot-log { animation: paneFadeOut 0.8s ease forwards; }
  @keyframes paneFadeOut { to { opacity: 0; } }
  .invert {
    display: inline-block;
    background: #000;
    color: #fff;
    padding: 3px 8px;
    letter-spacing: 0.2em;
    font-size: clamp(0.5em, 2.5vw, 0.6em);
  }
  #loading-name {
    font-size: clamp(0.7em, 3.5vw, 1.1em);
    margin: 12px 0 10px;
    color: #000;
    min-height: 1.2em;
  }
  #loading-bar-container {
    width: min(70%, 460px);
    margin: 0 auto;
    border: 2px solid #000;
    padding: 2px;
    height: 18px;
    box-sizing: border-box;
  }
  #loading-bar {
    position: relative;
    background: #000;
    height: 100%;
    width: 0;
    overflow: hidden;
    transition: width 0.25s ease-out;
  }
  #loading-connected {
    position: absolute;
    top: 50%; left: 0;
    width: 100%;
    transform: translateY(-50%);
    text-align: center;
    opacity: 0;
    pointer-events: none;
  }
  #loading-connected.show { opacity: 1; }
  #loading-connected.hide { opacity: 0; }
  #loading-connected .label {
    display: inline-block;
    background: #000;
    color: #fff;
    font-family: "magdacleanmono", "Courier New", monospace;
    font-size: clamp(1.2em, 6vw, 2.4em);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 20px 40px;
    max-width: min(82vw, 560px);
    border: 2px solid #000;
  }
  #loading-connected.show .label { animation: labelIn 0.5s ease; }
  #loading-connected.hide .label { animation: labelOut 0.5s ease forwards; }
  #loading-connected.error .label { background: #F00; }
