/* ==========================================================================
   Rift Dice (裂隙神骰) — Obsidian Cyber-Prism Styling
   ========================================================================== */
:root {
    --bg: #070b18;
    --bg-card: #0e1529;
    --bg-slot: #131d38;
    --border: rgba(148, 163, 184, 0.22);
    --text: #f1f5f9;
    --muted: #94a3b8;
    --cyan: #38bdf8;
    --purple: #c084fc;
    --gold: #facc15;
    --red: #f43f5e;
    --green: #34d399;
    --orange: #fb923c;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    background: radial-gradient(circle at 18% 0%, #111d3f 0%, #070b18 55%, #050812 100%);
    color: var(--text);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
    user-select: none;
}

.hidden { display: none !important; }

.app-shell {
    max-width: 1120px;
    margin: 0 auto;
    padding: 10px 14px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Header */
.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(14, 21, 41, 0.88);
    border: 1px solid var(--border);
    border-radius: 14px;
    backdrop-filter: blur(10px);
}

.top-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--muted);
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    padding: 5px 9px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: 0.15s;
}
.back-link:hover { color: #fff; border-color: var(--cyan); }

.brand-title {
    display: flex;
    align-items: center;
    gap: 7px;
}
.mini-logo { width: 24px; height: 24px; }
.brand-name {
    font-weight: 900;
    font-size: 15px;
    letter-spacing: 0.08em;
    background: linear-gradient(90deg, #38bdf8, #c084fc, #f43f5e);
    -webkit-background-clip: text;
    color: transparent;
}

.run-pills {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.hud-pill {
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--border);
    color: #e2e8f0;
}
.shard-pill b { color: var(--gold); }
.hp-pill b { color: var(--green); }
.shield-pill b { color: var(--cyan); }

.top-actions {
    display: flex;
    align-items: center;
    gap: 5px;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 5px 9px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: 0.15s;
}
.icon-btn:hover { border-color: var(--cyan); background: rgba(56, 189, 248, 0.14); }

/* Arena */
.arena-panel {
    position: relative;
    background: #081022;
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

#battle-canvas {
    display: block;
    width: 100%;
    cursor: pointer;
}

.arena-overlay-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    padding: 7px 12px;
    background: rgba(7, 11, 24, 0.92);
    border-top: 1px solid rgba(148, 163, 184, 0.16);
}

.relic-strip {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.relic-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    background: rgba(250, 204, 21, 0.12);
    border: 1px solid rgba(250, 204, 21, 0.38);
    color: #fef08a;
    cursor: help;
    transition: transform 0.15s;
}
.relic-chip:hover { transform: translateY(-1px); background: rgba(250, 204, 21, 0.22); }

.preview-strip {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-left: auto;
}

.prev-item {
    font-size: 11px;
    font-weight: 700;
    padding: 3px 9px;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--border);
    color: var(--muted);
}
.prev-item b { font-size: 13px; margin-left: 3px; }
.prev-item.dmg b { color: #fb7185; }
.prev-item.shd b { color: #38bdf8; }
.prev-item.mult b { color: #facc15; }

.prev-combos {
    display: flex;
    gap: 5px;
}

.combo-tag {
    font-size: 11px;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 999px;
    animation: popIn 0.2s ease;
}
.combo-tag.triple { background: rgba(250, 204, 21, 0.22); border: 1px solid #facc15; color: #fef08a; }
.combo-tag.straight { background: rgba(34, 211, 238, 0.2); border: 1px solid #22d3ee; color: #a5f3fc; }

/* Tactical Deck */
.tactical-deck {
    display: grid;
    grid-template-columns: 1.2fr 0.95fr;
    gap: 12px;
    margin-top: 10px;
    align-items: start;
}

.matrix-panel, .dice-panel {
    background: rgba(14, 21, 41, 0.88);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 12px;
    backdrop-filter: blur(8px);
}

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}
.panel-title {
    margin: 0;
    font-size: 13px;
    font-weight: 900;
    letter-spacing: 0.08em;
    color: #e2e8f0;
}
.panel-hint {
    margin: 2px 0 0;
    font-size: 11px;
    color: var(--muted);
}

.small-btn {
    background: rgba(192, 132, 252, 0.14);
    color: #e9d5ff;
    border: 1px solid rgba(192, 132, 252, 0.45);
    border-radius: 8px;
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
    white-space: nowrap;
    transition: 0.15s;
}
.small-btn.active {
    background: #9333ea;
    color: #fff;
    border-color: #e9d5ff;
    box-shadow: 0 0 14px rgba(192, 132, 252, 0.5);
}

/* 3x3 Matrix Grid */
.matrix-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.matrix-cell {
    position: relative;
    min-height: 106px;
    background: linear-gradient(160deg, rgba(22, 33, 62, 0.92), rgba(12, 18, 36, 0.96));
    border: 1.5px solid rgba(148, 163, 184, 0.25);
    border-radius: 12px;
    padding: 7px 8px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    transition: transform 0.14s, border-color 0.15s, box-shadow 0.15s;
}

.matrix-cell:hover {
    border-color: rgba(56, 189, 248, 0.65);
    transform: translateY(-1px);
}

.matrix-cell.tier-2 { border-color: rgba(56, 189, 248, 0.55); box-shadow: inset 0 0 14px rgba(56, 189, 248, 0.1); }
.matrix-cell.tier-3 { border-color: rgba(250, 204, 21, 0.78); box-shadow: inset 0 0 18px rgba(250, 204, 21, 0.16); }

.matrix-cell.eligible {
    border-color: #38bdf8;
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.35), inset 0 0 12px rgba(56, 189, 248, 0.15);
    animation: pulseGlow 1.1s infinite alternate;
}

.matrix-cell.ineligible {
    opacity: 0.45;
}

.matrix-cell.combo-triple {
    box-shadow: 0 0 16px rgba(250, 204, 21, 0.45), inset 0 0 10px rgba(250, 204, 21, 0.18);
    border-color: #facc15;
}

.matrix-cell.combo-straight {
    box-shadow: 0 0 14px rgba(34, 211, 238, 0.42), inset 0 0 10px rgba(34, 211, 238, 0.14);
    border-color: #22d3ee;
}

.matrix-cell.firing {
    transform: scale(1.05);
    border-color: #ffffff;
    box-shadow: 0 0 24px rgba(255, 255, 255, 0.75), 0 0 36px rgba(56, 189, 248, 0.65);
    z-index: 3;
}

.matrix-cell.swap-src {
    border-color: #e879f9;
    box-shadow: 0 0 18px rgba(232, 121, 249, 0.6);
}

.matrix-cell.jammed {
    background: repeating-linear-gradient(45deg, rgba(100, 116, 139, 0.2), rgba(100, 116, 139, 0.2) 8px, rgba(15, 23, 42, 0.8) 8px, rgba(15, 23, 42, 0.8) 16px);
    border-color: #ef4444;
    cursor: not-allowed;
}

.cell-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}

.cell-mod-name {
    font-size: 11px;
    font-weight: 800;
    color: #f8fafc;
    display: flex;
    align-items: center;
    gap: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tier-pip {
    font-size: 9px;
    font-weight: 900;
    padding: 1px 5px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.08);
    color: #cbd5e1;
}
.tier-2 .tier-pip { background: rgba(56, 189, 248, 0.22); color: #7dd3fc; }
.tier-3 .tier-pip { background: rgba(250, 204, 21, 0.25); color: #fef08a; }

.cell-mid {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 4px 0;
    min-height: 44px;
}

.cond-badge {
    font-size: 10px;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 6px;
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid rgba(148, 163, 184, 0.3);
    color: #cbd5e1;
}
.cond-badge.strict { border-color: rgba(250, 204, 21, 0.5); color: #fde047; }

.synergy-dir {
    font-size: 11px;
    color: #c084fc;
    font-weight: 800;
}

.cell-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 10px;
    color: var(--muted);
}
.cell-output {
    font-weight: 800;
    color: #7dd3fc;
}

/* Slotted mini die inside matrix cell */
.slotted-die {
    width: 40px;
    height: 40px;
    border-radius: 9px;
    background: linear-gradient(145deg, #1e293b, #0f172a);
    border: 2px solid #38bdf8;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 17px;
    color: #fff;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.45);
    position: relative;
}
.slotted-die.spectral { border-color: #c084fc; background: linear-gradient(145deg, #2e1065, #1e1b4b); }
.slotted-die .mini-mod {
    position: absolute;
    top: -6px;
    right: -6px;
    font-size: 11px;
    background: #0f172a;
    border-radius: 50%;
    padding: 1px 3px;
    border: 1px solid rgba(255,255,255,0.25);
}

/* Dice Tray */
.reroll-badge {
    font-size: 12px;
    font-weight: 800;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(56, 189, 248, 0.14);
    border: 1px solid rgba(56, 189, 248, 0.4);
    color: #7dd3fc;
}

.dice-tray {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    min-height: 82px;
    padding: 10px;
    background: rgba(7, 11, 24, 0.65);
    border: 1px dashed rgba(148, 163, 184, 0.25);
    border-radius: 12px;
    align-items: center;
    justify-content: center;
}

.die-card {
    position: relative;
    width: 62px;
    height: 66px;
    border-radius: 12px;
    background: linear-gradient(155deg, #243356, #111932);
    border: 2px solid rgba(148, 163, 184, 0.45);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.16);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.14s, border-color 0.14s, box-shadow 0.14s;
}
.die-card:hover { transform: translateY(-3px); border-color: var(--cyan); }
.die-card.selected {
    border-color: #facc15;
    box-shadow: 0 0 18px rgba(250, 204, 21, 0.55);
    transform: translateY(-4px) scale(1.04);
}
.die-card.locked {
    border-color: #38bdf8;
    background: linear-gradient(155deg, #0c4a6e, #082f49);
}
.die-card.spectral {
    border-color: #c084fc;
    background: linear-gradient(155deg, #3b0764, #1e1b4b);
}
.die-card.rolling {
    animation: diceRollSpin 0.28s ease;
}

.die-val {
    font-size: 24px;
    font-weight: 900;
    line-height: 1;
    color: #f8fafc;
}
.die-mod-tag {
    font-size: 9px;
    font-weight: 800;
    margin-top: 3px;
    padding: 1px 5px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.45);
}

.die-lock-btn {
    position: absolute;
    top: -7px;
    right: -7px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1px solid rgba(148, 163, 184, 0.4);
    background: #0f172a;
    color: #94a3b8;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.die-card.locked .die-lock-btn {
    background: #0284c7;
    color: #fff;
    border-color: #7dd3fc;
}

.die-inspector {
    margin-top: 8px;
    min-height: 26px;
    font-size: 11px;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}
.face-chip {
    padding: 2px 6px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-weight: 700;
}
.face-chip.current { border-color: var(--gold); color: var(--gold); }

/* Action Bar */
.action-bar {
    display: grid;
    grid-template-columns: 1.1fr 0.75fr 0.75fr 1.35fr;
    gap: 8px;
    margin-top: 10px;
}

.act-btn {
    border: none;
    border-radius: 11px;
    padding: 11px 8px;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.03em;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: transform 0.12s, filter 0.15s, opacity 0.15s;
}
.act-btn:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.1); }
.act-btn:disabled { opacity: 0.38; cursor: not-allowed; }

.act-btn.reroll { background: linear-gradient(135deg, #0284c7, #2563eb); }
.act-btn.secondary { background: rgba(148, 163, 184, 0.15); border: 1px solid var(--border); color: #e2e8f0; }
.act-btn.execute {
    background: linear-gradient(135deg, #f43f5e, #a855f7, #06b6d4);
    box-shadow: 0 6px 20px rgba(244, 63, 94, 0.35);
    font-size: 13px;
}

.btn-badge {
    background: rgba(0, 0, 0, 0.32);
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 11px;
}

/* Overlays & Modals */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(3, 6, 16, 0.82);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 40;
}

.modal-card {
    width: 100%;
    max-width: 720px;
    max-height: 90vh;
    overflow-y: auto;
    background: #0e162e;
    border: 1px solid rgba(56, 189, 248, 0.35);
    border-radius: 18px;
    padding: 20px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65);
}
.modal-card.wide { max-width: 860px; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 6px;
}
.modal-title {
    margin: 0;
    font-size: 19px;
    font-weight: 900;
    background: linear-gradient(90deg, #f8fafc, #38bdf8);
    -webkit-background-clip: text;
    color: transparent;
}
.modal-sub {
    margin: 0 0 16px;
    font-size: 13px;
    color: var(--muted);
}

.cards-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
    gap: 12px;
}

.choice-card {
    background: rgba(19, 29, 56, 0.9);
    border: 1.5px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 10px;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.choice-card:hover:not(.disabled) {
    transform: translateY(-3px);
    border-color: var(--cyan);
    box-shadow: 0 8px 24px rgba(56, 189, 248, 0.22);
}
.choice-card.disabled { opacity: 0.42; cursor: not-allowed; }
.choice-card.active-frame { border-color: var(--gold); box-shadow: 0 0 18px rgba(250, 204, 21, 0.28); }

.choice-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.choice-icon { font-size: 24px; }
.choice-tag {
    font-size: 10px;
    font-weight: 800;
    padding: 2px 7px;
    border-radius: 999px;
    background: rgba(56, 189, 248, 0.18);
    color: #7dd3fc;
}
.choice-name { font-size: 15px; font-weight: 800; color: #f8fafc; }
.choice-desc { font-size: 12px; color: #cbd5e1; line-height: 1.45; }
.choice-cost {
    font-size: 12px;
    font-weight: 900;
    color: var(--gold);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.primary-btn {
    background: linear-gradient(135deg, #0284c7, #7c3aed);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}
.ghost-btn {
    background: rgba(255, 255, 255, 0.06);
    color: #e2e8f0;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.guide-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-top: 10px;
}
.guide-card {
    background: rgba(19, 29, 56, 0.75);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
}
.guide-card h4 { margin: 0 0 6px; color: var(--cyan); font-size: 14px; }
.guide-card p { margin: 0; font-size: 12px; color: #cbd5e1; line-height: 1.5; }

/* Tooltip */
.tooltip-box {
    position: fixed;
    max-width: 260px;
    background: rgba(7, 11, 24, 0.96);
    border: 1px solid rgba(56, 189, 248, 0.55);
    border-radius: 10px;
    padding: 8px 11px;
    font-size: 12px;
    color: #e2e8f0;
    pointer-events: none;
    z-index: 90;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.6);
}
.tooltip-box b { display: block; color: #f8fafc; margin-bottom: 3px; }

/* Animations */
@keyframes pulseGlow {
    from { box-shadow: 0 0 8px rgba(56, 189, 248, 0.25); }
    to { box-shadow: 0 0 18px rgba(56, 189, 248, 0.55); }
}
@keyframes popIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
@keyframes diceRollSpin {
    0% { transform: rotate(-12deg) scale(0.85); }
    50% { transform: rotate(10deg) scale(1.1); }
    100% { transform: rotate(0deg) scale(1); }
}

/* Mobile Responsive */
@media (max-width: 820px) {
    .tactical-deck { grid-template-columns: 1fr; }
    .action-bar { grid-template-columns: 1fr 1fr; }
    .act-btn.execute { grid-column: span 2; }
    .matrix-cell { min-height: 92px; }
}
@media (max-width: 520px) {
    .app-shell { padding: 8px; }
    .brand-name { font-size: 13px; }
    .run-pills { width: 100%; justify-content: center; }
    .die-card { width: 54px; height: 58px; }
    .die-val { font-size: 20px; }
}
