  :root {
    --ground: #0d2128;
    --ground-deep: #091820;
    --panel: #12303a;
    --panel-hi: #183c48;
    --line: #23505e;
    --ink: #e9efe6;
    --ink-soft: #a9c0bf;
    --ink-faint: #7f9c9d;
    --accent: #f2c14e;


    --t-plain: #6d8c4f;
    --t-forest: #3b6638;
    --t-water: #2c6c88;
    --t-wall: #5a5148;
    --t-fort: #8c6b3f;
  }
  * { box-sizing: border-box; }
  html { scrollbar-color: var(--line) var(--ground-deep); }
  body {
    margin: 0; background: var(--ground); color: var(--ink);
    font: 400 15px/1.5 Barlow, system-ui, sans-serif;
    font-variant-numeric: tabular-nums;
  }
  ::selection { background: var(--accent); color: var(--ground-deep); }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  h1, h2, h3 { font-family: "Jersey 10", system-ui; font-weight: 400; margin: 0; letter-spacing: 0.01em; line-height: 1; }

  .bar {
    display: flex; align-items: center; gap: 28px; padding: 14px 28px;
    background: var(--ground-deep); border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 5;
  }
  .bar h1 { font-size: 34px; color: var(--accent); }
  .bar nav { display: flex; gap: 4px; }
  .bar nav a {
    color: var(--ink-soft); text-decoration: none; padding: 6px 12px; border-radius: 6px;
    font: 600 14px "Barlow Semi Condensed";
  }
  .bar nav a:hover { color: var(--ink); background: var(--panel); }
  .bar nav a.on { color: var(--ink); background: var(--panel-hi); }
  .bar .seed { margin-left: auto; color: var(--ink-faint); font: 500 13px "Barlow Semi Condensed"; }

  main { max-width: 1240px; margin: 0 auto; padding: 8px 28px 80px; }
  section { padding-top: 56px; }
  section > header { display: flex; align-items: baseline; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
  section > header h2 { font-size: 52px; }
  section > header p { margin: 0; color: var(--ink-soft); max-width: 62ch; }
  .note { color: var(--ink-faint); font-size: 13px; }

  /* ── Factions: hanging pennants ── */
  .pennants { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; }
  .pennant {
    --c: var(--ink);
    position: relative; padding: 18px 16px 64px;
    background: linear-gradient(180deg, color-mix(in oklab, var(--c) 92%, black) 0%, color-mix(in oklab, var(--c) 70%, black) 100%);
    color: color-mix(in oklab, var(--c) 12%, #0a0f12);
    clip-path: polygon(0 0, 100% 0, 100% 100%, 50% calc(100% - 40px), 0 100%);
    transition: transform .4s cubic-bezier(.16,1,.3,1);
    transform-origin: top center;
  }
  .pennant:hover { transform: rotate(-1.2deg) translateY(2px); }
  .pennant::before {
    content: ""; position: absolute; left: -6px; right: -6px; top: 0; height: 6px;
    background: #1d1a17;
  }
  .pennant svg.emblem { width: 44px; height: 44px; display: block; margin: 6px 0 12px; }
  .pennant h3 { font-size: 30px; color: color-mix(in oklab, var(--c) 6%, #0a0f12); }
  .pennant .ai { font: 600 12px "Barlow Semi Condensed"; text-transform: uppercase; letter-spacing: .08em; opacity: .78; margin-top: 4px; }
  .pennant .motto { font-style: italic; font-size: 14px; margin: 12px 0 14px; line-height: 1.35; }
  .pennant ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
  .pennant li { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; }
  .pennant li svg { width: 16px; height: 16px; flex: none; }
  .behaviour { margin-top: 12px; font-size: 13px; line-height: 1.35; opacity: .85; }

  /* ── Battle ── */
  .battle { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
  .board {
    background: var(--ground-deep); border-radius: 14px; padding: 16px;
    box-shadow: 0 18px 40px -18px rgba(0,0,0,.6);
  }
  .board-top { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; font: 600 14px "Barlow Semi Condensed"; color: var(--ink-soft); }
  .turn { font: 400 26px "Jersey 10"; color: var(--ink); }
  .side { display: inline-flex; align-items: center; gap: 6px; }
  .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
  .grid { display: grid; grid-template-columns: repeat(var(--w), 1fr); gap: 2px; }
  .tile { aspect-ratio: 1; position: relative; border-radius: 3px; overflow: hidden; }
  .tile.P { background: var(--t-plain); }
  .tile.F { background: var(--t-forest); }
  .tile.W { background: var(--t-water); }
  .tile.M { background: var(--t-wall); }
  .tile.T { background: var(--t-fort); }
  .tile > svg.terrain { position: absolute; inset: 0; width: 100%; height: 100%; }
  .tile.move::after, .tile.reach::after {
    content: ""; position: absolute; inset: 0;
  }
  .tile.move::after { background: rgba(84, 160, 255, .26); box-shadow: inset 0 0 0 1px rgba(170, 210, 255, .55); }
  .tile.reach::after { background: rgba(232, 87, 58, .3); box-shadow: inset 0 0 0 1px rgba(255, 170, 150, .5); }
  .tile.dest { outline: 2px solid #fff; outline-offset: -2px; z-index: 2; }
  .unit {
    position: absolute; inset: 12%; z-index: 3; border-radius: 50%;
    background: var(--c); display: grid; place-items: center;
    box-shadow: 0 3px 6px rgba(0,0,0,.45), inset 0 -3px 0 rgba(0,0,0,.25);
  }
  .unit svg { width: 58%; height: 58%; color: #10161a; }
  .unit.done { filter: saturate(.25) brightness(.8); }
  .unit.sel { box-shadow: 0 0 0 3px #fff, 0 3px 8px rgba(0,0,0,.5); }
  .hp { position: absolute; left: 16%; right: 16%; bottom: 5%; height: 4px; background: rgba(0,0,0,.55); border-radius: 2px; z-index: 4; }
  .hp i { display: block; height: 100%; background: #c7f08a; border-radius: 2px; }
  .legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; font-size: 13px; color: var(--ink-soft); }
  .legend span { display: inline-flex; align-items: center; gap: 6px; }
  .legend b { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }

  .panel { background: var(--panel); border-radius: 14px; padding: 18px; }
  .panel + .panel { margin-top: 14px; }
  .panel h3 { font-size: 26px; margin-bottom: 12px; }
  .forecast { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px 10px; align-items: center; }
  .fc-name { font-weight: 700; display: flex; align-items: center; gap: 6px; }
  .fc-name svg { width: 16px; height: 16px; }
  .fc-name.r { justify-content: flex-end; }
  .fc-k { text-align: center; font: 600 12px "Barlow Semi Condensed"; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .06em; }
  .fc-v { font: 400 24px "Jersey 10"; }
  .fc-v.r { text-align: right; }
  .tri {
    grid-column: 1 / -1; margin-top: 8px; padding: 8px 10px; border-radius: 8px;
    background: rgba(232, 87, 58, .14); color: #ffb9a6; font-size: 13px;
  }
  .think { font-size: 14px; color: var(--ink-soft); margin: 0; }
  .think strong { color: var(--ink); }
  .log { list-style: none; margin: 0; padding: 0; font-size: 13px; display: grid; gap: 6px; }
  .log li { display: grid; grid-template-columns: 30px 1fr; gap: 8px; color: var(--ink-soft); }
  .log li em { font-style: normal; color: var(--ink-faint); font: 600 12px "Barlow Semi Condensed"; }
  .log .k { color: var(--ink); font-weight: 600; }
  .controls { display: flex; gap: 6px; margin-top: 14px; }
  .controls button {
    flex: 1; background: var(--panel-hi); color: var(--ink); border: 0; border-radius: 8px; padding: 8px 0;
    font: 600 13px "Barlow Semi Condensed"; cursor: pointer;
  }
  .controls button:hover { background: var(--line); }
  .controls button.play { background: var(--accent); color: var(--ground-deep); }

  /* ── Tournament ── */
  .tourney { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 20px; align-items: start; }
  table { width: 100%; border-collapse: collapse; }
  .rank th { text-align: left; font: 600 12px "Barlow Semi Condensed"; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .06em; padding: 0 10px 10px; }
  .rank td { padding: 10px; border-top: 1px solid var(--line); }
  .rank td.n { font: 400 28px "Jersey 10"; color: var(--ink-faint); width: 36px; }
  .rank tr:first-of-type td.n { color: var(--accent); }
  .who { display: flex; align-items: center; gap: 12px; }
  .chip { width: 22px; height: 30px; background: var(--c); clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 78%, 0 100%); flex: none; }
  .who b { display: block; font-weight: 700; }
  .who small { color: var(--ink-faint); font-size: 12px; }
  .elo { font: 400 26px "Jersey 10"; }
  .delta { font-size: 12px; margin-left: 4px; }
  .up { color: #9be38a; } .down { color: #ff9a85; }
  .wr { width: 120px; }
  .bar-wr { height: 6px; background: var(--ground-deep); border-radius: 3px; overflow: hidden; margin-top: 4px; }
  .bar-wr i { display: block; height: 100%; background: var(--c); }

  .matrix { max-width: 440px; display: grid; grid-template-columns: 28px repeat(6, 1fr); gap: 3px; }
  .matrix .h { display: grid; place-items: center; padding-bottom: 4px; }
  .matrix .h .chip { width: 14px; height: 19px; }
  .cell {
    aspect-ratio: 1; border-radius: 4px; display: grid; place-items: center;
    font: 400 18px "Jersey 10"; color: #0b1418;
  }
  .cell.self { background: var(--ground-deep); color: var(--ink-faint); }
  .scale { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 12px; color: var(--ink-faint); }
  .scale i { height: 8px; flex: 1; border-radius: 4px; background: linear-gradient(90deg, #d9644a, #e9d9a6, #5fbf7c); }

  @media (max-width: 1080px) {
    .pennants { grid-template-columns: repeat(3, 1fr); }
    .battle, .tourney { grid-template-columns: 1fr; }
  }
  @media (max-width: 560px) {
    .bar { padding: 12px 16px; gap: 14px; flex-wrap: wrap; }
    .bar .seed { display: none; }
    main { padding: 0 16px 60px; }
    section > header h2 { font-size: 40px; }
    .pennants { grid-template-columns: repeat(2, 1fr); }
    .wr { display: none; }
  }
  /* ── Classes ── */
  .cls-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; align-items: start; }
  .tree-wrap { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 20px; align-items: start; }
  .tri-wheel { background: var(--panel); border-radius: 14px; padding: 16px; text-align: center; }
  .tri-wheel svg { width: 100%; height: auto; }
  .tri-wheel .wn circle { fill: var(--panel-hi); stroke: var(--line); stroke-width: 2; }
  .tri-wheel .wn use { color: var(--ink); }
  .tree { display: grid; gap: 14px; }
  .line { display: grid; grid-template-columns: minmax(0, 1fr) 36px minmax(0, 1fr); align-items: center; background: var(--panel); border-radius: 14px; padding: 14px; }
  .line .forks { display: grid; gap: 8px; }
  .line svg.link { width: 36px; height: 100%; min-height: 90px; }
  .node {
    all: unset; box-sizing: border-box; cursor: pointer; display: grid; grid-template-columns: 34px 1fr; gap: 2px 10px; align-items: center;
    padding: 10px 12px; border-radius: 10px; background: var(--panel-hi);
    transition: background .25s, box-shadow .25s;
  }
  .node:hover { background: var(--line); }
  .node[aria-pressed="true"] { background: var(--ground-deep); box-shadow: inset 0 0 0 2px var(--accent); }
  .node:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .node .ic { grid-row: span 2; width: 34px; height: 34px; border-radius: 8px; background: var(--ground-deep); display: grid; place-items: center; }
  .node .ic svg { width: 20px; height: 20px; color: var(--ink); }
  .node b { font: 400 22px "Jersey 10"; line-height: 1; }
  .node small { color: var(--ink-faint); font-size: 12px; }
  .node.t1 { padding: 14px; }
  .node.t1 b { font-size: 28px; }
  .tier { font: 600 11px "Barlow Semi Condensed"; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }

  .sheet h3 { font-size: 34px; margin: 0; }
  .sheet .sub { color: var(--ink-soft); font-size: 14px; margin: 6px 0 14px; }
  .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
  .tag { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-hi); border-radius: 999px; padding: 3px 10px; font: 600 12px "Barlow Semi Condensed"; }
  .tag svg { width: 14px; height: 14px; }
  .tag.off { opacity: .5; }
  .lvl { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
  .lvl label { font: 600 13px "Barlow Semi Condensed"; color: var(--ink-soft); }
  .lvl output { font: 400 30px "Jersey 10"; min-width: 2ch; }
  .lvl input { flex: 1; accent-color: var(--accent); }
  .stats { width: 100%; border-collapse: collapse; font-size: 14px; }
  .stats th { text-align: left; font: 600 12px "Barlow Semi Condensed"; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .06em; padding: 0 0 6px; }
  .stats td { padding: 5px 0; border-top: 1px solid var(--line); }
  .stats td.k { font-weight: 600; width: 44px; }
  .stats td.v { font: 400 22px "Jersey 10"; width: 40px; }
  .stats td.g { color: var(--ink-soft); width: 52px; text-align: right; }
  .stats td.c { color: var(--ink-faint); width: 40px; text-align: right; }
  .meter { height: 8px; background: var(--ground-deep); border-radius: 4px; overflow: hidden; margin-right: 10px; }
  .meter i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .35s cubic-bezier(.16,1,.3,1); }
  .stats tr.dim { opacity: .4; }
  .promo { margin-top: 14px; font-size: 13px; color: var(--ink-soft); }
  .promo b { color: var(--ink); }

  @media (max-width: 1080px) { .cls-layout { grid-template-columns: 1fr; } }
  @media (max-width: 700px) {
    .tree-wrap { grid-template-columns: 1fr; }
    .tri-wheel { max-width: 240px; }
    .line { grid-template-columns: 1fr; }
    .line svg.link { display: none; }
  }

  /* ── Viewer additions ── */
  .bar a.brand { text-decoration: none; }
  .tag.soon { background: rgba(10,15,18,.25); color: inherit; margin-left: 8px; vertical-align: middle; }
  .empty, .error { background: var(--panel); border-radius: 14px; padding: 24px; max-width: 70ch; }
  .error { box-shadow: inset 0 0 0 2px #d9644a; }
  .empty h3, .error h3 { font-size: 30px; margin-bottom: 8px; }
  .empty code, .error code, code.cmd {
    display: block; margin-top: 10px; padding: 10px 12px; background: var(--ground-deep); border-radius: 8px;
    color: var(--accent); font: 500 13px ui-monospace, Menlo, monospace; overflow-x: auto; white-space: pre;
  }
  .tri-wheel .wheel-note { margin: 0; }
  .stats td.meter-cell { padding-right: 0; }
  .sheet .lvl { margin-top: 4px; }

  /* picker + arena */
  .picker { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; font: 600 13px "Barlow Semi Condensed"; color: var(--ink-soft); }
  select, input[type="number"] {
    background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 8px;
    padding: 6px 10px; font: 500 14px Barlow, system-ui, sans-serif; max-width: 100%;
  }
  input[type="number"] { width: 6ch; }
  .picker button, .controls button, .more {
    background: var(--panel-hi); color: var(--ink); border: 0; border-radius: 8px; padding: 7px 12px;
    font: 600 13px "Barlow Semi Condensed"; cursor: pointer;
  }
  .picker button:hover, .more:hover { background: var(--line); }
  .controls { flex-wrap: wrap; align-items: center; }
  .controls .speed { flex: none; padding: 8px 10px; }
  .controls .speed[aria-pressed="true"] { background: var(--line); box-shadow: inset 0 0 0 1px var(--accent); }
  .controls button { flex: 1 1 auto; padding: 8px 10px; }
  .scrub { width: 100%; accent-color: var(--accent); margin-top: 10px; }
  .board-top { flex-wrap: wrap; }
  .board-top .meta { margin-left: auto; }
  .board { min-width: 0; }
  .tile.dest { outline: 2px solid #fff; outline-offset: -2px; z-index: 2; }
  .tile.hit-out::before { content: ""; position: absolute; inset: 0; box-shadow: inset 0 0 0 2px #fff; z-index: 5; border-radius: 3px; }
  .unit { overflow: visible; }
  .unit.sprite { background: transparent; box-shadow: none; inset: 4%; border-radius: 0; }
  .unit.sprite::before { content: ""; position: absolute; inset: 6%; border-radius: 50%; box-shadow: 0 0 0 2px var(--c), 0 3px 6px rgba(0,0,0,.45); background: rgba(0,0,0,.25); }
  .unit .strip { position: absolute; inset: 0; overflow: hidden; }
  .unit .strip img {
    display: block; height: 100%; width: calc(var(--n) * 100%); image-rendering: pixelated;
    animation: strip calc(var(--n) * 160ms) steps(var(--n)) infinite;
  }
  @keyframes strip { to { transform: translateX(-100%); } }
  .unit.sprite.done { filter: saturate(.25) brightness(.8); }
  .path { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 6; }
  .grid { position: relative; }
  .tri.good { background: rgba(95,191,124,.16); color: #b6efc6; }
  .strikes { list-style: none; margin: 10px 0 0; padding: 0; font-size: 13px; color: var(--ink-soft); display: grid; gap: 4px; grid-column: 1 / -1; }
  .log { max-height: 260px; overflow-y: auto; }
  .log li.cur .k, .log li.cur { color: var(--ink); }
  .log li.phase { color: var(--accent); font-weight: 600; }
  .legend b.dest-sw { outline: 2px solid #fff; outline-offset: -2px; background: transparent; }

  /* tournament */
  .wr-cell small { color: var(--ink-faint); }
  .per-map { overflow-x: auto; }
  .per-map td, .per-map th { padding: 6px 10px; border-top: 1px solid var(--line); text-align: right; font-size: 14px; }
  .per-map th { font: 600 12px "Barlow Semi Condensed"; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .06em; border-top: 0; }
  .per-map td:first-child, .per-map th:first-child { text-align: left; }
  .per-map td.best { font-weight: 700; color: var(--accent); }
  .games { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 4px; }
  .games a {
    display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) 60px minmax(0, 1fr); gap: 10px; align-items: center;
    padding: 8px 12px; border-radius: 8px; background: var(--panel-hi); color: var(--ink); text-decoration: none; font-size: 14px;
  }
  .games a:hover { background: var(--line); }
  .games .vs { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .tourney-wrap > .panel { margin-top: 20px; }
  .matrix { max-width: 440px; }
  .scale { max-width: 440px; }
  .pennant .name-row { display: flex; align-items: center; }

  @media (max-width: 560px) {
    .games a { grid-template-columns: 1fr 1fr; }
    .board { padding: 10px; }
    .matrix .cell { font-size: 14px; }
    .bar nav { flex-wrap: wrap; }
  }

  /* ── Control room: buttons, tabs, forms, jobs ── */
  .btn, button.btn {
    display: inline-block; background: var(--panel-hi); color: var(--ink); border: 0; border-radius: 8px; padding: 8px 14px;
    font: 600 13px "Barlow Semi Condensed"; text-decoration: none; cursor: pointer;
  }
  .btn:hover { background: var(--line); }
  .btn.primary { background: var(--accent); color: var(--ground-deep); }
  .btn.primary:hover { background: color-mix(in oklab, var(--accent) 85%, white); }
  .btn:disabled, button:disabled { opacity: .5; cursor: not-allowed; }
  button.link { all: unset; color: var(--accent); cursor: pointer; font: 600 12px "Barlow Semi Condensed"; margin-left: 8px; }
  button.link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  .tabs { display: flex; gap: 4px; margin-bottom: 16px; }
  .tabs a { padding: 7px 16px; border-radius: 8px; color: var(--ink-soft); text-decoration: none; font: 600 14px "Barlow Semi Condensed"; }
  .tabs a:hover { background: var(--panel); color: var(--ink); }
  .tabs a.on { background: var(--panel-hi); color: var(--ink); box-shadow: inset 0 -2px 0 var(--accent); }
  .form { display: grid; gap: 18px; max-width: 760px; }
  .field { display: grid; gap: 6px; min-width: 0; border: 0; padding: 0; margin: 0; }
  .field label, .field legend { font: 600 13px "Barlow Semi Condensed"; color: var(--ink-soft); padding: 0; }
  .field input[type="text"], .field input:not([type]), .field input[type="number"], .field select { width: 100%; }
  .field input[type="number"] { width: 100%; max-width: 12ch; }
  .field input:not([type]), .field input[type="text"] {
    background: var(--panel); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font: 500 14px Barlow, system-ui, sans-serif;
  }
  .field-row { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; }
  .field-row[hidden], [hidden] { display: none !important; }
  .field-row > .field { flex: 1 1 140px; }
  .radio { display: flex; align-items: center; gap: 8px; color: var(--ink); font: 500 14px Barlow, system-ui, sans-serif; padding: 2px 0; }
  .check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 6px 14px; }
  .check { display: flex; align-items: center; gap: 8px; font: 500 14px Barlow, system-ui, sans-serif; color: var(--ink); cursor: pointer; }
  .check small { color: var(--ink-faint); }
  .check .chip { width: 14px; height: 19px; }
  input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--accent); }
  .estimate { margin: 0; font: 400 24px "Jersey 10"; color: var(--accent); }
  .form-error {
    margin: 0; padding: 10px 12px; border-radius: 8px; background: rgba(217,100,74,.16); color: #ffb9a6;
    box-shadow: inset 0 0 0 1px #d9644a; font-size: 14px;
  }
  .error-text { color: #ffb9a6; }
  .actionbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
  table.jobs th { text-align: left; font: 600 12px "Barlow Semi Condensed"; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .06em; padding: 0 10px 10px; }
  table.jobs td { padding: 10px; border-top: 1px solid var(--line); vertical-align: middle; }
  table.jobs td small { display: block; color: var(--ink-faint); font-size: 12px; }
  table.jobs .acts { text-align: right; white-space: nowrap; }
  table.jobs .acts button { background: var(--panel-hi); color: var(--ink); border: 0; border-radius: 8px; padding: 8px 14px; font: 600 13px "Barlow Semi Condensed"; cursor: pointer; }
  .progress { height: 8px; min-width: 120px; background: var(--ground-deep); border-radius: 4px; overflow: hidden; }
  .progress i { display: block; height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s; }
  .status { display: inline-block; padding: 2px 10px; border-radius: 999px; font: 600 12px "Barlow Semi Condensed"; background: var(--panel-hi); }
  .status.s-running { background: rgba(84,160,255,.25); color: #bcd9ff; }
  .status.s-done { background: rgba(95,191,124,.22); color: #b6efc6; }
  .status.s-failed, .status.s-cancelled { background: rgba(217,100,74,.2); color: #ffb9a6; }
  @media (max-width: 700px) {
    table.jobs thead { display: none; }
    table.jobs tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; padding: 10px 0; border-top: 1px solid var(--line); }
    table.jobs td { border: 0; padding: 0; }
    table.jobs .acts { text-align: left; grid-column: 1 / -1; }
  }

  /* ── Jouer ── */
  .tile.target::after { content: ""; position: absolute; inset: 0; background: rgba(232,87,58,.45); box-shadow: inset 0 0 0 2px #ff8d73; animation: pulse 1s ease-in-out infinite; z-index: 1; }
  .tile.target.chosen::after { background: rgba(232,87,58,.7); box-shadow: inset 0 0 0 3px #fff; }
  @keyframes pulse { 50% { opacity: .55; } }
  @media (prefers-reduced-motion: reduce) { .tile.target::after { animation: none; } }
  .tile[tabindex] { cursor: pointer; }

  /* ── Tournament charts ── */
  .chart { margin-top: 20px; overflow-x: auto; }
  /* charts are drawn at 640 wide: below ~560px the labels shrink past legibility, so scroll instead */
  .chart svg { width: 100%; min-width: 560px; height: auto; display: block; }
  .chart svg text.ax { fill: var(--ink-faint); font: 500 12px Barlow, system-ui, sans-serif; }
  .chart svg text.who { fill: var(--ink-soft); font-weight: 600; }
  .chart svg .grid-l { stroke: var(--line); stroke-width: 1; opacity: .55; }
  .chart svg .ring { stroke: var(--panel); stroke-width: 2; }
  .chart svg .dotp { fill: var(--ink-soft); opacity: .65; }
  .chart .legend { margin: 0 0 8px; }
  .chart .legend .chip { width: 12px; height: 16px; margin-right: 6px; }
  .chart td.hm { text-align: center; color: #0b1418; font-weight: 600; border-top: 2px solid var(--panel); }
  .chart .who { display: inline-flex; align-items: center; gap: 8px; }
  .seg { display: flex; gap: 2px; height: 14px; margin-top: 10px; }
  .seg i { display: block; border-radius: 4px; min-width: 0; }
  .seg .first { background: #54a0ff; } .seg .second { background: #e8573a; } .seg .draw { background: var(--ink-faint); }

/* Brann 3v3 battle: candy-pastel chibi world. Sticker units, rounded tiles, pressable buttons. Scoped to .duel-squad. */
body.duel-active { overflow: hidden; }
.duel-active > .bar { display: none; }
.static .duel-toolbar a[href^="#/"] { display: none; } /* online: no other screens to go back to */
.duel-immersive [hidden] { display: none !important; }

.duel-squad, .chibi {
  --paper: #fffdf8; --cream: #fff4e4; --ink: #3d2b3d; --ink-2: #6b5468;
  --mint: #8fe3c8; --mint-d: #2a8f72; --coral: #ff9a9a; --coral-d: #c93c52;
  --butter: #ffd86b; --butter-d: #d99a1c; --sky: #9fd2ff; --sky-d: #2f7fd0;
  --soft: 0 8px 22px rgb(61 43 61 / .16), 0 2px 4px rgb(61 43 61 / .08);
}
.duel-squad {
  position: fixed; inset: 0; z-index: 30; margin: 0; padding: 0; max-width: none;
  display: flex; flex-direction: column; width: 100%; height: 100dvh; box-sizing: border-box;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  color: var(--ink); font: 500 15px/1.3 Fredoka, system-ui, sans-serif; font-variant-numeric: tabular-nums;
  background: linear-gradient(#ffe8dc, #fff4e6 45%, #eaf7ef);
}
:is(.duel-squad, .chibi) ::selection { background: var(--butter); color: var(--ink); }
.duel-squad :is(h3, b, strong, small, p) { font-family: inherit; margin: 0; }
:is(.duel-squad, .chibi) :focus-visible { outline: 3px solid var(--sky-d); outline-offset: 3px; }
:is(.duel-squad, .chibi) .i { width: 20px; height: 20px; flex: none; }

/* Buttons: candy pills with a press lip. */
:is(.duel-squad, .chibi) .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 42px; padding: 0 16px;
  font: 600 15px/1 Fredoka, system-ui, sans-serif; color: var(--ink); text-decoration: none; white-space: nowrap;
  background: var(--paper); border: 2.5px solid var(--ink); border-radius: 999px; cursor: pointer;
  box-shadow: 0 3px 0 var(--ink), 0 6px 14px rgb(61 43 61 / .12);
  transition: translate .12s ease-out, box-shadow .12s ease-out, background-color .15s;
}
:is(.duel-squad, .chibi) .btn:hover:not(:disabled) { translate: 0 -1px; box-shadow: 0 4px 0 var(--ink), 0 8px 16px rgb(61 43 61 / .14); background-color: #fff; }
:is(.duel-squad, .chibi) .btn:active:not(:disabled) { translate: 0 3px; box-shadow: 0 0 0 var(--ink), 0 2px 4px rgb(61 43 61 / .12); }
:is(.duel-squad, .chibi) .btn:disabled { opacity: .4; cursor: default; }
:is(.duel-squad, .chibi) .btn.icon { width: 42px; padding: 0; }
:is(.duel-squad, .chibi) .btn.primary, :is(.duel-squad, .chibi) .btn.primary:hover:not(:disabled) { background-color: var(--butter); }
:is(.duel-squad, .chibi) .btn.attack, :is(.duel-squad, .chibi) .btn.attack:hover:not(:disabled) { background-color: var(--coral); }
:is(.duel-squad, .chibi) .btn.calm, :is(.duel-squad, .chibi) .btn.calm:hover:not(:disabled) { background-color: var(--mint); }
:is(.duel-squad, .chibi) .btn.ghost { border-color: transparent; background: none; box-shadow: none; color: var(--ink-2); }
:is(.duel-squad, .chibi) .btn.ghost:hover:not(:disabled) { background: rgb(61 43 61 / .07); box-shadow: none; translate: none; }
.duel-squad [data-action="music"] .i + .i, .duel-squad [data-action="music"][aria-pressed="true"] .i:first-child { display: none; }
.duel-squad [data-action="music"][aria-pressed="true"] .i + .i { display: block; }
.duel-squad [data-action="music"][aria-pressed="true"] { background-color: var(--mint); }

/* Toolbar */
.duel-toolbar { flex: none; display: flex; align-items: center; gap: 12px; padding: 12px 18px 4px; }
.duel-title { min-width: 0; }
.duel-title strong { display: block; font-size: 22px; font-weight: 700; letter-spacing: -.01em; line-height: 1.1; }
.duel-title small { display: block; font-size: 13px; color: var(--ink-2); }
.duel-squad .squad-turn {
  margin: 0 auto; padding: 7px 16px; border-radius: 999px; background: var(--paper); box-shadow: var(--soft);
  font-weight: 600; font-size: 15px; white-space: nowrap;
}
.squad-turn.foe { background: #ffe1e1; }
.squad-turn.win { background: var(--butter); }
.duel-tools { display: flex; gap: 8px; align-items: center; }

/* Board */
.duel-field { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 14px 22px; container-type: size; }
.duel-map-wrap { position: relative; width: min(100cqw, 150cqh); aspect-ratio: 3 / 2; }
.duel-squad .duel-map {
  position: absolute; inset: 0; display: grid; grid-template: repeat(4, 1fr) / repeat(6, 1fr);
  background: #8bbf5a url('assets/brann/training-ground.png') center / 100% 100% no-repeat;
  border-radius: 26px; box-shadow: 0 0 0 6px var(--paper), 0 0 0 9px var(--ink), 0 22px 34px rgb(61 43 61 / .28);
}
.duel-squad .duel-cell {
  position: relative; min-width: 0; margin: 0; padding: 0; border: 0; background: none; color: inherit; font: inherit;
  cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.duel-squad .duel-cell:disabled, .duel-squad .squad-card:disabled { cursor: default; opacity: 1; }
.duel-squad .duel-cell:focus-visible { outline: 0; }
.duel-squad .duel-cell::before {
  content: ""; position: absolute; inset: 5%; border-radius: 18px; box-shadow: inset 0 0 0 1.5px rgb(255 255 255 / .22);
  transition: background-color .18s, box-shadow .18s, scale .18s cubic-bezier(.3, 1.4, .5, 1);
}
.duel-squad .duel-cell.reachable::before { background: rgb(64 150 240 / .42); box-shadow: inset 0 0 0 2.5px rgb(255 255 255 / .85); }
.duel-squad .duel-cell.reachable:is(:hover, :focus-visible)::before { background: rgb(255 216 107 / .7); box-shadow: inset 0 0 0 3px #fff, 0 0 0 3px var(--butter-d); scale: 1.04; }
.duel-squad .duel-cell:focus-visible::before { box-shadow: inset 0 0 0 3px #fff, 0 0 0 3px var(--sky-d); }
.duel-squad .duel-cell.selected::before { background: rgb(255 216 107 / .6); box-shadow: inset 0 0 0 3px #fff, 0 0 0 3px var(--ink); }
.duel-squad .duel-cell:is(.can-hit, .threat)::before { background: rgb(255 154 154 / .5); box-shadow: inset 0 0 0 2.5px rgb(255 255 255 / .9); }
.duel-squad .duel-cell.can-hit::before { animation: none; }
.duel-squad .duel-cell.unit-target::before { background: rgb(255 120 130 / .72); box-shadow: inset 0 0 0 3px #fff, 0 0 0 3px var(--coral-d); animation: none; }
/* Ground blob under each unit, tinted by team. */
.duel-squad .duel-cell:is(.ally, .enemy)::after {
  content: ""; position: absolute; left: 20%; right: 20%; bottom: 13%; height: 15%; border-radius: 50%; z-index: 1;
  background: radial-gradient(closest-side, rgb(61 43 61 / .4), rgb(61 43 61 / .1) 75%, transparent);
  box-shadow: 0 0 0 2.5px rgb(143 227 200 / .9);
}
.duel-squad .duel-cell.enemy::after { box-shadow: 0 0 0 2.5px rgb(255 154 154 / .95); }
.duel-squad .duel-mini {
  position: absolute; left: 3%; width: 94%; top: -13%; height: 104%; z-index: 2; pointer-events: none;
  background: center bottom / contain no-repeat; image-rendering: pixelated; transform-origin: 50% 90%;
  filter: drop-shadow(2px 0 0 #fff) drop-shadow(-2px 0 0 #fff) drop-shadow(0 2px 0 #fff) drop-shadow(0 -2px 0 #fff) drop-shadow(0 5px 4px rgb(61 43 61 / .35));
  animation: none;
}
.duel-squad .duel-cell:nth-child(odd) .duel-mini { animation-delay: -.9s; }
.duel-squad .duel-cell.selected .duel-mini { animation: none; }
.duel-squad .duel-cell.unit-acted .duel-mini { animation: none; filter: grayscale(.85) brightness(.92) drop-shadow(2px 0 0 #fff) drop-shadow(-2px 0 0 #fff) drop-shadow(0 2px 0 #fff) drop-shadow(0 -2px 0 #fff); }
.duel-squad .duel-mini.shadow { transform: scaleX(-1); filter: brightness(.25) grayscale(1) drop-shadow(2px 0 0 #fff) drop-shadow(-2px 0 0 #fff) drop-shadow(0 2px 0 #fff); }
.squad-plate {
  position: absolute; left: 50%; bottom: 3%; translate: -50% 0; z-index: 3; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; gap: 3px; max-width: 112%;
}
.squad-map-name {
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 1px 8px; border-radius: 999px; background: var(--paper); border: 2px solid var(--mint-d);
  font-size: clamp(10px, 1.6cqh, 13px); font-weight: 600; line-height: 1.25;
}
.enemy .squad-map-name { border-color: var(--coral-d); }
.duel-squad .duel-map-hp { display: block; width: 64%; min-width: 34px; height: 8px; border-radius: 999px; background: #fff; border: 2px solid var(--ink); overflow: hidden; }
.duel-squad .duel-map-hp i { display: block; height: 100%; border-radius: 999px; background: var(--mint-d); transition: width .35s ease-out; }
.duel-squad .enemy .duel-map-hp i { background: var(--coral-d); }

.duel-route { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 4; pointer-events: none; filter: drop-shadow(0 2px 1px rgb(61 43 61 / .5)); }
.duel-route polyline { stroke-width: 11; stroke-dasharray: 0 22; }

/* Phase banner: the one authored moment. */
.squad-banner {
  position: absolute; left: 50%; top: 50%; translate: -50% -50%; z-index: 9; margin: 0; pointer-events: none; opacity: 0;
  padding: .32em 1em .38em; border-radius: 999px; border: 3px solid var(--ink); background: var(--butter);
  font: 700 clamp(24px, 6cqh, 50px)/1 Fredoka, system-ui, sans-serif; letter-spacing: -.02em; white-space: nowrap;
  box-shadow: 0 6px 0 var(--ink), 0 20px 40px rgb(61 43 61 / .3);
}
.squad-banner.foe { background: var(--coral); }
.squad-banner.show { animation: chibi-banner 1.5s cubic-bezier(.2, .9, .25, 1) both; }
.squad-banner.stay.show { animation: chibi-banner-in .6s cubic-bezier(.2, .9, .25, 1) both; }

/* Dock: hint bubble, or the command card once a unit has moved. */
.duel-dock { flex: none; display: flex; align-items: center; justify-content: center; padding: 6px 22px 10px; min-height: 112px; }
.duel-dock:has(.duel-orders:not([hidden])) .duel-hud { display: none; }
.duel-squad .duel-hud {
  align-self: center; display: flex; align-items: center; gap: 14px; max-width: 1060px; width: 100%;
  padding: 10px 18px; border-radius: 20px; background: var(--paper); box-shadow: var(--soft);
}
.duel-squad .duel-hint { flex: 1; font-size: 16px; font-weight: 600; }
.duel-squad .duel-message { font-size: 13px; color: var(--ink-2); text-align: right; max-width: 48%; }
.duel-orders {
  width: 100%; max-width: 1060px; display: grid; grid-template-columns: minmax(120px, 200px) minmax(0, 1fr) auto; align-items: center; gap: 10px 18px;
  padding: 12px 16px; border-radius: 22px; background: var(--paper); box-shadow: var(--soft);
  animation: chibi-pop .28s cubic-bezier(.2, 1.3, .4, 1);
}
.orders-who { display: grid; gap: 6px; }
.orders-who h3 { font-size: 20px; font-weight: 700; line-height: 1; }
.squad-class { display: flex; gap: 4px; min-width: 0; overflow: hidden; }
.squad-class span { overflow: hidden; text-overflow: ellipsis; padding: 2px 8px; border-radius: 999px; background: var(--cream); font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.squad-targets { grid-column: 1; display: flex; flex-wrap: wrap; gap: 6px; }
.squad-targets:empty { display: none; }
.squad-target {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 999px; cursor: pointer;
  font: 600 13px Fredoka, system-ui, sans-serif; color: var(--ink); background: #ffe9e9; border: 2px solid transparent;
}
.squad-target img { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; object-position: 50% 12%; background: #fff; image-rendering: pixelated; }
.squad-target.is-selected { border-color: var(--coral-d); background: var(--coral); }
.duel-forecast { grid-column: 2; grid-row: 1 / span 2; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 4px 14px; min-width: 0; }
.duel-forecast:empty { display: flex; justify-content: center; }
.duel-forecast:empty::before { content: "Aucun ennemi à portée. Tu peux attendre ici."; grid-column: 1 / -1; text-align: center; color: var(--ink-2); }
.fc-side { display: grid; gap: 4px; min-width: 0; }
.fc-side.foe { text-align: right; }
.fc-side b { font-size: 15px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fc-side em { font-style: normal; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.fc-side em strong { color: var(--ink); font-weight: 700; }
.fc-bar { display: block; height: 10px; border-radius: 999px; background: #fff; border: 2px solid var(--ink); overflow: hidden; }
.fc-bar i { display: block; height: 100%; width: calc(var(--from) * 100%); border-radius: 999px;
  background: linear-gradient(90deg, var(--mint-d) calc(var(--to) / var(--from) * 100%), var(--coral) 0); }
.fc-side.foe .fc-bar i { margin-left: auto; background: linear-gradient(270deg, var(--coral-d) calc(var(--to) / var(--from) * 100%), #ffd0d0 0); }
.fc-grid { display: grid; grid-template-columns: auto auto auto; gap: 1px 10px; align-items: baseline; text-align: center; }
.fc-grid span { font-size: 17px; font-weight: 700; white-space: nowrap; }
.fc-grid small { font-size: 11px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .06em; }
.orders-actions { grid-column: 3; grid-row: 1 / span 2; display: flex; gap: 8px; }

/* Rosters */
.squad-rosters { flex: none; display: grid; grid-template-columns: 1fr 1fr; gap: 18px; padding: 4px 22px 14px; }
.squad-rosters h3 { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.squad-rosters h3::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--mint-d); }
.squad-rosters > div:last-child h3::before { background: var(--coral-d); }
.squad-allies, .squad-enemies { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.squad-card {
  position: relative; display: flex; align-items: center; gap: 8px; min-width: 0; padding: 6px 10px 8px 6px; border-radius: 16px; cursor: pointer; text-align: left;
  font: inherit; color: var(--ink); background: var(--paper); border: 2.5px solid transparent; box-shadow: var(--soft);
  transition: translate .15s ease-out, border-color .15s, background-color .15s;
}
.squad-card:hover:not(:disabled) { translate: 0 -2px; border-color: var(--mint); }
.squad-card:disabled { cursor: default; }
.squad-card.is-selected { border-color: var(--ink); background: #fff3c8; }
.squad-card.has-acted, .squad-card.is-dead { background: #f3ece4; box-shadow: none; }
.squad-card.is-dead { opacity: .55; }
.squad-avatar { flex: none; width: 42px; height: 42px; border-radius: 50%; overflow: hidden; background: #d9f5ea; border: 2.5px solid var(--mint-d); }
.squad-enemies .squad-avatar { background: #ffe1e1; border-color: var(--coral-d); }
.squad-avatar img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 8%; scale: 1.5; translate: 0 22%; image-rendering: pixelated; }
.squad-avatar img.shadow { filter: brightness(.25) grayscale(1); }
.has-acted .squad-avatar img, .is-dead .squad-avatar img { filter: grayscale(1); }
.squad-card-body { flex: 1; min-width: 0; display: grid; gap: 3px; }
.squad-card-body b { font-size: 14px; font-weight: 700; line-height: 1.1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.squad-card-body small { font-size: 12px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.squad-hp { display: flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; }
.squad-hp .i { width: 13px; height: 13px; color: var(--coral-d); }
.squad-hp > span { flex: 1; height: 7px; border-radius: 999px; background: #efe6dc; overflow: hidden; }
.squad-hp > span i { display: block; height: 100%; width: calc(var(--hp) * 100%); border-radius: 999px; background: var(--mint-d); transition: width .35s ease-out; }
.squad-enemies .squad-hp > span i { background: var(--coral-d); }
.squad-state { position: absolute; left: 6px; bottom: 3px; width: 46px; text-align: center; padding: 1px 0; border-radius: 999px; font-size: 10px; font-weight: 600; background: #d9f5ea; color: var(--ink); box-shadow: 0 0 0 2px var(--paper); }
.has-acted .squad-state { background: #ece3d9; }
.is-dead .squad-state { background: #ffe1e1; }

/* Combat window */
.duel-squad .duel-combat-overlay {
  position: absolute; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; pointer-events: none;
  background: rgb(61 43 61 / .28); backdrop-filter: blur(3px);
}
.duel-squad .duel-scene {
  width: min(780px, 94%); padding: 16px 20px 14px; border-radius: 30px; border: 3px solid var(--ink); overflow: hidden;
  background: #8bbf5a url('assets/brann/duel-meadow.png') center bottom / cover no-repeat;
  box-shadow: 0 0 0 6px var(--paper), 0 0 0 9px var(--ink), 0 30px 60px rgb(61 43 61 / .35);
  animation: chibi-pop .3s cubic-bezier(.2, 1.3, .4, 1);
}
.duel-squad .duel-health { position: relative; z-index: 3; display: flex; justify-content: space-between; gap: 16px; }
.duel-squad .duel-health label { display: grid; gap: 3px; width: 44%; padding: 8px 12px; border-radius: 18px; background: var(--paper); box-shadow: var(--soft); }
.duel-squad .duel-health label:last-child { text-align: right; }
.duel-squad .duel-health b { font-size: 17px; font-weight: 700; }
.duel-squad .duel-health small { font-size: 12px; color: var(--ink-2); }
.duel-squad .duel-health span { font-size: 14px; font-weight: 600; }
.duel-squad .duel-health progress { -webkit-appearance: none; appearance: none; width: 100%; height: 12px; border: 2px solid var(--ink); border-radius: 999px; background: #fff; overflow: hidden; }
.duel-squad .duel-health progress::-webkit-progress-bar { background: #fff; }
.duel-squad .duel-health progress::-webkit-progress-value { background: var(--mint-d); border-radius: 999px; transition: width .35s ease-out; }
.duel-squad .duel-health progress::-moz-progress-bar { background: var(--mint-d); border-radius: 999px; }
.duel-squad .duel-health label:last-child progress::-webkit-progress-value { background: var(--coral-d); }
.duel-squad .duel-health label:last-child progress::-moz-progress-bar { background: var(--coral-d); }
.duel-squad .duel-ground { position: relative; display: flex; justify-content: center; align-items: flex-end; min-height: 290px; }
.duel-squad .duel-fighter { position: relative; width: 280px; height: 280px; flex-shrink: 0; }
.duel-squad .duel-sprite { position: absolute; inset: 0; z-index: 1; image-rendering: pixelated; }
.duel-squad .duel-sprite > svg { display: block; width: 100%; height: 100%; overflow: visible; image-rendering: pixelated; }
.duel-squad .duel-sprite.is-flipped { transform: scaleX(-1); }
.duel-squad .duel-sprite.is-shadow { filter: brightness(.24) grayscale(1); }
.duel-squad .duel-fighter.fallen { opacity: .55; }
.duel-squad .duel-damage {
  position: absolute; top: 56px; left: 0; right: 0; text-align: center; z-index: 4; white-space: nowrap; pointer-events: none;
  font: 700 42px/1 Fredoka, system-ui, sans-serif; color: #fff; -webkit-text-stroke: 7px var(--ink); paint-order: stroke fill;
}
.duel-squad .duel-combat-caption { width: fit-content; margin: 8px auto 0; padding: 2px 14px; border-radius: 999px; background: var(--paper); box-shadow: var(--soft); text-align: center; font-size: 17px; font-weight: 600; min-height: 1.3em; }
.duel-squad .duel-combat-caption:empty { visibility: hidden; }

@keyframes chibi-bob { 50% { scale: 1.03 .965; } }
@keyframes chibi-hop { 0%, 100% { translate: 0 0; scale: 1; } 40% { translate: 0 -7%; scale: .97 1.04; } 70% { translate: 0 0; scale: 1.05 .94; } }
@keyframes chibi-pulse { to { background-color: rgb(255 154 154 / .78); } }
@keyframes chibi-pop { from { opacity: 0; scale: .92; } }
@keyframes chibi-banner { 0% { opacity: 0; scale: .4; rotate: -6deg; } 16% { opacity: 1; scale: 1.08; rotate: 1deg; } 26% { scale: 1; rotate: 0deg; } 78% { opacity: 1; scale: 1; } 100% { opacity: 0; scale: .9; } }
@keyframes chibi-banner-in { 0% { opacity: 0; scale: .4; rotate: -6deg; } 60% { opacity: 1; scale: 1.08; rotate: 1deg; } 100% { opacity: 1; scale: 1; rotate: 0deg; } }
@media (prefers-reduced-motion: reduce) {
  .duel-squad *, .duel-squad *::before { animation: none !important; transition: none !important; }
  .duel-squad .squad-banner.stay { opacity: 1; }
}

/* Tablets and narrow windows: the command card stacks before its columns can collide. */
@media (max-width: 1180px) {
  .duel-orders { grid-template-columns: minmax(0, 1fr) auto; }
  .duel-forecast { grid-column: 1 / -1; grid-row: auto; }
  .orders-who { grid-column: 1; }
  .squad-targets { grid-column: 2; justify-content: flex-end; }
  .orders-actions { grid-column: 1 / -1; grid-row: auto; justify-content: stretch; }
  .orders-actions .btn { flex: 1; }
  .duel-dock { height: auto; min-height: 76px; }
}
/* Phones, portrait */
@media (max-width: 640px) {
  .duel-toolbar { flex-wrap: wrap; gap: 8px 6px; padding: 10px 10px 2px; }
  .duel-title { flex: 1; }
  .duel-title strong { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .duel-title small { display: none; }
  .duel-squad .squad-turn { order: 3; width: 100%; text-align: center; padding: 6px 12px; font-size: 14px; }
  .duel-tools { gap: 6px; }
  :is(.duel-squad, .chibi) .btn { min-height: 36px; padding: 0 12px; font-size: 14px; border-width: 2px; }
  :is(.duel-squad, .chibi) .btn.icon { width: 36px; }
  :is(.duel-squad, .chibi) .btn .i { width: 18px; height: 18px; }
  .duel-tools .btn.primary span { display: none; }
  .duel-tools .btn.primary { width: 36px; padding: 0; }
  .duel-field { padding: 12px 12px 10px; }
  .duel-squad .duel-map { border-radius: 18px; box-shadow: 0 0 0 4px var(--paper), 0 0 0 6px var(--ink), 0 14px 24px rgb(61 43 61 / .25); }
  .duel-squad .duel-cell::before { border-radius: 12px; }
  .squad-map-name { display: none; }
  .duel-squad .duel-map-hp { height: 7px; border-width: 1.5px; min-width: 26px; }
  .duel-dock { padding: 4px 10px 8px; height: auto; }
  .duel-squad .duel-hud { flex-direction: column; align-items: stretch; gap: 2px; padding: 9px 14px; border-radius: 16px; }
  .duel-squad .duel-hint { font-size: 15px; }
  .duel-squad .duel-message { text-align: left; max-width: none; font-size: 12px; }
  .duel-orders { padding: 10px 12px; gap: 8px; border-radius: 18px; }
  .fc-grid span { font-size: 15px; }
  .duel-forecast { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 4px 8px; }
  .fc-grid { gap: 0 6px; }
  .fc-side em { font-size: 12px; }
  .squad-rosters { grid-template-columns: 1fr; gap: 8px; padding: 2px 10px 10px; }
  .squad-allies, .squad-enemies { gap: 6px; }
  .squad-card { flex-direction: column; align-items: stretch; gap: 4px; padding: 6px 8px; border-radius: 14px; position: relative; }
  .squad-avatar, .squad-card-body small, .squad-state { display: none; }
  .squad-card-body b { font-size: 13px; }
  .squad-rosters h3 { margin-bottom: 4px; font-size: 12px; }
  .duel-squad .duel-scene { padding: 10px; border-radius: 22px; }
  .duel-squad .duel-ground { min-height: 210px; }
  .duel-squad .duel-fighter { width: 150px; height: 210px; }
  .duel-squad .duel-sprite { width: 210px; height: 210px; left: 50%; margin-left: -105px; }
  .duel-squad .duel-damage { top: 40px; font-size: 30px; -webkit-text-stroke-width: 5px; }
  .duel-squad .duel-health { gap: 8px; }
  .duel-squad .duel-health label { width: 50%; padding: 6px 9px; }
  .duel-squad .duel-health b { font-size: 14px; }
  /* Fullscreen on a phone: the board takes the rosters' room (HP stays on the map). */
  .duel-squad.is-full :is(.squad-rosters, .duel-title) { display: none; }
  .duel-squad.is-full .duel-tools { margin-left: auto; }
}
/* Short landscape screens (phones on their side): the board gets the height, rosters step aside. */
@media (max-height: 520px) and (orientation: landscape) {
  .duel-toolbar { padding: 6px 12px 0; gap: 8px; }
  .duel-title small { display: none; }
  .duel-title strong { font-size: 16px; }
  .duel-squad .squad-turn { padding: 4px 12px; font-size: 13px; }
  :is(.duel-squad, .chibi) .btn { min-height: 34px; padding: 0 12px; font-size: 13px; }
  :is(.duel-squad, .chibi) .btn.icon { width: 34px; }
  .duel-field { padding: 8px 14px 6px; }
  .squad-rosters { display: none; }
  .duel-dock { padding: 2px 12px 6px; height: 88px; }
  .fc-grid { gap: 0 8px; }
  .fc-grid span { font-size: 14px; }
  .orders-who h3 { font-size: 16px; }
  .duel-squad .duel-hud { padding: 6px 14px; border-radius: 14px; }
  .duel-squad .duel-hint { font-size: 14px; }
  .duel-orders { grid-template-columns: minmax(110px, 170px) minmax(0, 1fr) auto; padding: 6px 12px; gap: 4px 12px; border-radius: 16px; }
  .orders-who .squad-class { display: none; }
  .orders-who { grid-column: 1; }
  .squad-targets { grid-column: 1; justify-content: flex-start; }
  .duel-forecast { grid-column: 2; grid-row: 1 / span 2; }
  .orders-actions { grid-column: 3; grid-row: 1 / span 2; }
  .orders-actions .btn { flex: none; }
  .orders-actions .btn span { display: none; }
  .orders-actions .btn { width: 38px; padding: 0; }
  .squad-map-name { display: none; }
  .duel-squad .duel-scene { padding: 6px 12px; }
  .duel-squad .duel-ground { min-height: 160px; height: 160px; }
  .duel-squad .duel-fighter { width: 170px; height: 160px; }
  .duel-squad .duel-sprite { width: 170px; height: 170px; top: -10px; }
  .duel-squad .duel-health label { padding: 4px 10px; }
  .duel-squad .duel-health small { display: none; }
}

/* Battle setup: same candy world as the battle, as a scrolling page. */
.chibi.duel-setup {
  position: fixed; inset: 0; z-index: 30; overflow-y: auto; margin: 0; padding: 0 0 110px; max-width: none;
  color: var(--ink); font: 500 15px/1.35 Fredoka, system-ui, sans-serif; font-variant-numeric: tabular-nums;
  background: linear-gradient(#ffe8dc, #fff4e6 45%, #eaf7ef) fixed;
}
.chibi .sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.duel-setup .duel-toolbar { max-width: 1100px; margin: 0 auto; padding: 20px 22px 6px; }
.duel-setup .duel-title strong { font-size: 30px; }
.duel-setup .duel-title small { font-size: 14px; }
.setup-form { max-width: 1100px; margin: 0 auto; padding: 12px 22px; display: grid; gap: 20px; }
.chibi select, .chibi input[type="number"] {
  min-width: 0; height: 44px; padding: 0 38px 0 16px; border: 2.5px solid var(--ink); border-radius: 999px;
  font: 600 15px Fredoka, system-ui, sans-serif; color: var(--ink); background: var(--paper) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5' fill='none' stroke='%233d2b3d' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center / 18px;
  appearance: none; -webkit-appearance: none; cursor: pointer; transition: box-shadow .15s;
}
.chibi input[type="number"] { background-image: none; padding: 0 14px; cursor: text; }
.chibi select:hover { box-shadow: 0 0 0 4px rgb(255 216 107 / .55); }
.chibi .field { display: grid; gap: 6px; }
.chibi .field label { font: 600 13px Fredoka, system-ui, sans-serif; color: var(--ink-2); }
.setup-teams { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 430px), 1fr)); gap: 20px; align-items: start; }
.setup-team { position: relative; display: grid; gap: 12px; min-width: 0; margin: 0; padding: 58px 16px 16px; border: 0; border-radius: 28px; background: var(--paper); box-shadow: var(--soft); }
.setup-team legend { position: absolute; top: 16px; left: 18px; padding: 5px 16px; border-radius: 999px; background: var(--mint); font-size: 16px; font-weight: 700; }
.setup-team.foe legend { background: var(--coral); }
.setup-unit { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 14px; align-items: center; padding: 12px; border-radius: 22px; background: var(--cream); }
.setup-avatar { display: grid; place-items: end center; width: 76px; height: 76px; border-radius: 50%; overflow: hidden; background: #d9f5ea; border: 3px solid var(--mint-d); }
.foe .setup-avatar { background: #ffe1e1; border-color: var(--coral-d); }
.setup-avatar img { width: 92%; height: 108%; object-fit: contain; object-position: 50% 0; image-rendering: pixelated; transform-origin: 50% 100%; animation: chibi-bob 1.8s ease-in-out infinite; }
.setup-unit:nth-child(even) .setup-avatar img { animation-delay: -.9s; }
.setup-avatar img.shadow { filter: brightness(.25) grayscale(1); }
.setup-fields { display: grid; gap: 8px; min-width: 0; }
.setup-line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; }
.setup-pick, .setup-weapon { position: relative; flex: 1 1 160px; min-width: 0; display: grid; }
.setup-weapon .i { position: absolute; left: 14px; top: 50%; translate: 0 -50%; width: 18px; height: 18px; color: var(--ink-2); pointer-events: none; }
.setup-weapon select { padding-left: 40px; }
.setup-level { display: inline-flex; align-items: center; gap: 2px; height: 44px; padding: 0 5px; border: 2.5px solid var(--ink); border-radius: 999px; background: var(--paper); }
.setup-level label { padding-left: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.chibi .setup-level input { width: 3ch; height: auto; padding: 0; border: 0; text-align: center; font-size: 17px; font-weight: 700; background: none; -moz-appearance: textfield; }
.setup-level input::-webkit-inner-spin-button, .setup-level input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.setup-level button { display: grid; place-items: center; width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%; background: var(--butter); color: var(--ink); cursor: pointer; transition: scale .12s; }
.setup-level button:hover { scale: 1.1; }
.setup-level button:active { scale: .9; }
.setup-level svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; }
.duel-setup .tag { padding: 4px 12px; border-radius: 999px; background: #e7dcff; color: var(--ink); font: 600 13px Fredoka, system-ui, sans-serif; }
.duel-inventory { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; margin: 0; font-size: 12px; color: var(--ink-2); }
.duel-inventory span { margin-right: 2px; }
.duel-inventory i { padding: 2px 10px; border-radius: 999px; border: 1.5px solid #e6d8c6; background: var(--paper); font-style: normal; color: var(--ink); }
.duel-inventory i.on { background: var(--butter); border-color: var(--butter-d); font-weight: 600; }
.duel-inventory i.none { color: var(--ink-2); }
.setup-hint { margin: 0; font-size: 13px; color: var(--ink-2); }
.setup-ai { display: grid; grid-template-columns: minmax(0, 360px) auto; gap: 10px 18px; align-items: end; padding: 18px; border-radius: 28px; background: var(--paper); box-shadow: var(--soft); }
.setup-ai .setup-hint { grid-column: 1 / -1; }
.setup-go { position: fixed; left: 0; right: 0; bottom: 0; z-index: 2; display: flex; justify-content: center; padding: 26px 22px 20px; background: linear-gradient(rgb(234 247 239 / 0), #eaf7ef 55%); pointer-events: none; }
.chibi .setup-go .btn { pointer-events: auto; min-height: 58px; padding: 0 34px; font-size: 19px; box-shadow: 0 4px 0 var(--ink), 0 12px 24px rgb(61 43 61 / .2); }
.chibi .setup-go .btn .i { width: 22px; height: 22px; }
@media (prefers-reduced-motion: reduce) { .setup-avatar img { animation: none; } }
@media (max-width: 640px) {
  .duel-setup .duel-toolbar { padding: 12px 12px 4px; }
  .duel-setup .duel-title strong { font-size: 22px; }
  .duel-setup .duel-title small { display: block; font-size: 13px; }
  .setup-form { padding: 8px 12px; gap: 14px; }
  .setup-team { padding: 52px 10px 10px; border-radius: 22px; }
  .setup-unit { grid-template-columns: 56px minmax(0, 1fr); gap: 10px; padding: 10px; border-radius: 18px; }
  .setup-avatar { width: 56px; height: 56px; align-self: start; }
  .setup-ai { grid-template-columns: 1fr; }
  .chibi .setup-go .btn { width: 100%; }
}

/* Victory / defeat screen */
.duel-squad .duel-end { position: absolute; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgb(61 43 61 / .55); }
.duel-end-card { text-align: center; padding: 28px 36px; border-radius: 28px; background: var(--paper); box-shadow: var(--soft); border: 4px solid var(--mint-d); max-width: 420px; }
.duel-end-card.lose { border-color: var(--coral-d); background: linear-gradient(#f3ecf4, #e4dbe8); }
.duel-end-card h2 { margin: 0 0 6px; font: 700 clamp(40px, 9vw, 64px) / 1 Fredoka, system-ui, sans-serif; color: var(--mint-d); }
.duel-end-card.lose h2 { color: var(--coral-d); }
.duel-end-card p { margin: 0 0 18px; color: var(--ink-2); }
.duel-end-card .orders-actions { justify-content: center; flex-wrap: wrap; }
@media (prefers-reduced-motion: no-preference) {
  .duel-end-card.win { animation: end-pop .6s cubic-bezier(.2, 1.4, .3, 1) both; }
  .duel-end-card.lose { animation: end-sink 1.2s ease-out both; }
  @keyframes end-pop { from { opacity: 0; scale: .6; } to { opacity: 1; scale: 1; } }
  @keyframes end-sink { from { opacity: 0; translate: 0 -24px; } to { opacity: 1; translate: 0 0; } }
}

/* Portrait phones: clockwise terrain and grid, upright units. */
@media (max-width: 640px) and (orientation: portrait) {
  .duel-map-wrap { width: min(100cqw, 66.6667cqh); aspect-ratio: 2 / 3; }
  .duel-squad .duel-map { grid-template: repeat(6, 1fr) / repeat(4, 1fr); background: none; isolation: isolate; }
  .duel-squad .duel-map::before {
    content: ""; position: absolute; z-index: -1; left: 50%; top: 50%;
    width: 150%; height: 66.6667%; border-radius: inherit;
    background: #8bbf5a url('assets/brann/training-ground.png') center / 100% 100% no-repeat;
    transform: translate(-50%, -50%) rotate(90deg); pointer-events: none;
  }
}

/* The map owns the remaining space; changing orders never resizes it. */
.duel-squad .duel-dock {
  box-sizing: border-box; height: 156px; min-height: 0;
  display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr);
}
.duel-dock > :is(.duel-hud, .duel-orders) {
  grid-area: 1 / 1; box-sizing: border-box; max-height: 100%; overflow: auto;
  justify-self: center; animation: none;
}
@media (max-width: 1180px) {
  .duel-squad .duel-dock { height: 220px; }
}
@media (max-width: 640px) {
  .duel-squad { height: 100svh; }
  .duel-squad .duel-dock { height: 220px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .duel-squad { height: 100svh; }
  .duel-squad .duel-dock { height: 120px; }
  .duel-squad.is-full .duel-title { display: none; }
  .duel-squad.is-full .duel-tools { margin-left: auto; }
}
.duel-squad:fullscreen { height: 100dvh; }
.boot-loading {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  padding: 24px; background: #fff4e6; color: #3d2b3d;
  font: 500 16px/1.4 Fredoka, system-ui, sans-serif;
}
.boot-loading-content { width: min(100%, 360px); text-align: center; }
.boot-loading h2 { margin: 0 0 16px; font-size: 36px; }
.boot-loading progress { display: block; width: 100%; height: 16px; accent-color: #317962; margin: 20px 0; }
.boot-loading [hidden] { display: none; }

/* Immersive battles: transient orders overlay the map, never occupy a row. */
.duel-squad.is-full { height: 100dvh; }
.duel-squad.is-full .squad-rosters { display: none; }
.duel-squad.is-full .duel-dock {
  position: absolute; z-index: 12;
  left: env(safe-area-inset-left); right: env(safe-area-inset-right);
  bottom: env(safe-area-inset-bottom); height: auto; min-height: 0;
  max-height: calc(100% - var(--toolbar-bottom, 100px) - 16px);
  display: block; pointer-events: none; padding: 10px 12px 14px;
}
.duel-squad.is-full .duel-dock[data-edge="top"]:has(.duel-orders:not([hidden])) {
  top: var(--toolbar-bottom, 100px); bottom: auto;
}
.duel-squad.is-full .duel-orders {
  pointer-events: auto; width: min(100%, 520px); margin: 0 auto;
  max-height: calc(100dvh - var(--toolbar-bottom, 100px) - 32px);
  grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px;
  padding: 12px; border-radius: 16px; box-shadow: 0 8px 28px rgb(61 43 61 / .28);
}
.duel-squad.is-full .orders-who { grid-column: 1; grid-row: 1; }
.duel-squad.is-full .orders-who h3 { font-size: 16px; }
.duel-squad.is-full .orders-who .squad-class { display: none; }
.duel-squad.is-full .squad-targets { grid-column: 2; grid-row: 1; justify-content: flex-end; }
.duel-squad.is-full .duel-forecast { grid-column: 1 / -1; grid-row: 2; }
.duel-squad.is-full .orders-actions { grid-column: 1 / -1; grid-row: 3; }
.duel-squad.is-full .orders-actions .btn { flex: 1; width: auto; min-height: 44px; }
.duel-squad.is-full .orders-actions .btn span { display: inline; }
.duel-squad.is-full .duel-hud {
  width: fit-content; max-width: 100%; margin: 0 auto; padding: 7px 14px;
  border-radius: 12px; text-align: center;
}
.duel-squad.is-full .duel-hint { font-size: 14px; }
.duel-squad.is-full .duel-message { display: none; }
.duel-squad.is-full .duel-hud:has([data-action="retry"]:not([hidden])) { pointer-events: auto; }
.duel-fullscreen-help {
  position: absolute; z-index: 45; top: var(--toolbar-bottom, 100px); left: 12px; right: 12px;
  display: flex; align-items: center; gap: 12px; margin: auto; max-width: 520px;
  padding: 14px; border-radius: 16px; background: var(--paper); box-shadow: 0 8px 28px rgb(61 43 61 / .28);
}
@media (max-height: 520px) and (orientation: landscape) {
 .duel-squad.is-full .duel-orders { width: min(100%, 740px); grid-template-columns: 100px minmax(0, 1fr) auto; padding: 8px 12px; gap: 5px 12px; }
 .duel-squad.is-full .squad-targets { grid-column: 1; grid-row: 2; justify-content: flex-start; }
 .duel-squad.is-full .duel-forecast { grid-column: 2; grid-row: 1 / span 2; }
 .duel-squad.is-full .orders-actions { grid-column: 3; grid-row: 1 / span 2; flex-direction: column; gap: 4px; }
 .duel-squad.is-full .orders-actions .btn { min-height: 36px; }
}
@media (max-width: 360px) {
 .duel-squad.is-full .orders-actions .btn { min-width: 0; padding: 0 8px; }
 .duel-squad.is-full .orders-actions .btn .i { display: none; }
}
