:root {
  --bg: #071018;
  --panel: rgba(12, 28, 36, 0.88);
  --accent: #3ecfbf;
  --accent-gold: #d4a017;
  --text: #e4f4f2;
  --muted: #7aa8a8;
  --player: #3b9eff;
  --enemy: #ef4444;
  --border: #2a5a5e;
  --violet: #6b4c9a;
  --teal: #1a9b8e;
  --rbx: #00a2ff;
  --rbx-green: #00b06f;
  --rbx-panel: rgba(18, 24, 36, 0.82);
  font-family: "Segoe UI", "Gotham SSm", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background-color: var(--bg);
  background-image:
    linear-gradient(180deg, rgba(7, 16, 24, 0.55) 0%, rgba(7, 16, 24, 0.85) 100%),
    url('assets/materia-lifestream-bg.jpg');
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  color: var(--text);
}

#root,
.ffk {
  min-height: 100%;
}

.ffk-header {
  text-align: center;
  padding: 0.75rem 1rem 0.25rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(20, 50, 60, 0.9) 0%, transparent 100%);
}

.ffk-header h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.06em;
  color: var(--accent);
  text-shadow: 0 0 18px rgba(212, 160, 23, 0.35);
}

.ffk-header .tag {
  margin: 0.25rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

#ffk-screens {
  padding: 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  max-width: 420px;
  margin: 1rem auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

/* Roblox-like rounded chrome (keep materia bg on body) */
.roblox-panel {
  background: var(--rbx-panel);
  border: 2px solid rgba(0, 162, 255, 0.45);
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.roblox-menu-badge {
  width: 56px;
  height: 56px;
  margin: 0 auto;
  border-radius: 12px;
  background: linear-gradient(145deg, #00a2ff, #0066aa);
  color: #fff;
  font-weight: 900;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 162, 255, 0.4);
}

.roblox-title {
  text-align: center;
  letter-spacing: 0.04em;
  color: #fff !important;
  text-shadow: 0 2px 0 #003d66;
}

.roblox-sub {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0;
}

.roblox-btn {
  border-radius: 10px !important;
  font-weight: 700 !important;
  border: 2px solid rgba(255, 255, 255, 0.12) !important;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}

.roblox-btn.primary,
.btn.primary.roblox-btn {
  background: linear-gradient(180deg, #00c878, #00a05a) !important;
  border-color: #00804a !important;
}

.loadout-preview {
  border-radius: 14px !important;
  border: 2px solid rgba(0, 162, 255, 0.35) !important;
  background: linear-gradient(180deg, #2a3548, #1a2230) !important;
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.35);
}

/* Lower-left dock: Confirm FAB + recent-action status bar */
.ll-action-dock {
  position: absolute;
  left: 0.45rem;
  bottom: 0.5rem;
  z-index: 25;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.35rem;
  max-width: min(92vw, 22rem);
  pointer-events: none;
}

.confirm-fab {
  position: relative;
  left: 0;
  bottom: 0;
  pointer-events: none;
}

.confirm-fab.hidden {
  display: none !important;
}

.confirm-fab-btn {
  pointer-events: auto;
  min-width: 7.5rem;
  padding: 0.7rem 1rem !important;
  font-size: 0.95rem !important;
  font-weight: 800 !important;
  border-radius: 14px !important;
  background: rgba(0, 176, 111, 0.82) !important;
  border: 2px solid rgba(255, 255, 255, 0.35) !important;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(6px);
}

.confirm-fab-btn:active {
  transform: scale(0.97);
}

.action-status-bar {
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  width: min(92vw, 16.5rem);
  padding: 0.45rem 0.65rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(12, 22, 34, 0.72);
  color: #e8f4ff;
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
}

.action-status-bar:active {
  transform: scale(0.98);
}

.action-status-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.7;
  font-weight: 700;
}

.action-status-text {
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.25;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-status-hint {
  font-size: 0.68rem;
  opacity: 0.85;
  color: #9fd8ff;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-status-panel {
  position: absolute;
  left: 0.45rem;
  bottom: 5.2rem;
  z-index: 28;
  width: min(94vw, 22rem);
  max-height: min(55vh, 22rem);
  overflow: auto;
  padding: 0.65rem 0.75rem;
  border-radius: 14px;
  border: 1px solid rgba(120, 200, 255, 0.35);
  background: rgba(8, 16, 28, 0.94);
  color: #e8f4ff;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
}

.action-status-panel.hidden {
  display: none !important;
}

.status-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.status-panel-sec h4 {
  margin: 0.45rem 0 0.25rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8ec8f0;
}

.status-log-list,
.status-ct-list,
.status-cast-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 7.5rem;
  overflow: auto;
}

.status-log-line,
.status-ct-line,
.status-cast-line {
  font-size: 0.72rem;
  padding: 0.28rem 0.2rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.status-ct-line.is-active {
  background: rgba(0, 176, 111, 0.18);
  border-radius: 6px;
}

.status-ct-line .ct-when,
.status-cast-line .cast-eta {
  float: right;
  color: #9fd8ff;
  font-weight: 700;
}

.status-log-line.muted,
.status-cast-line.muted {
  opacity: 0.55;
  font-style: italic;
}

/* Full-screen Ghibli character card */
.char-detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
}

.char-detail-overlay.hidden {
  display: none !important;
}

.char-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 10, 18, 0.78);
  backdrop-filter: blur(4px);
}

.char-overlay-card {
  position: relative;
  z-index: 1;
  width: min(96vw, 560px);
  max-height: min(94vh, 820px);
  overflow: auto;
  border-radius: 18px;
  border: 2px solid rgba(255, 255, 255, 0.22);
  background: linear-gradient(165deg, #1a2a3a 0%, #0e1824 55%, #152030 100%);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  color: #f0f6ff;
}

.char-overlay-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  z-index: 2;
  min-width: 2.25rem !important;
  padding: 0.35rem 0.5rem !important;
}

.char-overlay-hero {
  display: grid;
  grid-template-columns: minmax(140px, 46%) 1fr;
  gap: 0.75rem;
  padding: 1rem 1rem 0.5rem;
  align-items: end;
}

.char-hero-portrait {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 14px;
  border: 3px solid rgba(255, 220, 140, 0.55);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  background: #1a3048;
}

.char-hero-kicker {
  margin: 0;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9fd8ff;
}

.char-hero-name {
  margin: 0.2rem 0;
  font-size: 1.55rem;
  line-height: 1.15;
  font-weight: 800;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
}

.char-hero-job {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: #f4d35e;
}

.char-hero-desc {
  margin: 0.4rem 0 0;
  font-size: 0.8rem;
  opacity: 0.88;
  line-height: 1.35;
}

.char-overlay-body {
  padding: 0.5rem 1rem 1.1rem;
}

.char-overlay-body h3 {
  margin: 0.75rem 0 0.4rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #8ec8f0;
}

.char-attr-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 0.75rem;
  font-size: 0.82rem;
}

.fun-stat-row {
  display: grid;
  grid-template-columns: 4.2rem 1fr 2rem;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 0.35rem;
  font-size: 0.75rem;
}

.fun-bar-track {
  height: 0.45rem;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.fun-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #3ecfbf, #f4d35e);
}

.fun-hint {
  grid-column: 2 / -1;
  font-size: 0.65rem;
  opacity: 0.55;
  margin-top: -0.15rem;
}

.char-skill-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.8rem;
}

.char-skill-list .muted {
  opacity: 0.65;
  font-weight: 400;
}

.unit-portrait.ghibli-portrait {
  object-fit: cover;
  background: linear-gradient(180deg, #a9cce3, #d6eaf8);
}

.hint-tap {
  margin-left: auto;
  font-size: 0.65rem;
  opacity: 0.55;
  font-weight: 500;
}

.bottom-unit-panel {
  cursor: pointer;
}

.bottom-unit-panel:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 520px) {
  .char-overlay-hero {
    grid-template-columns: 1fr;
  }
  .char-hero-portrait {
    max-width: 220px;
    margin: 0 auto;
  }
}

.panel.wide {
  max-width: 920px;
}

.loadout-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 700px) {
  .loadout-grid {
    grid-template-columns: 1fr;
  }
}

.loadout-form label {
  margin-bottom: 0.35rem;
}

.job-desc,
.eq-desc {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}

.stat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.stat-table td {
  padding: 0.25rem 0.4rem;
  border-bottom: 1px solid var(--border);
}

.stat-table td:nth-child(odd) {
  color: var(--muted);
  width: 22%;
}

.stat-table td:nth-child(even) {
  font-weight: 600;
  color: var(--accent);
  width: 28%;
}

.skill-panel h3 {
  margin: 0.5rem 0;
  color: var(--accent);
  font-size: 0.95rem;
}

.skill-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 220px;
  overflow: auto;
}

.skill-card {
  background: #0d121a;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
}

.skill-name {
  font-weight: 600;
  font-size: 0.85rem;
}

.skill-kind {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.75rem;
  margin-left: 0.35rem;
}

.skill-summary {
  font-size: 0.72rem;
  color: var(--accent);
  margin-top: 0.15rem;
}

.skill-desc {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
  line-height: 1.3;
}

.water-hint {
  border-left: 3px solid #3b82f6;
  padding-left: 0.5rem;
}

.cam-help {
  width: 100%;
  margin: 0 0 0.35rem;
  font-size: 0.7rem;
  line-height: 1.35;
}

/* FFT-style panels */
.fft-panel,
.materia-panel {
  box-shadow:
    0 0 0 1px #1a4a50,
    0 0 0 3px rgba(62, 207, 191, 0.35),
    0 0 40px rgba(107, 76, 154, 0.2),
    inset 0 0 50px rgba(0, 0, 0, 0.4);
  background: linear-gradient(160deg, rgba(16, 40, 48, 0.92) 0%, rgba(12, 24, 40, 0.94) 50%, rgba(30, 20, 48, 0.9) 100%);
  backdrop-filter: blur(6px);
}

.btn.primary {
  background: linear-gradient(180deg, #2ec4b6, #0d7377);
  border-color: #5eead4;
  color: #042f2e;
}

.gil-bar {
  background: #0d121a;
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.45rem 0.65rem;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.gil-bar.over {
  border-color: #ef4444;
  color: #fca5a5;
}

.gil-bar .err {
  color: #ef4444;
  margin-left: 0.5rem;
}

.loadout-grid.three {
  grid-template-columns: 1.1fr 0.9fr 1fr;
}

@media (max-width: 900px) {
  .loadout-grid.three {
    grid-template-columns: 1fr;
  }
}

.item-icon {
  image-rendering: pixelated;
  vertical-align: middle;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.with-icon {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.loadout-preview {
  margin-top: 0.75rem;
  height: 220px;
  background: radial-gradient(ellipse at center, #2a3a55 0%, #0d121a 70%);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.loadout-preview canvas {
  display: block;
  margin: 0 auto;
}

.arena-wrap {
  position: relative;
  min-height: 360px;
}

.float-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 5;
}

.combat-floater {
  position: absolute;
  font-weight: 800;
  font-size: 1.05rem;
  text-shadow: 0 1px 2px #000, 0 0 6px #000;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 0.1s;
  white-space: nowrap;
  z-index: 6;
  pointer-events: none;
}

.combat-floater.show {
  opacity: 1;
}

.battle-banner {
  position: absolute;
  left: 50%;
  top: 40%;
  transform: translate(-50%, -50%);
  font-size: 2.4rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-shadow: 0 0 20px #000, 0 2px 0 #3d2a10;
  z-index: 8;
  pointer-events: none;
}

.battle-banner.hidden {
  display: none;
}

.battle-banner.intro {
  font-size: 2.8rem;
  color: #ffe066;
  animation: introPulse 1.2s ease-in-out infinite alternate;
}

@keyframes introPulse {
  from { opacity: 0.85; letter-spacing: 0.1em; }
  to { opacity: 1; letter-spacing: 0.16em; }
}

.cast-name-banner {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  font-size: 1.45rem;
  font-weight: 800;
  color: #c4f1ff;
  text-shadow: 0 0 12px #0a3a50, 0 2px 0 #000;
  opacity: 0;
  pointer-events: none;
  z-index: 9;
  transition: opacity 0.2s;
  letter-spacing: 0.08em;
}

.cast-name-banner.show {
  opacity: 1;
}

.cmd-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.cmd-row.muted {
  opacity: 0.55;
}

.ability-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 12rem;
  overflow: auto;
}

.math-ct-picker {
  margin-top: 0.4rem;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
}

.math-ct-picker.hidden {
  display: none;
}

.math-ct-label {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.math-ct-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.stat-delta {
  font-size: 0.85em;
  font-weight: 800;
  margin-left: 0.25rem;
  animation: deltaPop 0.35s ease-out;
}

.stat-delta.up {
  color: #4ade80;
}

.stat-delta.down {
  color: #f87171;
}

@keyframes deltaPop {
  from { opacity: 0; transform: translateX(-4px); }
  to { opacity: 1; transform: translateX(0); }
}

.badge.active-turn {
  background: #ca8a04;
  color: #111;
}

.inspect-panel {
  font-size: 0.8rem;
}

.inspect-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.badge {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  background: #334155;
}

.badge.player {
  background: #1d4ed8;
}

.badge.enemy {
  background: #b91c1c;
}

.inspect-bars {
  display: flex;
  gap: 0.75rem;
  margin: 0.35rem 0;
}

.inspect-gear {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin: 0.35rem 0;
  color: var(--muted);
}

.stat-table.compact td {
  font-size: 0.78rem;
}

.face-pad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  margin: 0.5rem 0;
}

.face-mid {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.face-cur {
  font-weight: 800;
  color: var(--accent);
  min-width: 1.5rem;
  text-align: center;
}

.casting,
.ct-row.casting {
  color: #7dd3fc;
}

.ct-row {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.panel h2 {
  margin: 0 0 0.5rem;
  color: var(--accent);
}

.btn {
  background: #2a3a55;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
  font-size: 0.95rem;
}

.btn:hover:not(:disabled) {
  background: #354a6b;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: linear-gradient(180deg, #c49212, #8a6508);
  border-color: #e0b83a;
  color: #1a1200;
  font-weight: 600;
}

.btn.small {
  padding: 0.35rem 0.55rem;
  font-size: 0.8rem;
}

.btn.tiny {
  padding: 0.25rem 0.4rem;
  font-size: 0.75rem;
  margin: 0.15rem;
}

.hint {
  color: var(--muted);
  font-size: 0.8rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

input,
select {
  background: #0d121a;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.4rem 0.5rem;
}

.row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.unit-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.tab {
  background: #243044;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  font-size: 0.8rem;
}

.tab.active {
  border-color: var(--accent);
  color: var(--accent);
}

.battle-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 0.75rem;
  height: calc(100vh - 100px);
  max-width: 1400px;
  margin: 0 auto;
}

.battle-layout-v2 {
  grid-template-columns: 1fr 260px;
  height: calc(100vh - 90px);
}

.battle-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 0.4rem;
}

.map-title {
  font-size: 0.8rem;
  color: var(--accent);
  letter-spacing: 0.06em;
  padding: 0 0.25rem;
  text-shadow: 0 0 8px rgba(62, 207, 191, 0.4);
}

.battle-main .arena-wrap {
  flex: 1;
  min-height: 280px;
}

.bottom-unit-panel {
  flex-shrink: 0;
  min-height: 120px;
  max-height: 160px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  box-shadow: 0 0 20px rgba(26, 155, 142, 0.15), inset 0 0 30px rgba(0, 0, 0, 0.25);
  overflow: auto;
}

.bottom-unit-inner {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.unit-portrait {
  border-radius: 8px;
  border: 2px solid var(--accent);
  box-shadow: 0 0 12px rgba(62, 207, 191, 0.35);
  flex-shrink: 0;
}

.bottom-unit-main {
  flex: 1;
  min-width: 0;
  font-size: 0.8rem;
}

.row-gear {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin: 0.25rem 0;
}

.badge.active-turn {
  background: var(--accent);
  color: #04201c;
}

.status-pill {
  display: inline-block;
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  margin: 0.1rem;
  border-radius: 4px;
  background: rgba(62, 207, 191, 0.2);
  border: 1px solid var(--border);
  text-transform: capitalize;
}

.act-confirm-row {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.35rem;
}

.act-confirm-row .hint {
  font-size: 0.7rem;
  color: var(--muted);
}

.action-rail {
  overflow: auto;
}

/* Sticky loadout — must remain reachable on short phone viewports */
.loadout-sticky-layout {
  max-width: 960px;
  max-height: calc(100dvh - 70px);
  max-height: calc(100vh - 70px);
  display: flex;
  flex-direction: column;
  padding: 0;
  /* Never clip Start / chips with overflow:hidden alone — allow inner scroll as safety */
  overflow: hidden;
}

.loadout-sticky-layout.loadout-noscroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.loadout-sticky-top {
  flex-shrink: 0;
  padding: 0.65rem 0.85rem 0.4rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(20, 50, 55, 0.95), rgba(12, 28, 36, 0.95));
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.loadout-sticky-top h2 {
  margin: 0;
  font-size: 1.05rem;
}

.loadout-sticky-preview-row {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 0.75rem;
  align-items: start;
  margin-top: 0.25rem;
}

.loadout-scroll-body {
  flex: 1;
  overflow: auto;
  padding: 0.5rem 0.85rem 0.85rem;
  min-height: 0;
}

.loadout-grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 800px) {
  .loadout-sticky-preview-row,
  .loadout-grid.two {
    grid-template-columns: 1fr;
  }
  .battle-layout-v2 {
    grid-template-columns: 1fr;
    height: auto;
  }
}

.arena-host {
  position: relative;
  background: #000;
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
  min-height: 360px;
}

.arena-host canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.hud {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow: auto;
}

.hud-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem;
  font-size: 0.82rem;
}

.ct-list .ct-title {
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.35rem;
}

.ct-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0;
}

.ct-row.active {
  background: rgba(212, 160, 23, 0.12);
  border-radius: 4px;
}

.ct-row em {
  margin-left: auto;
  color: var(--muted);
  font-style: normal;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot.player {
  background: var(--player);
}

.dot.enemy {
  background: var(--enemy);
}

.log {
  max-height: 160px;
  overflow: auto;
  color: var(--muted);
  font-size: 0.75rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-content: flex-start;
}

.cam-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 8px;
  z-index: 50;
}

.toast.hidden {
  display: none;
}

/* Fixed floating action chrome — semi-transparent so arena shows through */
.battle-action-chrome {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
  width: min(168px, 42vw);
  max-height: 88%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.18s ease;
}

.battle-action-chrome.is-hidden,
.battle-action-chrome[hidden],
.battle-action-chrome.hidden {
  opacity: 0 !important;
  visibility: hidden;
  pointer-events: none !important;
}

.battle-action-chrome .hud-block,
.battle-action-chrome .btn {
  pointer-events: auto;
}

.chrome-actions,
.chrome-wait-face {
  /* Semi-transparent panels — arena remains partially visible */
  background: rgba(8, 22, 28, 0.48);
  border: 1px solid rgba(62, 207, 191, 0.55);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(5px);
}

.chrome-wait-face {
  font-size: 0.78rem;
}

.chrome-wait-face .face-pad {
  transform: scale(0.95);
  transform-origin: top center;
}

.desktop-actions-mirror {
  display: none;
}

/* Formation chip pickers — primary equip UI without page scroll */
.loadout-meta-row {
  margin-top: 0.35rem;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.loadout-meta-row .inline-field select {
  max-width: 8.5rem;
}

.loadout-chip-pickers {
  margin-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.chip-row {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
}

.chip-label {
  flex: 0 0 3.2rem;
  font-size: 0.72rem;
  color: var(--muted);
  padding-top: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chip-scroll {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  flex: 1;
  max-height: 4.8rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.chip {
  appearance: none;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  border-radius: 999px;
  padding: 0.28rem 0.55rem;
  font-size: 0.72rem;
  cursor: pointer;
  white-space: nowrap;
}

.chip.active {
  border-color: var(--accent);
  background: rgba(62, 207, 191, 0.2);
  color: var(--accent);
  font-weight: 700;
}

.chip small {
  opacity: 0.75;
  margin-left: 0.15rem;
}

.meta-row {
  flex-wrap: wrap;
  align-items: center;
}

.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  margin: 0;
}

.inline-field input,
.inline-field select {
  max-width: 7rem;
  font-size: 0.78rem;
}

.loadout-actions-sticky {
  margin-top: 0.35rem;
  position: sticky;
  bottom: 0;
  z-index: 6;
  padding: 0.4rem 0 0.15rem;
  background: linear-gradient(180deg, transparent, rgba(8, 20, 26, 0.96) 30%);
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.loadout-noscroll .loadout-scroll-body {
  max-height: min(22vh, 160px);
}

@media (max-width: 800px) {
  .battle-layout {
    grid-template-columns: 1fr;
    height: auto;
  }
  .battle-layout-v2 {
    height: auto;
    min-height: calc(100dvh - 70px);
  }
  .arena-host,
  .battle-main .arena-wrap {
    height: min(62dvh, 520px);
    min-height: 280px;
  }
  .action-rail {
    display: none; /* actions live in fixed chrome on mobile */
  }
  .battle-action-chrome {
    right: 0.25rem;
    width: min(150px, 40vw);
  }
  .bottom-unit-panel {
    max-height: 110px;
    min-height: 80px;
    font-size: 0.75rem;
  }

  /* Formation: compact so chips + Start fit on 390×844 without clipping */
  .loadout-sticky-layout,
  .loadout-sticky-layout.loadout-noscroll {
    max-height: calc(100dvh - 56px);
    max-height: calc(100vh - 56px);
    overflow-y: auto;
  }
  .loadout-sticky-top {
    padding: 0.45rem 0.55rem 0.3rem;
    gap: 0.25rem;
  }
  .loadout-sticky-top h2 {
    font-size: 0.95rem;
  }
  .gil-bar {
    font-size: 0.72rem;
    padding: 0.25rem 0.4rem;
  }
  .unit-tabs .tab {
    font-size: 0.7rem;
    padding: 0.25rem 0.4rem;
  }
  .loadout-sticky-preview-row {
    grid-template-columns: 88px 1fr;
    gap: 0.4rem;
    margin-top: 0.15rem;
  }
  .loadout-preview {
    width: 88px !important;
    min-height: 96px !important;
    max-height: 100px;
  }
  .loadout-preview canvas {
    width: 88px !important;
    height: 96px !important;
  }
  .loadout-stats h3 {
    font-size: 0.8rem;
    margin: 0 0 0.2rem;
  }
  .stat-table {
    font-size: 0.72rem;
  }
  .loadout-chip-pickers {
    order: 0;
    margin-top: 0.2rem;
    gap: 0.2rem;
  }
  .chip-label {
    flex: 0 0 2.6rem;
    font-size: 0.65rem;
    padding-top: 0.25rem;
  }
  .chip {
    font-size: 0.68rem;
    padding: 0.22rem 0.45rem;
  }
  .chip-scroll {
    max-height: 2.6rem;
  }
  .meta-row .inline-field input,
  .meta-row .inline-field select {
    max-width: 5.5rem;
    font-size: 0.72rem;
  }
  .loadout-actions-sticky {
    position: sticky;
    bottom: 0;
    padding: 0.35rem 0 0.25rem;
  }
  .loadout-noscroll .loadout-scroll-body {
    max-height: min(16vh, 120px);
    padding: 0.35rem 0.55rem 0.5rem;
  }
  .loadout-scroll-body .job-desc,
  .loadout-scroll-body .eq-desc {
    font-size: 0.7rem;
    margin: 0.15rem 0;
  }
}

@media (min-width: 801px) {
  .battle-action-chrome {
    /* Still pin over arena on desktop for consistency */
    width: 180px;
  }
}
