:root {
  --paper: #ffffff; --strip: #f1f3f6; --line: #dfe3e8; --text: #3f444b; --muted: #8a9099;
  --accent: #f39a1e; --accent-dark: #c97405; --accent-soft: #fff4e4;
  --info: #2e9fc4; --info-soft: #e8f5fa; --danger: #de453a; --danger-soft: #fdecea; --good: #6fb536; --good-soft: #edf7e4; --idle: #9aa0a8;
  --bg: #eceff3; --radius: 12px; --shadow: 0 1px 2px rgba(20,30,40,.06), 0 4px 16px rgba(20,30,40,.04);
  --nav-w: 92px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.ic.sm { width: 15px; height: 15px; }
#i-play path, #i-next path:first-child, #i-stop rect, #i-bolt path { fill: currentColor; }
.brand { font-size: 19px; letter-spacing: .6px; white-space: nowrap; }
.brand b { color: var(--accent); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600; min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); background: var(--paper); color: var(--text); border-radius: 10px; cursor: pointer; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.block { width: 100%; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-dark); }
.btn.icon-only { padding: 0 14px; }
.link { border: none; background: none; color: var(--muted); text-decoration: underline; cursor: pointer; font: inherit; font-size: 13px; padding: 4px; margin-left: auto; }

input, select { font: inherit; width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: #f6f8fa; color: var(--text); }
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
label input, label select { margin-top: 4px; }

/* Loading (SAO) */
.loader { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: radial-gradient(circle at 50% 40%, #ffffff 0%, #eef1f5 60%, #e2e7ee 100%); transition: opacity .5s; }
.loader.done { opacity: 0; pointer-events: none; }
.loader-core { text-align: center; }
.rings { position: relative; width: 120px; height: 120px; margin: 0 auto 18px; }
.rings span { position: absolute; inset: 0; border-radius: 50%; border: 3px solid transparent; border-top-color: var(--accent); animation: spin 1.6s linear infinite; }
.rings span:nth-child(2) { inset: 14px; border-top-color: var(--info); animation-duration: 1.1s; animation-direction: reverse; }
.rings span:nth-child(3) { inset: 30px; border-top-color: #c7ccd3; animation-duration: 2.4s; }
@keyframes spin { to { transform: rotate(360deg); } }
.loader-brand { font-size: 28px; letter-spacing: 3px; }
.loader-brand b { color: var(--accent); }
.loader-step { margin: 8px 0 12px; color: var(--muted); letter-spacing: 1px; font-size: 13px; text-transform: uppercase; }
.loader-bar { width: 220px; height: 4px; background: #dde2e8; border-radius: 4px; overflow: hidden; margin: 0 auto; }
.loader-bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #ffc061); transition: width .4s; }

/* Login */
.screen { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--paper); border-radius: var(--radius); padding: 26px; box-shadow: var(--shadow); border-top: 4px solid var(--accent); }
.login-card .btn { margin-top: 14px; }
.error { color: var(--danger); min-height: 1.2em; font-size: 13px; }

/* Layout */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(255,255,255,.94); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.chips { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 4px 10px; border-radius: 999px; background: var(--strip); color: var(--muted); white-space: nowrap; }
.chip .ic { width: 14px; height: 14px; }
.chip.good { background: var(--good-soft); color: #4b8a1c; }
.chip.warn { background: var(--accent-soft); color: var(--accent-dark); }
.chip.info { background: var(--info-soft); color: #1f7f9f; }
.chip.bad { background: var(--danger-soft); color: var(--danger); }
.chip.pulse::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .25; } }
#stopBtn { min-height: 38px; padding: 0 14px; }

.nav { position: fixed; z-index: 9; top: 59px; left: 0; bottom: 0; width: var(--nav-w); display: flex; flex-direction: column; gap: 4px; padding: 12px 8px; background: var(--paper); border-right: 1px solid var(--line); }
.nav button { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border: none; border-radius: 10px; background: none; color: var(--muted); font: inherit; font-size: 11.5px; cursor: pointer; }
.nav button .ic { width: 24px; height: 24px; }
.nav button:hover { color: var(--text); background: var(--strip); }
.nav button.active { color: var(--accent-dark); background: var(--accent-soft); }
.nav .dot { position: absolute; top: 8px; right: 20px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.views { margin-left: var(--nav-w); padding: 16px; max-width: calc(1080px + var(--nav-w)); }
.view { display: grid; gap: 14px; }
.foot { margin-left: var(--nav-w); display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 0 16px 20px; color: var(--accent-dark); font-size: 13px; max-width: calc(1080px + var(--nav-w)); }

.card { background: var(--paper); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-title { display: flex; align-items: center; gap: 8px; font-size: 12px; letter-spacing: 1.2px; color: var(--muted); margin-bottom: 12px; }
.card-title .bar { width: 3px; height: 14px; background: var(--accent); border-radius: 2px; }
.eyebrow { font-size: 11.5px; letter-spacing: 1.4px; color: var(--muted); }

/* Hero */
.hero-head { display: flex; align-items: center; gap: 14px; }
.hero-icon { width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-dark); flex: none; }
.hero-icon .ic { width: 28px; height: 28px; }
.hero-icon.idle { background: var(--strip); color: var(--idle); }
.hero-icon.info { background: var(--info-soft); color: var(--info); }
.hero-icon.bad { background: var(--danger-soft); color: var(--danger); }
.hero-text { flex: 1; min-width: 0; }
.hero-title { font-size: 22px; line-height: 1.2; color: var(--text); overflow-wrap: anywhere; }
.hero-count { text-align: right; }
#missionCount { font-size: 26px; font-weight: 600; color: var(--accent-dark); font-variant-numeric: tabular-nums; white-space: nowrap; }
.segments { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; margin: 14px 0 10px; }
.segments span { height: 9px; background: var(--strip); transform: skewX(-25deg); border-radius: 1px; transition: background .4s; }
.segments span.on { background: var(--accent); }
.activity { font-size: 14px; color: var(--text); }
.banner { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.banner.info { background: var(--info-soft); color: #1f6f8b; }
.banner.warn { background: var(--accent-soft); color: var(--accent-dark); }
.banner.bad { background: var(--danger-soft); color: var(--danger); }

/* Action bar (Maintenant and Stream) */
.actionbar { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.actionbar .main { flex: 1 1 220px; min-height: 52px; font-size: 16px; }
.actionbar .quick { flex: 0 0 auto; }
.actionbar .quick span { display: inline; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--paper); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); display: flex; gap: 10px; align-items: center; min-width: 0; }
.kpi .ic { color: var(--accent-dark); width: 22px; height: 22px; }
.kpi .v { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .k { font-size: 12px; color: var(--muted); }
.kpi .bar2 { height: 4px; background: var(--strip); border-radius: 3px; margin-top: 4px; overflow: hidden; }
.kpi .bar2 span { display: block; height: 100%; background: var(--good); }
.kpi .bar2 span.low { background: var(--danger); }

/* Stream */
.frame { position: relative; aspect-ratio: 16 / 9; border-radius: 10px; overflow: hidden; background: linear-gradient(160deg, #1d2430, #2a3340 60%, #36404e); color: #fff; }
.wait { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 16px; text-align: center; }
.wait-ic { width: 42px; height: 42px; color: var(--accent); }
.wait-label { font-size: clamp(15px, 2.4vw, 22px); letter-spacing: .4px; }
.wait-bar { width: min(420px, 80%); height: 6px; background: rgba(255,255,255,.15); border-radius: 6px; overflow: hidden; }
.wait-bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #ffc061); transition: width .8s; }
.wait-pct { font-variant-numeric: tabular-nums; color: #cfd6df; font-size: 14px; }
.wait-steps { list-style: none; display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; padding: 0; margin: 6px 0 0; }
.wait-steps li { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: rgba(255,255,255,.08); color: #aeb7c3; display: inline-flex; gap: 5px; align-items: center; }
.wait-steps li.done { color: #bfe59a; }
.wait-steps li.now { background: rgba(243,154,30,.25); color: #ffd497; }
.wait-steps .ic { width: 13px; height: 13px; }
.stream-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.stream-top { position: absolute; top: 0; left: 0; right: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px;
  background: linear-gradient(180deg, rgba(0,0,0,.45), transparent); }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; letter-spacing: 1px; font-weight: 700; color: #fff; background: var(--danger); padding: 3px 8px; border-radius: 5px; }
.live b { font-weight: 500; opacity: .85; }
.stream-tools { display: flex; gap: 6px; margin-left: auto; }
.seg.dark { border-color: rgba(255,255,255,.25); background: rgba(0,0,0,.35); }
.seg.dark button { background: transparent; color: #d6dce4; min-height: 30px; padding: 3px 10px; font-size: 12.5px; }
.seg.dark button.active { background: rgba(243,154,30,.85); color: #fff; }
.btn.ghost { background: rgba(0,0,0,.35); border-color: rgba(255,255,255,.25); color: #fff; min-height: 32px; }
.stage:fullscreen { border-radius: 0; display: flex; flex-direction: column; padding: 10px; background: #111; }
.stage:fullscreen .frame { flex: 1; aspect-ratio: auto; }
.stage:fullscreen .stage-info { display: none; }
.stage-info { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* Missions */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { display: inline-flex; align-items: center; gap: 6px; border: none; padding: 9px 16px; background: var(--paper); font: inherit; color: var(--muted); cursor: pointer; min-height: 40px; }
.seg button.active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.seg.small { margin-left: auto; }
.seg.small button { min-height: 32px; padding: 4px 12px; font-size: 13px; }
.chips-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.chip-btn { font: inherit; font-size: 13.5px; padding: 8px 14px; min-height: 38px; border-radius: 999px; border: 1px solid var(--line); background: var(--paper); color: var(--text); cursor: pointer; }
.chip-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.form .row, .row { display: flex; gap: 8px; margin-top: 14px; }
.row .btn { flex: 1; }
.queue-list { margin: 0; padding: 0; list-style: none; counter-reset: q; }
.queue-list li { counter-increment: q; display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--strip); font-size: 14px; }
.queue-list li::before { content: counter(q); width: 24px; height: 24px; border-radius: 50%; background: var(--strip); display: grid; place-items: center; font-size: 12px; color: var(--muted); flex: none; }
.queue-list li.empty::before { display: none; }

/* Items */
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: #f6f8fa; margin-bottom: 14px; }
.search input { border: none; background: none; min-height: 42px; padding: 0; outline: none; }
.items { display: flex; flex-wrap: wrap; gap: 6px; font-size: 13.5px; }
.items span { background: var(--strip); border-radius: 8px; padding: 5px 10px; }
.items span b { color: var(--accent-dark); font-weight: 600; margin-left: 6px; }

/* Minecraft-like inventory grids */
.mc-panel { display: inline-block; max-width: 100%; background: #c6c6c6; padding: 8px; border-radius: 4px;
  box-shadow: inset 2px 2px 0 #fff, inset -2px -2px 0 #555; }
.mc-grid { display: grid; grid-template-columns: repeat(9, var(--slot, 44px)); gap: 2px; }
.mc-gap { height: 8px; }
.slot { position: relative; width: var(--slot, 44px); height: var(--slot, 44px); background: #8b8b8b; box-shadow: inset 2px 2px 0 #373737, inset -2px -2px 0 #fff; display: grid; place-items: center; overflow: hidden; }
/* Animated textures are a vertical strip of frames: only the first one, like the game at rest. */
.slot img { width: 76%; height: 76%; object-fit: cover; object-position: top; image-rendering: pixelated; }
.slot .fallback { font-size: 10px; line-height: 1.05; color: #2b2b2b; text-align: center; padding: 3px; overflow: hidden; max-height: 100%; word-break: break-word; }
.slot .n { position: absolute; right: 3px; bottom: 1px; color: #fff; font: 600 13px/1 "Segoe UI", system-ui, sans-serif; text-shadow: 2px 2px 0 #3f3f3f; }
.slot.dim { opacity: .3; }
.slot.match { box-shadow: inset 2px 2px 0 #373737, inset -2px -2px 0 #fff, 0 0 0 2px var(--accent); }
.slot.held::after { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 0 2px #fff; }
.small-btn { min-height: 32px; padding: 0 10px; font-size: 13px; margin-left: auto; letter-spacing: 0; }

/* Chat */
.chat-card { display: flex; flex-direction: column; }
.chat { height: min(60vh, 520px); overflow-y: auto; font-size: 14px; background: #fafbfc; border: 1px solid var(--strip); border-radius: 10px; padding: 8px 10px; }
.chat div { padding: 2px 0; overflow-wrap: anywhere; }
.chat-form { display: flex; gap: 8px; margin-top: 10px; }

/* Console */
.console { overflow-y: auto; font-size: 13.5px; }
.console.tall { height: min(68vh, 640px); }
.console.compact { max-height: 210px; }
.console .line { display: flex; gap: 10px; padding: 5px 0; align-items: center; border-bottom: 1px solid #f4f5f7; }
.console .t { color: var(--muted); font-size: 12px; min-width: 58px; font-variant-numeric: tabular-nums; }
.console .tone { width: 8px; height: 8px; border-radius: 50%; background: var(--text); flex: none; }
.console.detail { font-family: Consolas, "SFMono-Regular", Menlo, monospace; font-size: 11.5px; white-space: pre-wrap; overflow-wrap: anywhere; }

/* Sheets (dialogs) */
.sheet { border: none; border-radius: 16px; padding: 18px; width: min(440px, calc(100% - 20px)); box-shadow: 0 16px 50px rgba(0,0,0,.25); color: var(--text); }
.sheet::backdrop { background: rgba(18,22,28,.5); }
.sheet-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.choices { display: grid; gap: 8px; margin: 14px 0; }
.choice { display: flex; align-items: center; gap: 12px; text-align: left; font: inherit; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--text); cursor: pointer; }
.choice:hover { border-color: var(--accent); background: #fffaf3; }
.choice .ic { width: 22px; height: 22px; color: var(--accent-dark); }
.choice span { display: flex; flex-direction: column; }
.choice small { color: var(--muted); font-size: 12.5px; }
.choice.danger .ic, .choice.danger b { color: var(--danger); }
.choice:disabled { opacity: .45; cursor: default; }

/* Toasts: "Envoyé…" then "Fait" */
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; background: #2c3138; color: #fff; padding: 12px 16px; border-radius: 12px;
  font-size: 14px; max-width: calc(100% - 28px); z-index: 30; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.toast .ic { width: 18px; height: 18px; }
.toast.ok { background: #3f7d1e; }
.toast.bad { background: var(--danger); }
.toast .spin { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; flex: none; }

/* Phone */
@media (max-width: 760px) {
  :root { --nav-w: 0px; }
  .top { padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
  .brand { font-size: 17px; }
  #stopBtn span { display: none; }
  .nav { top: auto; bottom: 0; right: 0; width: auto; height: calc(64px + env(safe-area-inset-bottom)); flex-direction: row; justify-content: space-around; padding: 4px 4px env(safe-area-inset-bottom);
    border-right: none; border-top: 1px solid var(--line); background: rgba(255,255,255,.97); }
  .nav button { flex: 1; font-size: 10.5px; padding: 6px 0; }
  .nav .dot { right: 30%; }
  .views { padding: 10px 10px 90px; }
  .foot { padding-bottom: 84px; }
  .hero-title { font-size: 18px; }
  #missionCount { font-size: 20px; }
  .actionbar .main { flex: 1 1 100%; }
  .actionbar .quick { flex: 1 1 0; min-height: 48px; padding: 0 8px; font-size: 13px; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
  .kpis { grid-template-columns: 1fr 1fr; }
  /* 10 px page + 16 px card + 6 px panel on each side, 8 gaps of 2 px. */
  .mc-panel { --slot: calc((100vw - 82px) / 9); padding: 6px; }
  .slot .n { font-size: 11px; }
}
