/*
 * Desktop battle HUD stabilization
 * Built after responsive-layout-fixes.css so these rules win over legacy float heuristics.
 */

/* 1) Battle header: timeline and button groups must occupy separate columns, never overlay. */
.app.device-desktop.battle-started .topbar.in-battle {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "timeline main-actions";
  align-items: stretch;
  gap: 10px;
}

.app.device-desktop.battle-started .topbar.in-battle #topbarTitle.hidden {
  display: none !important;
}

.app.device-desktop.battle-started .topbar.in-battle .topbar-timeline-host:not(:empty) {
  grid-area: timeline;
  display: block;
  width: 100%;
  min-width: 0;
  overflow: hidden;
}

.app.device-desktop.battle-started .topbar.in-battle .timeline-float.in-topbar {
  position: relative;
  inset: auto;
  left: auto;
  top: auto;
  width: 100%;
  min-width: 0;
  max-width: none;
  transform: none;
  box-shadow: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "clock clock"
    "timeline global-actions";
  align-items: center;
  column-gap: 10px;
  row-gap: 6px;
}

.app.device-desktop.battle-started .topbar.in-battle .timeline-float.in-topbar .timeline-head {
  grid-area: clock;
  min-width: 0;
}

.app.device-desktop.battle-started .topbar.in-battle .timeline-float.in-topbar .timeline {
  grid-area: timeline;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.app.device-desktop.battle-started .topbar.in-battle .timeline-float.in-topbar .global-actions {
  grid-area: global-actions;
  display: grid;
  grid-template-columns: repeat(2, max-content);
  align-items: center;
  justify-content: end;
  gap: 8px;
  margin-top: 0;
  min-width: max-content;
}

.app.device-desktop.battle-started .topbar.in-battle .timeline-float.in-topbar .global-actions button {
  min-width: 104px;
  white-space: nowrap;
}

.app.device-desktop.battle-started .topbar.in-battle > .actions {
  grid-area: main-actions;
  display: grid;
  grid-template-columns: repeat(3, max-content);
  align-content: stretch;
  align-items: stretch;
  justify-content: end;
  gap: 8px;
  width: auto;
  min-width: max-content;
  flex-wrap: nowrap;
}

.app.device-desktop.battle-started .topbar.in-battle > .actions button {
  white-space: nowrap;
  min-width: 74px;
}

/* 2) Desktop board: fill the battle viewport as much as possible while retaining square cells. */
.app.device-desktop.battle-started .battle-stage > .board-shell,
.app.device-desktop.battle-started .board-panel,
.app.device-desktop.battle-started .battle-board-wrap {
  align-self: stretch;
  justify-self: stretch;
  min-height: 0;
  height: 100%;
}

.app.device-desktop.battle-started .battle-board-wrap {
  padding-left: 0;
  padding-right: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

/*
 * 12 x 7 cells = board aspect ratio 12:7.
 * Width is capped by viewport height so the board grows until it nearly fills the main battle window,
 * rather than shrinking to leave artificial side gutters.
 */
.app.device-desktop.battle-started .board {
  width: min(100%, calc((100dvh - 220px) * 12 / 7));
  max-width: 100%;
  margin: 0 auto;
}

.app.device-desktop.battle-started .selected-portrait {
  left: 0;
  right: 0;
}

/* 3) Keep HUD panels at the edges without compressing the board itself. */
.app.device-desktop.battle-started .team-float {
  right: 18px;
  width: clamp(260px, 22vw, 320px);
  max-width: calc(100vw - 36px);
}

.app.device-desktop.battle-started .focus-float,
.app.device-desktop.battle-started .ready-float {
  width: clamp(300px, 25vw, 360px);
  max-width: calc(100vw - 36px);
}

.app.device-desktop.battle-started .turn-float {
  width: clamp(320px, 29vw, 430px);
  max-width: calc(100vw - 36px);
}

/* 4) Keep desktop out-of-turn HUD visible as an explicit state surface. */
.app.device-desktop.battle-started .extra-float,
.app.device-desktop.battle-started .extra-float:not(.active) {
  display: block !important;
}

.app.device-desktop.battle-started .extra-float:not(.active) {
  opacity: 0.92;
  border-color: rgba(153, 123, 56, 0.28);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
}

/* 5) Desktop slim battle portraits: side-anchored, vertically centered, smaller than before. */
.app.device-desktop.battle-started .board-portrait-overlay {
  inset: 0 6px;
}

.app.device-desktop.battle-started .board-portrait {
  top: calc(50% + var(--portrait-offset, 0) * 14px);
  width: min(246px, 19vw);
}

.app.device-desktop.battle-started .board-portrait.portrait-round,
.app.device-desktop.battle-started .board-portrait.portrait-stamina {
  width: min(270px, 21vw);
}

.app.device-desktop.battle-started .board-portrait.ally {
  left: -2px;
  right: auto;
  animation-name: boardPortraitSettle, boardPortraitSlideLeftCentered;
}

.app.device-desktop.battle-started .board-portrait.enemy {
  right: -2px;
  left: auto;
  animation-name: boardPortraitSettle, boardPortraitSlideRightCentered;
}

@keyframes boardPortraitSlideLeftCentered {
  0% {
    transform: translate(-34px, -50%) scale(0.86);
  }
  18% {
    transform: translate(0, -50%) scale(1.02);
  }
  100% {
    transform: translate(0, -50%) scale(1);
  }
}

@keyframes boardPortraitSlideRightCentered {
  0% {
    transform: translate(34px, -50%) scale(0.86);
  }
  18% {
    transform: translate(0, -50%) scale(1.02);
  }
  100% {
    transform: translate(0, -50%) scale(1);
  }
}

/* 6) Medium desktop windows: keep the structure, but tune the board budget and topbar wrap cleanly. */
@media (min-width: 901px) and (max-width: 1360px) {
  .app.device-desktop.battle-started .topbar.in-battle {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "timeline"
      "main-actions";
  }

  .app.device-desktop.battle-started .topbar.in-battle > .actions {
    justify-content: start;
  }

  .app.device-desktop.battle-started .board {
    width: min(100%, calc((100dvh - 250px) * 12 / 7));
  }

  .app.device-desktop.battle-started .team-float {
    width: clamp(240px, 24vw, 300px);
  }

  .app.device-desktop.battle-started .focus-float,
  .app.device-desktop.battle-started .ready-float {
    width: clamp(280px, 28vw, 340px);
  }

  .app.device-desktop.battle-started .turn-float {
    width: clamp(300px, 31vw, 380px);
  }

  .app.device-desktop.battle-started .board-portrait {
    width: min(224px, 19vw);
  }

  .app.device-desktop.battle-started .board-portrait.portrait-round,
  .app.device-desktop.battle-started .board-portrait.portrait-stamina {
    width: min(248px, 21vw);
  }
}

/* 7) If desktop is very narrow but still classified as desktop, preserve fit before maxing out size. */
@media (min-width: 901px) and (max-width: 1080px) {
  .app.device-desktop.battle-started .timeline-float.in-topbar {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "clock"
      "timeline"
      "global-actions";
  }

  .app.device-desktop.battle-started .timeline-float.in-topbar .global-actions {
    justify-content: start;
  }

  .app.device-desktop.battle-started .board {
    width: min(100%, calc((100dvh - 278px) * 12 / 7));
  }
}
