:root {
    --bg-main: #0f1115;
    --bg-panel: #1a1d24;
    --bg-card: #232730;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --danger: #ef4444;
    --warning: #f59e0b;
    --success: #10b981;

    --c-red: #ef4444;
    --c-purple: #a855f7;
    --c-green: #22c55e;
    --c-white: #e5e7eb;
    --c-yellow: #eab308;
    --c-blue: #3b82f6;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-main);
    color: var(--text-main);
}

.hidden {
    display: none !important;
}

/* ---- ロビー ---- */
#lobby {
    max-width: 400px;
    margin: 100px auto;
    padding: 32px;
    background: var(--bg-panel);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    text-align: center;
}

#lobby h1 {
    margin-top: 0;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: 1px;
}

.lobby-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.lobby-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: left;
    font-size: 13px;
    color: var(--text-muted);
}

.lobby-form input,
.lobby-form select {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #333;
    background: #14161b;
    color: var(--text-main);
    font-size: 14px;
    transition: border-color 0.2s;
}

.lobby-form input:focus,
.lobby-form select:focus {
    outline: none;
    border-color: var(--accent);
}

button {
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-weight: 500;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s, transform 0.1s;
}

button:hover {
    background: var(--accent-hover);
}

button:active {
    transform: scale(0.98);
}

#waiting-message {
    margin-top: 16px;
    color: var(--warning);
    font-size: 14px;
}

/* 参加取り消しモード */
#join-btn.cancel-mode {
    background: #8b2030;
    transition: background 0.2s;
}

#join-btn.cancel-mode:hover {
    background: #a52838;
}

#deck-builder-link {
    margin-top: 8px;
    font-size: 13px;
    color: var(--accent);
    text-decoration: none;
}

#deck-builder-link:hover {
    text-decoration: underline;
}

#deck-select option:disabled {
    color: #555;
}

/* ---- ランダムマッチ・AI対戦セクション ---- */
.lobby-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #333;
}

.lobby-section-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 4px;
}

.lobby-section-desc {
    font-size: 12px;
    color: var(--text-muted);
    margin: 0 0 12px;
}

.lobby-section button {
    width: 100%;
}

.match-waiting-text {
    color: var(--warning);
    font-size: 14px;
    margin: 8px 0;
    animation: pulse-text 1.5s ease-in-out infinite;
}

@keyframes pulse-text {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.cancel-btn {
    background: #8b2030;
    width: 100%;
}

.cancel-btn:hover {
    background: #a52838;
}

.ai-deck-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.ai-deck-label {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: left;
    font-size: 13px;
    color: var(--text-muted);
}

.ai-deck-label select {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #333;
    background: #14161b;
    color: var(--text-main);
    font-size: 14px;
    transition: border-color 0.2s;
    width: 100%;
}

.ai-deck-label select:focus {
    outline: none;
    border-color: var(--accent);
}

.ai-deck-label select option:disabled {
    color: #555;
}

/* ---- ステータスバー ---- */
#status-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: var(--bg-panel);
    font-size: 14px;
    border-bottom: 1px solid #2a2d38;
}


#targeting-info {
    color: var(--danger);
    font-weight: 600;
}

#center-info-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 50px;
    padding: 8px 20px;
    gap: 8px;
    border-top: 1px solid rgba(239, 68, 68, 0.3);
    border-bottom: 1px solid rgba(59, 130, 246, 0.3);
    background: linear-gradient(
        to bottom,
        rgba(239, 68, 68, 0.05) 0%,
        transparent 50%,
        rgba(59, 130, 246, 0.05) 100%
    );
}

#action-buttons-container {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: auto;
}

#action-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
#action-buttons button {
    padding: 10px 24px;
    font-size: 15px;
    font-weight: bold;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    background: var(--bg-card);
    color: #fff;
    border: 1px solid var(--accent);
    cursor: pointer;
    transition: all 0.2s;
}
#action-buttons button:hover {
    background: var(--accent);
    transform: translateY(-2px);
}
#action-buttons button.hidden {
    display: none;
}

#btn-pass.pulse {
    animation: pulse-btn 1.5s infinite;
}
@keyframes pulse-btn {
    0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.6); }
    50% { box-shadow: 0 0 0 8px rgba(59, 130, 246, 0); }
}

#btn-take-life {
    background: var(--danger);
}
#btn-take-life:hover {
    background: #f87171;
}

/* ---- 盤面 ---- */
#board {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: box-shadow 0.3s;
}

#board.your-priority {
    box-shadow: inset 0 0 0 3px var(--warning), inset 0 0 30px rgba(245, 158, 11, 0.15);
}

#board.opp-thinking {
    box-shadow: inset 0 0 0 2px rgba(156, 163, 175, 0.3), inset 0 0 20px rgba(156, 163, 175, 0.08);
}

.player-area {
    flex: 1;
    padding: 12px 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 16px;
}
#opponent-area { border-left: 4px solid rgba(239, 68, 68, 0.4); }
#player-area { border-left: 4px solid rgba(59, 130, 246, 0.4); }

.player-info {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-muted);
}

.player-info .life {
    display: inline-block;
    color: var(--danger);
    font-weight: 700;
    font-size: 15px;
}

.player-info .reserve {
    display: inline-block;
    color: var(--accent);
    font-weight: 700;
    font-size: 15px;
}

/* ライフ減少時の演出（次回再描画でクラスが外れるため一過性のアニメーションでよい）。
   イベント通知レイヤー（GameEvent type:"lifeDamage"）駆動でクラス付与する。シェイク＋赤パルスを1本化 */
.player-info .life.life-changed {
    animation: life-changed-anim 500ms ease-out;
}
@keyframes life-changed-anim {
    0% { transform: scale(1.3) translateX(0); color: #fca5a5; }
    20% { transform: scale(1.15) translateX(-4px); }
    40% { transform: scale(1.15) translateX(4px); }
    60% { transform: scale(1.05) translateX(-2px); }
    80% { transform: scale(1.05) translateX(2px); }
    100% { transform: scale(1) translateX(0); color: var(--danger); }
}

/* ---- イベント通知レイヤー（GameEvent駆動のオーバーレイ演出） ---- */
#event-layer {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    pointer-events: none;
}

.event-banner {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 18px;
    font-weight: 700;
    background: rgba(26, 29, 36, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--text-main);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.5);
    white-space: nowrap;
    animation: event-banner-inout 3000ms ease-out forwards;
}

.event-banner.event-summon {
    border-color: rgba(16, 185, 129, 0.6);
}
.event-banner.event-destroy {
    border-color: rgba(239, 68, 68, 0.6);
    color: #fca5a5;
}
.event-banner.event-magic {
    border-color: rgba(59, 130, 246, 0.6);
}
.event-banner.event-draw {
    border-color: rgba(156, 163, 175, 0.6);
    color: var(--text-muted);
}
.event-banner.event-returnToHand,
.event-banner.event-returnToDeck {
    border-color: rgba(6, 182, 212, 0.6);
    color: #67e8f9;
}

@keyframes event-banner-inout {
    0% { opacity: 0; transform: translateY(-8px); }
    5% { opacity: 1; transform: translateY(0); }
    90% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-6px); }
}

.player-info .turn-mark {
    color: var(--warning);
    font-weight: 600;
}

/* 覚醒モード中にリザーブからコアを移せるときのハイライト */
.player-info span.targetable {
    color: var(--danger);
    font-weight: 700;
    text-shadow: 0 0 8px rgba(239, 68, 68, 0.6);
    cursor: pointer;
    animation: reserve-pulse 1.2s ease-in-out infinite;
}

@keyframes reserve-pulse {
    0%, 100% { text-shadow: 0 0 8px rgba(239, 68, 68, 0.6); }
    50% { text-shadow: 0 0 16px rgba(239, 68, 68, 0.9), 0 0 4px rgba(239, 68, 68, 0.4); }
}

.field-row {
    display: flex;
    gap: 20px;
    min-height: 150px;
    flex: 1;
    align-items: center;
}

.spirit-zone,
.nexus-zone {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed rgba(255, 255, 255, 0.1);
    min-height: 160px;
}

.nexus-zone {
    min-width: 260px;
}
.spirit-zone {
    flex: 1;
}

/* バーストエリア（docs/design/BURST.md）。ネクサスゾーンと同じ行に横並びさせるための
   ラッパー（field-row がスマホでcolumnになっても、この中だけは常にrow） */
.nexus-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.burst-zone {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* 通常のフィールドカードより小さめの枠（既存の盤面の高さを増やさないため） */
.burst-slot {
    width: 46px;
    height: 56px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
    font-size: 9px;
}

.burst-empty {
    border: 1px dashed rgba(255, 255, 255, 0.15);
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.02);
}

/* 相手のバースト：裏面のみ。カード名・効果は一切出さない */
.burst-back {
    background: linear-gradient(135deg, #3a3f4b, #20232c);
    border: 2px solid rgba(255, 255, 255, 0.25);
}

/* 自分のバースト：裏向きだが自分にはカード名が見える */
.burst-mine {
    background: linear-gradient(#2a2e39, #2a2e39) padding-box,
                linear-gradient(135deg, var(--c-main, #333), var(--c-sub, #333)) border-box;
    border: 2px solid transparent;
    padding: 2px;
}
.burst-mine .name {
    font-size: 8px;
    max-width: 40px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.burst-hidden-icon {
    position: absolute;
    top: -6px;
    right: -6px;
    font-size: 10px;
}

/* 手札のバーストセットボタン */
.burst-set-badge {
    position: absolute;
    bottom: 2px;
    left: 2px;
    right: 2px;
    font-size: 9px;
    padding: 2px 4px;
    border-radius: 4px;
    border: 1px solid var(--accent, #6b7fd7);
    background: rgba(107, 127, 215, 0.25);
    color: #fff;
    cursor: pointer;
}
.burst-set-badge.disabled {
    opacity: 0.4;
    cursor: not-allowed;
}



#battle-info {
    padding: 10px 16px;
    background: rgba(239, 68, 68, 0.1);
    border-left: 4px solid var(--danger);
    border-radius: 4px;
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 500;
}

/* ---- ログパネル ---- */
.log-toggle-btn {
    background: var(--bg-card);
    border: 1px solid #444;
    color: var(--text-main);
    padding: 6px 12px;
    font-size: 13px;
    border-radius: 6px;
    cursor: pointer;
}
.log-toggle-btn:hover { background: #2c3044; }

#log-panel, #trash-panel, #tegamoto-panel {
    position: fixed;
    right: 20px;
    bottom: 80px;
    width: 320px;
    height: 400px;
    background: rgba(15, 17, 21, 0.95);
    backdrop-filter: blur(8px);
    border: 1px solid #3a3f4e;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 30px rgba(0,0,0,0.8);
    z-index: 150;
    overflow: hidden;
}

#trash-panel, #tegamoto-panel {
    right: 350px; /* offset from log panel */
}

#log-panel .log-header,
#trash-panel .trash-header, #tegamoto-panel .trash-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg-panel);
    border-bottom: 1px solid #3a3f4e;
    font-size: 13px;
    font-weight: 600;
}

#log-panel .log-header button,
#trash-panel .trash-header button#btn-close-trash, #tegamoto-panel .trash-header button#btn-close-tegamoto {
    background: transparent;
    padding: 4px 8px;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
}
#log-panel .log-header button:hover,
#trash-panel .trash-header button#btn-close-trash:hover, #tegamoto-panel .trash-header button#btn-close-tegamoto:hover { color: #fff; transform: none; }

.trash-tabs {
    display: flex;
    gap: 8px;
}
.trash-tabs button {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    padding: 4px 8px;
    cursor: pointer;
}
.trash-tabs button.active {
    color: #fff;
    font-weight: bold;
    border-bottom: 2px solid var(--accent);
}

#log {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-muted);
}

/* ---- ログの構造化: 内容ヒューリスティックによる強調 ---- */
#log .log-turn {
    font-weight: 700;
    color: var(--text-main);
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid #3a3f4e;
}
#log .log-turn:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}
#log .log-phase {
    color: #cbd5e1;
}
#log .log-important {
    color: var(--warning);
    font-weight: 600;
}

#log .log-effect {
    border-left: 2px solid rgba(59, 130, 246, 0.5);
    padding-left: 6px;
    margin-left: 2px;
    background: rgba(59, 130, 246, 0.05);
    border-radius: 0 4px 4px 0;
}

#log .log-card-name {
    display: inline-block;
    padding: 2px 6px;
    margin: 0 2px;
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.4);
    border-radius: 4px;
    color: #93c5fd;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

#log .log-card-name:hover {
    background: rgba(59, 130, 246, 0.3);
    border-color: rgba(59, 130, 246, 0.7);
}

#global-tooltip {
    position: fixed;
    pointer-events: none;
    z-index: 1000;
    background: rgba(15, 17, 21, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    padding: 10px 14px;
    color: #f3f4f6;
    font-size: 13px;
    line-height: 1.5;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
    max-width: 300px;
    backdrop-filter: blur(4px);
    transition: opacity 0.1s ease-out;
}


#trash-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-content: flex-start;
}

/* トラッシュのカードサイズを少し小さく */
#trash-content .card {
    width: 68px;
    height: 96px;
    font-size: 11px;
    padding: 4px;
}
#trash-content .card::before {
    display: block; /* border color */
}

/* ---- カード ---- */
.card {
    width: 100px;
    height: 140px;
    border-radius: 8px;
    padding: 8px;
    font-size: 11px;
    background: linear-gradient(145deg, #2a2e39, #20232c);
    border: 1px solid #3a3f4e;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    cursor: default;
    position: relative;
    display: flex;
    flex-direction: column;
    transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.2s;
}

.card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; height: 4px;
    border-radius: 8px 8px 0 0;
    background: #555;
}

.card .name {
    font-weight: 600;
    font-size: 11px;
    margin-top: 2px;
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.card .stats {
    color: var(--text-main);
    font-size: 10px;
    margin-bottom: 4px;
    font-variant-numeric: tabular-nums;
}

.card .cores {
    color: var(--accent-hover);
    font-weight: bold;
    font-size: 10px;
}



/* 効果全文のツールチップ */
#effect-tooltip {
    position: fixed;
    z-index: 1000;
    max-width: 340px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 12px;
    background: rgba(20, 22, 27, 0.95);
    backdrop-filter: blur(8px);
    border: 1px solid #3a3f4e;
    border-radius: 8px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-main);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
    pointer-events: none;
    font-variant-numeric: tabular-nums;
    white-space: pre-wrap;
}

#effect-tooltip .tooltip-name {
    font-weight: 700;
    color: var(--warning);
    margin-bottom: 6px;
    border-bottom: 1px solid #333;
    padding-bottom: 4px;
}

/* 効果テキスト内の「Lv1」「Lv2」「Lv3」「フラッシュ」始まりの行を強調 */
#effect-tooltip .tooltip-effect-line {
    margin-bottom: 2px;
}
#effect-tooltip .tooltip-effect-highlight {
    font-weight: 700;
    color: var(--accent-hover);
}

#turn-info {
    font-weight: 600;
}

#phase-bar {
    display: flex;
    gap: 4px;
    align-items: center;
    margin-left: auto;
}
.phase-step {
    padding: 4px 10px;
    font-size: 11px;
    border-radius: 12px;
    background: rgba(255,255,255,0.05);
    color: var(--text-muted);
    transition: all 0.3s;
}
.phase-step.active {
    background: var(--warning);
    color: #000;
    font-weight: 700;
    transform: scale(1.1);
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.5);
}

#targeting-info {
    font-weight: 700;
    color: var(--danger);
    font-size: 18px;
    text-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
}

.card::before { background: linear-gradient(135deg, var(--c-main, var(--c-red)), var(--c-sub, var(--c-red))); }

.card.rested {
    transform: rotate(10deg);
    opacity: 0.7;
}

.card.clickable {
    cursor: pointer;
}

.card.clickable:hover {
    transform: translateY(-6px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
    border-color: #555;
}

.card.rested.clickable:hover {
    transform: rotate(10deg) translateY(-6px);
}

.card.usable {
    box-shadow: 0 0 0 2px var(--warning), 0 0 12px rgba(245, 158, 11, 0.4);
}

.card.usable-field {
    outline: 2px dashed var(--warning);
    outline-offset: -2px;
    box-shadow: 0 0 16px rgba(245, 158, 11, 0.4);
    animation: usable-field-pulse 2s infinite;
}

@keyframes usable-field-pulse {
    0%, 100% { opacity: 1; outline-color: var(--warning); }
    50% { opacity: 0.8; outline-color: rgba(245, 158, 11, 0.4); }
}

.card.unusable {
    filter: brightness(0.5) grayscale(30%);
    opacity: 0.6;
}

.card.targetable {
    box-shadow: 0 0 0 2px var(--danger), 0 0 12px rgba(239, 68, 68, 0.4);
}

/* トグル選択（予算内で好きなだけ破壊する）で選択済みのもの。候補の赤枠と区別する */
.card.targetable.choice-selected {
    box-shadow: 0 0 0 3px var(--success), 0 0 16px rgba(16, 185, 129, 0.6);
}

.card.awaken-target {
    box-shadow: 0 0 0 2px var(--warning), 0 0 16px rgba(245, 158, 11, 0.6);
}

.card.selected {
    box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(59, 130, 246, 0.7);
    transform: translateY(-8px);
    z-index: 10;
    filter: brightness(1.15);
}

/* 支払いモードで「破棄してコストに充てる」ために選んだ手札（BS08ビクティム） */
.card.pay-discard {
    box-shadow: 0 0 0 2px var(--danger, #ef4444), 0 0 16px rgba(239, 68, 68, 0.6);
    filter: brightness(0.85) saturate(0.7);
}

.pay-discard-badge {
    position: absolute;
    top: 2px;
    left: 2px;
    background: var(--danger, #ef4444);
    color: #fff;
    font-size: 11px;
    font-weight: bold;
    border-radius: 4px;
    padding: 1px 4px;
    z-index: 11;
}

.card.step-active {
    box-shadow: 0 0 0 2px var(--success), 0 0 16px rgba(16, 185, 129, 0.6);
    animation: step-active-pulse 2s infinite;
}

@keyframes step-active-pulse {
    0%, 100% { box-shadow: 0 0 0 2px var(--success), 0 0 12px rgba(16, 185, 129, 0.4); }
    50% { box-shadow: 0 0 0 2px var(--success), 0 0 20px rgba(16, 185, 129, 0.8); }
}

.awaken-badge,
.activate-badge,
.pay-badge,
.cant-attack-badge,
.step-active-badge,
.combine-badge,
.as-spirit-badge {
    position: absolute;
    min-width: 44px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
    cursor: pointer;
    line-height: 1.2;
    text-align: center;
}
.awaken-badge::after,
.activate-badge::after,
.pay-badge::after,
.cant-attack-badge::after,
.step-active-badge::after,
.combine-badge::after,
.as-spirit-badge::after {
    content: '';
    position: absolute;
    inset: -8px;
}

/* 合体しているブレイヴ：ホストの右へ半分ずらして重ねる（docs/design/BRAVE.md §6.4）。
   はみ出すぶんの幅は has-brave 側の margin-right で確保し、隣のカードと重ならないようにする */
/* スピリットのカードは 76px 角なので、はみ出す幅は40px（ほぼ半分）に取る。
   .spirit-zone .card の margin-right を上書きするため、同じ詳細度で後ろに置いてある（下部を参照） */
/* ⚠️ z-index: -1 で「ホストの背面へ回す」ことはできない。.card は stacking context を
   作らないため、負のz-indexは .spirit-zone の背景の下まで沈み、クリックもホバーも
   ゾーンに取られる（2026-09-02 に実際に踏んだ。DOM API の .click() は当たるので
   自動確認では気づけない）。重なりを持たせずホストへ密着させる形にしてある */
.brave-combined-box {
    position: absolute;
    left: 100%;
    top: 3px;
    bottom: 3px;
    width: 40px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.brave-combined {
    position: relative;
    flex: 1;
    min-height: 0;
    padding: 3px 2px;
    border-radius: 0 6px 6px 0;
    background: linear-gradient(#22252e, #22252e) padding-box,
                linear-gradient(135deg, var(--c-main, #333), var(--c-sub, #333)) border-box;
    border: 2px solid transparent;
    box-shadow: 3px 4px 6px rgba(0, 0, 0, 0.35);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
/* 幅が狭いので名前は縦書きにする。あふれた分は省略され、フル名は title 属性で出る */
.brave-name {
    writing-mode: vertical-rl;
    font-size: 9px;
    line-height: 1.1;
    max-height: 100%;
    overflow: hidden;
    color: #cfd3dc;
}

/* 分離（メインステップの任意分離。§6.4）。ブレイヴのはみ出した部分の下端に置く */
.detach-badge {
    position: absolute;
    left: 1px;
    right: 1px;
    bottom: 1px;
    padding: 1px 0;
    font-size: 9px;
    line-height: 1.2;
    border: none;
    border-radius: 3px;
    background: var(--c-sub);
    color: #fff;
    cursor: pointer;
}
.detach-badge:hover {
    filter: brightness(1.2);
}

/* 合体（メインステップの任意合体。§6.4）。スピリット状態のブレイヴにだけ出る */
.combine-badge {
    bottom: -6px; left: -6px;
    background: var(--c-sub);
    color: #fff;
}
.combine-badge:hover { filter: brightness(1.2); }

.awaken-badge {
    bottom: -6px; right: -6px;
    background: var(--warning);
    color: #000;
}
.awaken-badge:hover { background: #fbbf24; }

.activate-badge {
    bottom: -6px; right: -6px;
    background: var(--success);
    color: #000;
}
.activate-badge:hover { background: #34d399; }

.pay-badge {
    bottom: -6px; right: -6px;
    background: var(--accent);
    color: #fff;
}

.cant-attack-badge {
    top: -6px; left: -6px;
    background: #4b5563;
    color: #fff;
    cursor: default;
}

.step-active-badge {
    top: -6px; right: -6px;
    background: var(--success);
    color: #000;
    pointer-events: none;
}

.as-spirit-badge {
    top: -22px; right: -6px;
    background: var(--warning);
    color: #000;
    pointer-events: none;
}

.field-req-badge {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(245, 158, 11, 0.9);
    color: #000;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 800;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.8);
    pointer-events: none;
    z-index: 5;
    white-space: nowrap;
}

.card.attacker-mark {
    box-shadow: 0 0 0 2px var(--danger), 0 0 16px rgba(239, 68, 68, 0.6);
}

.card.directed-attacker {
    box-shadow: 0 0 0 2px var(--accent), 0 0 16px rgba(59, 130, 246, 0.6);
}

.core-buttons {
    position: absolute;
    top: 0;
    right: -26px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
}

.card:hover .core-buttons {
    opacity: 1;
}

.core-buttons button {
    min-width: 24px;
    height: 24px;
    padding: 0 6px;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    border-radius: 12px;
    background: var(--bg-panel);
    border: 1px solid #444;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.core-buttons button:hover {
    background: var(--accent);
    border-color: var(--accent);
}

/* ---- 手札 ---- */
#hand {
    display: flex;
    gap: 8px;
    padding-top: 12px;
    flex-wrap: wrap;
}

/* ---- 結果表示・トースト ---- */
#result-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

#result-message {
    font-size: 42px;
    font-weight: 800;
    letter-spacing: 2px;
    color: var(--warning);
    text-shadow: 0 4px 20px rgba(245, 158, 11, 0.6);
}

#toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border-left: 4px solid var(--danger);
    color: var(--text-main);
    padding: 12px 24px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
    z-index: 200;
}

/* ---- 盤面に出ているカード（トークン風） ---- */
.spirit-zone .card,
.nexus-zone .card {
    justify-content: center;
    align-items: center;
    padding: 2px;
    border: none;
}

.spirit-zone .card .name,
.nexus-zone .card .name {
    display: block;
    font-size: 9px;
    max-width: 64px;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 2px;
}


.spirit-zone .card::before,
.nexus-zone .card::before {
    display: none;
}

.spirit-zone .card .stats,
.spirit-zone .card .cores,
.nexus-zone .card .stats,
.nexus-zone .card .cores {
    font-size: 11px;
    text-align: center;
    margin: 1px 0;
}

/* スピリットは四角形 */
.spirit-zone .card {
    width: 76px;
    height: 76px;
    border-radius: 6px;
    background: linear-gradient(#2a2e39, #2a2e39) padding-box,
                linear-gradient(135deg, var(--c-main, #333), var(--c-sub, #333)) border-box;
    border: 2px solid transparent;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    margin-right: 22px; /* ボタンが右にはみ出す分の余白 */
}

/* 合体しているブレイヴが右へ34pxはみ出すぶん、隣のカードとの余白を広げる（BRAVE.md §6.4）。
   .spirit-zone .card と同じ詳細度なので、必ずこの後ろに置くこと */
.spirit-zone .card.has-brave {
    /* ブレイヴのはみ出し40px＋隣のカードとの間隔26px。
       ホストとブレイヴの間は隙間ゼロ・隣のカードとは広い隙間、という差で
       「どれと合体しているか」が空間だけで読めるようにする（2026-09-02 ユーザー指示） */
    margin-right: 66px;
}
/* コア増減ボタン（hover で出る）はブレイヴの外側へ逃がす */
.card.has-brave .core-buttons {
    right: -68px;
}

/* ネクサスは六角形 */
.nexus-zone .card {
    width: 70px;
    height: 78px;
    border-radius: 0;
    box-shadow: none; /* clip-path hides box-shadow */
    background: transparent;
    border: none;
}
.nexus-zone .card::after {
    content: '';
    position: absolute;
    inset: 0;
    clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
    background: linear-gradient(145deg, color-mix(in srgb, var(--c-main, #333) 30%, #20232c), color-mix(in srgb, var(--c-sub, #333) 30%, #20232c), #20232c 80%);
    z-index: -1;
}

/* ホバー時の上書き（トークン用） */
.spirit-zone .card.clickable:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.5);
}

.nexus-zone .card.clickable:hover {
    transform: translateY(-4px);
}

/* 状態バッジの上書き（トークン用） */
.spirit-zone .card.usable { box-shadow: inset 0 0 0 2px var(--warning), 0 0 16px rgba(245, 158, 11, 0.6); }
.spirit-zone .card.targetable { border-color: var(--danger); box-shadow: 0 0 12px var(--danger); }
.spirit-zone .card.targetable.choice-selected { border-color: var(--success); box-shadow: 0 0 14px var(--success); }
.spirit-zone .card.attacker-mark { border-color: var(--danger); box-shadow: 0 0 12px var(--danger); }
.nexus-zone .card.usable::after { background: linear-gradient(145deg, var(--warning), #20232c); }
.nexus-zone .card.targetable::after { background: linear-gradient(145deg, var(--danger), #20232c); }
.nexus-zone .card.attacker-mark::after { background: linear-gradient(145deg, var(--danger), #20232c); }

/* ---- シンボルアイコン（盤面トークン用） ---- */
.symbols {
    position: absolute;
    bottom: -4px;
    right: -4px;
    display: flex;
    gap: 2px;
    justify-content: flex-end;
    margin-top: 0;
    z-index: 10;
}
.sym-icon {
    position: relative;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: inline-block;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    box-shadow: 0 1px 2px rgba(0,0,0,0.5);
    border: none;
}

.sym-icon.bg-red { background-image: url('/imgs/symbols/red_symbol.png'); }
.sym-icon.bg-purple { background-image: url('/imgs/symbols/violet_symbol.png'); }
.sym-icon.bg-green { background-image: url('/imgs/symbols/green_symbol.png'); }
.sym-icon.bg-white { background-image: url('/imgs/symbols/white_symbol.png'); }
.sym-icon.bg-yellow { background-image: url('/imgs/symbols/yellow_symbol.png'); }
.sym-icon.bg-blue { background-image: url('/imgs/symbols/blue_symbol.png'); }

/* ---- 手札のコストバッジ ---- */
.cost-badge {
    position: absolute;
    top: -8px;
    left: -8px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #1e293b;
    border: 2px solid #475569;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(0,0,0,0.5);
    z-index: 10;
}
.cost-badge.discounted {
    width: auto;
    border-radius: 13px;
    padding: 0 8px;
    background: #064e3b;
    border-color: var(--success);
    color: var(--success);
}
.original-cost {
    text-decoration: line-through;
    color: #94a3b8;
    font-size: 11px;
    margin-right: 4px;
}
.current-cost {
    color: #34d399; /* light green */
}

/* ---- まとまった枚数の表示（手札・トラッシュ用） ---- */
.count-badge {
    position: absolute;
    bottom: -6px;
    right: -6px;
    background: #eab308;
    color: #000;
    font-size: 11px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.6);
    z-index: 10;
}

/* ---- 相手の思考中インジケータ ---- */
.thinking-dots::after {
    content: '';
    animation: thinking 1.5s infinite;
}
@keyframes thinking {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

/* ---- モバイル: コア操作ボタン ---- */
@media (hover: none) {
    .core-buttons {
        opacity: 1;
    }
    .core-buttons button {
        min-width: 32px;
        height: 32px;
        font-size: 14px;
        padding: 0 8px;
    }
}

/* ---- レスポンシブ: タブレット ---- */
@media (max-width: 768px) {
    #status-bar {
        padding: 8px 12px;
        gap: 8px;
        font-size: 12px;
        flex-wrap: wrap;
    }
    #phase-bar {
        gap: 2px;
        margin-left: 0;
    }
    .phase-step {
        padding: 3px 6px;
        font-size: 10px;
    }
    .field-row {
        flex-direction: column;
        gap: 8px;
        min-height: auto;
    }
    .nexus-zone {
        min-width: auto;
        min-height: auto;
        flex-direction: row;
    }
    .spirit-zone {
        min-height: auto;
    }
    .spirit-zone .card {
        width: 64px;
        height: 64px;
    }
    .spirit-zone .card .name {
        font-size: 8px;
        max-width: 54px;
    }
    .nexus-zone .card {
        width: 58px;
        height: 64px;
    }
    .burst-slot {
        width: 38px;
        height: 48px;
        font-size: 8px;
    }
    .player-area {
        padding: 8px 12px;
        gap: 8px;
    }
    .player-info {
        font-size: 11px;
        gap: 8px;
        flex-wrap: wrap;
    }
    #hand {
        gap: 4px;
    }
    #hand .card {
        width: 80px;
        height: 112px;
        font-size: 10px;
    }
    #hand .card .name {
        font-size: 10px;
    }

    #action-buttons-container {
        position: fixed;
        bottom: 8px;
        right: 8px;
        top: auto;
        transform: none;
    }
    #action-buttons {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
    }
    #action-buttons button {
        padding: 8px 14px;
        font-size: 13px;
    }
    #log-panel, #trash-panel, #tegamoto-panel {
        width: 260px;
        height: 300px;
        right: 8px;
        bottom: 60px;
    }
    #trash-panel, #tegamoto-panel {
        right: 280px;
    }
    #targeting-info {
        font-size: 14px;
    }
}

/* ---- レスポンシブ: スマホ ---- */
@media (max-width: 480px) {
    /* アクティブでないステップのみ1文字表記に切り替え */
    .phase-step:not(.active) {
        font-size: 0;
        padding: 3px 5px;
    }
    .phase-step:not(.active)::before {
        content: attr(data-short);
        font-size: 10px;
    }
    .spirit-zone .card {
        width: 64px;
        height: 64px;
    }
    .spirit-zone .card .name {
        font-size: 8px;
        max-width: 56px;
    }
    .spirit-zone .card .stats,
    .spirit-zone .card .cores,
    .nexus-zone .card .stats,
    .nexus-zone .card .cores {
        font-size: 10px;
    }
    .nexus-zone .card {
        width: 60px;
        height: 60px;
    }
    .nexus-zone .card .name {
        font-size: 8px;
    }
    .burst-slot {
        width: 32px;
        height: 42px;
        font-size: 7px;
    }
    .burst-mine .name {
        max-width: 26px;
        font-size: 7px;
    }
    #hand .card {
        width: 68px;
        height: 95px;
        font-size: 9px;
        padding: 4px;
    }

    .cost-badge {
        width: 22px;
        height: 22px;
        font-size: 12px;
    }
    .player-info {
        font-size: 10px;
    }
    #log-panel, #trash-panel, #tegamoto-panel {
        width: calc(100vw - 16px);
        right: 8px;
        left: 8px;
        height: 250px;
    }
    #trash-panel, #tegamoto-panel {
        right: 8px;
    }
    #action-buttons-container {
        left: 8px;
        right: 8px;
    }
    #action-buttons {
        justify-content: center;
    }
    #action-buttons button {
        padding: 8px 10px;
        font-size: 12px;
    }
    .awaken-badge, .activate-badge, .pay-badge {
        min-width: 36px;
        font-size: 10px;
        padding: 3px 6px;
    }
    #targeting-info {
        font-size: 12px;
    }
}

/* ---- アクセシビリティ: モーション低減設定を尊重 ---- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---- 召喚レベル選択：リザーブだけでは足りず、フィールドのコアを使うレベル ---- */
#choice-options button.needs-field-cores {
    border-color: #c9a227;
    background: rgba(201, 162, 39, 0.15);
}
#choice-options button.needs-field-cores::before {
    content: "💠 ";
}

/* ---- 増減式の選択（PendingChoice.stepper） ----
   トラッシュに置くコアの数のように「どれを選ぶか」でなく個数だけを決めるものを、
   ボタンの列ではなく −／＋ で選ばせる。候補が20個を超えることがあるため */
#choice-options .stepper-value {
    display: inline-block;
    min-width: 4.5em;
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

/* ---- ネクサスのコア移動ボタン ----
   ネクサスは clip-path で六角形に切り抜くため、カード要素の子に置いたボタンは
   まるごとクリップされて消える。ラッパー（.nexus-slot）の直下にカードと兄弟で置き、
   六角形の外側へはみ出させる。小さな六角形の上でホバーを狙わせるのは押しづらいので常時表示する */
.nexus-slot {
    position: relative;
    display: inline-flex;
    /* ボタンが右へはみ出すぶんの余白。隣のネクサスに重ねてクリックを奪わないようにする */
    margin-right: 22px;
}
.nexus-slot .core-buttons {
    opacity: 0;
    top: 0;
    right: -26px;
    flex-direction: column;
    gap: 4px;
    z-index: 10;
}
.nexus-slot:hover .core-buttons {
    opacity: 1;
}
.nexus-slot .core-buttons button {
    min-width: 26px;
    height: 26px;
    font-size: 13px;
    padding: 0 6px;
    background: var(--bg-panel);
    border: 1px solid #666;
    box-shadow: 0 2px 8px rgba(0,0,0,0.6);
}
.log-card-name {
    color: #66b3ff;
    text-decoration: underline;
    text-decoration-style: dotted;
    cursor: help;
}

/* ---- お知らせパネル ---- */
.lobby-announcements {
    margin-top: 32px;
    background: rgba(30, 33, 40, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 20px;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
    text-align: left;
    backdrop-filter: blur(8px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}

.announcement-header {
    font-size: 16px;
    font-weight: 700;
    color: #e5e7eb;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 12px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.announcement-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: 300px;
    overflow-y: auto;
}

.announcement-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
    transition: all 0.2s;
}

.announcement-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
    transform: translateX(4px);
}

.announcement-date-header {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    margin-bottom: 4px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.announcement-meta {
    display: flex;
    align-items: center;
    gap: 12px;
}

.announcement-meta .date {
    font-size: 12px;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.announcement-meta .badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    color: #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.badge.update {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
}

.badge.new {
    background: linear-gradient(135deg, #10b981, #059669);
}

.badge.fix {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

.badge.info {
    background: linear-gradient(135deg, #8b5cf6, #6d28d9);
}

.announcement-entry {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 2px 0;
    line-height: 1.4;
}

.announcement-entry .badge {
    flex-shrink: 0;
}

.announcement-text {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
    color: #d1d5db;
}

.announcement-loading {
    text-align: center;
    padding: 16px;
    color: var(--text-muted);
    font-size: 13px;
}
