:root {
  --bg: #0b0d16;
  --bg2: #121628;
  --panel: rgba(20, 24, 44, 0.86);
  --panel-edge: #3a3556;
  --gold: #e6c27a;
  --gold-dim: #8f7444;
  --ember: #ff7a3d;
  --ember-glow: rgba(255, 122, 61, 0.45);
  --text: #ece6d8;
  --muted: #9a94ab;
  --good: #63e0a0;
  --bad: #ff6b6b;
  --warn: #ffc65c;
  --r5: linear-gradient(135deg, #fff2b8, #e3a83a 40%, #fff0a8 60%, #b97a1d);
  --r4: linear-gradient(135deg, #e7c8ff, #9454d8 45%, #d8b0ff 60%, #5f2c9b);
  --r3: linear-gradient(135deg, #c9e6ff, #4f8fcf 45%, #b8dcff 60%, #2c5b8f);
  --r0: linear-gradient(135deg, #b6b6c4, #5d5d70);
  --radius: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: 'Zen Kaku Gothic New', system-ui, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(255, 122, 61, 0.14), transparent 60%),
    radial-gradient(900px 500px at 0% 110%, rgba(120, 80, 220, 0.16), transparent 60%),
    linear-gradient(180deg, var(--bg2), var(--bg));
  background-attachment: fixed;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
code { font-size: .85em; color: var(--gold); }
.muted { color: var(--muted); font-size: .85rem; }

/* 舞い上がる火の粉 */
.embers {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .5;
  background-image:
    radial-gradient(2px 2px at 10% 90%, var(--ember), transparent),
    radial-gradient(1.5px 1.5px at 30% 80%, #ffb36b, transparent),
    radial-gradient(2px 2px at 55% 95%, var(--ember), transparent),
    radial-gradient(1.5px 1.5px at 75% 85%, #ffd08a, transparent),
    radial-gradient(2px 2px at 90% 92%, var(--ember), transparent);
  background-size: 100% 100%;
  animation: rise 14s linear infinite;
}
@keyframes rise { from { transform: translateY(0); opacity: .6; } to { transform: translateY(-100vh); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .embers { animation: none; display: none; } }

/* ---------- ヘッダ ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px;
  background: linear-gradient(180deg, rgba(14, 16, 30, .97), rgba(14, 16, 30, .88));
  border-bottom: 1px solid var(--gold-dim);
  box-shadow: 0 2px 0 rgba(230, 194, 122, .15), 0 8px 24px rgba(0, 0, 0, .5);
}
.brand { display: flex; flex-direction: column; line-height: 1.15; }
.brand-en {
  font-family: 'Cinzel', serif; font-weight: 800; letter-spacing: .18em; font-size: 1.25rem;
  background: linear-gradient(180deg, #fff3cf, var(--gold) 55%, #a07534);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: 0 0 18px rgba(255, 160, 80, .25);
}
.brand-ja { font-size: .72rem; color: var(--muted); letter-spacing: .08em; }
.top-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.field { display: flex; align-items: center; gap: 6px; font-size: .78rem; color: var(--muted); }
.field input { width: 84px; }

input[type=number], input[type=search], select, .squad-name {
  background: rgba(0, 0, 0, .35); border: 1px solid var(--panel-edge); border-radius: 6px;
  padding: 6px 8px; outline: none;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

.btn {
  border: 1px solid var(--gold-dim); border-radius: 6px; padding: 7px 14px; font-weight: 700; font-size: .85rem;
  background: linear-gradient(180deg, #4a3a24, #2a2116);
  color: #ffe7b5; box-shadow: inset 0 1px 0 rgba(255, 230, 170, .25);
  transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.2); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--muted); border-color: var(--panel-edge); }
.btn.small { padding: 4px 10px; font-size: .78rem; }

/* ---------- レイアウト ---------- */
.layout {
  position: relative; z-index: 1;
  display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 18px;
  max-width: 1400px; margin: 0 auto; padding: 18px 20px 30px;
}
.formation { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.panel {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35), inset 0 0 0 1px rgba(255, 255, 255, .02);
  backdrop-filter: blur(6px);
}
/* 角飾り */
.panel::before, .panel::after {
  content: ''; position: absolute; width: 14px; height: 14px; border: 2px solid var(--gold-dim); pointer-events: none;
}
.panel::before { top: -1px; left: -1px; border-right: 0; border-bottom: 0; border-top-left-radius: var(--radius); }
.panel::after { bottom: -1px; right: -1px; border-left: 0; border-top: 0; border-bottom-right-radius: var(--radius); }

.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.panel-head h3, .troops-head h3 {
  margin: 0; font-size: .95rem; letter-spacing: .12em; color: var(--gold);
  display: flex; align-items: center; gap: 8px;
}
.panel-head h3::before, .troops-head h3::before { content: '◆'; font-size: .6rem; color: var(--ember); }

/* ---------- 部隊タブ ---------- */
.squad-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tab {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  padding: 8px 10px; border-radius: 8px 8px 2px 2px;
  border: 1px solid var(--panel-edge); background: rgba(16, 19, 36, .8); color: var(--muted);
  text-align: left;
}
.tab-no {
  flex: none; width: 24px; height: 24px; display: grid; place-items: center; border-radius: 50%;
  font-family: 'Cinzel', serif; font-weight: 800; background: #2a2640; color: var(--gold);
}
.tab-name { font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab.on { color: var(--text); border-color: var(--gold); background: linear-gradient(180deg, #3a2c1e, #1d1a2c); box-shadow: 0 0 14px var(--ember-glow); }
.tab.on .tab-no { background: var(--ember); color: #2a1206; }
.tab.locked { opacity: .45; cursor: not-allowed; }

/* ---------- 部隊パネル ---------- */
.squad-name { font-weight: 900; font-size: 1.05rem; width: 12em; background: transparent; border-color: transparent; }
.squad-name:hover, .squad-name:focus { border-color: var(--panel-edge); background: rgba(0, 0, 0, .3); }
.power-badge { font-size: .8rem; color: var(--muted); }
.power-badge b { font-family: 'Cinzel', serif; font-size: 1.2rem; color: var(--gold); margin-left: 4px; }

.slots { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: stretch; }
.slot {
  position: relative; display: flex; gap: 12px; align-items: center; min-height: 128px; min-width: 0;
  padding: 22px 12px 12px; text-align: left;
  border-radius: 10px; border: 1px solid var(--panel-edge);
  background: linear-gradient(160deg, rgba(60, 50, 90, .35), rgba(10, 10, 20, .6));
  transition: border-color .15s, box-shadow .15s;
}
.slot:hover { border-color: var(--gold-dim); }
.slot.active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 22px var(--ember-glow); }
.slot-label {
  position: absolute; top: 0; left: 12px; transform: translateY(-50%);
  font-family: 'Cinzel', serif; font-weight: 800; font-size: .72rem; letter-spacing: .15em;
  padding: 2px 10px; border-radius: 3px; background: linear-gradient(90deg, #6b3a14, #b5622a); color: #ffe9c9;
  border: 1px solid #e3965a;
}
.slot[data-slot=second] .slot-label { background: linear-gradient(90deg, #2d2a52, #514a8a); border-color: #8b80d4; }
.slot-empty { flex: 1; display: grid; place-items: center; font-size: 2rem; color: var(--gold-dim); }
.slot-empty small { display: block; font-size: .75rem; color: var(--muted); }
.slot-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.slot-stars { font-size: .78rem; letter-spacing: -1px; }
.slot-name { font-weight: 900; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.slot-meta { font-size: .72rem; color: var(--muted); }
.slot-tags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 4px; }
.slot-tags i { font-style: normal; font-size: .62rem; padding: 1px 5px; border-radius: 3px; background: rgba(255, 255, 255, .06); color: #cfc6e8; }
.slot-remove {
  position: absolute; top: 6px; right: 8px; width: 22px; height: 22px; display: grid; place-items: center;
  border-radius: 50%; background: rgba(0, 0, 0, .5); color: var(--muted); font-size: .9rem;
}
.slot-remove:hover { color: var(--bad); }

.bonus-link { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-width: 62px; }
.bl-idle { writing-mode: vertical-rl; font-size: .7rem; color: var(--muted); letter-spacing: .2em; }
.bl-rank {
  font-weight: 900; font-size: .9rem; padding: 4px 8px; border-radius: 4px; background: #2a2640; color: var(--muted);
}
.bl-rank.rank2 { background: linear-gradient(180deg, #ffb35c, #c4561d); color: #2a1206; box-shadow: 0 0 12px var(--ember-glow); }
.bl-rank.rank3 { background: var(--r5); color: #3b2300; box-shadow: 0 0 16px rgba(255, 220, 120, .6); }
.bl-rank.rank1 { background: #3d3a5c; color: var(--text); }
.bl-item { font-size: .66rem; padding: 1px 6px; border-radius: 10px; border: 1px solid var(--panel-edge); color: var(--muted); }
.bl-item.on { border-color: var(--gold); color: var(--gold); background: rgba(230, 194, 122, .12); }

/* ---------- 兵士 ---------- */
.troops { margin-top: 16px; }
.troops-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.troops-actions { display: flex; gap: 6px; }
.troop-row {
  display: grid; grid-template-columns: 28px 74px 70px 1fr 82px; gap: 8px; align-items: center;
  padding: 6px 8px; border-radius: 6px; margin-bottom: 4px; background: rgba(0, 0, 0, .22);
  border: 1px solid transparent;
}
.troop-row.fav { border-color: rgba(230, 194, 122, .35); background: linear-gradient(90deg, rgba(230, 194, 122, .1), rgba(0, 0, 0, .2)); }
.troop-icon { display: grid; place-items: center; }
.troop-icon .ico { width: 22px; height: 22px; }
.troop-name { font-weight: 700; font-size: .85rem; display: flex; flex-direction: column; line-height: 1.1; }
.troop-name em { font-style: normal; font-size: .62rem; color: var(--gold); }
.troop-row .num { width: 100%; min-width: 0; text-align: right; }
.troop-row .tier { min-width: 0; }
.troop-row .tier { padding: 4px; font-size: .78rem; }
.range { width: 100%; accent-color: var(--ember); }
.troop-total { display: flex; align-items: center; gap: 10px; margin-top: 8px; font-size: .82rem; font-family: 'Cinzel', serif; }
.troop-total .over { color: var(--bad); }
.bar { flex: 1; height: 8px; border-radius: 4px; background: rgba(0, 0, 0, .4); overflow: hidden; border: 1px solid var(--panel-edge); }
.bar-fill { height: 100%; width: 0; background: linear-gradient(90deg, #c4561d, var(--ember), #ffd08a); transition: width .2s; }
.bar-fill.over { background: var(--bad); }

/* ---------- 分析 ---------- */
.enemy { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: .78rem; color: var(--muted); }
.enemy select { font-size: .8rem; padding: 4px 6px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.stat {
  display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 6px;
  background: rgba(0, 0, 0, .25); border-left: 3px solid var(--panel-edge);
}
.stat.big { grid-column: span 2; border-left-color: var(--ember); }
.stat.big .stat-value { font-size: 1.5rem; color: var(--gold); }
.stat.good { border-left-color: var(--good); }
.stat.good .stat-value { color: var(--good); }
.stat.bad { border-left-color: var(--bad); }
.stat.bad .stat-value { color: var(--bad); }
.stat-label { font-size: .7rem; color: var(--muted); }
.stat-value { font-weight: 900; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: .65rem; color: var(--muted); }
.notes { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.notes li { font-size: .8rem; padding: 5px 10px; border-radius: 4px; background: rgba(0, 0, 0, .2); }
.notes li::before { margin-right: 6px; }
.notes .info::before { content: 'ℹ'; color: #8fb8ff; }
.notes .warn::before { content: '▲'; color: var(--warn); }
.notes .bad::before { content: '✖'; color: var(--bad); }
.notes .good::before { content: '✔'; color: var(--good); }

/* ---------- 全部隊 ---------- */
.overview-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.ov {
  display: flex; flex-direction: column; gap: 4px; align-items: center; padding: 10px 6px; border-radius: 8px;
  border: 1px solid var(--panel-edge); background: rgba(0, 0, 0, .25); min-width: 0;
}
.ov.on { border-color: var(--gold); box-shadow: 0 0 12px var(--ember-glow); }
.ov.locked { opacity: .4; justify-content: center; font-size: .8rem; }
.ov-name { font-size: .78rem; font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ov-pics { display: flex; gap: 4px; }
.ov-meta { font-size: .66rem; color: var(--muted); }

/* ---------- ポートレート ---------- */
.portrait {
  --size: 64px;
  position: relative; flex: none; display: block;
  width: var(--size); height: var(--size); border-radius: 8px; padding: 3px;
  background: var(--r0);
}
.portrait.r5 { background: var(--r5); box-shadow: 0 0 10px rgba(255, 200, 90, .35); }
.portrait.r4 { background: var(--r4); }
.portrait.r3 { background: var(--r3); }
.portrait.lg { --size: 92px; }
.portrait.sm { --size: 44px; padding: 2px; border-radius: 6px; }
.portrait.empty { background: rgba(255, 255, 255, .06); border: 1px dashed var(--panel-edge); }
.pt-fallback, .portrait > img {
  position: absolute; inset: 3px; border-radius: 6px; width: calc(100% - 6px); height: calc(100% - 6px);
}
.portrait.sm .pt-fallback, .portrait.sm > img { inset: 2px; width: calc(100% - 4px); height: calc(100% - 4px); border-radius: 4px; }
.pt-fallback {
  display: grid; place-items: center;
  font-weight: 900; font-size: calc(var(--size) * .42); color: rgba(255, 255, 255, .92);
  text-shadow: 0 2px 6px rgba(0, 0, 0, .6);
  background:
    radial-gradient(circle at 50% 30%, color-mix(in srgb, var(--el) 70%, white 10%), transparent 70%),
    linear-gradient(160deg, color-mix(in srgb, var(--el) 55%, #111), #0c0c18);
}
.portrait > img { object-fit: cover; opacity: 0; }
.portrait > img.ok { opacity: 1; }
.pt-el, .pt-troop {
  position: absolute; display: block; line-height: 0;
  width: calc(var(--size) * .34); height: calc(var(--size) * .34); min-width: 18px; min-height: 18px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .7));
}
.pt-el { top: -5px; left: -5px; }
.pt-troop { bottom: -5px; right: -5px; }
.pt-el .ico, .pt-troop .ico { width: 100%; height: 100%; }
.portrait.sm .pt-troop { display: none; }
.portrait.sm .pt-el { min-width: 15px; min-height: 15px; top: -4px; left: -4px; }

/* アイコン共通 */
.ico { display: inline-block; width: 1.25em; height: 1.25em; vertical-align: -.3em; flex: none; }
.ico-troop { color: #f1e2b8; }
.chip .ico, .train-attr .ico { margin-right: 3px; }
.chip .ico-el { width: 1.35em; height: 1.35em; margin-left: -6px; }

/* ---------- 一覧 ---------- */
.roster { align-self: start; position: sticky; top: calc(var(--topbar-h, 64px) + var(--ov-h, 0px) + 12px); max-height: calc(100vh - var(--topbar-h, 64px) - var(--ov-h, 0px) - 24px); display: flex; flex-direction: column; }
.filters { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.filters input[type=search] { width: 100%; }
.filter-row { display: flex; gap: 6px; }
.filter-row select { flex: 1; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex; align-items: center;
  font-size: .74rem; padding: 3px 10px; border-radius: 12px;
  border: 1px solid var(--panel-edge); background: rgba(0, 0, 0, .3); color: var(--muted);
}
.chip.on { color: #1b1206; background: var(--gold); border-color: var(--gold); font-weight: 700; }
.chip.on[style] { background: color-mix(in srgb, var(--el) 30%, #1a1626); border-color: var(--el); color: var(--text); }
.chip.on .ico-troop { color: #1b1206; }

.char-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px;
  overflow-y: auto; padding: 6px 4px 4px; margin: 0 -4px;
  scrollbar-color: var(--gold-dim) transparent;
}
.char {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px 6px; border-radius: 8px; border: 1px solid transparent; background: rgba(0, 0, 0, .2);
  transition: transform .1s, border-color .15s, background .15s;
}
.char:hover { transform: translateY(-2px); border-color: var(--gold-dim); background: rgba(230, 194, 122, .06); }
.char.used { opacity: .5; }
.char.here { opacity: 1; border-color: var(--ember); }
.char-name { font-size: .68rem; line-height: 1.2; text-align: center; word-break: keep-all; overflow-wrap: anywhere; }
.char-used {
  position: absolute; top: 4px; right: 4px; font-size: .6rem; font-weight: 900; padding: 0 4px; border-radius: 3px;
  background: var(--ember); color: #2a1206;
}
.char-match { position: absolute; top: 2px; right: 6px; font-size: .6rem; letter-spacing: -1px; color: var(--muted); }
.char-match.m2 { color: var(--ember); }
.char-match.m3 { color: var(--gold); text-shadow: 0 0 6px var(--gold); }
.char.used .char-match { display: none; }
.empty-msg { grid-column: 1 / -1; text-align: center; padding: 20px; }

.footer { position: relative; z-index: 1; text-align: center; font-size: .7rem; color: var(--muted); padding: 10px 20px 30px; line-height: 1.7; }

/* ---------- ダイアログ・トースト ---------- */
.dialog {
  max-width: 560px; width: calc(100% - 32px); color: var(--text);
  background: #151a2e; border: 1px solid var(--gold-dim); border-radius: 12px; padding: 20px;
}
.dialog::backdrop { background: rgba(0, 0, 0, .65); }
.dialog h3 { margin: 0 0 8px; color: var(--gold); }
.dialog p, .dialog li { font-size: .85rem; line-height: 1.6; }
.dialog ol { padding-left: 1.2em; }
.dialog-actions { display: flex; justify-content: space-between; margin-top: 14px; }
.id-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 2px 10px; font-size: .75rem; max-height: 220px; overflow: auto; margin-top: 6px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); z-index: 50;
  background: #2a2116; border: 1px solid var(--gold); color: #ffe7b5; padding: 8px 16px; border-radius: 6px;
  font-size: .85rem; opacity: 0; pointer-events: none; transition: .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- レスポンシブ ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px 24px; }
  .roster { position: static; max-height: none; }
  .char-grid { max-height: 70vh; }
  .topbar { position: static; padding: 10px 16px; }
}
@media (max-width: 560px) {
  .slots { grid-template-columns: 1fr; }
  .bonus-link { flex-direction: row; flex-wrap: wrap; min-width: 0; }
  .bl-idle { writing-mode: horizontal-tb; }
  .slot { min-height: 112px; }
  .portrait.lg { --size: 76px; }
  .troop-row { grid-template-columns: 24px 1fr 70px 76px; }
  .troop-row .range { grid-column: 1 / -1; grid-row: 2; }
  .tab-name { display: none; }
  .tab { justify-content: center; }
  .overview-grid { grid-template-columns: repeat(2, 1fr); }
  .stat.big { grid-column: 1 / -1; }
  .squad-name { width: 100%; }
  .field input { width: 70px; }
  .char-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
  .char .portrait { --size: 56px; }
}

/* ---------- 育成・スキル ---------- */
.slot { padding-bottom: 30px; }
.slot-lv { font-size: .66rem; color: var(--gold); margin-top: 2px; }
.slot-lv.unowned { color: var(--warn); }
.slot-btns { position: absolute; bottom: 6px; right: 8px; display: flex; gap: 4px; }
.slot-btn {
  font-size: .66rem; padding: 1px 7px; border-radius: 3px;
  border: 1px solid var(--panel-edge); color: var(--muted); background: rgba(0, 0, 0, .4);
}
.slot-btn:hover { color: var(--gold); border-color: var(--gold-dim); }
.slot-btn[data-train] { color: var(--gold); border-color: var(--gold-dim); }

.ctx { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.ctx select { font-size: .82rem; padding: 5px 6px; }
.ctx select[hidden] { display: none; }
.ctx-label { font-size: .75rem; color: var(--muted); }
.ctx .field input { width: 56px; }
.small-note { font-size: .72rem; margin: 4px 0 8px; }
.stat.score .stat-value { color: var(--ember); text-shadow: 0 0 12px var(--ember-glow); }

.breakdown details { margin-top: 10px; }
.breakdown summary, .reco-result summary, #recoResult summary { cursor: pointer; font-size: .8rem; color: var(--gold); }
.fx { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 3px; }
.fx li { font-size: .74rem; padding: 3px 8px; border-radius: 4px; background: rgba(0, 0, 0, .22); }
.fx li b { color: var(--text); }
.fx.on li { border-left: 2px solid var(--good); }
.fx.off li { color: var(--muted); border-left: 2px solid var(--panel-edge); }

/* おすすめ */
.reco-list { display: grid; gap: 6px; margin-top: 6px; }
.reco-card {
  display: grid; grid-template-columns: 28px auto 1fr auto auto; gap: 10px; align-items: center;
  padding: 8px 10px; border-radius: 8px; background: rgba(0, 0, 0, .28); border: 1px solid var(--panel-edge);
}
.reco-rank { font-family: 'Cinzel', serif; font-weight: 800; color: var(--gold); text-align: center; font-size: 1.1rem; }
.reco-pics { display: flex; gap: 4px; }
.reco-body { min-width: 0; }
.reco-names { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reco-meta { font-size: .68rem; color: var(--muted); display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.reco-meta .ico { width: 1.1em; height: 1.1em; }
.reco-fx { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; }
.reco-fx i { font-style: normal; font-size: .62rem; padding: 1px 5px; border-radius: 3px; background: rgba(99, 224, 160, .12); color: var(--good); }
.reco-score { text-align: right; font-family: 'Cinzel', serif; font-weight: 800; font-size: 1.15rem; color: var(--ember); }
.reco-score small { display: block; font-family: inherit; font-size: .6rem; color: var(--muted); font-weight: 400; }
.reco-actions { display: flex; justify-content: flex-end; margin: 8px 0; }

/* 一覧: モード・育成 */
.mode-switch { display: inline-flex; border: 1px solid var(--gold-dim); border-radius: 6px; overflow: hidden; }
.mode-btn { border: 0; background: transparent; color: var(--muted); font-size: .78rem; padding: 5px 12px; }
.mode-btn.on { background: linear-gradient(180deg, #4a3a24, #2a2116); color: #ffe7b5; font-weight: 700; }
.roster-sub { display: flex; justify-content: space-between; margin: -4px 0 8px; }
.train-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 8px; padding: 8px; border-radius: 6px; background: rgba(230, 194, 122, .06); border: 1px dashed var(--gold-dim); }
.train-tools[hidden] { display: none; }
.train-tools .spacer { flex: 1; }
.train-tools .small-note { flex-basis: 100%; margin: 0; }
.char.unowned .portrait { filter: grayscale(.9) brightness(.55); }
.char.unowned .char-name { color: var(--muted); }
.char-unowned { position: absolute; top: 30px; left: 50%; transform: translateX(-50%); font-size: .6rem; padding: 0 5px; border-radius: 3px; background: rgba(0, 0, 0, .75); color: var(--muted); }
.char-lv { font-size: .62rem; color: var(--gold); font-family: 'Cinzel', serif; letter-spacing: .02em; }
.char-grid.training .char { border-color: rgba(230, 194, 122, .18); }

/* 育成ダイアログ */
.train-dialog { max-width: 620px; }
.train-head { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.train-name { font-size: 1.2rem; font-weight: 900; }
.train-attr { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; margin-top: 2px; }
.train-attr .ico { width: 1.4em; height: 1.4em; }
.own-toggle { display: inline-flex; gap: 6px; align-items: center; margin-top: 6px; font-size: .85rem; }
.train-row { padding: 8px 10px; border-radius: 6px; background: rgba(0, 0, 0, .25); margin-bottom: 6px; border-left: 3px solid var(--gold-dim); }
.train-row.locked { opacity: .55; }
.train-skill { display: flex; align-items: center; gap: 8px; }
.train-skill b { flex: 1; font-size: .9rem; }
.train-skill select { padding: 3px 6px; }
.sk-kind { font-size: .66rem; padding: 1px 6px; border-radius: 3px; background: #2d2a52; color: #cfc6ff; white-space: nowrap; }
.sk-kind.charge { background: #5a2d14; color: #ffd3a8; }
.sk-desc { font-size: .75rem; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.sk-fx { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.sk-fx i { font-style: normal; font-size: .7rem; padding: 1px 6px; border-radius: 3px; background: rgba(230, 194, 122, .12); color: var(--gold); }
.train-quick { display: flex; gap: 6px; justify-content: flex-end; }

@media (max-width: 560px) {
  .reco-card { grid-template-columns: 22px auto 1fr; }
  .reco-score { grid-column: 2 / 3; text-align: left; }
  .reco-card .btn { grid-column: 3 / 4; justify-self: end; }
  .mode-btn { padding: 5px 8px; }
}

/* 兵士(リーダー兵種で全兵出撃) */
.troops-head .muted { font-size: .72rem; }
.troop-line {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px;
  background: linear-gradient(90deg, rgba(230, 194, 122, .1), rgba(0, 0, 0, .2)); border: 1px solid rgba(230, 194, 122, .35);
}
.troop-line .troop-icon .ico { width: 26px; height: 26px; }
.troop-main { flex: 1; font-size: .9rem; }
.troop-main b { color: var(--gold); margin-right: 4px; }
.troop-line .tier { padding: 4px 6px; font-size: .8rem; }
.cmd-pick { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; font-size: .75rem; }
.cmd-pick .chip.on .ico-troop { color: #1b1206; }

.slot-plus { display: grid; place-items: center; color: var(--gold-dim); font-size: 1.4rem; font-weight: 900; }
@media (max-width: 560px) { .slot-plus { font-size: 1rem; line-height: 1; } }

/* プレイヤー管理 */
.field.player select { max-width: 9em; }
.profile-list { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 4px; }
.profile-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; background: rgba(0, 0, 0, .25); border: 1px solid var(--panel-edge); }
.profile-list li.on { border-color: var(--gold); }
.pf-name { font-weight: 700; }
.pf-btns { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.pf-add { display: flex; gap: 6px; margin: 6px 0 10px; }
.pf-add input { flex: 1; min-width: 0; background: rgba(0, 0, 0, .35); border: 1px solid var(--panel-edge); border-radius: 6px; padding: 6px 8px; }
.dialog h4 { margin: 12px 0 2px; color: var(--gold); font-size: .9rem; }

/* 育成アドバイス */
.advice { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 10px 0; }
.advice h4 { margin: 0; font-size: .85rem; color: var(--gold); }
.adv-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.adv-list li { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; padding: 5px 8px; border-radius: 6px; background: rgba(0, 0, 0, .25); font-size: .78rem; }
.adv-list small { color: var(--muted); font-size: .68rem; }
.adv-gain { font-family: 'Cinzel', serif; font-weight: 800; color: var(--good); }
@media (max-width: 700px) { .advice { grid-template-columns: 1fr; } }

/* ===== 3人編成・5部隊 ===== */
.squad-tabs { grid-template-columns: repeat(5, 1fr); }
.overview-grid { grid-template-columns: repeat(5, 1fr); }
.ov-pics { gap: 2px; }
.ov-pics .portrait.sm { --size: 34px; }
.ov-fx { font-size: .6rem; color: var(--good); text-align: center; line-height: 1.3; }
.ov-meta { display: flex; align-items: center; gap: 2px; }

.slots { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.slot {
  flex-direction: column; align-items: center; text-align: center; gap: 8px;
  min-height: 220px; padding: 22px 8px 34px;
}
.slot .slot-info { align-items: center; width: 100%; }
.slot .slot-tags { justify-content: center; }
.slot .slot-name { max-width: 100%; }
.slot[data-slot=third] .slot-label { background: linear-gradient(90deg, #1f3d4f, #2f6b80); border-color: #6fb5cc; }
.slot-btns { left: 0; right: 0; justify-content: center; }

/* 属性(左上)・得意兵種(その下) ― ゲーム内カードの配置 */
.pt-el { top: -4px; left: -4px; }
.pt-troop { top: calc(var(--size) * .3); left: -4px; bottom: auto; right: auto; }
.portrait.sm .pt-troop { display: block; top: calc(var(--size) * .34); width: 15px; height: 15px; min-width: 15px; min-height: 15px; }

/* タイトル: 白いセリフ体に残り火の赤 */
.brand-en {
  background: linear-gradient(180deg, #ffffff, #f3e9e4 55%, #d9c3bb);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 0 6px rgba(255, 70, 30, .55)) drop-shadow(0 1px 0 #3a0d06);
  letter-spacing: .14em;
}
.brand-en::first-letter { font-size: 1.25em; }

/* ===== 部隊の効果 ===== */
.analysis h4 { margin: 4px 0 8px; font-size: .85rem; color: var(--gold); display: flex; align-items: center; gap: 4px; }
.ch-list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 12px; }
.ch-card { padding: 8px; border-radius: 6px; background: rgba(0, 0, 0, .28); border-left: 3px solid #b5622a; min-width: 0; }
.ch-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .8rem; }
.ch-head .muted { font-size: .66rem; }
.ch-main { font-size: .75rem; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.ch-main b { color: var(--gold); }
.ch-target { font-size: .62rem; padding: 0 6px; border-radius: 8px; border: 1px solid var(--panel-edge); color: var(--muted); }
.ch-target.aoe { border-color: var(--ember); color: var(--ember); }
.fx-group { margin-bottom: 8px; }
.fx-gname { font-size: .66rem; color: var(--muted); letter-spacing: .1em; margin-bottom: 3px; }
.fx-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; align-items: baseline;
  padding: 5px 8px; border-radius: 4px; background: rgba(0, 0, 0, .22); margin-bottom: 3px; border-left: 2px solid var(--good);
}
.fx-row.focus { background: rgba(255, 122, 61, .14); border-left-color: var(--ember); }
.fx-row.invalid { border-left-color: var(--panel-edge); opacity: .7; }
.fx-name { font-size: .8rem; font-weight: 700; }
.fx-val { font-family: 'Cinzel', serif; font-weight: 800; color: var(--good); text-align: right; }
.fx-row.focus .fx-val { color: var(--ember); }
.fx-row.invalid .fx-val { color: var(--muted); text-decoration: line-through; }
.fx-parts { grid-column: 1 / -1; font-size: .66rem; color: var(--muted); line-height: 1.5; }
.fx-parts em { color: var(--warn); font-style: normal; }
.analysis details summary { cursor: pointer; font-size: .8rem; color: var(--gold); margin: 6px 0; }

/* ===== おすすめ検索 ===== */
.reco-form { display: grid; gap: 8px; margin-bottom: 6px; }
.rf-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.rf-label { font-size: .75rem; color: var(--muted); min-width: 9em; }
.rf-row select { font-size: .82rem; padding: 5px 6px; max-width: 100%; }
.rf-row .chips { flex-basis: 100%; padding-left: 9.4em; }
.rf-row .field input { width: 52px; }
.reco-card { grid-template-columns: 26px auto minmax(0, 1fr) auto; }
.reco-pics .portrait.sm { --size: 40px; }
.reco-fx i.zero { background: rgba(255, 255, 255, .05); color: var(--muted); }
.reco-ch { display: flex; flex-wrap: wrap; gap: 2px 10px; margin-top: 3px; font-size: .64rem; color: var(--muted); }
.reco-ch b { color: #ffd3a8; }
.adv-gain { font-size: .72rem; text-align: right; }

@media (max-width: 900px) {
  .overview-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 560px) {
  .slots { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .slot { min-height: 0; padding: 18px 4px 30px; }
  .slot .portrait.lg { --size: 64px; }
  .slot .slot-tags, .slot .slot-meta { display: none; }
  .slot .slot-name { font-size: .78rem; white-space: normal; }
  .slot .slot-lv { font-size: .58rem; }
  .ch-list { grid-template-columns: 1fr; }
  .rf-label { min-width: 0; flex-basis: 100%; }
  .rf-row .chips { padding-left: 0; }
  .overview-grid { grid-template-columns: repeat(2, 1fr); }
  .reco-card { grid-template-columns: 22px minmax(0, 1fr); }
  .reco-card .reco-pics { grid-column: 2; }
  .reco-card .reco-body { grid-column: 1 / -1; }
  .reco-card .btn { grid-column: 1 / -1; justify-self: end; }
}
.reco-form { grid-template-columns: minmax(0, 1fr); }
.rf-row select { min-width: 0; }

/* 兵種マーク(画像＋SVGフォールバック) */
.ico-mark { position: relative; display: inline-block; }
.ico-mark > svg, .ico-mark > img { position: absolute; inset: 0; width: 100%; height: 100%; }
.ico-mark > img { object-fit: contain; }
.chip .ico-mark { width: 1.45em; height: 1.45em; margin-left: -6px; margin-right: 4px; }
.troop-icon .ico-mark { width: 28px; height: 28px; }
.reco-meta .ico-mark, .ov-meta .ico-mark, .analysis h4 .ico-mark { width: 1.3em; height: 1.3em; margin-right: 2px; }
.cmd-pick .chip.on .ico-mark, .chip.on .ico-mark { filter: none; }
.chip .ico-el.ico-mark { width: 1.45em; height: 1.45em; margin-left: -6px; margin-right: 4px; }
.train-attr .ico-mark { width: 1.4em; height: 1.4em; }
.ico-mark > svg { margin: 0 !important; }

/* ===== 全部隊(最上部) ===== */
.panel.overview { grid-column: 1 / -1; }
.overview-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.ov { align-items: stretch; gap: 6px; padding: 8px; text-align: left; }
.ov:hover { border-color: var(--gold-dim); }
.ov-head { display: flex; align-items: center; gap: 6px; min-width: 0; }
.ov-head .tab-no { width: 22px; height: 22px; font-size: .8rem; }
.ov.on .tab-no { background: var(--ember); color: #2a1206; }
.ov-head .ov-name { flex: 1; min-width: 0; font-size: .82rem; }
.ov-head .ov-meta { font-size: .66rem; white-space: nowrap; }
.ov-pics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.ov-mem { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0; }
.ov-mem small { font-size: .58rem; color: var(--muted); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ov-pics .portrait.sm { --size: 42px; }
.ov-fxs { display: flex; flex-wrap: wrap; gap: 2px 6px; justify-content: center; }
@media (max-width: 900px) {
  .overview-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .overview-grid { display: flex; overflow-x: auto; gap: 8px; scroll-snap-type: x mandatory; padding-bottom: 4px; }
  .ov { flex: 0 0 72%; scroll-snap-align: start; }
}

/* エンバース詳細 */
.sk-kind.active { background: #1f4a3a; color: #b8f0d4; }
.sk-kind.core { background: #4a3a1f; color: #ffe2a8; }
.train-skill .muted { font-size: .7rem; }
.sk-text { margin-top: 4px; }
.sk-text summary { cursor: pointer; font-size: .7rem; color: var(--gold-dim); }
.sk-text p { margin: 4px 0 0; font-size: .74rem; line-height: 1.6; color: var(--text); background: rgba(0, 0, 0, .25); padding: 6px 8px; border-radius: 4px; }
.core-list { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 2px; }
.core-list li { font-size: .72rem; color: var(--muted); }
.core-list b { display: inline-block; width: 1.6em; color: var(--gold); }
.load-error { grid-column: 1 / -1; padding: 12px; border: 1px solid var(--bad); border-radius: 8px; color: var(--bad); background: rgba(255, 107, 107, .08); }

/* モーダルの閉じるボタン(右上固定・本文のみスクロール) */
.dialog[open] { display: flex; flex-direction: column; max-height: min(90vh, 900px); overflow: hidden; padding: 48px 0 0; }
.dialog[open]::before { content: ''; position: absolute; left: 0; right: 0; top: 47px; border-top: 1px solid var(--panel-edge); }
.dialog > form { overflow-y: auto; padding: 14px 20px 20px; }
.dlg-close {
  position: absolute; top: 7px; right: 10px; z-index: 5;
  width: 34px; height: 34px; padding: 0;
  display: grid; place-items: center; line-height: 1;
  font-size: 1.3rem; color: var(--muted);
  background: rgba(21, 26, 46, .92); border: 1px solid var(--panel-edge); border-radius: 50%;
}
.dlg-close:hover { color: var(--gold); border-color: var(--gold-dim); }

/* 長押しで詳細 */
.char, .slot, .portrait, .portrait img { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; -webkit-user-drag: none; }
.char.pressing .portrait, .portrait.pressing, .slot.pressing .portrait {
  transform: scale(.94);
  box-shadow: 0 0 0 2px var(--gold), 0 0 18px var(--ember-glow);
  transition: transform .9s ease-out, box-shadow .9s ease-out;
}
.train-quick { align-items: center; }
.train-quick .spacer { flex: 1; }

/* 枠の入れ替え(ドラッグ) */
.slot.filled { cursor: grab; -webkit-user-drag: element; }
.slot.dragging { opacity: .45; }
.slot.drop-over { border-color: var(--ember); box-shadow: 0 0 0 2px var(--ember), 0 0 22px var(--ember-glow); }

/* チャージ連携 */
.timeline { display: flex; align-items: stretch; gap: 4px; margin-bottom: 8px; }
.tl-node { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 6px 8px; border-radius: 6px; background: rgba(0, 0, 0, .28); border-top: 2px solid var(--panel-edge); font-size: .72rem; }
.tl-node.boosted { border-top-color: var(--ember); background: rgba(255, 122, 61, .1); }
.tl-node.empty { opacity: .5; }
.tl-t { font-family: 'Cinzel', serif; font-weight: 800; color: var(--gold); font-size: .7rem; }
.tl-who { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tl-who b { color: #ffd3a8; margin-right: 2px; }
.tl-pw em { font-style: normal; color: var(--ember); font-weight: 800; }
.tl-pw small { color: var(--muted); font-size: .6rem; }
.tl-fx { display: flex; flex-wrap: wrap; gap: 2px; }
.tl-fx i { font-style: normal; font-size: .6rem; padding: 0 4px; border-radius: 3px; background: rgba(255, 255, 255, .06); color: var(--muted); }
.tl-fx i.amp { background: rgba(255, 122, 61, .15); color: var(--ember); }
.tl-arrow { align-self: center; color: var(--gold-dim); }
.chain-sum { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .78rem; margin: 6px 0; }
.chain-sum b { font-family: 'Cinzel', serif; font-size: 1.05rem; color: var(--ember); margin: 0 4px; }
.chain-sum small { color: var(--muted); font-size: .64rem; }
.reco-syn { display: flex; flex-wrap: wrap; gap: 2px 8px; margin-top: 3px; font-size: .64rem; color: var(--muted); align-items: center; }
.reco-syn b { color: var(--ember); }
.reco-syn i { font-style: normal; padding: 0 5px; border-radius: 3px; background: rgba(255, 122, 61, .12); color: var(--ember); }
@media (max-width: 560px) {
  .timeline { flex-direction: column; }
  .tl-arrow { transform: rotate(90deg); }
}
.tl-eff { font-size: .68rem; color: var(--muted); }
.tl-eff b { color: var(--ember); font-family: 'Cinzel', serif; }

/* 選定理由 */
.reason { margin-top: 4px; font-size: .68rem; }
.reason summary { cursor: pointer; color: var(--gold); }
.reason ol { margin: 4px 0 2px; padding-left: 1.4em; display: grid; gap: 2px; }
.reason li b { color: #ffd3a8; margin-right: 4px; }
.reason p { margin: 2px 0 0; font-size: .62rem; }
.rf-row #recoCount { width: 64px; background: rgba(0, 0, 0, .35); border: 1px solid var(--panel-edge); border-radius: 6px; padding: 5px 8px; }
.rf-hint { font-size: .66rem; }
/* 見出し幅をそろえる */
.rf-label { width: 9.5rem; min-width: 0; flex: none; }
.rf-row .chips { padding-left: calc(9.5rem + 6px); }
@media (max-width: 560px) {
  .rf-label { width: auto; flex-basis: 100%; }
  .rf-row .chips { padding-left: 0; }
}

/* 部隊の効果: 開閉 */
.collapse-head { width: 100%; background: none; border: 0; padding: 0; margin: 0; text-align: left; cursor: pointer; color: inherit; flex-wrap: nowrap; }
.analysis:not(.collapsed) .collapse-head { margin-bottom: 8px; }
.collapse-head h3 { flex: none; }
.analysis-summary { flex: 1; min-width: 0; text-align: right; display: flex; justify-content: flex-end; align-items: center; gap: 2px; flex-wrap: wrap; font-size: .74rem; }
.analysis-summary b { color: var(--ember); font-family: 'Cinzel', serif; }
.analysis-summary .ico-mark { width: 1.3em; height: 1.3em; }
.collapse-icon { flex: none; color: var(--gold); transition: transform .2s; font-size: .9rem; }
.analysis:not(.collapsed) .collapse-icon { transform: rotate(180deg); }
.analysis.collapsed { padding-top: 12px; padding-bottom: 12px; }
.collapse-head:hover h3 { color: #ffe7b5; }
@media (max-width: 560px) {
  .collapse-head { flex-wrap: wrap; }
  .analysis-summary { flex-basis: 100%; order: 3; justify-content: flex-start; text-align: left; }
}

/* 配置中バッジ: [部隊番号]枠名 */
.char-used { display: inline-flex; align-items: center; gap: 2px; padding: 0 4px 0 1px; line-height: 1.5; }
.char-used b { display: inline-grid; place-items: center; min-width: 1.3em; height: 1.3em; border-radius: 50%; background: #2a1206; color: #ffd3a8; font-size: .58rem; }

/* ===== 全部隊: 上部に固定 ===== */
.ov-sentinel { grid-column: 1 / -1; height: 1px; margin-bottom: -1px; }
.panel.overview { position: sticky; top: var(--topbar-h, 64px); z-index: 8; transition: padding .15s; }
.panel.overview.compact { padding: 6px 12px; background: rgba(14, 17, 33, .97); box-shadow: 0 8px 20px rgba(0, 0, 0, .5); }
.overview.compact .panel-head, .overview.compact .ov-mem small, .overview.compact .ov-fxs { display: none; }
.overview.compact .overview-grid { gap: 6px; }
.overview.compact .ov { flex-direction: row; align-items: center; padding: 4px 6px; gap: 6px; }
.overview.compact .ov-head { flex: none; flex-direction: column; gap: 0; }
.overview.compact .ov-head .ov-name { display: none; }
.overview.compact .ov-head .ov-meta { font-size: 0; }
.overview.compact .ov-head .ov-meta .ico-mark { width: 16px; height: 16px; }
.overview.compact .ov-pics { flex: 1; gap: 2px; }
.overview.compact .ov-pics .portrait.sm { --size: 30px; }
.overview.compact .ov-pics .portrait.sm .pt-el, .overview.compact .ov-pics .portrait.sm .pt-troop { display: none; }
.overview.compact::before, .overview.compact::after { display: none; }
@media (max-width: 900px) {
  .roster { position: static; max-height: none; }
}
@media (max-width: 560px) {
  .overview.compact .ov { flex: 0 0 46%; }
}

.squad-panel .panel-head { flex-wrap: nowrap; }
.squad-panel .squad-name { flex: 1; min-width: 0; }
#btnResetSquad { flex: none; }

/* 全部隊カードのリセット(×) */
.ov { position: relative; }
.ov-reset {
  position: absolute; top: 4px; right: 4px; z-index: 2;
  width: 20px; height: 20px; display: grid; place-items: center; border-radius: 50%;
  font-size: .8rem; line-height: 1; color: var(--muted);
  background: rgba(0, 0, 0, .55); border: 1px solid var(--panel-edge);
}
.ov-reset:hover, .ov-reset:focus-visible { color: var(--bad); border-color: var(--bad); }
.ov-head { padding-right: 22px; }
.overview.compact .ov-reset { top: 2px; right: 2px; width: 16px; height: 16px; font-size: .65rem; }
.overview.compact .ov-head { padding-right: 0; }

/* 確認・入力モーダル */
.dialog.ask-dialog[open] { padding: 0; max-width: 420px; }
.ask-body { padding: 20px 22px 18px; overflow-y: auto; }
.ask-body h3 { margin: 0 0 8px; color: var(--gold); font-size: 1rem; }
.ask-body p { margin: 0 0 14px; font-size: .86rem; line-height: 1.7; }
.ask-body input, .ask-body textarea {
  width: 100%; margin-bottom: 14px; background: rgba(0, 0, 0, .35); color: var(--text);
  border: 1px solid var(--panel-edge); border-radius: 6px; padding: 8px 10px; font: inherit; font-size: .85rem;
}
.ask-body textarea { resize: vertical; font-size: .72rem; word-break: break-all; }
.ask-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.btn.danger { background: linear-gradient(180deg, #7a2323, #4a1414); border-color: #c45050; color: #ffd6d6; }
.dialog.ask-dialog[open]::before { display: none; }

/* 使い方 */
.help-btn { background: linear-gradient(180deg, #24406e, #172a4a); border-color: #4f7fe0; color: #d6e6ff; }
.help-dialog { max-width: 760px; }
.help-dialog h3 { margin: 0 0 10px; color: var(--gold); font-size: 1.2rem; }
.help-toc { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 12px; margin-bottom: 8px; border-bottom: 1px solid var(--panel-edge); }
.help-toc a { font-size: .74rem; padding: 3px 10px; border-radius: 12px; border: 1px solid var(--panel-edge); color: var(--text); text-decoration: none; background: rgba(0, 0, 0, .25); }
.help-toc a:hover { border-color: var(--gold-dim); color: var(--gold); }
.help-dialog section { padding: 10px 0 6px; scroll-margin-top: 8px; }
.help-dialog section + section { border-top: 1px dashed rgba(255, 255, 255, .08); }
.help-dialog h4 { margin: 0 0 6px; color: var(--gold); font-size: .95rem; display: flex; align-items: center; gap: 6px; }
.help-dialog h4::before { content: '◆'; font-size: .55rem; color: var(--ember); }
.help-dialog p, .help-dialog li, .help-dialog td, .help-dialog th { font-size: .8rem; line-height: 1.75; }
.help-dialog ul, .help-dialog ol { margin: 4px 0; padding-left: 1.3em; }
.help-dialog li + li { margin-top: 2px; }
.help-dialog b { color: #ffe7b5; }
.help-steps li::marker { color: var(--ember); font-weight: 800; }
.help-table { width: 100%; border-collapse: collapse; margin: 6px 0; }
.help-table th, .help-table td { text-align: left; vertical-align: top; padding: 6px 8px; border-bottom: 1px solid rgba(255, 255, 255, .06); }
.help-table th { width: 9.5em; color: #ffd3a8; font-weight: 700; white-space: nowrap; background: rgba(0, 0, 0, .2); }
@media (max-width: 560px) {
  .help-table th, .help-table td { display: block; width: auto; }
  .help-table th { border-bottom: 0; padding-bottom: 0; }
}

/* =============================================================
 *  レスポンシブ: スマホはタブ切り替えのアプリ型UI
 * ============================================================= */
.menu-btn, .mobile-nav, .filters-toggle { display: none; }
.pick-banner[hidden] { display: none; }
.topbar .field.player { margin-left: auto; }
.search-row { display: flex; gap: 6px; }
.search-row input { flex: 1; min-width: 0; }

@media (max-width: 900px) {
  /* --- ヘッダー: 1行 + ☰ --- */
  .topbar {
    position: sticky; top: 0; z-index: 20; flex-wrap: nowrap; gap: 8px;
    padding: calc(8px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left));
  }
  .brand { min-width: 0; }
  .brand-en { font-size: 1rem; letter-spacing: .12em; white-space: nowrap; }
  .brand-ja { display: none; }
  .topbar .field.player { margin-left: auto; flex: none; }
  .player-label { display: none; }
  .topbar .field.player select { max-width: 7.5em; padding: 6px 8px; }
  .menu-btn {
    display: inline-flex; flex-direction: column; justify-content: center; gap: 4px; flex: none;
    width: 42px; height: 42px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--panel-edge); background: rgba(255, 255, 255, .06);
  }
  .menu-btn span { display: block; height: 2px; border-radius: 2px; background: currentColor; color: var(--text); transition: transform .2s, opacity .2s; }
  .menu-open .menu-btn span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
  .menu-open .menu-btn span:nth-child(2) { opacity: 0; }
  .menu-open .menu-btn span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }
  .top-actions {
    display: none; position: absolute; left: 0; right: 0; top: 100%;
    flex-direction: column; align-items: stretch; gap: 8px;
    padding: 12px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left));
    background: var(--bg2, #121628); border-bottom: 1px solid var(--panel-edge); box-shadow: 0 16px 32px rgba(0, 0, 0, .25);
  }
  .menu-open .top-actions { display: flex; background: rgba(255, 252, 254, .99); }
  .top-actions .btn { width: 100%; min-height: 46px; font-size: .95rem; }

  /* --- 下部タブバー --- */
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .mobile-nav {
    display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: 4px max(8px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    background: rgba(14, 17, 33, .96); border-top: 1px solid var(--panel-edge); backdrop-filter: blur(12px);
  }
  .mobile-nav button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 54px; border: 0; background: none; color: var(--muted); font-size: .68rem; border-radius: 10px;
  }
  .mobile-nav svg { width: 24px; height: 24px; fill: currentColor; }
  .mobile-nav button.on { color: var(--ember); }
  .mobile-nav button.on svg { filter: drop-shadow(0 0 6px var(--ember-glow)); }

  /* --- タブごとの表示切り替え --- */
  body[data-view] [data-mview] { display: none !important; }
  body[data-view] [data-mview=all], body[data-view=squad] [data-mview=squad], body[data-view=reco] [data-mview=reco], body[data-view=roster] [data-mview=roster] { display: block !important; }
  body[data-view=roster] .roster { display: flex !important; }
  .layout { padding: 12px max(12px, env(safe-area-inset-right)) 16px max(12px, env(safe-area-inset-left)); gap: 12px; }
  .formation { gap: 12px; }
  .footer { display: none; }

  /* --- エンバース一覧: ページ全体でスクロール --- */
  .roster { position: static; max-height: none; }
  .char-grid { max-height: none; overflow: visible; }
  .filters-toggle {
    display: inline-flex; align-items: center; gap: 6px; flex: none; padding: 0 14px; min-height: 44px;
    border-radius: 8px; border: 1px solid var(--panel-edge); background: rgba(255, 255, 255, .06); color: var(--text); font-size: .85rem;
  }
  .filters-toggle::after { content: '▾'; color: var(--gold); transition: transform .2s; }
  .show-filters .filters-toggle::after { transform: rotate(180deg); }
  .filter-count:not(:empty) { display: inline-grid; place-items: center; min-width: 20px; height: 20px; border-radius: 10px; background: var(--ember); color: #fff; font-size: .7rem; padding: 0 5px; }
  .roster:not(.show-filters) .filters-more { display: none; }
  .filters-more { display: flex; flex-direction: column; gap: 8px; }

  /* キャラ選択バー(枠をタップして選ぶとき) */
  .pick-banner {
    position: sticky; top: calc(var(--topbar-h, 58px) + var(--ov-h, 0px) + 6px); z-index: 7; margin: -4px -4px 10px;
    display: grid; grid-template-columns: 1fr auto; grid-template-areas: "info done" "slots slots"; gap: 8px; align-items: center;
    padding: 10px 12px; border-radius: 12px; background: var(--panel); border: 1px solid var(--ember); box-shadow: 0 8px 20px rgba(0, 0, 0, .25);
    backdrop-filter: blur(10px);
  }
  .pick-info { grid-area: info; display: flex; flex-direction: column; font-size: .8rem; }
  .pick-info b { color: var(--gold); font-size: .95rem; }
  #pickDone { grid-area: done; min-height: 40px; }
  .pick-slots { grid-area: slots; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .pick-slot { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 10px; border: 1px solid var(--panel-edge); background: rgba(255, 255, 255, .04); color: var(--text); min-height: 52px; }
  .pick-slot.on { border-color: var(--ember); box-shadow: 0 0 0 1px var(--ember); }
  .pick-slot small { font-size: .72rem; font-weight: 700; }
  .pick-slot .portrait.sm { --size: 36px; }

  /* --- 押しやすさ / iOSの自動ズーム防止(16px) --- */
  input, select, textarea { font-size: 16px !important; }
  select, input[type=number], input[type=search] { min-height: 44px; }
  .btn { min-height: 40px; }
  .btn.small { min-height: 36px; padding: 6px 12px; }
  .chip { min-height: 34px; padding: 4px 12px; font-size: .8rem; }
  .slot-btn { padding: 6px 10px; font-size: .74rem; }
  .slot-remove { width: 30px; height: 30px; }
  .ov-reset { width: 28px; height: 28px; font-size: .9rem; }
  .mode-btn { min-height: 40px; }
  .char { min-height: 96px; }
  .collapse-head { min-height: 44px; }
  .rf-row select { flex: 1; }

  /* トースト: タブバーの上に */
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); text-align: center; }
}

/* --- モーダル: スマホは全画面シート(×は常に押せる位置) --- */
@media (max-width: 600px) {
  .dialog[open]:not(.ask-dialog) {
    width: 100%; max-width: none; height: 100dvh; max-height: none; margin: 0; inset: 0;
    border: 0; border-radius: 0; padding-top: calc(56px + env(safe-area-inset-top));
  }
  .dialog[open]:not(.ask-dialog)::before { top: calc(55px + env(safe-area-inset-top)); }
  .dialog:not(.ask-dialog) .dlg-close {
    top: calc(8px + env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right));
    width: 42px; height: 42px; font-size: 1.5rem;
  }
  .dialog:not(.ask-dialog) > form { padding: 14px max(16px, env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  .dialog-actions .btn { min-height: 46px; padding: 0 22px; }
  .dialog.ask-dialog[open] { width: calc(100% - 32px); max-height: calc(100dvh - 48px); }
  .ask-actions .btn { min-height: 46px; flex: 1; }
}
.lv-short { display: none; }
@media (max-width: 560px) {
  .lv-full { display: none; }
  .lv-short { display: inline; }
  .rf-hint { flex-basis: 100%; }
  .rf-row #recoDecay { flex: 1; }
}
.help-mobile { padding: 8px 10px; border-radius: 8px; background: rgba(138, 106, 216, .1); }
/* キャラ選択バーをコンパクトに(全部隊の一覧と並ぶため) */
@media (max-width: 900px) {
  .pick-banner { padding: 6px 8px; gap: 6px; margin: -6px -6px 8px; }
  .pick-info { flex-direction: row; align-items: baseline; gap: 6px; font-size: .78rem; flex-wrap: wrap; }
  .pick-info b { font-size: .85rem; }
  #pickDone { min-height: 34px; padding: 4px 12px; font-size: .78rem; }
  .pick-slots { gap: 6px; }
  .pick-slot { min-height: 40px; padding: 3px 6px; gap: 6px; }
  .pick-slot .portrait.sm { --size: 30px; }
  .pick-slot .portrait.sm .pt-el, .pick-slot .portrait.sm .pt-troop { display: none; }
}

/* ヘッダーのボタン: 線画アイコン＋文字 */
.top-actions .btn { display: inline-flex; align-items: center; gap: 6px; }
.bi { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 900px) {
  .top-actions .btn { justify-content: flex-start; gap: 14px; padding: 0 20px; border-radius: 12px; font-weight: 700; }
  .top-actions .bi { width: 22px; height: 22px; }
}

/* 全部隊の見出し右: 説明＋すべてリセット */
.ov-head-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
#btnReset { display: inline-flex; align-items: center; gap: 5px; }
#btnReset .bi { width: 15px; height: 15px; }
@media (max-width: 900px) {
  .ov-head-right .muted { display: none; }
  /* ☰メニュー: 区切り線のあるリスト */
  .top-actions { gap: 0; padding-top: 4px; padding-bottom: 8px; }
  .top-actions .btn, .theme-dawn .top-actions .btn, .theme-dawn .top-actions .btn.help-btn {
    min-height: 54px; border: 0; border-bottom: 1px solid var(--line, rgba(255,255,255,.1)); border-radius: 0;
    background: transparent; box-shadow: none; padding: 0 6px; font-size: 1rem;
  }
  .top-actions .btn:last-child { border-bottom: 0; }
  .top-actions .btn::after { content: '›'; margin-left: auto; font-size: 1.3rem; color: var(--gold-dim); font-weight: 400; }
}

/* レアリティ表示は廃止: 枠は全キャラ共通の金 */
.portrait { background: var(--r5); box-shadow: 0 0 8px rgba(255, 200, 90, .25); }
.portrait.empty { box-shadow: none; }

/* ===== シーンから選ぶ ===== */
.scene-lead { margin: 0 0 10px; font-size: .85rem; line-height: 1.7; }
.scene-group + .scene-group { margin-top: 10px; }
.scene-gname { font-size: .7rem; color: var(--muted); letter-spacing: .15em; margin-bottom: 4px; }
.scene-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.scene-card {
  display: flex; flex-direction: column; gap: 3px; text-align: left; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--panel-edge); background: rgba(255, 255, 255, .05); color: var(--text); min-height: 64px;
  transition: border-color .15s, box-shadow .15s, transform .05s;
}
.scene-card b { font-size: .88rem; }
.scene-card span { font-size: .7rem; color: var(--muted); line-height: 1.5; }
.scene-card:hover { border-color: var(--ember); }
.scene-card:active { transform: translateY(1px); }
.scene-card.on { border-color: var(--ember); box-shadow: 0 0 0 1px var(--ember), 0 4px 14px var(--ember-glow); }
.scene-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; padding: 10px; border-radius: 10px; background: rgba(0, 0, 0, .12); }
.scene-sub .small-note { flex-basis: 100%; margin: 0; }
.scene-custom { margin-top: 8px; }
.reco-advanced { margin: 14px 0 6px; border-top: 1px dashed var(--panel-edge); padding-top: 10px; }
.reco-advanced > summary { cursor: pointer; font-size: .82rem; color: var(--gold); padding: 4px 0; }
.reco-advanced[open] > summary { margin-bottom: 10px; }
@media (max-width: 560px) {
  .scene-grid { grid-template-columns: 1fr 1fr; }
  .scene-card { min-height: 72px; padding: 10px; }
}

.reco-loading { padding: 18px; text-align: center; color: var(--muted); font-size: .85rem; animation: pulse 1s ease-in-out infinite alternate; }
@keyframes pulse { from { opacity: .45; } to { opacity: 1; } }
@media (max-width: 560px) {
  .scene-lead { font-size: .8rem; margin-bottom: 6px; }
  .scene-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .scene-card { min-height: 48px; padding: 8px; justify-content: center; text-align: center; }
  .scene-card b { font-size: .76rem; line-height: 1.35; }
  .scene-card span { display: none; }
  .scene-group + .scene-group { margin-top: 6px; }
}
.scene-desc { display: none; margin: 8px 0 0; font-size: .8rem; color: var(--muted); }
.scene-desc b { color: var(--gold); }
@media (max-width: 560px) { .scene-desc { display: block; } }
@media (max-width: 560px) {
  #sceneList { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  #sceneList .scene-group, #sceneList .scene-grid { display: contents; }
  #sceneList .scene-gname { display: none; }
  .scene-lead { display: none; }
}

/* 編成方針(セグメント) */
.strategy-box { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; flex: 1; min-width: 260px; }
.seg button { display: flex; flex-direction: column; gap: 2px; text-align: left; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--panel-edge); background: rgba(255,255,255,.05); color: var(--text); }
.seg button b { font-size: .84rem; }
.seg button small { font-size: .68rem; color: var(--muted); }
.seg button.on { border-color: var(--ember); box-shadow: 0 0 0 1px var(--ember); }
/* 総合スコアの内訳 */
.score-parts { list-style: none; padding: 0; margin: 4px 0 0; display: grid; gap: 3px; }
.score-parts li { display: grid; grid-template-columns: 70px auto 1fr; gap: 2px 8px; align-items: center; }
.score-parts li > :nth-child(n+4) { grid-column: 1 / -1; }
.sp-bar { height: 6px; border-radius: 3px; background: rgba(0,0,0,.12); overflow: hidden; }
.sp-bar i { display: block; height: 100%; background: linear-gradient(90deg, #9a7ee0, #e0906a); }
.score-parts small { color: var(--muted); }
@media (max-width: 560px) { .seg { min-width: 0; flex-basis: 100%; } .strategy-box .rf-label { flex-basis: 100%; } }
.score-parts .sp-detail { grid-column: 1 / -1; color: var(--muted); font-size: .64rem; line-height: 1.5; }
.exc-badge { font-size: .6rem; padding: 0 6px; border-radius: 8px; background: #f2b8a0; color: #5a2a12; margin-right: 4px; }
.scene-card .sz { font-style: normal; font-size: .62rem; font-weight: 700; margin-left: 6px; padding: 0 6px; border-radius: 8px; background: rgba(138,106,216,.14); color: #6a4fc0; vertical-align: 1px; }
.slot-note { font-style: normal; font-size: .64rem; color: var(--muted); }
.reco-fx i.role { background: rgba(194,135,31,.15); color: #8a6114; font-weight: 700; }
.scene-note { margin: 8px 0 0; }

.near-ties { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin-top: 4px; font-size: .66rem; color: var(--muted); }
.near-ties .chip { font-size: .66rem; min-height: 0; padding: 2px 8px; }
.near-ties .chip small { margin-left: 4px; color: var(--muted); }
.hit-mult { color: var(--ember) !important; }

/* アリーナの列配置 */
.lane-plan { margin: 8px 0 10px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--panel-edge); background: rgba(138,106,216,.06); }
.lane-plan h4 { margin: 0 0 6px; font-size: .82rem; color: var(--gold); }
.lane { display: grid; grid-template-columns: 44px 1fr; gap: 2px 8px; padding: 5px 0; border-top: 1px dashed var(--panel-edge); font-size: .78rem; }
.lane:first-of-type { border-top: 0; }
.lane > b { grid-row: span 2; display: grid; place-items: center; border-radius: 6px; background: var(--ember); color: #fff; font-size: .75rem; }
.lane-sq { display: flex; flex-wrap: wrap; gap: 4px 10px; font-weight: 700; }
.lane small { color: var(--muted); font-size: .68rem; }

/* 重視する属性 */
.el-box { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px dashed var(--panel-edge); }
.el-box .small-note { flex-basis: 100%; margin: 0; }
.el-box .chip .ico-el.ico-mark { width: 1.45em; height: 1.45em; }
.el-box .chip.on[style] { background: color-mix(in srgb, var(--el) 28%, #fff); border-color: var(--el); color: var(--text); font-weight: 700; }
.ghost-chip { font-size: .7rem; }
@media (max-width: 560px) { .el-box .rf-label { flex-basis: 100%; } }

/* エンバース一覧: 見出し付きプルダウン */
.filter-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ffield { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ffield > span { font-size: .66rem; color: var(--muted); letter-spacing: .05em; padding-left: 2px; }
.ffield select { width: 100%; min-width: 0; }
.ffield.active > span { color: var(--ember); font-weight: 700; }
.ffield.active > span::after { content: ' ●'; font-size: .6rem; }
.ffield.active select { border-color: var(--ember); box-shadow: 0 0 0 1px var(--ember); }
.filter-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 0; }
.filter-foot .muted { font-size: .72rem; }
.filter-foot:has(#btnClearFilters[hidden]) .muted:empty { display: none; }
#btnClearFilters[hidden] { display: none; }

/* 用途の絞り込み */
.role-chips::before { content: '用途'; font-size: .66rem; color: var(--muted); align-self: center; margin-right: 2px; }
.role-chips .chip small { margin-left: 4px; font-size: .62rem; color: var(--muted); }
.role-chips .chip.on small { color: inherit; }
.role-tag { padding: 0 6px; border-radius: 8px; background: rgba(138,106,216,.14); color: #5a43a8; font-size: .72rem; }
