/*
 * 盤面(輪)。area_order の6エリアを、時計回りに上から並べた六角形の輪にする。
 * 左隣 = 並びの1つ前 = 反時計回りの隣。外周の矢印(↺の向き)と凡例で常に示す。
 * 飛空艇(拡張)は輪の中心に置き、6エリアすべてへ線(スポーク)でつなぐ。
 * 幅は container query の単位(cqw)で決めるので、PCでもスマホでも同じ部品を縮小して使う。
 */
.board-wrap { container-type: inline-size; }

.board {
  --r: 35cqw;           /* 中心からエリアの中心までの距離 */
  --aw: 29cqw;          /* エリアの幅 */
  --ah: 21cqw;          /* エリアの高さ */
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 760px;
  margin: 0 auto;
}

.board__svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.board__svg--under { z-index: 0; }
.board__svg--over { z-index: 3; }
.board__circle { fill: none; stroke: var(--line); stroke-width: .35; stroke-dasharray: 1.4 1.2; opacity: .8; }
.board__spoke { stroke: var(--citizen); stroke-width: .5; stroke-dasharray: 1.6 1.1; opacity: .85; }
.board__arrow { fill: var(--turn); stroke: #101636; stroke-width: .25; }

.board__legend {
  position: absolute; left: 0; bottom: 0; font-size: .8rem; color: var(--muted); display: flex; gap: 6px; align-items: center;
}
.board__legend::before { content: "↺"; color: var(--turn); font-size: 1.3rem; line-height: 1; }

.area {
  position: absolute; left: 50%; top: 50%; width: var(--aw); min-height: var(--ah);
  transform: translate(-50%, -50%) rotate(calc(var(--i) * 60deg - 90deg)) translateX(var(--r)) rotate(calc(var(--i) * -60deg + 90deg));
  background: linear-gradient(var(--panel-2), var(--panel));
  border: 2px solid var(--line); border-radius: 14px; padding: 6px 8px;
  display: flex; flex-direction: column; gap: 4px;
}
.area__head { display: flex; justify-content: space-between; gap: 4px; align-items: baseline; }
.area__name { font-weight: 700; font-size: clamp(.62rem, 2.6cqw, 1rem); line-height: 1.2; }
.area__dice { font-size: clamp(.55rem, 2.2cqw, .85rem); color: var(--turn); white-space: nowrap; }
.area__action { font-size: clamp(.5rem, 2cqw, .8rem); color: var(--muted); line-height: 1.25; }
.area__pieces { display: flex; flex-wrap: wrap; gap: 3px; align-content: flex-start; }

/* 攻撃の範囲(縁取り+ラベル) */
.area[data-reach="self"] { border-color: var(--ok); }
.area[data-reach="range"] { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(255, 122, 122, .35); }
.area__reach {
  display: none; font-size: clamp(.5rem, 2cqw, .75rem); font-weight: 700; padding: 0 6px; border-radius: 999px; width: fit-content;
}
.area[data-reach="range"] .area__reach { display: inline-block; background: var(--danger); color: #2b0d0d; }
.area[data-reach="self"] .area__reach { display: inline-block; background: var(--ok); color: #0d2b1a; }

/* 飛空艇(中心) */
.airship {
  position: absolute; left: 50%; top: 50%; width: 27cqw; min-height: 17cqw; transform: translate(-50%, -50%);
  background: radial-gradient(circle at 50% 30%, #3b4a8f, #1b2557); border: 2px solid var(--citizen); border-radius: 50% / 45%;
  padding: 6px 8px; text-align: center; z-index: 2;
}
.airship[data-reach="range"] { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(255, 122, 122, .35); }
.airship[data-reach="self"] { border-color: var(--ok); }
.airship__name { font-weight: 700; font-size: clamp(.58rem, 2.4cqw, .95rem); line-height: 1.2; }
.airship__note { font-size: clamp(.5rem, 1.9cqw, .75rem); color: var(--muted); }
.airship .area__pieces { justify-content: center; }
.airship .area__reach { margin: 2px auto 0; }
.airship[data-reach="range"] .area__reach { display: inline-block; background: var(--danger); color: #2b0d0d; }
.airship[data-reach="self"] .area__reach { display: inline-block; background: var(--ok); color: #0d2b1a; }

/* ---- 駒 ---- */
.piece {
  position: relative; display: inline-flex; flex-direction: column; align-items: center; gap: 1px;
  width: clamp(40px, 8.4cqw, 66px); padding: 2px; border: 2px solid transparent; border-radius: 10px; background: rgba(0, 0, 0, .25);
  font-size: clamp(.5rem, 1.9cqw, .8rem); line-height: 1.15; text-align: center;
}
.piece__avatar {
  width: clamp(28px, 5.8cqw, 46px); height: clamp(28px, 5.8cqw, 46px); border-radius: 50%; object-fit: cover; background: #33437a;
  display: grid; place-items: center; font-weight: 700; color: var(--text); overflow: hidden;
}
.piece__name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.piece__damage { font-weight: 700; color: var(--turn); }
.piece__tag {
  position: absolute; top: -9px; left: 50%; transform: translateX(-50%); padding: 0 6px; border-radius: 999px; white-space: nowrap;
  font-size: clamp(.45rem, 1.7cqw, .7rem); font-weight: 700; background: var(--text); color: #101636;
}
.piece[data-turn="true"] { border-color: var(--turn); box-shadow: 0 0 0 3px rgba(255, 209, 102, .4); }
.piece[data-turn="true"] .piece__tag--turn { background: var(--turn); }
.piece[data-me="true"] .piece__avatar { outline: 3px solid var(--text); outline-offset: 1px; }
.piece[data-targetable="true"] { border-color: var(--danger); background: rgba(255, 122, 122, .25); }
.piece[data-targetable="true"]::after {
  content: "⚔"; position: absolute; right: -6px; top: -6px; width: 18px; height: 18px; line-height: 18px; border-radius: 50%;
  background: var(--danger); color: #2b0d0d; font-size: 11px;
}
/* 脱落: 灰色+取り消し線+「脱落」ラベル+破線の縁(色だけにしない) */
.piece[data-eliminated="true"] { border-style: dashed; border-color: #7a84a8; filter: grayscale(1); opacity: .75; }
.piece[data-eliminated="true"] .piece__name { text-decoration: line-through; }
.piece__id { display: inline-flex; align-items: center; gap: 2px; font-size: clamp(.45rem, 1.7cqw, .7rem); color: var(--muted); }

/* 陣営の印(色+形+ラベル) */
.faction { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; }
.faction svg { width: 1.1em; height: 1.1em; flex: none; }
.faction--raider { color: var(--raider); }
.faction--shadow { color: var(--shadow); }
.faction--citizen { color: var(--citizen); }

/* ダイスと移動の演出 */
.dice-toast {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) scale(.9); z-index: 6;
  background: rgba(10, 14, 36, .92); border: 2px solid var(--turn); border-radius: 16px; padding: 10px 18px; text-align: center;
  opacity: 0; pointer-events: none;
}
.dice-toast[data-show="true"] { animation: dice-pop 2.6s ease both; }
.dice-toast__faces { display: flex; gap: 10px; justify-content: center; margin-bottom: 4px; }
.die {
  width: 48px; height: 48px; border-radius: 10px; background: var(--paper); color: var(--paper-ink); display: grid; place-items: center;
  font-size: 1.5rem; font-weight: 800; border: 2px solid var(--paper-edge);
}
.die--d4 { clip-path: polygon(50% 4%, 96% 92%, 4% 92%); border-radius: 0; }
@keyframes dice-pop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.6) rotate(-12deg); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.05) rotate(4deg); }
  25% { transform: translate(-50%, -50%) scale(1) rotate(0); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

@media (max-width: 860px) {
  .area { padding: 3px 4px; border-radius: 10px; }
  .area__action { display: none; }
}

/* 盤面が狭いときは、文字を絞る(スマホや、PCで右の列が広いとき) */
@container (max-width: 640px) {
  .piece__id span:last-child { display: none; }
  .area__action { display: none; }
  .piece { width: clamp(38px, 9.4cqw, 56px); }
}

/* 駒の下に出す「公開済みの正体」: 印+キャラ名だけ(1行) */
.piece__id { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; justify-content: center; }
.piece__id .faction span { display: none; }
.piece__id .faction svg { width: 1.2em; height: 1.2em; }
.area { z-index: 1; }
.airship { z-index: 2; }
.area__pieces { margin-top: 8px; }

/* 凡例は盤面の下(エリアに重ならない) */
.board__legend { position: static; margin-top: 4px; }
.board { margin-bottom: 8px; }

/* 盤面が狭いとき(スマホ)は、飛空艇を小さくして、エリアに重ならないようにする */
@container (max-width: 520px) {
  .airship { width: 25cqw; min-height: 13cqw; padding: 2px 4px; }
  .airship__note { display: none; }
  .airship .piece { width: clamp(34px, 9cqw, 44px); }
}

/* ダイスの結果は、画面の更新で消えないよう、body に出す(盤面の上に固定) */
#dice-toast-live { position: fixed; top: 34%; left: 50%; z-index: 35; font-size: 1.05rem; }
